/* =====================================================================
   Sistema PSE — Design System
   ===================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    /* Marca */
    --primary: #4f46e5;
    --primary-600: #4338ca;
    --primary-50: #eef2ff;
    --primary-100: #e0e7ff;
    --accent: #0ea5e9;
    --gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #0ea5e9 100%);

    /* Neutros */
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e7e9f0;
    --border-strong: #d6dae3;
    --text: #0f172a;
    --text-2: #475569;
    --text-3: #94a3b8;

    /* Status */
    --success: #16a34a;
    --success-50: #ecfdf3;
    --warning: #d97706;
    --warning-50: #fffbeb;
    --danger: #dc2626;
    --danger-50: #fef2f2;
    --info: #2563eb;
    --info-50: #eff6ff;

    /* Forma */
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow: 0 4px 16px -4px rgba(15, 23, 42, .08), 0 2px 6px -2px rgba(15, 23, 42, .05);
    --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, .25);
    --ring: 0 0 0 4px rgba(79, 70, 229, .15);

    --sidebar-w: 264px;
    --topbar-h: 68px;
    --ease: cubic-bezier(.2, .8, .2, 1);

    /* Tokens auxiliares (redefinidos no tema escuro) */
    --topbar-bg: rgba(245, 246, 250, .82);
    --topbar-bg-scrolled: rgba(255, 255, 255, .86);
    --border-hover: #c4c9d4;
    --row-hover: #fafbff;
    --neutral-bg: #f1f5f9;
    --track: #eef0f5;
    --segment-bg: #eceef4;
    --grid-line: #f1f3f8;
    --toast-bg: #0f172a;
    --violet-50: #f5f3ff;
    --sky-50: #f0f9ff;
    --pink-50: #fdf2f8;
    --success-text: #166534;  --success-border: #bbf7d0;
    --danger-text: #991b1b;   --danger-border: #fecaca;
    --warning-text: #92400e;  --warning-border: #fde68a;
    --info-text: #1e40af;     --info-border: #bfdbfe;
    --tabbar-h: 64px;
    color-scheme: light;
}

/* ===================== Tema escuro ===================== */
:root[data-theme="dark"] {
    --primary: #6366f1;
    --primary-600: #818cf8;
    --primary-50: rgba(99, 102, 241, .16);
    --primary-100: rgba(99, 102, 241, .28);

    --bg: #0b1020;
    --surface: #121a2b;
    --surface-2: #182136;
    --border: #232d45;
    --border-strong: #2f3a56;
    --border-hover: #3d4a6b;
    --text: #e7eaf3;
    --text-2: #a9b1c7;
    --text-3: #6f7a96;

    --success: #22c55e;  --success-50: rgba(34, 197, 94, .14);
    --warning: #f59e0b;  --warning-50: rgba(245, 158, 11, .14);
    --danger: #f43f5e;   --danger-50: rgba(244, 63, 94, .14);
    --info: #3b82f6;     --info-50: rgba(59, 130, 246, .14);
    --success-text: #86efac;  --success-border: rgba(34, 197, 94, .3);
    --danger-text: #fda4af;   --danger-border: rgba(244, 63, 94, .3);
    --warning-text: #fcd34d;  --warning-border: rgba(245, 158, 11, .3);
    --info-text: #93c5fd;     --info-border: rgba(59, 130, 246, .3);

    --topbar-bg: rgba(11, 16, 32, .78);
    --topbar-bg-scrolled: rgba(18, 26, 43, .86);
    --row-hover: #162038;
    --neutral-bg: #1e2840;
    --track: #1e2840;
    --segment-bg: #0f1627;
    --grid-line: #1c253b;
    --toast-bg: #1e2840;
    --violet-50: rgba(139, 92, 246, .16);
    --sky-50: rgba(14, 165, 233, .16);
    --pink-50: rgba(236, 72, 153, .16);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .35);
    --shadow: 0 6px 20px -6px rgba(0, 0, 0, .5);
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .6);
    --ring: 0 0 0 4px rgba(99, 102, 241, .3);
    color-scheme: dark;
}

