/* moneyPilot — design tokens */
:root {
    color-scheme: light;
    --page:           #f4f3f0;
    --surface:        #fcfcfb;
    --surface-2:      #f0efec;
    --border:         #e3e1dc;
    --text:           #0b0b0b;
    --text-secondary: #52514e;
    --text-muted:     #78776f;
    --accent:         #2a78d6;
    --accent-ink:     #ffffff;
    --accent-soft:    #cde2fb;
    --income:         #006300;
    --expense:        #c03e3d;
    --good:           #0ca30c;
    --warning:        #fab219;
    --critical:       #d03b3b;
    --series-1:       #2a78d6;
    --shadow:         0 1px 2px rgba(11, 11, 11, .06), 0 4px 12px rgba(11, 11, 11, .04);
    --radius:         10px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --page:           #131312;
        --surface:        #1a1a19;
        --surface-2:      #232322;
        --border:         #33332f;
        --text:           #ffffff;
        --text-secondary: #c3c2b7;
        --text-muted:     #94938a;
        --accent:         #3987e5;
        --accent-ink:     #0b0b0b;
        --accent-soft:    #184f95;
        --income:         #3fa83f;
        --expense:        #e66767;
        --series-1:       #3987e5;
        --shadow:         0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px rgba(0, 0, 0, .3);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --page:           #131312;
    --surface:        #1a1a19;
    --surface-2:      #232322;
    --border:         #33332f;
    --text:           #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #94938a;
    --accent:         #3987e5;
    --accent-ink:     #0b0b0b;
    --accent-soft:    #184f95;
    --income:         #3fa83f;
    --expense:        #e66767;
    --series-1:       #3987e5;
    --shadow:         0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

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

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }

.app-loading { padding: 3rem 1rem; text-align: center; color: var(--text-muted); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.sidebar-body { display: flex; flex-direction: column; gap: 1.5rem; flex: 1; min-height: 0; }

.menu-toggle { display: none; }
.menu-toggle span { display: block; width: 18px; height: 2px; border-radius: 1px; background: currentColor; transition: transform .2s ease, opacity .2s ease; }

.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.05rem; }

/* A logo é um lockup quadrado (símbolo + wordmark + tagline). Aqui recortamos
   só o símbolo, por proporção, pra ele funcionar como ícone da sidebar. */
.brand-mark {
    width: 34px;
    height: 34px;
    flex: none;
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    background: #fff;
}
.brand-mark img { position: absolute; width: 244%; left: -73%; top: -47.5%; }

.nav { display: flex; flex-direction: column; gap: .15rem; }
.nav a {
    display: block;
    padding: .5rem .65rem;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: .92rem;
    white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: .5rem; font-size: .85rem; }
.user-chip { color: var(--text-secondary); overflow-wrap: anywhere; }

.main { padding: 1.5rem 1.75rem 4rem; max-width: 1100px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin: .2rem 0 0; color: var(--text-secondary); font-size: .9rem; }

