/* ============================================================
   Design tokens
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
h1, h2, h3, p, ul, ol { margin: 0 0 .5rem 0; }
ul { padding-left: 1.1rem; }
a { color: inherit; }
img { max-width: 100%; }

:root {
    color-scheme: light;

    /* Surfaces & ink */
    --page:            #f4f5f3;
    --surface:         #ffffff;
    --surface-sunken:  #f9f9f7;
    --text:            #0b0b0b;
    --text-secondary:  #52514e;
    --text-muted:      #898781;
    --border:          rgba(11,11,11,0.10);
    --border-strong:   rgba(11,11,11,0.16);
    --gridline:        #e1e0d9;

    /* Brand / categorical slots (validated palette, light mode) */
    --brand:           #2a78d6; /* slot 1 blue */
    --brand-hover:     #1c5cab;
    --brand-wash:      #eaf2fc;
    --slot-1: #2a78d6; /* blue */
    --slot-2: #eb6834; /* orange */
    --slot-3: #1baf7a; /* aqua */
    --slot-4: #eda100; /* yellow */
    --slot-5: #e87ba4; /* magenta */
    --slot-6: #008300; /* green */
    --slot-7: #4a3aa7; /* violet */
    --slot-8: #e34948; /* red */

    /* Status (fixed, never themed for identity) */
    --status-good:     #0ca30c;
    --status-warning:  #fab219;
    --status-serious:  #ec835a;
    --status-critical: #d03b3b;
    --status-good-bg:     #eafbea;
    --status-warning-bg:  #fff8e8;
    --status-serious-bg:  #fdece5;
    --status-critical-bg: #fbeaea;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(11,11,11,0.06);
    --shadow: 0 2px 8px rgba(11,11,11,0.06), 0 1px 2px rgba(11,11,11,0.05);
    --shadow-lg: 0 12px 32px rgba(11,11,11,0.10);

    --sidebar-w: 232px;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --page:            #0d0d0d;
        --surface:         #18181a;
        --surface-sunken:  #1e1e21;
        --text:            #ffffff;
        --text-secondary:  #c3c2b7;
        --text-muted:      #8b8a85;
        --border:          rgba(255,255,255,0.09);
        --border-strong:   rgba(255,255,255,0.16);
        --gridline:        #2c2c2a;

        --brand:           #3987e5;
        --brand-hover:     #5a9eec;
        --brand-wash:      #16283f;
        --slot-1: #3987e5;
        --slot-2: #d95926;
        --slot-3: #199e70;
        --slot-4: #c98500;
        --slot-5: #d55181;
        --slot-6: #24b224;
        --slot-7: #9085e9;
        --slot-8: #e66767;

        --status-good:     #1fbf3a;
        --status-warning:  #fab219;
        --status-serious:  #ec835a;
        --status-critical: #e66767;
        --status-good-bg:     #103018;
        --status-warning-bg:  #332708;
        --status-serious-bg:  #35190f;
        --status-critical-bg: #331313;

        --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
        --shadow: 0 2px 8px rgba(0,0,0,0.35), 0 1px 2px rgba(0,0,0,0.3);
        --shadow-lg: 0 16px 40px rgba(0,0,0,0.5);
    }
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--page);
    color: var(--text);
    line-height: 1.5;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

.tabular { font-variant-numeric: tabular-nums; }

/* ============================================================
   App shell — sidebar (desktop) / bottom tab bar (mobile)
   ============================================================ */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 20;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 1.3rem 1.2rem 1.1rem;
}

.brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--brand), var(--slot-3));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: .95rem;
    flex-shrink: 0;
}

.brand-word {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -.01em;
    color: var(--text);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    padding: .5rem .7rem;
    flex: 1;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .55rem .7rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: .89rem;
    transition: background .12s ease, color .12s ease;
}

.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-link:hover { background: var(--surface-sunken); color: var(--text); }

.nav-link.active {
    background: var(--brand-wash);
    color: var(--brand);
    font-weight: 600;
}

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

.sidebar-footer .nav-link { color: var(--status-critical); }
.sidebar-footer .nav-link:hover { background: var(--status-critical-bg); }

.topbar-mobile {
    display: none;
}

.bottom-nav {
    display: none;
}

@media (max-width: 860px) {
    .sidebar { display: none; }
    .container { padding-bottom: 84px; }

    .topbar-mobile {
        display: flex;
        align-items: center;
        gap: .55rem;
        padding: .85rem 1rem;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        position: sticky;
        top: 0;
        z-index: 15;
    }

    .bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        background: var(--surface);
        border-top: 1px solid var(--border);
        padding: .35rem .2rem calc(.35rem + env(safe-area-inset-bottom));
        z-index: 20;
    }

    .bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: .15rem;
        text-decoration: none;
        color: var(--text-muted);
        font-size: .65rem;
        font-weight: 600;
        padding: .3rem .4rem;
        border-radius: var(--radius-sm);
        flex: 1;
    }

    .bottom-nav a svg { width: 19px; height: 19px; }
    .bottom-nav a.active { color: var(--brand); }
}

.container {
    margin-left: var(--sidebar-w);
    max-width: calc(1080px + var(--sidebar-w));
    padding: 1.6rem 2rem 2.5rem;
}

@media (max-width: 860px) {
    .container { margin-left: 0; padding: 1.2rem 1.2rem 2rem; max-width: none; }
}