/* Transição suave ao trocar o tema */
html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after {
    transition: background-color .25s ease, border-color .25s ease, color .25s ease !important;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

a { color: var(--primary); }

h1, h2, h3, h4 { letter-spacing: -0.01em; color: var(--text); }

::selection { background: var(--primary-100); }

/* Ícones SVG (sprite em assets/img/icons.svg) */
.i {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: middle;
}
.i-sm { width: 15px; height: 15px; }
.i-lg { width: 22px; height: 22px; }
.i-xl { width: 28px; height: 28px; }

/* =====================================================================
   App shell: sidebar + topbar
   ===================================================================== */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 900;
    transition: transform .3s var(--ease);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px 16px;
    text-decoration: none;
}

.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--gradient);
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: 0 6px 16px -4px rgba(79, 70, 229, .5);
}

.brand-text strong {
    display: block;
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.brand-text span {
    font-size: 12px;
    color: var(--text-3);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.nav-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 14px 12px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: 10px;
    color: var(--text-2);
    text-decoration: none;
    font-weight: 500;
    transition: background .15s, color .15s;
}

.nav-item .i { color: var(--text-3); transition: color .15s; }

.nav-item:hover {
    background: var(--surface-2);
    color: var(--text);
}

.nav-item:hover .i { color: var(--text-2); }

.nav-item.active {
    background: var(--primary-50);
    color: var(--primary);
    font-weight: 600;
}

.nav-item.active .i { color: var(--primary); }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
}

.user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 12px;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--gradient);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}

.user-meta {
    flex: 1;
    min-width: 0;
}

.user-meta strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-meta span {
    font-size: 12px;
    color: var(--text-3);
}

.sidebar-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.sidebar-actions .btn { flex: 1; }

.app-main {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 800;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 32px;
    background: var(--topbar-bg);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid transparent;
    transition: border-color .2s, background .2s;
}

.topbar.scrolled {
    border-bottom-color: var(--border);
    background: var(--topbar-bg-scrolled);
}

.topbar-title { flex: 1; min-width: 0; }

.topbar-title h1 {
    font-size: 20px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-title p {
    font-size: 13px;
    color: var(--text-3);
}

.topbar .menu-toggle { display: none; }

.topbar-date {
    font-size: 13px;
    color: var(--text-2);
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 7px 12px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.sidebar-backdrop {
    display: none;
}

.container {
    width: 100%;
    max-width: 1320px;
    margin: 0 auto;
    padding: 8px 32px 32px;
    flex: 1;
}

/* Páginas sem app shell (ex.: legado) continuam centralizadas */
body:not(.has-shell) .container { padding-top: 24px; }

/* =====================================================================
   Botões
   ===================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 16px;
    border-radius: 10px;
    border: 1px solid transparent;
    font: inherit;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .1s;
    user-select: none;
}

.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 1px 2px rgba(79, 70, 229, .3), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.btn-primary:hover { background: var(--primary-600); }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-hover); }

.btn-ghost {
    background: transparent;
    color: var(--text-2);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { background: #b91c1c; }

.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-success:hover { background: #15803d; }

.btn-sm {
    height: 34px;
    padding: 0 12px;
    font-size: 13px;
    border-radius: 9px;
}

.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 9px;
}

.btn-icon.btn-lg { width: 40px; height: 40px; }

/* Botões de ação em tabelas: discretos */
.action-buttons {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}

.action-buttons .btn {
    background: transparent;
    border-color: transparent;
    color: var(--text-3);
    box-shadow: none;
}

.action-buttons .btn:hover { background: var(--surface-2); color: var(--text); }
.action-buttons .btn-danger:hover { background: var(--danger-50); color: var(--danger); }
.action-buttons .btn-primary:hover { background: var(--primary-50); color: var(--primary); }

/* Cards de tema usam botões com texto */
.card .action-buttons.full .btn {
    flex: 1;
    border-color: var(--border);
    color: var(--text-2);
}

/* =====================================================================
   Cards, cabeçalhos de seção, grids
   ===================================================================== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.card + .card { margin-top: 20px; }
.grid > .card + .card { margin-top: 0; }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.card-title {
    font-size: 17px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-title .i { color: var(--primary); }

.card-subtitle {
    font-size: 13px;
    color: var(--text-3);
    margin-top: 2px;
}

.section-title {
    font-size: 16px;
    font-weight: 700;
    margin: 28px 0 14px;
}

.grid {
    display: grid;
    gap: 20px;
}

.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* Barra de filtros */
.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 18px;
}

.toolbar .form-control { width: auto; min-width: 160px; }

.search-field {
    position: relative;
    flex: 1;
    min-width: 220px;
    max-width: 380px;
}

.search-field .i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-3);
    pointer-events: none;
}

