/* ==========================================================================
   Visualizador de OFX — tokens
   ========================================================================== */
:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --line: #e2e0d8;
  --line-strong: #cfccc1;
  --ink: #1b2430;
  --ink-2: #4a5462;
  --ink-3: #7a8290;
  --brand: #1f3a5f;
  --brand-ink: #ffffff;
  --brand-soft: #e6ecf4;
  --credit: #1d7a46;
  --credit-soft: #e5f3ea;
  --debit: #b4312b;
  --debit-soft: #f9e8e6;
  --warn: #9a6400;
  --warn-soft: #fdf1d8;
  --excel: #17703f;
  --excel-hover: #125c33;
  --excel-ink: #ffffff;
  --focus: #2f6fd6;
  --tag: #1f5fa8;
  --tag-attr: #8a4c00;
  --raw-bg: #fbfaf7;
  --shadow: 0 1px 2px rgba(20, 30, 45, .05), 0 2px 8px rgba(20, 30, 45, .04);
  --shadow-lg: 0 18px 50px rgba(20, 30, 45, .18);
  --radius: 10px;
  --radius-sm: 7px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c;
    --surface: #1a1f27;
    --surface-2: #222833;
    --line: #2c3340;
    --line-strong: #3a4352;
    --ink: #e8ebf0;
    --ink-2: #b3bac6;
    --ink-3: #848c99;
    --brand: #8fb4e8;
    --brand-ink: #0f1622;
    --brand-soft: #1f2b3d;
    --credit: #5cc98b;
    --credit-soft: #173225;
    --debit: #f0807a;
    --debit-soft: #3a1f1e;
    --warn: #f0c060;
    --warn-soft: #3a2f17;
    --excel: #2a9d5c;
    --excel-hover: #33b06a;
    --excel-ink: #ffffff;
    --focus: #7aa7f0;
    --tag: #86b6f5;
    --tag-attr: #e6b26a;
    --raw-bg: #151a21;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c;
  --surface: #1a1f27;
  --surface-2: #222833;
  --line: #2c3340;
  --line-strong: #3a4352;
  --ink: #e8ebf0;
  --ink-2: #b3bac6;
  --ink-3: #848c99;
  --brand: #8fb4e8;
  --brand-ink: #0f1622;
  --brand-soft: #1f2b3d;
  --credit: #5cc98b;
  --credit-soft: #173225;
  --debit: #f0807a;
  --debit-soft: #3a1f1e;
  --warn: #f0c060;
  --warn-soft: #3a2f17;
  --excel: #2a9d5c;
  --excel-hover: #33b06a;
  --excel-ink: #ffffff;
  --focus: #7aa7f0;
  --tag: #86b6f5;
  --tag-attr: #e6b26a;
  --raw-bg: #151a21;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
code { font-family: var(--mono); font-size: .9em; }

/* ==========================================================================
   Topo
   ========================================================================== */
