/* Tema: escuro por padrão (estilo painel), claro opcional. Laranja = destaque. */
:root, :root[data-theme="dark"] {
  --bg: #0a0a0b; --card: #141416; --card2: #1b1b1e; --ink: #f4f4f5; --muted: #a1a1aa; --line: #26262b;
  --brand: #f97316; --brand2: #fb923c; --brand-ink: #160a02; --ok: #22c55e; --bad: #f43f5e; --warn: #f59e0b;
  --soft: rgba(249, 115, 22, .12); --green-soft: rgba(34, 197, 94, .14);
  --radius: 14px; --shadow: none; color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #faf8f5; --card: #ffffff; --card2: #f5f2ee; --ink: #1c1917; --muted: #78716c; --line: #ebe5de;
  --brand: #ea8a10; --brand2: #f59e0b; --brand-ink: #1c1917; --soft: rgba(234, 138, 16, .12); --green-soft: rgba(22, 163, 74, .12);
  --shadow: 0 1px 2px rgba(28, 25, 23, .05), 0 6px 20px rgba(28, 25, 23, .05); color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14.5px/1.45 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
h1, h2, h3, .kpi .v, .big, .brand { font-family: "Space Grotesk", Inter, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
.hidden { display: none !important; }

/* Cabeçalho + abas no topo */
.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.bar1 { max-width: 1240px; margin: 0 auto; display: flex; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 10px) 16px 6px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--ink); }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; color: #fff; font-size: 15px; }
.ws { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--ok) 45%, transparent); background: var(--green-soft); color: var(--ok); font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.ws::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.ws small { color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; font-size: 10px; }
.bar1 .sp { flex: 1; }
.iconbtn { background: none; border: 0; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; color: var(--muted); font-size: 16px; }
.iconbtn:hover { background: var(--card2); color: var(--ink); }
.who { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; border: 0; cursor: pointer; }
.tabsnav { max-width: 1240px; margin: 0 auto; display: flex; gap: 2px; overflow-x: auto; padding: 4px 12px 8px; scrollbar-width: none; }
.tabsnav::-webkit-scrollbar { display: none; }
.tabsnav a { color: var(--muted); padding: 6px 11px; border-radius: 8px; white-space: nowrap; font-size: 13.5px; font-weight: 500; }
.tabsnav a:hover { color: var(--ink); }
.tabsnav a.on { background: var(--card2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
main { max-width: 1240px; margin: 0 auto; padding: 18px 16px calc(96px + env(safe-area-inset-bottom)); }
.pagehead { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.pagehead h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.pagehead p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.pagehead .sp { flex: 1; }

/* Layout com menu lateral (Financeiro) */
.split { display: grid; gap: 18px; }
@media (min-width: 900px) { .split { grid-template-columns: 200px 1fr; } }
.side { display: flex; flex-direction: column; gap: 2px; }
.side .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 0 10px 6px; font-weight: 600; }
.side button { display: flex; align-items: center; gap: 10px; background: none; border: 0; text-align: left; padding: 8px 10px; border-radius: 9px; color: var(--muted); cursor: pointer; font-size: 13.5px; }
.side button:hover { color: var(--ink); background: var(--card2); }
.side button.on { color: var(--brand); background: var(--soft); font-weight: 600; }
.side .scopes { margin-top: 14px; display: flex; flex-direction: column; gap: 4px; }
.side .scopes button { border: 1px solid var(--line); }
.side .scopes button.on { border-color: color-mix(in srgb, var(--ok) 50%, transparent); background: var(--green-soft); color: var(--ok); }
@media (max-width: 899px) {
  .side { flex-direction: row; overflow-x: auto; scrollbar-width: none; gap: 6px; }
  .side .lbl { display: none; }
  .side button { white-space: nowrap; border: 1px solid var(--line); padding: 6px 11px; }
  .side .scopes { flex-direction: row; margin: 0; }
}

/* Componentes */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; border: 1px solid var(--line); }
.card h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
.card h2 .sp { flex: 1; }
.card h2 small { display: block; font: 400 12px Inter, sans-serif; color: var(--muted); margin-top: 1px; }
.hico { width: 34px; height: 34px; border-radius: 10px; background: var(--soft); color: var(--brand); display: grid; place-items: center; font-size: 16px; flex: none; }
.grid { display: grid; gap: 14px; }
@media (min-width: 760px) { .g2 { grid-template-columns: 1fr 1fr; } .g3 { grid-template-columns: repeat(3, 1fr); } .g21 { grid-template-columns: 2fr 1fr; } }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi .ki { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-size: 14px; background: var(--soft); color: var(--brand); margin-bottom: 10px; }
.kpi .v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: 12px; margin-top: 3px; }
.kpi .s { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.pos { color: var(--ok); } .neg { color: var(--bad); }
.muted { color: var(--muted); } .small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chk { width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line); background: none; display: grid; place-items: center; cursor: pointer; flex: none; font-size: 13px; color: var(--brand-ink); }
.chk.on { background: var(--brand); border-color: var(--brand); }
.btn { background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 10px; padding: 9px 15px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { filter: brightness(1.07); }
.btn.sec { background: var(--soft); color: var(--brand); }
.btn.out { background: none; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn.ghost { background: none; color: var(--muted); padding: 6px 8px; }
.btn.danger { background: none; color: var(--bad); }
.btn.sm { padding: 6px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; }
.fab { position: fixed; right: 20px; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 9; width: 52px; height: 52px; border-radius: 50%; font-size: 26px; padding: 0; justify-content: center; box-shadow: 0 8px 24px rgba(249, 115, 22, .35); }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 14px; scrollbar-width: none; }
.tabs button { border: 1px solid var(--line); background: var(--card); padding: 6px 12px; border-radius: 9px; white-space: nowrap; cursor: pointer; font-size: 13px; color: var(--muted); }
.tabs button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.pill { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--brand); white-space: nowrap; font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; font-size: 16px; }
.bar { height: 7px; border-radius: 99px; background: var(--card2); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.empty { color: var(--muted); text-align: center; padding: 20px 8px; font-size: 13.5px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .sp { flex: 1; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.monthnav { display: inline-flex; align-items: center; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
.monthnav b { min-width: 110px; text-align: center; font-size: 13px; }
.seg2 { display: inline-flex; background: var(--card2); border-radius: 9px; padding: 3px; border: 1px solid var(--line); }
.seg2 button { border: 0; background: none; padding: 4px 10px; border-radius: 7px; font-size: 12px; cursor: pointer; color: var(--muted); }
.seg2 button.on { background: var(--brand); color: var(--brand-ink); font-weight: 600; }

/* Cards de categoria ("Onde foi seu dinheiro") */
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.catc { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; text-align: left; color: inherit; }
.catc:hover { border-color: color-mix(in srgb, var(--brand) 50%, var(--line)); }
.catc .h { display: flex; align-items: center; gap: 10px; }
.catc .n { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.catc .s { color: var(--muted); font-size: 11.5px; margin-top: 8px; }
.bigv { font: 700 28px "Space Grotesk", sans-serif; letter-spacing: -.02em; }

/* Formulários */
label.f { display: block; margin-bottom: 11px; font-size: 12.5px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { display: block; width: 100%; margin-top: 5px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card2); color: var(--ink); font-size: 16px; }
label.f > input:focus, select:focus, textarea:focus, input:focus { outline: 2px solid color-mix(in srgb, var(--brand) 60%, transparent); outline-offset: 0; }
.inl { display: flex; gap: 8px; } .inl > * { flex: 1; min-width: 0; }
select.mini, input.mini { padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); color: var(--ink); }
.seg { display: flex; background: var(--card2); border-radius: 10px; padding: 3px; margin-bottom: 12px; border: 1px solid var(--line); }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.seg button.on.desp { color: var(--bad); } .seg button.on.rec { color: var(--ok); }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days button { width: 40px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--card2); cursor: pointer; font-size: 12px; }
.days button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .6); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); border: 1px solid var(--line); width: 100%; max-width: 540px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet h3 { margin: 0 0 14px; font-size: 19px; }
.sheet .acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
@media (min-width: 700px) { .modal { align-items: center; } .sheet { border-radius: 18px; } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 30; font-size: 14px; max-width: calc(100% - 32px); }

/* Login */
.login { max-width: 380px; margin: 12vh auto; padding: 0 16px; }
.login .brand { font-size: 22px; margin-bottom: 6px; }

/* Gráficos */
svg.chart { width: 100%; height: auto; max-height: 240px; display: block; }
svg.chart text { fill: var(--muted); font-size: 10px; font-family: Inter, sans-serif; }
svg.chart .grid { stroke: var(--line); stroke-width: 1; }
.heat { display: grid; grid-template-rows: repeat(7, 11px); grid-auto-flow: column; grid-auto-columns: 11px; gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heat i { width: 11px; height: 11px; border-radius: 3px; background: var(--card2); box-shadow: inset 0 0 0 1px var(--line); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; max-width: 640px; margin: 0 auto; }
.cal .wd { text-align: center; font-size: 11px; color: var(--muted); padding-bottom: 2px; }
.cal .d { aspect-ratio: 1 / .78; border-radius: 9px; background: var(--card2); border: 1px solid var(--line); padding: 5px 6px; display: flex; flex-direction: column; justify-content: space-between; font-size: 11px; color: var(--muted); min-height: 44px; }
.cal .d b { color: var(--ink); font-size: 12px; font-weight: 700; }
.cal .d.hot b, .cal .d.hot { color: #fff; }
.cal .d.today { outline: 2px solid var(--brand); outline-offset: -1px; }
.cal .d.out { visibility: hidden; }
.tracker { overflow-x: auto; }
.tracker table { border-collapse: collapse; font-size: 12px; }
.tracker th, .tracker td { padding: 2px; text-align: center; font-weight: 500; }
.tracker td.n { text-align: left; white-space: nowrap; padding-right: 10px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; position: sticky; left: 0; background: var(--card); }
.tracker button { width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line); background: var(--card2); cursor: pointer; padding: 0; }
.tracker button.on { background: var(--brand); border-color: var(--brand); }
.tracker button.off { opacity: .25; }
.tracker th.today { color: var(--brand); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* Chat */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; margin-bottom: 10px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; font-size: 14px; }
.msg.user { align-self: flex-end; background: var(--brand); color: var(--brand-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--card2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }

@media print {
  :root { --bg: #fff; --card: #fff; --card2: #f5f5f5; --ink: #000; --muted: #555; --line: #ddd; }
  .top, .fab, .noprint, .side { display: none !important; }
  .split { display: block; }
  main { padding: 0; max-width: none; }
  .card { break-inside: avoid; }
}

/* Ajustes de celular */
.split > *, .grid > * { min-width: 0; }
@media (max-width: 899px) { .side { align-items: center; } .side .scopes { align-items: center; } }
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px; } .kpi .v { font-size: 18px; }
  .pagehead h1 { font-size: 20px; }
  main { padding-top: 14px; }
  .ws small { display: none; }
}

/* Nada passa da largura da tela (sem arrastar para os lados) */
html, body { overflow-x: clip; max-width: 100%; }
.cal { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal .d { min-width: 0; overflow: hidden; }
.cal .d span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
img, svg, table { max-width: 100%; }
@media (max-width: 520px) {
  .cal { gap: 3px; }
  .cal .d { min-height: 0; aspect-ratio: 1 / 1; padding: 3px 4px; border-radius: 7px; font-size: 9px; }
  .cal .d b { font-size: 11px; }
  /* iPhone dá zoom sozinho em campo com letra < 16px: todos os campos com 16px */
  input, select, textarea, input.mini, select.mini { font-size: 16px !important; }
}