.search-field .form-control {
    width: 100%;
    padding-left: 38px;
}

/* =====================================================================
   Formulários
   ===================================================================== */
.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    height: 42px;
    padding: 0 14px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    font: inherit;
    font-size: 14px;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
    box-shadow: var(--shadow-xs);
}

.form-control::placeholder { color: var(--text-3); }

.form-control:hover { border-color: var(--border-hover); }

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--ring);
}

textarea.form-control {
    height: auto;
    min-height: 90px;
    padding: 10px 14px;
    resize: vertical;
    line-height: 1.5;
}

select.form-control {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    cursor: pointer;
}

input[type="color"].form-control {
    padding: 4px;
    cursor: pointer;
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

.form-hint {
    display: block;
    font-size: 12px;
    color: var(--text-3);
    margin-top: 6px;
}

.form-section {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-3);
    margin: 8px 0 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
}

/* Caixas de seleção de permissões */
.check-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.check-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    font-weight: 500;
    transition: border-color .15s, background .15s;
}

.check-item:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-50);
}

/* =====================================================================
   Alertas e badges
   ===================================================================== */
.alert {
    display: none;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid transparent;
}

.alert-success { background: var(--success-50); color: var(--success-text); border-color: var(--success-border); }
.alert-error   { background: var(--danger-50);  color: var(--danger-text);  border-color: var(--danger-border); }
.alert-warning { background: var(--warning-50); color: var(--warning-text); border-color: var(--warning-border); }
.alert-info    { background: var(--info-50);    color: var(--info-text);    border-color: var(--info-border); }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.5;
}

.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: .85;
}

.badge-plain::before { display: none; }

.badge-success { background: var(--success-50); color: var(--success); }
.badge-warning { background: var(--warning-50); color: var(--warning); }
.badge-danger  { background: var(--danger-50);  color: var(--danger); }
.badge-info    { background: var(--info-50);    color: var(--info); }
.badge-neutral { background: var(--neutral-bg);          color: var(--text-2); }

/* =====================================================================
   Tabelas
   ===================================================================== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -24px;
    padding: 0 24px;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.table th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 10px 14px;
    background: var(--surface-2);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table th:first-child { border-left: 1px solid var(--border); border-radius: 10px 0 0 10px; }
.table th:last-child  { border-right: 1px solid var(--border); border-radius: 0 10px 10px 0; }

.table td {
    padding: 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text-2);
}

.table td strong { color: var(--text); font-weight: 600; }

.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--row-hover); }
.table tbody tr:last-child td { border-bottom: none; }

.cell-sub {
    display: block;
    font-size: 12px;
    color: var(--text-3);
    margin-top: 2px;
}

/* =====================================================================
   Modais (diálogo no desktop, "bottom sheet" no celular)
   ===================================================================== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(15, 23, 42, .45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 24px;
    overflow-y: auto;
    align-items: flex-start;
    justify-content: center;
    animation: fadeIn .2s ease;
}

.modal-content {
    background: var(--surface);
    width: 100%;
    max-width: 640px;
    margin: auto;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 48px);
    animation: modalIn .28s var(--ease);
}

.modal-content.modal-sm { max-width: 440px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 20px 24px 12px;
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background .15s;
    flex-shrink: 0;
}

.modal-close:hover { background: var(--border); color: var(--text); }

.modal-body {
    padding: 8px 24px 16px;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(16px) scale(.98); }
    to { opacity: 1; transform: none; }
}

@keyframes sheetIn {
    from { transform: translateY(100%); }
    to { transform: none; }
}

/* Diálogo de confirmação */
.confirm-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    margin-bottom: 14px;
    background: var(--danger-50);
    color: var(--danger);
}

.confirm-icon.info { background: var(--primary-50); color: var(--primary); }

.confirm-text { color: var(--text-2); font-size: 14px; }

/* =====================================================================
   Toasts
   ===================================================================== */
.toast-stack {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(380px, calc(100vw - 36px));
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: var(--toast-bg);
    color: #fff;
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    font-weight: 500;
    pointer-events: auto;
    animation: toastIn .3s var(--ease);
}

