/* AnalisaExtratos — mobile primeiro, tema claro/escuro automático. */

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg: #F6F7FB;
  --surface: #FFFFFF;
  --surface-2: #F0F2F7;
  --text: #1B1D26;
  --text-2: #5E6372;
  --line: #E3E6EE;
  --primary: #4F46E5;
  --primary-ink: #FFFFFF;
  --primary-soft: #EEF0FF;
  --neg: #D93B25;
  --pos: #0E9F6E;
  --warn: #B7791F;
  --warn-soft: #FFF6E5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1117;
    --surface: #181B24;
    --surface-2: #222634;
    --text: #ECEEF4;
    --text-2: #A2A8B8;
    --line: #2C3141;
    --primary: #818CF8;
    --primary-ink: #0F1117;
    --primary-soft: #262B45;
    --neg: #FF7A66;
    --pos: #34D399;
    --warn: #F6C26B;
    --warn-soft: #3A2F1C;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0F1117;
  --surface: #181B24;
  --surface-2: #222634;
  --text: #ECEEF4;
  --text-2: #A2A8B8;
  --line: #2C3141;
  --primary: #818CF8;
  --primary-ink: #0F1117;
  --primary-soft: #262B45;
  --neg: #FF7A66;
  --pos: #34D399;
  --warn: #F6C26B;
  --warn-soft: #3A2F1C;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.neg { color: var(--neg); }
.pos { color: var(--pos); }
.right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

/* ── Estrutura ─────────────────────────────────────────────────────────── */

.shell { min-height: 100dvh; }
.content { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 20px; }
main { padding: 4px 16px 16px; outline: none; max-width: 1200px; margin: 0 auto; }
.view { display: flex; flex-direction: column; gap: 14px; }

.nav {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.nav .brand { display: none; }
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-2); text-decoration: none; font-size: 11px; font-weight: 500;
}
.nav a .ico { font-size: 20px; line-height: 1; }
.nav a.active { color: var(--primary); }
.nav a.nav-scan .ico {
  display: grid; place-items: center; width: 44px; height: 30px; border-radius: 999px;
  background: var(--primary); color: var(--primary-ink); font-size: 18px;
}

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 220px 1fr; }
  .nav {
    position: sticky; top: 0; height: 100dvh; inset: auto;
    display: flex; flex-direction: column; gap: 4px; padding: 18px 12px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 10px 18px; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 15px; padding: 10px 12px; border-radius: 10px; }
  .nav a.active { background: var(--primary-soft); }
  .nav a.nav-scan .ico { width: auto; height: auto; background: none; color: inherit; font-size: 20px; }
  .content { padding-bottom: 32px; }
  .topbar { padding: 18px 24px 10px; }
  main { padding: 4px 24px 24px; }
}

body.logged-out .shell { display: none; }
#login:empty { display: none; }
#login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center;
  background: var(--surface); padding: 28px 22px; border-radius: 20px; box-shadow: var(--shadow); border: 1px solid var(--line);
}
.login-card img { align-self: center; border-radius: 18px; }
.login-card h1 { font-size: 22px; }

