/* ==========================================================================
   iAccounting — Design system da aplicação
   ========================================================================== */
:root {
    --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

    --ink: #0f172a;
    --ink-2: #334155;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-2: #cbd5e1;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;

    --brand: #0f766e;
    --brand-2: #0d9488;
    --brand-soft: #ccfbf1;
    --accent: #2dd4bf;
    --navy: #0f172a;
    --navy-2: #1e293b;

    --ok: #16a34a;
    --ok-soft: #dcfce7;
    --warn: #d97706;
    --warn-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --info: #2563eb;
    --info-soft: #dbeafe;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
    --shadow-lg: 0 10px 40px rgba(15, 23, 42, .12);
    --sidebar-w: 248px;
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font-sans); color: var(--ink); background: var(--bg); line-height: 1.5; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .35rem; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0 0 .75rem; }
code, .mono { font-family: var(--font-mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.text-right { text-align: right; }
.text-danger { color: var(--danger); }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Layout ------------------------------------------------------------------ */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #cbd5e1; display: flex; flex-direction: column; padding: 1rem .85rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; font-weight: 800; font-size: 1.15rem; padding: .35rem .5rem 1rem; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), var(--brand)); color: var(--navy); font-weight: 900; font-size: 1.1rem; }
.brand-dark { color: var(--ink); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 1rem .75rem .35rem; font-weight: 600; }
.nav-link { display: flex; align-items: center; gap: .6rem; padding: .5rem .75rem; border-radius: var(--radius-sm); color: #cbd5e1; font-weight: 500; font-size: .93rem; }
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-link.active { background: rgba(45, 212, 191, .16); color: #fff; }
.nav-icon { width: 1.2rem; text-align: center; color: var(--accent); font-size: .95rem; }
.nav-badge { margin-left: auto; background: var(--warn); color: #fff; border-radius: 999px; font-size: .7rem; padding: .05rem .45rem; font-weight: 700; }
.sidebar-footer { margin-top: auto; padding-top: 1rem; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.user-chip { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--navy-2); color: #fff; font-weight: 700; font-size: .8rem; flex: none; }
.user-name { color: #fff; font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.user-role { font-size: .74rem; color: #94a3b8; }
.logout-form { margin: 0; }
.app-main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-right { display: flex; gap: .5rem; align-items: center; }
.content { padding: 1.5rem; max-width: 1400px; width: 100%; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-header .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.company-switcher { display: flex; align-items: center; gap: .6rem; }
.company-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.loading-screen { padding: 4rem; text-align: center; color: var(--muted); }
.empty-state { text-align: center; padding: 4rem 1rem; color: var(--muted); }
.empty-state h2 { color: var(--ink); }

/* Cards & grids ----------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .85rem; }
.card-header h2, .card-header h3 { margin: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-header { padding: 1rem 1.25rem 0; }
.grid { display: grid; gap: 1.25rem; }
.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)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; box-shadow: var(--shadow); }
.kpi-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; margin: .2rem 0; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: .82rem; color: var(--muted); }
.kpi.ok .kpi-value { color: var(--ok); }
.kpi.warn .kpi-value { color: var(--warn); }
.kpi.danger .kpi-value { color: var(--danger); }
.kpi.brand .kpi-value { color: var(--brand); }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--line); margin: 1rem 0; }

/* Tables ------------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .6rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table tbody tr:hover { background: #f8fafc; }
.table tr.clickable { cursor: pointer; }
.table tfoot td { font-weight: 700; background: var(--surface-2); }
.table .num { text-align: right; }
.table.compact th, .table.compact td { padding: .4rem .55rem; }
.table tr.level-1 td { font-weight: 700; background: #f1f5f9; }
.table tr.level-2 td { font-weight: 600; }
.table tr.total td { font-weight: 700; border-top: 2px solid var(--line-2); }

/* Buttons ----------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; border-radius: var(--radius-sm); border: 1px solid transparent; font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; background: var(--surface); color: var(--ink); transition: background .15s, box-shadow .15s, transform .05s; white-space: nowrap; }
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-outline { border-color: var(--line-2); background: var(--surface); }
.btn-outline:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: inherit; }
.btn-ghost:hover { background: rgba(255,255,255,.08); }
.btn-success { background: var(--ok); color: #fff; }
.btn-warn { background: var(--warn); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; }
.btn-lg { padding: .8rem 1.4rem; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-group { display: inline-flex; gap: .4rem; flex-wrap: wrap; }

/* Forms ------------------------------------------------------------------- */
.form-field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .85rem; }
.form-field label { font-size: .82rem; font-weight: 600; color: var(--ink-2); }
.form-inline label { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.input, .select, .textarea, input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
    font: inherit; padding: .5rem .7rem; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); width: 100%; min-height: 38px;
}
.input:focus, .select:focus, .textarea:focus, input:focus, select:focus, textarea:focus { outline: 2px solid rgba(13, 148, 136, .35); border-color: var(--brand); }
.input.invalid, .modified.invalid { border-color: var(--danger); }
.validation-message { color: var(--danger); font-size: .8rem; }
.input-sm { padding: .3rem .5rem; min-height: 32px; font-size: .88rem; }
.select { appearance: auto; }
.help { font-size: .8rem; color: var(--muted); }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
.dropzone { border: 2px dashed var(--line-2); border-radius: var(--radius); padding: 2rem; text-align: center; color: var(--muted); background: var(--surface-2); }
.dropzone.active { border-color: var(--brand); background: var(--brand-soft); }
.file-input { display: block; margin: .5rem auto 0; }

/* Badges & alerts --------------------------------------------------------- */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap; background: var(--line); color: var(--ink-2); }
.badge-ok { background: var(--ok-soft); color: #166534; }
.badge-warn { background: var(--warn-soft); color: #92400e; }
.badge-danger { background: var(--danger-soft); color: #991b1b; }
.badge-info { background: var(--info-soft); color: #1e3a8a; }
.badge-brand { background: var(--brand-soft); color: #115e59; }
.badge-muted { background: #f1f5f9; color: var(--muted); }
.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); border: 1px solid transparent; margin-bottom: 1rem; font-size: .92rem; }
.alert-danger { background: var(--danger-soft); border-color: #fecaca; color: #7f1d1d; }
.alert-ok { background: var(--ok-soft); border-color: #bbf7d0; color: #14532d; }
.alert-warn { background: var(--warn-soft); border-color: #fde68a; color: #78350f; }
.alert-info { background: var(--info-soft); border-color: #bfdbfe; color: #1e3a8a; }
.confidence { display: inline-flex; align-items: center; gap: .4rem; font-variant-numeric: tabular-nums; font-weight: 600; font-size: .85rem; }
.confidence-bar { width: 64px; height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.confidence-bar > span { display: block; height: 100%; background: var(--ok); }
.confidence.low .confidence-bar > span { background: var(--danger); }
.confidence.mid .confidence-bar > span { background: var(--warn); }
.check-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; }
.check-list li::before { content: "✓ "; color: var(--ok); font-weight: 700; }
.check-list li.fail::before { content: "✗ "; color: var(--danger); }
.pill-tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.pill-tabs button, .pill-tabs a { background: none; border: 0; border-bottom: 2px solid transparent; padding: .6rem .9rem; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.pill-tabs .active { color: var(--brand); border-bottom-color: var(--brand); }

/* Auth -------------------------------------------------------------------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% -10%, #ccfbf1 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #fef3c7 0%, transparent 55%), var(--bg); padding: 2rem 1rem; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 2rem; box-shadow: var(--shadow-lg); }
.auth-card .brand { padding: 0 0 1rem; }
.auth-card h1 { font-size: 1.5rem; }
.auth-demo { margin-top: 1.25rem; padding: .75rem; border-radius: var(--radius-sm); background: var(--surface-2); font-size: .85rem; display: flex; flex-direction: column; gap: .25rem; }

/* Modal ------------------------------------------------------------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 100; padding: 1rem; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 760px; max-height: 92vh; overflow: auto; box-shadow: var(--shadow-lg); padding: 1.5rem; }
.modal.wide { max-width: 1100px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }

/* Misc -------------------------------------------------------------------- */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.split-3-2 { grid-template-columns: 3fr 2fr; }
.doc-preview { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #f1f5f9; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .5rem 0 .5rem 1.25rem; border-left: 2px solid var(--line); position: relative; font-size: .9rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .9rem; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.kbd { font-family: var(--font-mono); font-size: .78rem; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 4px; padding: 0 .35rem; }
.progress { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); }
.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .input, .toolbar .select { width: auto; min-width: 180px; }
.pagination { display: flex; gap: .35rem; justify-content: flex-end; padding: .75rem; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line-2); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .5rem; }
    .nav { flex-direction: row; flex-wrap: wrap; }
    .nav-section { display: none; }
    .sidebar-footer { margin-top: 0; border: 0; padding: 0; margin-left: auto; }
    .grid-2, .grid-3, .grid-4, .split, .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
    .content { padding: 1rem; }
}