.toast .i { margin-top: 1px; }
.toast-success .i { color: #4ade80; }
.toast-error .i { color: #f87171; }
.toast-warning .i { color: #fbbf24; }
.toast-info .i { color: #60a5fa; }

.toast.hide { animation: toastOut .25s ease forwards; }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-10px) scale(.97); }
    to { opacity: 1; transform: none; }
}

@keyframes toastOut {
    to { opacity: 0; transform: translateX(20px); }
}

/* =====================================================================
   Estados: carregando, vazio
   ===================================================================== */
.loading {
    display: none;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-3);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--primary-100);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-3);
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 14px;
    border-radius: 20px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    font-size: 28px;
    color: var(--text-3);
}

.empty-state-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-2);
}

/* =====================================================================
   Dashboard / estatísticas
   ===================================================================== */
.hero {
    position: relative;
    overflow: hidden;
    background: var(--gradient);
    color: #fff;
    border-radius: var(--radius-xl);
    padding: 28px 32px;
    margin-bottom: 24px;
    box-shadow: 0 18px 40px -18px rgba(79, 70, 229, .6);
}

.hero::after {
    content: '';
    position: absolute;
    right: -60px;
    top: -60px;
    width: 260px;
    height: 260px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, .25), transparent 70%);
}

.hero h2 { color: #fff; font-size: 24px; font-weight: 800; }
.hero p { opacity: .9; margin-top: 4px; max-width: 560px; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 8px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-decoration: none;
    color: inherit;
    transition: transform .2s var(--ease), box-shadow .2s;
}

a.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.stat-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
}

.stat-value {
    font-size: 30px;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.stat-hint { font-size: 12px; color: var(--text-3); min-height: 18px; }
.stat-hint.danger { color: var(--danger); font-weight: 600; }

.tone-primary { background: var(--primary-50); color: var(--primary); }
.tone-success { background: var(--success-50); color: var(--success); }
.tone-warning { background: var(--warning-50); color: var(--warning); }
.tone-danger  { background: var(--danger-50);  color: var(--danger); }
.tone-info    { background: var(--info-50);    color: var(--info); }
.tone-violet  { background: var(--violet-50);     color: #8b5cf6; }
.tone-sky     { background: var(--sky-50);        color: #0ea5e9; }
.tone-pink    { background: var(--pink-50);       color: #ec4899; }

.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
}

.module-card {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow-sm);
    transition: transform .2s var(--ease), box-shadow .2s, border-color .2s;
}

.module-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
    border-color: var(--primary-100);
}

.module-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.module-title { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.module-description { font-size: 13px; color: var(--text-3); }

/* Barras de progresso */
.progress {
    height: 8px;
    background: var(--track);
    border-radius: 999px;
    overflow: hidden;
}

.progress > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    transition: width .6s var(--ease);
}

.progress-row + .progress-row { margin-top: 16px; }

.progress-head {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-bottom: 6px;
    color: var(--text-2);
}

.progress-head strong { color: var(--text); }

/* Lista chave/valor */
.kv-list { display: grid; gap: 8px; }

.kv-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-2);
}

.kv-item strong { font-size: 16px; color: var(--text); }

/* =====================================================================
   Abas (segmented control)
   ===================================================================== */
.tabs {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    background: var(--segment-bg);
    border-radius: 12px;
    margin-bottom: 20px;
    max-width: 100%;
    overflow-x: auto;
}

.tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: none;
    background: transparent;
    border-radius: 9px;
    font: inherit;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-2);
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, color .15s, box-shadow .15s;
}

.tab:hover { color: var(--text); }

.tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn .2s ease; }

/* =====================================================================
   Matriz de controle
   ===================================================================== */
.resumo-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.resumo-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.resumo-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--primary);
}

.resumo-card.verde::before { background: var(--success); }
.resumo-card.amarelo::before { background: var(--warning); }
.resumo-card.vermelho::before { background: var(--danger); }