/* ---------- cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem 1.15rem;
}
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.card-head .sub { color: var(--text-muted); font-size: .82rem; }

.grid { display: grid; gap: 1rem; }
.grid > .card + .card { margin-top: 0; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

/* ---------- stat tiles ---------- */
.stat { display: flex; flex-direction: column; gap: .3rem; }
.stat .label { font-size: .8rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .hint { font-size: .8rem; color: var(--text-muted); }
.value.pos { color: var(--income); }
.value.neg { color: var(--expense); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th {
    text-align: left;
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    padding: .5rem .6rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
td { padding: .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; }
td.muted { color: var(--text-muted); }

/* ---------- controls ---------- */
button, .btn {
    font: inherit;
    font-size: .88rem;
    font-weight: 550;
    padding: .45rem .85rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}
button:hover:not(:disabled), .btn:hover { background: var(--surface-2); }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn-ghost { border-color: transparent; background: transparent; padding: .3rem .5rem; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--critical); }
.btn-sm { font-size: .8rem; padding: .25rem .5rem; }

input, select, textarea {
    font: inherit;
    font-size: .9rem;
    padding: .45rem .6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .85rem; }
.field label { font-size: .82rem; font-weight: 550; color: var(--text-secondary); }
.field .error { font-size: .78rem; color: var(--critical); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }

.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin-bottom: 0; min-width: 132px; }

/* ---------- badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font-size: .75rem;
    font-weight: 600;
    padding: .12rem .45rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-secondary);
    white-space: nowrap;
}
.badge .swatch { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.badge-income .swatch { background: var(--income); }
.badge-expense .swatch { background: var(--expense); }
.badge-transfer .swatch { background: var(--text-muted); }

/* ---------- charts ---------- */
.bars { display: flex; flex-direction: column; gap: .8rem; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: .2rem .75rem; align-items: baseline; }
.bar-row .name { font-size: .87rem; }
.bar-row .amount { font-size: .87rem; font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.bar-track { grid-column: 1 / -1; height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; transition: width .2s ease; }
.bar-row:hover .bar-fill { filter: brightness(1.12); }

.meter { display: flex; flex-direction: column; gap: .3rem; }
.meter-head { display: flex; justify-content: space-between; gap: .75rem; font-size: .87rem; align-items: baseline; }
.meter-head .pct { font-variant-numeric: tabular-nums; font-weight: 600; font-size: .82rem; }
.meter-track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 0 4px 4px 0; }
.meter-fill.good { background: var(--good); }
.meter-fill.warning { background: var(--warning); }
.meter-fill.critical { background: var(--critical); }
.meter-foot { font-size: .8rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.meter + .meter { margin-top: .9rem; }

/* ---------- dialog ---------- */
dialog {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
    width: min(460px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(11, 11, 11, .45); }
.dialog-body { padding: 1.15rem 1.25rem; }
.dialog-body h2 { margin-bottom: .9rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.15rem; }
.dialog-error { color: var(--critical); font-size: .85rem; margin-bottom: .75rem; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 16px; }
.auth-card { width: min(380px, 100%); }
.auth-card .brand { justify-content: center; margin-bottom: .25rem; font-size: 1.25rem; }
.auth-logo {
    display: block;
    width: 220px;
    max-width: 80%;
    margin: -.35rem auto .9rem;
    border-radius: 12px;
    background: #fff;
}
.auth-tagline { text-align: center; color: var(--text-secondary); font-size: .88rem; margin: 0 0 1.25rem; }
.auth-switch { text-align: center; font-size: .85rem; color: var(--text-secondary); margin-top: 1rem; }
.auth-switch button { background: none; border: none; color: var(--accent); padding: 0 .2rem; font-weight: 600; }

/* ---------- misc ---------- */
.empty { text-align: center; padding: 2rem 1rem; color: var(--text-muted); font-size: .9rem; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: .6rem; margin-top: .9rem; font-size: .85rem; color: var(--text-secondary); }
.toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: .6rem .85rem;
    font-size: .87rem;
    max-width: 320px;
}
.toast.error { border-left-color: var(--critical); }
.toast.success { border-left-color: var(--good); }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
    .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
    .main { padding: 1.25rem 16px 3rem; }
    .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }

    /* sidebar vira barra fixa no topo; o menu abre num painel abaixo dela */
    .sidebar {
        z-index: 20;
        height: auto;
        padding: .6rem 16px;
        gap: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .menu-toggle {
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        gap: 4px;
        width: 42px;
        height: 42px;
        padding: 0;
        align-items: center;
        color: var(--text);
    }
    .sidebar.open .menu-toggle span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
    .sidebar.open .menu-toggle span:nth-child(2) { opacity: 0; }
    .sidebar.open .menu-toggle span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

    .sidebar-body {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        max-height: calc(100dvh - 100%);
        overflow-y: auto;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow);
        padding: .5rem 16px 1rem;
        gap: .75rem;
    }
    .sidebar.open .sidebar-body { display: flex; }
    .nav a { padding: .75rem .65rem; font-size: 1rem; }
    .sidebar-foot {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: .5rem;
        padding-top: .75rem;
        border-top: 1px solid var(--border);
    }
    .user-chip { flex: 1 1 100%; }
    .sidebar-foot button { padding: .5rem .75rem; font-size: .9rem; }

    /* page head: ações ocupam a largura toda */
    .page-head { flex-direction: column; align-items: stretch; }
    .page-head > div:last-child > * { flex: 1 1 auto; justify-content: center; }

    .card { padding: 1rem; }
    .card-head { flex-wrap: wrap; }

    /* filtros em grade de duas colunas */
    .filters { display: grid; grid-template-columns: 1fr 1fr; }
    .filters .field { min-width: 0; max-width: none !important; }
    .filters > button { grid-column: 1 / -1; justify-content: center; padding: .55rem; }

    /* iOS dá zoom em campos com fonte menor que 16px */
    input, select, textarea { font-size: 16px; padding: .55rem .65rem; }

    /* tabelas viram lista de cartões */
    .table-stack { overflow: visible; }
    .table-stack table, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
    .table-stack thead { display: none; }
    .table-stack tr {
        padding: .7rem 0;
        border-bottom: 1px solid var(--border);
    }
    .table-stack tr:last-child { border-bottom: none; }
    .table-stack tr:first-child { padding-top: 0; }
    .table-stack tbody tr:hover { background: none; }
    .table-stack td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        padding: .2rem 0;
        border: none;
        text-align: right;
        overflow-wrap: anywhere;
    }
    .table-stack td::before {
        content: attr(data-label);
        flex: none;
        text-align: left;
        font-size: .78rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: .04em;
        color: var(--text-muted);
    }
    .table-stack td:not([data-label])::before { content: none; }
    .table-stack td:first-child { font-weight: 600; }
    .table-stack td.actions { justify-content: flex-end; gap: .25rem; padding-top: .45rem; }
    .table-stack td.actions .btn-sm { padding: .4rem .7rem; font-size: .85rem; }

    .pager { flex-wrap: wrap; justify-content: center; }
    .pager > span:first-child { flex: 1 1 100%; text-align: center; }

    dialog { max-height: calc(100dvh - 32px); }
    .dialog-body { padding: 1rem; }
    .dialog-actions button { flex: 1; justify-content: center; padding: .6rem; }

    .toasts { left: 16px; right: 16px; bottom: 16px; }
    .toast { max-width: none; }
}

@media (max-width: 380px) {
    .filters { grid-template-columns: 1fr; }
    .stat .value { font-size: 1.4rem; }
}
