/* ===== Design system: Financeiro =====
   Direção: papel frio + tinta petróleo. Números grandes em Bricolage Grotesque,
   interface em Instrument Sans. Uma cor de dados (petróleo); vermelho e âmbar só para estado. */
@font-face { font-family: "Instrument Sans"; src: url("/fonts/instrument-sans.woff2") format("woff2"); font-weight: 400 700; font-display: swap; }
@font-face { font-family: "Bricolage"; src: url("/fonts/bricolage.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }

:root {
  color-scheme: light;
  --bg: #eef1ef; --surface: #fbfcfb; --sunk: #e6ebe8; --line: #d9e0dc; --line-2: #e7ece9;
  --text: #121a17; --text-2: #46524d; --text-3: #5d6a65;
  --accent: #0f5f73; --accent-ink: #ffffff; --accent-soft: rgba(15,95,115,.32); --accent-wash: rgba(15,95,115,.08);
  --bad: #b4372a; --bad-wash: rgba(180,55,42,.09); --warn: #8a5a00; --warn-wash: rgba(200,140,0,.12);
  --focus: #0f5f73;
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px;
  --font-ui: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-num: "Bricolage", "Instrument Sans", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c1214; --surface: #131b1e; --sunk: #0f1618; --line: #233035; --line-2: #1b262a;
    --text: #e8eeec; --text-2: #adbab6; --text-3: #8696a1;
    --accent: #4fb3c9; --accent-ink: #06232b; --accent-soft: rgba(79,179,201,.34); --accent-wash: rgba(79,179,201,.10);
    --bad: #f08072; --bad-wash: rgba(240,128,114,.12); --warn: #e0a93b; --warn-wash: rgba(224,169,59,.12);
    --focus: #4fb3c9;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1214; --surface: #131b1e; --sunk: #0f1618; --line: #233035; --line-2: #1b262a;
  --text: #e8eeec; --text-2: #adbab6; --text-3: #8696a1;
  --accent: #4fb3c9; --accent-ink: #06232b; --accent-soft: rgba(79,179,201,.34); --accent-wash: rgba(79,179,201,.10);
  --bad: #f08072; --bad-wash: rgba(240,128,114,.12); --warn: #e0a93b; --warn-wash: rgba(224,169,59,.12);
  --focus: #4fb3c9;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font-ui); font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Controles ---- */
button, select, input { font: inherit; color: var(--text); }
button { cursor: pointer; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 8px 14px; min-height: 36px; transition: background .12s, border-color .12s; }
button:hover { background: var(--sunk); }
button:active { transform: translateY(1px); }
.prim { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.prim:hover { background: var(--accent); filter: brightness(1.08); }
.peq { padding: 3px 10px; font-size: 13px; min-height: 30px; }
.link { background: none; border: 0; color: var(--accent); padding: 0; min-height: 0; text-decoration: underline; text-underline-offset: 3px; }
select, input:not([type=checkbox]) { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 8px 10px; min-height: 38px; }
select { padding-right: 28px; }
input:focus, select:focus { border-color: var(--accent); }
label { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); }

/* ---- Estrutura ---- */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 22px 14px; border-right: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 22px; font: 650 19px/1 var(--font-num); letter-spacing: -.01em; }
.brand i { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; flex: none; }
.brand i::after { content: ""; position: absolute; left: 5px; right: 5px; bottom: 5px; height: 8px; border-radius: 1px; background: var(--accent-ink); clip-path: polygon(0 100%, 0 55%, 33% 55%, 33% 25%, 66% 25%, 66% 0, 100% 0, 100% 100%); }
.nav { display: grid; gap: 2px; }
.nav button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; color: var(--text-2); padding: 9px 10px; border-radius: var(--r-md); }
.nav button svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav button:hover { background: var(--sunk); color: var(--text); }
.nav button[aria-selected="true"] { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.side .fim { margin-top: auto; }
.side .fim button { width: 100%; background: none; border: 0; color: var(--text-3); text-align: left; padding: 9px 10px; }
.side .fim button:hover { color: var(--text); }

.content { padding: 26px clamp(16px, 3vw, 40px) 56px; max-width: 1180px; width: 100%; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.top h1 { font: 650 24px/1.2 var(--font-num); letter-spacing: -.015em; }
.top .qual { display: flex; align-items: center; gap: 8px; }
.top .qual label { display: block; color: var(--text-3); }

/* ---- Alertas ---- */
.alertas { display: grid; gap: 8px; margin-bottom: 20px; }
.alertas:empty { display: none; }
.alerta { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--r-md); background: var(--warn-wash); color: var(--text); border: 1px solid transparent; }
.alerta svg { width: 18px; height: 18px; flex: none; margin-top: 2px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.alerta b { font-weight: 650; margin-right: 6px; }
.alerta.aviso { color: var(--warn); }
.alerta.aviso span { color: var(--text); }
.alerta.critico { background: var(--bad-wash); color: var(--bad); }
.alerta.critico span { color: var(--text); }

/* ---- Hero (fatura selecionada) ---- */
.hero { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: clamp(20px, 4vw, 56px); align-items: center; padding: 6px 0 26px; margin-bottom: 26px; border-bottom: 1px solid var(--line); }
.hero .rot { color: var(--text-2); font-size: 14px; }
.hero .val { font: 600 clamp(40px, 7vw, 68px)/1.02 var(--font-num); letter-spacing: -.03em; margin: 6px 0 8px; font-variation-settings: "wdth" 100; }
.hero .delta { font-size: 14px; color: var(--text-2); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--sunk); color: var(--text-2); }
.chip.up { background: var(--bad-wash); color: var(--bad); }
.chip.down { background: var(--accent-wash); color: var(--accent); }
.outras { display: grid; margin: 0; }
.outras > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.outras > div:first-child { border-top: 0; padding-top: 0; }
.outras dt { color: var(--text-2); font-size: 14px; }
.outras dt small { display: block; color: var(--text-3); font-size: 12px; }
.outras dd { margin: 0; font: 600 20px/1.2 var(--font-num); letter-spacing: -.01em; white-space: nowrap; }

/* ---- Seções do painel ---- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 28px; }
.full { grid-column: 1 / -1; }
.sec { min-width: 0; }
.sec + .sec.linha, .sec.linha { border-top: 1px solid var(--line); padding-top: 22px; }
.sec h2, .panel h2 { font: 650 16px/1.3 var(--font-ui); color: var(--text); letter-spacing: 0; }
.sec .dica, .panel .ajuda { color: var(--text-3); font-size: 13px; margin: 2px 0 14px; }
.sec h2 + .chart, .sec h2 + .bars, .sec h2 + .tb { margin-top: 14px; }
.chart { position: relative; height: 250px; }
.chart.baixo { height: 220px; }

/* ---- Barras de progresso / ranking ---- */
.bars { display: grid; gap: 14px; }
.bar-row .top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 14px; margin-bottom: 6px; }
.bar-row .top > span:first-child { display: flex; align-items: baseline; gap: 4px; flex-wrap: wrap; min-width: 0; }
.bar-row .top > span:last-child { color: var(--text-2); white-space: nowrap; }
.track { height: 6px; background: var(--sunk); border-radius: 3px; overflow: hidden; }
.fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .5s cubic-bezier(.2,.7,.2,1); }
.fill.estourou { background: var(--bad); }
.tag { font-size: 12px; color: var(--text-2); background: var(--sunk); border-radius: 99px; padding: 1px 8px; margin-left: 6px; white-space: nowrap; }
.pct-tag { font-size: 12px; color: var(--bad); background: var(--bad-wash); border-radius: 99px; padding: 1px 8px; margin-left: 6px; font-weight: 600; white-space: nowrap; }