.resumo-card h3 { font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
.resumo-card .valor { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.resumo-card .descricao { font-size: 12px; color: var(--text-3); }

.matriz-scroll {
    overflow: auto;
    max-height: 70vh;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.matriz-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
}

.matriz-table th {
    background: var(--surface-2);
    color: var(--text-2);
    padding: 10px 8px;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid var(--border);
    min-width: 92px;
    line-height: 1.3;
}

.matriz-table th:first-child {
    text-align: left;
    min-width: 220px;
    left: 0;
    z-index: 11;
}

.matriz-table td {
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--grid-line);
    padding: 4px;
    text-align: center;
    background: var(--surface);
}

.matriz-table td:first-child {
    font-weight: 600;
    text-align: left;
    color: var(--text);
    background: var(--surface);
    position: sticky;
    left: 0;
    z-index: 5;
    padding: 12px 14px;
    border-right: 1px solid var(--border);
}

.cell-content {
    padding: 8px 4px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: background .15s;
}

.cell-content:hover { background: var(--surface-2); }

.cell-status {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-size: 0;
}

.cell-info { font-size: 10px; font-weight: 600; color: var(--text-3); }

.status-vazio .cell-status { border: 2px dashed var(--border-strong); }
.status-planejado .cell-status { background: var(--warning-50); color: var(--warning); }
.status-realizado .cell-status { background: var(--success-50); color: var(--success); }
.status-cancelado .cell-status { background: var(--danger-50); color: var(--danger); }

.lista-escola {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
}

.escola-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.escola-nome { font-size: 15px; font-weight: 700; }

.escola-stats { display: flex; gap: 8px; flex-wrap: wrap; }

.stat-badge {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.stat-realizado { background: var(--success-50); color: var(--success); }
.stat-planejado { background: var(--warning-50); color: var(--warning); }
.stat-pendente  { background: var(--neutral-bg);color: var(--text-2); }

.temas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
}

.tema-item {
    position: relative;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    cursor: pointer;
    transition: transform .15s var(--ease), box-shadow .15s;
}

.tema-item:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.tema-item.realizado { background: var(--success-50); border-color: var(--success-border); }
.tema-item.planejado { background: var(--warning-50); border-color: var(--warning-border); }

.tema-numero { font-size: 18px; font-weight: 800; }
.tema-nome { font-size: 12px; color: var(--text-2); line-height: 1.35; }

.tema-status-icon {
    position: absolute;
    top: 10px;
    right: 10px;
}

.tema-item.realizado .tema-status-icon { color: var(--success); }
.tema-item.planejado .tema-status-icon { color: var(--warning); }
.tema-item.pendente .tema-status-icon { color: var(--text-3); }

/* =====================================================================
   Calendário
   ===================================================================== */
.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.calendar-header h2 { font-size: 20px; font-weight: 800; text-transform: capitalize; }

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
}

.calendar-day-header {
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: 6px 0 8px;
}

.calendar-day {
    min-height: 104px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px;
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
    overflow: hidden;
}

.calendar-day[onclick]:hover {
    border-color: var(--primary);
    box-shadow: var(--ring);
    cursor: pointer;
}

.calendar-day.other-month { background: var(--surface-2); opacity: .55; }

.day-number {
    font-weight: 600;
    font-size: 13px;
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    margin-bottom: 4px;
}

.calendar-day.today .day-number {
    background: var(--primary);
    color: #fff;
}

.day-events { display: grid; gap: 3px; }

.event-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 500;
    padding: 3px 6px;
    border-radius: 6px;
    background: var(--surface-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.event-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 16px;
    font-size: 13px;
    color: var(--text-2);
}

.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* =====================================================================
   Itens de detalhe (modais de ações)
   ===================================================================== */
.detail-card {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    background: var(--surface);
}

.detail-card + .detail-card { margin-top: 10px; }

.detail-card h4 { font-size: 15px; font-weight: 700; }

.detail-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 8px;
}

.detail-meta {
    display: grid;
    gap: 4px;
    font-size: 13px;
    color: var(--text-2);
}

.detail-meta span { display: flex; align-items: center; gap: 8px; }
.detail-meta .i { color: var(--text-3); width: 15px; height: 15px; }

/* =====================================================================
   Temas
   ===================================================================== */
.tema-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: transform .2s var(--ease), box-shadow .2s;
}

.tema-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.tema-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tema-num {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 16px;
}

.tema-card h3 { font-size: 15px; font-weight: 700; line-height: 1.35; }
.tema-card p { font-size: 13px; color: var(--text-2); flex: 1; }

.tema-card .action-buttons { justify-content: flex-start; }

/* =====================================================================
   Rodapé
   ===================================================================== */
.footer {
    padding: 20px 32px 28px;
    color: var(--text-3);
    font-size: 12px;
}

.footer-content {
    max-width: 1320px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    justify-content: space-between;
    align-items: center;
}

.footer a { color: var(--text-2); text-decoration: none; }
.footer a:hover { color: var(--primary); }