.topo { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topo-inner { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.marca { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 650; letter-spacing: -.01em; }
.marca-icone { color: var(--brand); display: flex; }
.marca-texto { font-size: 16px; }
.topo-acoes { display: flex; align-items: center; gap: 10px; }
.selo-privacidade {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--credit); background: var(--credit-soft);
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}
.btn-icone {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; cursor: pointer; color: var(--ink-2);
}
.btn-icone:hover { background: var(--surface-2); color: var(--ink); }
.ico-lua { display: none; }
:root[data-theme="dark"] .ico-sol { display: none; }
:root[data-theme="dark"] .ico-lua { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ico-sol { display: none; }
  :root:not([data-theme="light"]) .ico-lua { display: block; }
}

/* ==========================================================================
   Botões
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer; font-weight: 600; font-size: 14.5px;
  text-decoration: none; white-space: nowrap; transition: background-color .15s, border-color .15s, color .15s;
}
.btn-peq { height: 34px; padding: 0 12px; font-size: 13.5px; }
.btn-primario { background: var(--brand); color: var(--brand-ink); }
.btn-primario:hover { filter: brightness(1.08); }
.btn-secundario { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secundario:hover { background: var(--surface-2); }
.btn-link { background: none; border: 0; color: var(--brand); padding: 0 4px; height: auto; text-decoration: underline; text-underline-offset: 3px; font-weight: 600; }
.btn-excel { background: var(--excel); color: var(--excel-ink); height: 44px; padding: 0 20px; font-size: 15px; box-shadow: 0 1px 0 rgba(0,0,0,.08), 0 4px 14px rgba(23, 112, 63, .25); }
.btn-excel:hover { background: var(--excel-hover); }
.btn-excel[disabled] { opacity: .6; cursor: progress; }

/* ==========================================================================
   Tela inicial
   ========================================================================== */
main { flex: 1; width: 100%; }
.tela-inicial { max-width: 760px; margin: 0 auto; padding: 56px 16px 40px; }
.intro h1 { font-size: clamp(26px, 4vw, 36px); line-height: 1.15; letter-spacing: -.02em; margin: 0 0 12px; font-weight: 700; }
.intro-sub { color: var(--ink-2); font-size: 16.5px; margin: 0 0 28px; max-width: 62ch; }
.zona-soltar {
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  padding: 44px 20px; border: 2px dashed var(--line-strong); border-radius: 14px; background: var(--surface);
  color: var(--ink-3); cursor: pointer; transition: border-color .15s, background-color .15s;
}
.zona-soltar:hover, .zona-soltar.arrastando { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.zona-titulo { font-size: 18px; font-weight: 650; color: var(--ink); }
.zona-sub { font-size: 13px; }
.zona-dica { font-size: 13px; margin-top: 4px; }
.inicial-rodape { margin-top: 18px; display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; }
.aviso-privacidade { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--ink-3); max-width: 60ch; margin: 0; text-align: left; }
.aviso-privacidade svg { flex: none; margin-top: 3px; color: var(--credit); }

/* ==========================================================================
   Tela do extrato
   ========================================================================== */
.tela-extrato { max-width: 1280px; margin: 0 auto; padding: 18px 16px 40px; }

.abas-contas { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.abas-contas-lista { display: flex; gap: 6px; overflow-x: auto; flex: 1; min-width: 0; padding-bottom: 2px; scrollbar-width: thin; }
.aba-conta {
  display: inline-flex; align-items: center; gap: 2px; flex: none;
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; color: var(--ink-2);
}
.aba-conta > button.aba-sel { background: none; border: 0; padding: 7px 4px 7px 12px; cursor: pointer; text-align: left; line-height: 1.25; }
.aba-conta .aba-banco { display: block; font-weight: 600; font-size: 13.5px; color: var(--ink); }
.aba-conta .aba-sub { display: block; font-size: 12px; color: var(--ink-3); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aba-conta.ativa { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); background: var(--brand-soft); }
.aba-fechar { background: none; border: 0; width: 28px; height: 28px; margin-right: 4px; border-radius: 6px; cursor: pointer; color: var(--ink-3); display: grid; place-items: center; }
.aba-fechar:hover { background: var(--surface-2); color: var(--debit); }

.cabecalho-conta {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); display: grid; gap: 14px;
}
.cc-topo { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 14px; }
.cc-banco { font-size: 22px; font-weight: 700; letter-spacing: -.015em; margin: 0; }
.cc-tipo { font-size: 13px; color: var(--brand); background: var(--brand-soft); padding: 2px 9px; border-radius: 999px; font-weight: 600; }
.cc-dados { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 20px; margin: 0; }
.cc-dados div { min-width: 0; }
.cc-dados dt { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; }
.cc-dados dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.cc-arquivo { font-size: 12.5px; color: var(--ink-3); border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-wrap: wrap; gap: 4px 16px; }

.barra-acoes { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.barra-acoes-info { font-size: 13px; color: var(--ink-3); }

.cartoes { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
.cartao { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.cartao-rotulo { font-size: 12.5px; color: var(--ink-3); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.cartao-valor { font-size: 21px; font-weight: 700; letter-spacing: -.015em; margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cartao-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.cartao .ponto { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.ponto-credit { background: var(--credit); }
.ponto-debit { background: var(--debit); }
.pos { color: var(--credit); }
.neg { color: var(--debit); }

.sub-abas { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.sub-aba { background: none; border: 0; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--ink-3); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.sub-aba:hover { color: var(--ink); }
.sub-aba.ativa { color: var(--ink); border-bottom-color: var(--brand); }

/* Filtros */
.filtros { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 10px; }
.campo { display: inline-flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); height: 38px; padding: 0 10px; color: var(--ink-3); }
.campo:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
.campo input { border: 0; background: none; outline: none; height: 100%; color: var(--ink); min-width: 0; }
.campo-busca { flex: 1 1 260px; }
.campo-busca input { width: 100%; }
.campo-data span { font-size: 13px; font-weight: 600; }
.campo-data input { width: 132px; }
.segmentado { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; height: 38px; background: var(--surface); }
.segmentado button { border: 0; background: none; padding: 0 13px; cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.segmentado button + button { border-left: 1px solid var(--line); }
.segmentado button.ativo { background: var(--brand); color: var(--brand-ink); }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--ink-2); cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }

/* Tabela */
.tabela-meta { font-size: 13px; color: var(--ink-3); margin: 4px 0 8px; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.tabela-meta strong { color: var(--ink-2); }
.tabela-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); max-height: 72vh; }
.tabela { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.tabela th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); border-bottom: 1px solid var(--line-strong); padding: 0; white-space: nowrap; }
.tabela th button { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 5px; width: 100%; padding: 10px 12px; cursor: pointer; font-weight: 700; }
.tabela th button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tabela th button::after { content: ""; width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; opacity: .25; border-top: 5px solid currentColor; }
.tabela th[aria-sort="ascending"] button::after { border-top: 0; border-bottom: 5px solid currentColor; opacity: 1; }
.tabela th[aria-sort="descending"] button::after { opacity: 1; }
.tabela th[aria-sort] { color: var(--ink); }
.tabela th.col-num button { justify-content: flex-end; }
.tabela td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tabela tbody tr:hover td { background: color-mix(in srgb, var(--brand-soft) 55%, transparent); }
.tabela tbody tr:last-child td { border-bottom: 0; }
.col-data { white-space: nowrap; font-variant-numeric: tabular-nums; width: 1%; }
.col-desc { min-width: 240px; }
.col-tipo { white-space: nowrap; color: var(--ink-2); width: 1%; }
.col-doc { font-family: var(--mono); font-size: 12.5px; color: var(--ink-3); overflow-wrap: anywhere; min-width: 120px; max-width: 220px; }
.col-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; width: 1%; }
td.col-num { font-weight: 600; }
td.saldo { color: var(--ink-2); font-weight: 500; }
.desc-principal { display: block; }
.desc-sec { display: block; color: var(--ink-3); font-size: 12.5px; }
.badge-dup { display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 700; color: var(--warn); background: var(--warn-soft); border-radius: 4px; padding: 1px 6px; vertical-align: 1px; cursor: help; white-space: nowrap; }
tr.dup td { background: color-mix(in srgb, var(--warn-soft) 60%, transparent); }
tr.dup td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.tabela tfoot td { position: sticky; bottom: 0; background: var(--surface-2); border-top: 1px solid var(--line-strong); border-bottom: 0; font-weight: 700; }
.tabela-vazia { padding: 30px; text-align: center; color: var(--ink-3); margin: 0; }
mark { background: color-mix(in srgb, #ffd54a 55%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; }
.nota { font-size: 12.5px; color: var(--ink-3); margin: 10px 2px 0; }

/* Arquivo bruto */
.bruto-info { font-size: 13px; color: var(--ink-2); margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.bruto-info strong { color: var(--ink); }
.bruto {
  margin: 0; background: var(--raw-bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 0; font: 12.5px/1.6 var(--mono); overflow: auto; max-height: 75vh; counter-reset: linha; tab-size: 2;
}
.bruto .ln { display: block; padding: 0 16px 0 0; white-space: pre; }
.bruto .ln::before { counter-increment: linha; content: counter(linha); display: inline-block; width: 4.5em; padding-right: 1em; margin-right: 1em; text-align: right; color: var(--ink-3); opacity: .6; border-right: 1px solid var(--line); user-select: none; }
.bruto .t { color: var(--tag); font-weight: 600; }
.bruto .tf { color: var(--ink-3); }
.bruto .h { color: var(--tag-attr); }
.bruto .tr { background: color-mix(in srgb, var(--brand-soft) 60%, transparent); }

/* Sobreposição de arrastar */
.sobreposicao { position: fixed; inset: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 75%, transparent); backdrop-filter: blur(2px); display: grid; place-items: center; pointer-events: none; }
.sobreposicao-caixa { border: 2px dashed var(--brand); background: var(--surface); color: var(--brand); padding: 30px 40px; border-radius: 14px; font-weight: 700; font-size: 18px; box-shadow: var(--shadow-lg); }

/* Diálogo */
.dialogo { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--surface); color: var(--ink); width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); }
.dialogo::backdrop { background: rgba(10, 15, 25, .45); }
.dialogo-form { padding: 22px 22px 18px; display: grid; gap: 14px; }
.dialogo h2 { margin: 0; font-size: 19px; }
.dialogo fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; }
.dialogo legend { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--ink-3); margin-bottom: 6px; padding: 0; }
.opcao { display: flex; align-items: flex-start; gap: 10px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.opcao:has(input:checked) { border-color: var(--excel); background: color-mix(in srgb, var(--excel) 8%, transparent); }
.opcao input { margin-top: 4px; accent-color: var(--excel); }
.opcao small { display: block; color: var(--ink-3); font-size: 12.5px; font-weight: 400; }
.dialogo-arquivo { margin: 0; font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }
.dialogo-desc { margin: 0; font-size: 13px; color: var(--ink-3); }
.dialogo-erro { margin: 0; color: var(--debit); font-size: 13.5px; }
.dialogo-botoes { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* Toasts */
.toasts { position: fixed; bottom: 16px; right: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 60; pointer-events: none; }
.toast { pointer-events: auto; max-width: 440px; background: var(--ink); color: var(--bg); padding: 11px 14px; border-radius: 9px; font-size: 13.5px; box-shadow: var(--shadow-lg); }
.toast.erro { background: var(--debit); color: #fff; }
.toast.ok { background: var(--excel); color: #fff; }

.rodape { text-align: center; font-size: 12px; color: var(--ink-3); padding: 18px 16px 24px; }

/* ==========================================================================
   Responsivo
   ========================================================================== */
@media (max-width: 1100px) {
  .cartoes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .selo-privacidade span { display: none; }
  .selo-privacidade { padding: 6px; }
  .tela-inicial { padding-top: 32px; }
  .cartoes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cartao-valor { font-size: 18px; }
  .abas-contas { flex-direction: column; align-items: stretch; }
  .barra-acoes .btn-excel { flex: 1 1 100%; }
  .barra-acoes .btn-secundario { flex: 1; }
  .campo-data { flex: 1 1 140px; }
  .campo-data input { width: 100%; }
  .segmentado { flex: 1 1 100%; }
  .segmentado button { flex: 1; }
  .cabecalho-conta { padding: 14px; }
  .cc-banco { font-size: 19px; }
  .tabela { font-size: 13.5px; }
  .col-doc, .col-tipo { display: none; }
  .col-desc { min-width: 150px; }
  .tabela td, .tabela th button { padding-left: 9px; padding-right: 9px; }
  .tabela tfoot td { font-size: 12.5px; }
}
@media (max-width: 420px) {
  .cartoes { grid-template-columns: 1fr; }
}