/* ── Componentes ───────────────────────────────────────────────────────── */

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); min-width: 0;
}
.card-title { font-size: 15px; margin-bottom: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head .card-title { margin: 0; }
details.card > summary { cursor: pointer; font-weight: 600; }
details.card[open] > summary { margin-bottom: 8px; }
.sub { font-size: 14px; margin: 14px 0 8px; }

.grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-all { grid-column: 1 / -1; }
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn-danger { background: var(--neg); color: #fff; border-color: transparent; }
.btn-danger-ghost { color: var(--neg); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn-xl { min-height: 56px; font-size: 17px; border-radius: 16px; width: 100%; }
.btn-block { width: 100%; }
.btn-left { justify-content: flex-start; text-align: left; height: auto; padding: 10px 12px; font-weight: 500; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 18px; flex: none;
}
.row-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; margin-top: 12px; }
.row-actions.wrap { flex-wrap: wrap; justify-content: flex-start; }

input, select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px; /* 16px evita zoom no iOS */
}
textarea { min-height: 120px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .chip:focus-visible, .tx:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.select-sm { min-height: 34px; padding: 4px 8px; font-size: 14px; border-radius: 10px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label, .inline-label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.inline-label { margin-top: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline-form { display: flex; gap: 8px; flex: 1; min-width: 220px; }

.chip {
  flex: none; min-height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 14px; white-space: nowrap;
}
.chip.active { background: var(--primary); color: var(--primary-ink); border-color: transparent; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.month-picker {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px;
  scroll-snap-type: x proximity;
}
.month-picker::-webkit-scrollbar { display: none; }
.month-picker .chip { scroll-snap-align: center; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.segmented button { min-height: 36px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; font-weight: 600; color: var(--text-2); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  display: flex; flex-direction: column; gap: 2px; min-width: 0; box-shadow: var(--shadow);
  border-top: 4px solid var(--line);
}
.kpi span { font-size: 12px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi strong { font-size: clamp(17px, 5vw, 22px); font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi small { font-size: 11px; }
.kpi-d { border-top-color: var(--neg); }
.kpi-c { border-top-color: var(--pos); }
@media (max-width: 640px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpis .kpi:last-child { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; align-items: baseline; column-gap: 10px; }
  .kpis .kpi:last-child span { flex-basis: 100%; }
}

.chart-box { position: relative; width: 100%; }

.legend-list { list-style: none; margin: 8px 0 0; padding: 0; }
.legend-row {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 6px 4px;
  border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer;
}
li:last-child > .legend-row { border-bottom: 0; }
.legend-row strong { font-variant-numeric: tabular-nums; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.tx-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card .tx-list { border: 0; border-radius: 0; background: none; }
.tx-list > li + li { border-top: 1px solid var(--line); }
.tx {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px;
  border: 0; background: none; text-align: left; cursor: pointer;
}
.tx-list.compact .tx { padding: 9px 0; cursor: default; }
.tx-main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.tx-desc { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { font-size: 13px; color: var(--text-2); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tx strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.group-head { padding: 8px 14px; background: var(--surface-2); font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-2); }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }

.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge-ok { background: color-mix(in srgb, var(--pos) 16%, transparent); color: var(--pos); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--primary-soft); color: var(--primary); }
.badge-muted { background: var(--surface-2); color: var(--text-2); }

.filters { display: flex; flex-direction: column; gap: 8px; }
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 900px) { .filter-row { grid-template-columns: repeat(4, 1fr); } }
.list-summary { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 14px; font-weight: 600; }
.list-summary .btn { margin-left: auto; }

.table-wrap { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.data td:first-child { white-space: normal; min-width: 120px; }
table.data th { font-size: 12px; color: var(--text-2); font-weight: 700; background: var(--surface-2); position: sticky; top: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.total td { font-weight: 700; background: var(--surface-2); }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px 16px; text-align: center;
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--surface); cursor: pointer;
}
.dropzone.over { border-color: var(--primary); background: var(--primary-soft); }
.dz-icon { font-size: 30px; color: var(--primary); }
.file-results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file-results li { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 10px; font-size: 14px; }
.file-results li.ok { background: color-mix(in srgb, var(--pos) 10%, transparent); }
.file-results li.err { background: color-mix(in srgb, var(--neg) 10%, transparent); }

.review-list { list-style: none; margin: 0; padding: 0; }
.review { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.review:last-child { border-bottom: 0; }
.review input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; margin-top: 2px; flex: none; accent-color: var(--primary); }
.review .tx-main select { margin-top: 6px; max-width: 240px; }
.review.warn { background: var(--warn-soft); margin: 0 -14px; padding: 10px 14px; }
.warn-text { color: var(--warn); font-weight: 600; }
.type-toggle {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 10px;
  font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer; white-space: nowrap;
}
.type-toggle.neg { color: var(--neg); }
.type-toggle.pos { color: var(--pos); }
.sticky-actions {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 4;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12); font-size: 14px; font-weight: 600;
}
@media (min-width: 900px) { .sticky-actions { bottom: 12px; } }

.scan-hero { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.note-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.note-head h3 { font-size: 16px; }
.big { font-size: 20px; font-variant-numeric: tabular-nums; }
.help { font-size: 13px; color: var(--text-2); background: var(--surface-2); padding: 10px 12px; border-radius: 10px; }
.linked { font-size: 14px; }
ul.plain { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.alert { padding: 12px 14px; border-radius: 12px; background: var(--primary-soft); display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.alert-error { background: color-mix(in srgb, var(--neg) 12%, transparent); color: var(--text); }
.empty { text-align: center; padding: 40px 16px; color: var(--text-2); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 32px; color: var(--text-2); }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Folha modal ───────────────────────────────────────────────────────── */

dialog.sheet {
  width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; padding: 0;
  border: 0; border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
  display: flex; flex-direction: column;
}
dialog.sheet:not([open]) { display: none; }
dialog.sheet::backdrop { background: rgba(10, 12, 20, .5); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 8px; }
.sheet-head h2 { font-size: 17px; }
.sheet-body { padding: 4px 16px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; }
@media (min-width: 700px) {
  dialog.sheet { width: min(560px, 92vw); margin: auto; border-radius: 20px; max-height: 86dvh; }
}

.scan-frame { position: relative; border-radius: 16px; overflow: hidden; background: #000; aspect-ratio: 3 / 4; max-height: 60dvh; margin: 0 auto; width: 100%; }
.scan-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-target {
  position: absolute; inset: 18%; border: 3px solid rgba(255, 255, 255, .9); border-radius: 18px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .35);
}

/* ── Toasts ────────────────────────────────────────────────────────────── */

#toasts {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100% - 32px)); pointer-events: none;
}
.toast {
  padding: 12px 14px; border-radius: 12px; background: #1B1D26; color: #fff; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); transition: opacity .4s, transform .4s;
}
.toast-ok { background: #0B7A55; }
.toast-error { background: #B42318; }
.toast.leaving { opacity: 0; transform: translateY(8px); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