@media (max-width: 560px) {
    .container { padding: 1rem 1rem 2rem; }
}

/* ============================================================
   Cards & layout
   ============================================================ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.1rem;
}

.card h2 {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .82rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 700;
}

.grid { display: grid; gap: 1.1rem; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 900px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

/* Stat tiles */
.stat-card { position: relative; overflow: hidden; padding-right: 3.6rem; }
.stat-icon {
    position: absolute;
    top: 1.1rem; right: 1.1rem;
    width: 34px; height: 34px;
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
}
.stat-icon svg { width: 17px; height: 17px; }

.stat-value {
    font-size: 1.7rem;
    font-weight: 700;
    letter-spacing: -.01em;
    font-variant-numeric: proportional-nums;
}

.stat-value.positivo, .positivo { color: var(--status-good); }
.stat-value.negativo, .negativo { color: var(--status-critical); }

/* Barras de categoria */
.bar-row {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: .6rem;
    padding: .2rem;
    border-radius: var(--radius-sm);
    transition: background .12s ease;
}

a.bar-row:hover { background: var(--surface-sunken); }

.bar-label {
    flex: 0 0 190px;
    display: flex;
    align-items: center;
    gap: .45rem;
    font-size: .87rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px var(--surface);
}

.bar-track {
    flex: 1;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: 6px;
    height: 10px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 6px;
}

.bar-value {
    flex: 0 0 auto;
    font-size: .84rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 92px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ============================================================
   Tables
   ============================================================ */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .89rem;
}

th, td {
    padding: .65rem .55rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}

td { font-variant-numeric: tabular-nums; }

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

.badge {
    display: inline-block;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    color: #fff;
}

.badge-essencial { background: var(--status-good); }
.badge-nao-essencial { background: var(--status-warning); color: #4a3400; }

.badge-prazo {
    display: inline-block;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 700;
    margin-left: .4rem;
    white-space: nowrap;
}

.prazo-vencido { background: var(--status-critical-bg); color: var(--status-critical); }
.prazo-urgente { background: var(--status-warning-bg); color: #8a5a00; }
.prazo-atencao { background: var(--brand-wash); color: var(--brand); }

/* Navegação de mês */
.month-nav {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: 1.1rem;
    flex-wrap: wrap;
}

.month-nav .btn-sm { padding: .35rem .6rem; }

.month-nav strong {
    font-size: 1.02rem;
    min-width: 150px;
    text-align: center;
}

/* Ajuda / tooltip */
.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: .64rem;
    font-weight: 700;
    cursor: help;
    flex-shrink: 0;
    text-transform: none;
    letter-spacing: normal;
}

.alert {
    padding: .7rem .9rem;
    border-radius: var(--radius-sm);
    font-size: .86rem;
    margin-bottom: .9rem;
    border: 1px solid transparent;
}

.alert-error { background: var(--status-critical-bg); color: var(--status-critical); border-color: color-mix(in srgb, var(--status-critical) 25%, transparent); }
.alert-success { background: var(--status-good-bg); color: var(--status-good); border-color: color-mix(in srgb, var(--status-good) 25%, transparent); }
.alert-warning { background: var(--status-warning-bg); color: #8a5a00; border-color: color-mix(in srgb, var(--status-warning) 35%, transparent); }

.alert-list { list-style: none; padding: 0; margin: 0; }
.alert-list li {
    display: flex;
    justify-content: space-between;
    gap: .6rem;
    padding: .45rem 0;
    border-bottom: 1px dashed var(--border);
    font-size: .88rem;
}
.alert-list li:last-child { border-bottom: none; }

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 2.2rem 1rem;
    font-size: .9rem;
}

.subtotal-row { font-weight: 700; background: var(--surface-sunken); }

.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: 1rem; }

/* ============================================================
   Forms
   ============================================================ */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .9rem;
}

@media (max-width: 700px) {
    .form-grid { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: .35rem; }

.field label {
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

input, select, textarea {
    font-family: inherit;
    font-size: .93rem;
    padding: .58rem .7rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    width: 100%;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-wash);
}

.field-full { grid-column: 1 / -1; }

.actions-row {
    display: flex;
    gap: .6rem;
    margin-top: .4rem;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .58rem 1.05rem;
    border-radius: var(--radius-sm);
    border: none;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    background: var(--brand);
    color: #fff;
    transition: background .12s ease, transform .05s ease;
}

.btn:hover { background: var(--brand-hover); }
.btn:active { transform: translateY(1px); }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
}

.btn-secondary:hover { background: var(--surface-sunken); }

.btn-danger { background: var(--status-critical); }
.btn-danger:hover { filter: brightness(0.92); }

.btn-sm { padding: .32rem .68rem; font-size: .8rem; }

.filters {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 1rem;
}

.filters .field { min-width: 160px; flex: 1; }

/* ============================================================
   Login
   ============================================================ */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: var(--page);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.4rem 2rem;
    text-align: center;
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .7rem;
    margin-bottom: 1.6rem;
}

.login-brand .brand-mark { width: 44px; height: 44px; border-radius: 12px; font-size: 1.2rem; }
.login-brand h1 { font-size: 1.15rem; font-weight: 700; color: var(--text); }
.login-brand p { font-size: .82rem; color: var(--text-muted); margin: 0; }
