:root {
    --bn-red: #d71920;
    --bn-yellow: #f5b400;
    --ink: #172033;
    --muted: #667085;
    --line: #d8dde8;
    --surface: #ffffff;
    --bg: #f4f6fa;
    --sidebar: #101828;
    --success: #0f8a5f;
    --warning: #b7791f;
    --danger: #c53030;
    --info: #2563eb;
}

* { box-sizing: border-box; }
body.admin-body,
body.login-body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
}

a { color: inherit; }
button, input, select, textarea { font: inherit; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    min-height: 42px;
    padding: 0.65rem 0.75rem;
    background: #fff;
}
textarea { min-height: 96px; resize: vertical; }
label { display: block; margin-bottom: 0.4rem; font-weight: 700; font-size: 0.86rem; }

.app-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.admin-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 1.2rem;
    background: var(--sidebar);
    color: #fff;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
}
.brand-block { display: grid; gap: 0.35rem; justify-items: center; text-align: center; padding-bottom: 1rem; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-block img { width: 132px; max-height: 92px; object-fit: contain; }
.brand-block span, .sidebar-user span, .eyebrow { color: #98a2b3; font-size: 0.82rem; }
.institution-mark {
    width: 72px;
    height: 72px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: linear-gradient(145deg, var(--bn-red), #8f1d1d);
    color: #fff;
    font-size: 2rem;
    box-shadow: inset 0 -10px 0 rgba(0,0,0,.12);
}
.institution-mark-lg { width: 92px; height: 92px; font-size: 2.4rem; }
.admin-nav { display: grid; gap: 0.25rem; }
.admin-nav a, .logout-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 44px;
    padding: 0.72rem 0.85rem;
    border-radius: 8px;
    text-decoration: none;
    color: rgba(255,255,255,.88);
}
.admin-nav a:hover, .admin-nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.admin-nav i, .logout-link i { width: 20px; text-align: center; }
.admin-nav b {
    margin-left: auto;
    background: var(--bn-red);
    min-width: 24px;
    min-height: 24px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    font-size: 0.78rem;
}
.nav-divider {
    margin: 0.8rem 0 0.35rem;
    padding: 0 0.2rem;
    color: rgba(255,255,255,.52);
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.sidebar-user { margin-top: auto; display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem; border: 1px solid rgba(255,255,255,.12); border-radius: 8px; }
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--bn-red);
    color: #fff;
    font-weight: 800;
}
.avatar-img { object-fit: cover; display: block; }
.profile-thumb {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--line);
    background: #fff;
}
.profile-cell { display: flex; align-items: center; gap: 0.65rem; min-width: 220px; }
.file-note { color: var(--muted); font-size: 0.78rem; margin-top: 0.25rem; display: block; }
.logout-link { background: rgba(255,255,255,.08); }
.admin-main { min-width: 0; padding: 1.5rem; }
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.page-header h1 { margin: 0.15rem 0 0; font-size: 1.75rem; letter-spacing: 0; }
.header-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }
.header-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 36px;
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    text-decoration: none;
    color: var(--muted);
    font-weight: 800;
    font-size: 0.82rem;
}
.header-chip:hover { color: var(--ink); border-color: #b7c0d1; }
.mobile-menu {
    display: none;
    position: fixed;
    z-index: 50;
    top: 0.85rem;
    left: 0.85rem;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 8px;
    background: var(--bn-red);
    color: #fff;
}

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 6px 18px rgba(16,24,40,.05);
}
.panel-band {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 1rem;
    background: linear-gradient(180deg, #fff, #f8fafc);
}
.suite-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 1rem; align-items: start; }
.metric-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; }
.metric-tile { border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 0.9rem; min-height: 96px; display: grid; align-content: center; gap: 0.25rem; }
.metric-tile strong { font-size: 1.75rem; line-height: 1; }
.metric-tile span { color: var(--muted); font-size: 0.86rem; }
.office-list { display: grid; gap: 0.75rem; }
.office-row {
    display: grid;
    grid-template-columns: minmax(190px, 1fr) minmax(120px, .45fr) minmax(130px, .45fr) auto;
    gap: 0.75rem;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 0.85rem;
}
.office-row h3 { margin: 0 0 .25rem; font-size: 1rem; }
.office-row p { margin: 0; color: var(--muted); font-size: .86rem; }
.config-matrix { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.security-list { display: grid; gap: 0.65rem; margin: 0; padding: 0; list-style: none; }
.security-list li { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.7rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.security-list i { color: var(--success); margin-top: 0.1rem; }
.stat-card strong { display: block; font-size: 2rem; line-height: 1; margin-bottom: 0.35rem; }
.stat-card span { color: var(--muted); font-size: 0.9rem; }
.toolbar { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .grow { flex: 1; min-width: 220px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 42px;
    border: 0;
    border-radius: 8px;
    padding: 0.65rem 0.95rem;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    background: #edf0f7;
    color: var(--ink);
}
.btn-primary { background: var(--bn-red); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-sm { min-height: 34px; padding: 0.42rem 0.65rem; font-size: 0.84rem; }

.alert { border-radius: 8px; padding: 0.85rem 1rem; margin-bottom: 1rem; border-left: 4px solid; background: #fff; }
.alert-success { border-color: var(--success); color: #075f42; }
.alert-error { border-color: var(--danger); color: #9b1c1c; }

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 26px;
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    font-weight: 800;
    font-size: 0.78rem;
    background: #edf0f7;
    color: var(--ink);
}
.badge.rascunho, .badge.entrada, .badge.novo { background: #eef2f7; color: #344054; }
.badge.enviado, .badge.em_atendimento, .badge.respondendo { background: #dbeafe; color: #1d4ed8; }
.badge.devolvido { background: #fff4d6; color: #9a6700; }
.badge.aguardando { background: #fff4d6; color: #9a6700; }
.badge.aprovado, .badge.resolvida, .badge.respondido { background: #d1fadf; color: #067647; }
.badge.concluido { background: #d1fadf; color: #067647; }
.badge.arquivada, .badge.encaminhada { background: #eceff3; color: #475467; }
.badge.andamento { background: #dbeafe; color: #1d4ed8; }
.badge.risco, .badge.critica { background: #fee2e2; color: #991b1b; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.table { width: 100%; border-collapse: collapse; min-width: 760px; }
.table th, .table td { padding: 0.8rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { background: #f8fafc; font-size: 0.82rem; color: #475467; }

.kanban-board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 1rem; overflow-x: auto; padding-bottom: 0.5rem; }
.kanban-board.crm-board { grid-template-columns: repeat(5, minmax(220px, 1fr)); }
.kanban-column { min-width: 240px; background: #eef2f7; border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem; }
.kanban-column header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; font-weight: 900; }
.kanban-list { min-height: 120px; display: grid; gap: 0.75rem; align-content: start; }
.kanban-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 0.85rem; box-shadow: 0 6px 14px rgba(16,24,40,.06); cursor: grab; }
.kanban-card:active { cursor: grabbing; }
.kanban-card h3 { margin: 0 0 0.45rem; font-size: 0.98rem; }
.kanban-card p { margin: 0.25rem 0; color: var(--muted); font-size: 0.86rem; }
.kanban-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.75rem; }
.kanban-column.drag-over { outline: 3px solid rgba(215,25,32,.24); }

.report-print { background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.report-print section { padding: 1.25rem; border-bottom: 1px solid var(--line); }
.report-title { text-align: center; border-bottom: 3px solid var(--bn-red); background: #f8fafc; }
.activity-card { border: 1px solid var(--line); border-radius: 8px; padding: 1rem; background: #fff; }
.activity-card + .activity-card { margin-top: 0.75rem; }
.muted { color: var(--muted); }
.empty-state { min-height: 220px; display: grid; place-items: center; align-content: center; gap: 0.5rem; color: var(--muted); text-align: center; }
.empty-state i { font-size: 2.4rem; color: #98a2b3; }

.chat-panel { background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; min-height: calc(100vh - 170px); display: grid; grid-template-rows: 1fr auto; }
.chat-messages { max-height: calc(100vh - 260px); overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; background: #f8fafc; }
.chat-message { max-width: min(720px, 82%); display: grid; gap: 0.25rem; }
.chat-message.own { align-self: flex-end; }
.chat-message.other { align-self: flex-start; }
.chat-meta { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.8rem; }
.chat-message.own .chat-meta { justify-content: flex-end; }
.chat-reply { width: 28px; height: 28px; border: 0; border-radius: 50%; background: #edf0f7; color: var(--ink); cursor: pointer; }
.chat-bubble { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 0.75rem 0.9rem; box-shadow: 0 4px 12px rgba(16,24,40,.05); }
.chat-message.own .chat-bubble { background: #e9f7ef; border-color: #bbebd0; }
.chat-citation { border-left: 3px solid var(--bn-red); background: rgba(16,24,40,.05); padding: 0.45rem 0.55rem; margin-bottom: 0.5rem; display: grid; gap: 0.15rem; font-size: 0.84rem; }
.chat-form { border-top: 1px solid var(--line); padding: 1rem; background: #fff; }
.chat-input-row { display: flex; gap: 0.75rem; align-items: center; }
.chat-input-row input { flex: 1; }
.reply-preview { border-left: 4px solid var(--bn-red); background: #f8fafc; border-radius: 8px; padding: 0.65rem 2.5rem 0.65rem 0.75rem; margin-bottom: 0.75rem; position: relative; display: grid; gap: 0.15rem; }
.reply-preview button { position: absolute; top: 0.45rem; right: 0.45rem; border: 0; background: transparent; cursor: pointer; color: var(--muted); }

.agenda-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; margin-top: 1rem; }
.calendar-card { padding: 0; overflow: hidden; }
.calendar-weekdays, .calendar-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.calendar-weekdays span { padding: 0.75rem; text-align: center; font-weight: 800; color: var(--muted); background: #f8fafc; border-bottom: 1px solid var(--line); }
.calendar-day { min-height: 112px; padding: 0.55rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: grid; align-content: start; gap: 0.35rem; }
.calendar-day:nth-child(7n) { border-right: 0; }
.calendar-day.empty { background: #f8fafc; }
.calendar-day.today { background: #fff8e6; }
.calendar-event { color: #fff; border-radius: 6px; padding: 0.2rem 0.35rem; font-size: 0.76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agenda-side { display: grid; gap: 1rem; }
.agenda-side h2 { margin: 0 0 0.75rem; font-size: 1.05rem; }
.agenda-item { border-left: 4px solid var(--bn-red); background: #f8fafc; border-radius: 0 8px 8px 0; padding: 0.75rem; display: grid; gap: 0.25rem; margin-bottom: 0.65rem; }
.agenda-item span, .agenda-item small { color: var(--muted); }
.crm-detail { margin-bottom: 1rem; }
.crm-detail .grid { margin-top: 0.75rem; }
.crm-detail .grid > div { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem; min-width: 0; word-break: break-word; }
.crm-message-full { margin-top: 1rem; border: 1px solid var(--line); border-radius: 8px; padding: 1rem; background: #fff; }
.crm-message-full p { margin: 0.5rem 0 0; line-height: 1.55; white-space: pre-wrap; }

.login-body {
    display: grid;
    place-items: center;
    padding: clamp(1rem, 4vw, 3rem);
    background: #eef2f7;
    position: relative;
    overflow-x: hidden;
}
.login-body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(135deg, rgba(215,25,32,.10), rgba(37,99,235,.07) 52%, rgba(245,180,0,.12)),
        radial-gradient(circle at 18% 18%, rgba(15,138,95,.12), transparent 28%),
        radial-gradient(circle at 82% 78%, rgba(215,25,32,.10), transparent 30%);
}
.login-card {
    position: relative;
    z-index: 1;
    width: min(1120px, 100%);
    display: grid;
    grid-template-columns: minmax(320px, .86fr) minmax(360px, 1fr);
    overflow: hidden;
    background: #fff;
    border: 1px solid #e4e8f0;
    border-radius: 8px;
    box-shadow: 0 28px 70px rgba(16,24,40,.18);
}
.login-aside {
    padding: clamp(1.5rem, 3vw, 2.5rem);
    background: linear-gradient(180deg, #fff 0%, #fff 42%, #f8fafc 100%);
    color: var(--ink);
    display: grid;
    align-content: center;
    gap: 1.25rem;
    border-right: 1px solid var(--line);
}
.login-logo-panel {
    min-height: 244px;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 18px 38px rgba(16,24,40,.10);
}
.login-logo-panel img {
    width: 150px;
    height: 150px;
    object-fit: contain;
    image-rendering: auto;
}
.login-copy { display: grid; gap: 0.7rem; }
.login-copy .eyebrow { color: #0b5cab; font-weight: 900; }
.login-copy h1 { margin: 0; font-size: clamp(2rem, 4vw, 3rem); line-height: 1.08; }
.login-copy p { margin: 0; color: #344054; line-height: 1.55; max-width: 34rem; }
.login-panel {
    padding: clamp(1.5rem, 4vw, 3rem);
    display: grid;
    align-content: center;
}
.login-panel h2 { margin: 1.25rem 0 1rem; font-size: 1.85rem; line-height: 1.15; }
.login-panel form { gap: 1.05rem; }
.login-panel .btn-primary { width: 100%; min-height: 54px; font-size: 1rem; }
.portal-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.65rem; margin: 0 0 1rem; }
.portal-tabs a {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    text-align: center;
    text-decoration: none;
    padding: 0.8rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font-weight: 900;
}
.portal-tabs a.active { background: var(--bn-red); border-color: var(--bn-red); color: #fff; }

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .suite-grid { grid-template-columns: 1fr; }
    .config-matrix { grid-template-columns: 1fr; }
    .kanban-board { grid-template-columns: repeat(4, 280px); }
    .kanban-board.crm-board { grid-template-columns: repeat(5, 260px); }
}

@media (max-width: 900px) {
    .mobile-menu { display: grid; place-items: center; }
    .app-shell { display: block; }
    .admin-sidebar {
        position: fixed;
        z-index: 40;
        left: 0;
        top: 0;
        transform: translateX(-105%);
        width: min(86vw, 300px);
        transition: transform .2s ease;
    }
    .admin-sidebar.open { transform: translateX(0); }
    .admin-main { padding: 4.75rem 0.85rem 1rem; }
    .page-header { align-items: flex-start; }
    .header-actions { width: 100%; justify-content: stretch; }
    .header-chip { flex: 1; min-width: 130px; }
    .page-header h1 { font-size: 1.35rem; }
    .grid-2, .grid-3, .grid-4, .metric-strip { grid-template-columns: 1fr; }
    .office-row { grid-template-columns: 1fr; }
    .toolbar { align-items: stretch; }
    .toolbar > * { width: 100%; }
    .chat-message { max-width: 95%; }
    .chat-input-row { flex-direction: column; align-items: stretch; }
    .agenda-layout { grid-template-columns: 1fr; }
    .calendar-day { min-height: 86px; }
    .login-card { grid-template-columns: 1fr; }
    .login-aside { padding: 1.5rem; }
    .login-panel { padding: 1.25rem; }
    .portal-tabs { grid-template-columns: 1fr; }
}

@media print {
    .admin-sidebar, .mobile-menu, .page-header .btn, .toolbar, .kanban-actions { display: none !important; }
    .app-shell { display: block; }
    .admin-main { padding: 0; }
    body.admin-body { background: #fff; }
    .report-print { border: 0; }
}