/* ---- Tabelas ---- */
.tb { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--text-3); font-weight: 500; font-size: 13px; border-bottom: 1px solid var(--line); padding: 8px 10px 8px 0; white-space: nowrap; }
td { padding: 10px 10px 10px 0; border-bottom: 1px solid var(--line-2); vertical-align: baseline; }
td.n, th.n { text-align: right; padding-right: 0; padding-left: 10px; }
tbody tr:hover td { background: var(--accent-wash); }
tr:last-child td { border-bottom: 0; }
.acoes { white-space: nowrap; text-align: right; padding-right: 0; }
.acoes button + button { margin-left: 4px; }
.mini td, .mini th { padding-top: 8px; padding-bottom: 8px; }
.proj-hoje td { font-weight: 600; }

/* ---- Painéis (metas, cadastros) ---- */
.stack { display: grid; gap: 28px; }
.panel { min-width: 0; }
.panel + .panel, .stack > .panel { border-top: 1px solid var(--line); padding-top: 24px; }
.stack > .panel:first-child { border-top: 0; padding-top: 0; }
.panel .cab { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.vazio { color: var(--text-3); padding: 14px 0; font-size: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0; }
.card { padding: 4px 24px 4px 0; }
.card + .card { padding-left: 24px; border-left: 1px solid var(--line); }
.card .rot { color: var(--text-2); font-size: 14px; }
.card .val { font: 600 30px/1.15 var(--font-num); letter-spacing: -.02em; margin-top: 4px; }
.card .sub { color: var(--text-3); font-size: 13px; margin-top: 2px; }
.inline { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }

/* ---- Modal ---- */
dialog { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); color: var(--text); padding: 24px; width: min(440px, 92vw); box-shadow: 0 24px 60px -20px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(8,14,16,.5); backdrop-filter: blur(2px); }
dialog[open] { animation: abre .16s ease-out; }
@keyframes abre { from { opacity: 0; transform: translateY(6px) scale(.985); } }
dialog form { display: grid; gap: 14px; }
dialog h2 { font: 650 18px/1.3 var(--font-num); }
dialog .check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
dialog .rod { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.erro { color: var(--bad); font-size: 14px; }
.erro:empty { display: none; }
.erro.topo { margin-bottom: 14px; padding: 10px 14px; background: var(--bad-wash); border-radius: var(--r-md); }
.ok { color: var(--accent); font-size: 14px; }

/* ---- Carregando ---- */
.skel { background: linear-gradient(90deg, var(--sunk) 25%, var(--line-2) 50%, var(--sunk) 75%); background-size: 200% 100%; animation: brilho 1.3s linear infinite; border-radius: var(--r-md); }
@keyframes brilho { to { background-position: -200% 0; } }
body.carregando .hero .val { color: transparent; width: 9ch; border-radius: var(--r-md); background: linear-gradient(90deg, var(--sunk) 25%, var(--line-2) 50%, var(--sunk) 75%); background-size: 200% 100%; animation: brilho 1.3s linear infinite; }

/* ---- Login ---- */
.login-pg { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: min(380px, 100%); }
.login .brand { display: flex; padding: 0 0 28px; font-size: 22px; }
.login h1 { font: 650 28px/1.15 var(--font-num); letter-spacing: -.02em; margin-bottom: 6px; }
.login p.sub { margin: 0 0 22px; color: var(--text-2); }
.login form { display: grid; gap: 14px; }
.login input { width: 100%; }
.login .prim { min-height: 42px; margin-top: 4px; }

/* ---- Tablet e celular ---- */
@media (max-width: 960px) {
  .hero { grid-template-columns: 1fr; align-items: start; }
  .grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: auto 0 0 0; height: auto; flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); z-index: 20; }
  .brand, .side .fim { display: none; }
  .nav { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; }
  .nav button { flex-direction: column; gap: 2px; font-size: 12px; text-align: center; padding: 6px 4px; justify-content: center; }
  .content { padding: 18px 14px 96px; }
  .top h1 { font-size: 21px; }
  .card { padding: 10px 0; }
  .card + .card { padding-left: 0; border-left: 0; border-top: 1px solid var(--line); }
  .cards { grid-template-columns: 1fr; }
  .chart { height: 220px; }
  .mini th { white-space: normal; }
  .mini td, .mini th { padding-right: 4px; font-size: 12.5px; }
  .mini td.n, .mini th.n { padding-left: 4px; }
  .mini td:first-child { white-space: nowrap; }
  .stack { gap: 24px; }
  /* lançamentos: descrição ganha a linha, valor ao lado */
  .tb.res table, .tb.res tbody, .tb.res tr, .tb.res td { display: block; }
  .tb.res thead { display: none; }
  .tb.res tr { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
  .tb.res td { border: 0; padding: 0; }
  .tb.res td:nth-child(2) { grid-column: 1; grid-row: 1; font-weight: 500; }
  .tb.res td:nth-child(3) { grid-column: 1; grid-row: 2; color: var(--text-3); font-size: 13px; }
  .tb.res td:nth-child(1) { grid-column: 1; grid-row: 3; color: var(--text-3); font-size: 13px; }
  .tb.res td:nth-child(4) { grid-column: 2; grid-row: 1 / span 3; align-self: center; font-weight: 600; }
  .tb.res tr:hover td { background: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