/* =====================================================================
   Responsivo
   ===================================================================== */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    body.nav-open .sidebar { transform: none; }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, .4);
        z-index: 850;
        opacity: 0;
        pointer-events: none;
        transition: opacity .25s;
    }

    body.nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }

    .app-main { margin-left: 0; }

    .topbar .menu-toggle { display: inline-flex; }

    .topbar { padding: 0 20px; }

    .container { padding: 8px 20px 24px; }

    .footer { padding: 16px 20px 24px; }
}

@media (max-width: 640px) {
    :root { --topbar-h: 60px; }

    .topbar-title h1 { font-size: 17px; }
    .topbar-title p, .topbar-date { display: none; }

    .container { padding: 4px 14px 20px; }

    .card { padding: 18px; border-radius: 14px; }
    .table-responsive { margin: 0 -18px; padding: 0 18px; }

    .card-header { align-items: stretch; }
    .card-header > .btn,
    .card-header > div { width: 100%; }
    .card-header > div .btn { flex: 1; }

    .toolbar .form-control,
    .search-field { max-width: none; min-width: 0; flex: 1 1 100%; }

    .grid-2 { grid-template-columns: 1fr; }

    .hero { padding: 22px; }
    .hero h2 { font-size: 20px; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 14px; }
    .stat-value { font-size: 24px; }

    /* Modais viram "bottom sheet" */
    .modal { padding: 0; align-items: flex-end; }
    .modal-content {
        max-width: none;
        border-radius: 22px 22px 0 0;
        max-height: 92vh;
        margin: 0;
        animation: sheetIn .3s var(--ease);
    }
    .modal-footer .btn { flex: 1; }

    .calendar-grid { gap: 3px; }
    .calendar-day { min-height: 64px; padding: 4px; border-radius: 8px; }
    .event-item { font-size: 0; padding: 0; background: none; }
    .event-item .event-dot { width: 8px; height: 8px; }
    .day-events { display: flex; flex-wrap: wrap; gap: 3px; }

    .check-grid { grid-template-columns: 1fr 1fr; }

    .toast-stack { top: auto; bottom: 16px; right: 16px; left: 16px; width: auto; }
}

/* Impressão (ex.: Relatórios): só o conteúdo */
@media print {
    .sidebar, .sidebar-backdrop, .topbar .btn, .footer, .btn, .modal, .alert,
    .toolbar, .loading, .toast-stack, .no-print {
        display: none !important;
    }
    body { background: #fff !important; }
    .app-main { margin: 0 !important; }
    .topbar { position: static; background: none !important; padding: 0; }
    .container { padding: 0 !important; max-width: none !important; }
    .card, .stat-card, .resumo-card { box-shadow: none !important; break-inside: avoid; }
}

/* Grids dentro de formulários ficam mais compactos */
.modal .grid, form .grid { gap: 0 16px; }

/* Tabelas como cartões no celular (rótulos vêm de data-label, ver app.js) */
@media (max-width: 640px) {
    .table-responsive { margin: 0; padding: 0; overflow: visible; }
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }

    .table tbody tr {
        border: 1px solid var(--border);
        border-radius: 14px;
        padding: 4px 14px;
        margin-bottom: 10px;
        background: var(--surface);
    }

    .table tbody tr:hover { background: var(--surface); }

    .table td,
    .table tbody tr:last-child td {
        border: none;
        border-bottom: 1px dashed var(--border);
        padding: 9px 0;
        display: block;
        text-align: right;
        overflow: hidden;
    }

    .table td::before {
        content: attr(data-label);
        float: left;
        margin-right: 14px;
        font-size: 12px;
        font-weight: 600;
        color: var(--text-3);
        text-align: left;
        line-height: 22px;
    }

    .table tbody tr td:first-child {
        text-align: left;
        padding-top: 12px;
        font-size: 15px;
    }

    .table td:first-child::before,
    .table td[data-label=""]::before,
    .table td[colspan]::before { display: none; }

    .table tbody tr td:last-child { border-bottom: none; }
    .table td[data-label=""] .action-buttons { justify-content: flex-end; }
    .table td[colspan] { text-align: center; }
    .table .cell-sub { margin-top: 0; }
}

/* Formulários em modal: dois campos por linha no desktop, um no celular */
.modal .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 640px) {
    .modal .grid-2 { grid-template-columns: 1fr; }
}
