/* Cartão Fácil — estilo (claro e escuro), pensado para iPhone instalado na Tela de Início. */
:root {
  color-scheme: light;
  --page: #f2f2f0;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7873;
  --hairline: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-1-soft: #86b6ef;
  --meter-track: #cde2fb;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --danger-ink: #b42323;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 16px;
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: system-ui, -apple-system, "SF Pro Text", "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #252524;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9a988f;
    --hairline: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-1-soft: #184f95;
    --meter-track: #104281;
    --good-ink: #0ca30c;
    --danger-ink: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #252524; --text: #f0efec; --text-2: #c3c2b7;
  --muted: #9a988f; --hairline: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-wash: rgba(57, 135, 229, 0.16);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-1-soft: #184f95;
  --meter-track: #104281; --good-ink: #0ca30c; --danger-ink: #e66767; --shadow: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--page); color: var(--text); }
body {
  font-size: 16px; line-height: 1.4; min-height: 100dvh;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-ink); }
[hidden] { display: none !important; }

#app { padding: calc(var(--safe-t) + 8px) 16px calc(var(--tabbar-h) + var(--safe-b) + 24px); max-width: 640px; margin: 0 auto; }
.boot { display: grid; place-items: center; min-height: 70dvh; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--hairline); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- cabeçalho */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0 8px; }
.page-head h1 { font-size: 28px; line-height: 1.15; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.page-head .sub { color: var(--text-2); font-size: 14px; margin-top: 2px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--accent-ink); background: none; border: 0; padding: 8px 0; font-size: 17px; cursor: pointer; }

/* ---------- cartões (blocos) */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); padding: 16px; margin: 12px 0; }
.card h2 { font-size: 17px; margin: 0 0 12px; font-weight: 650; }
.card h2 .count { color: var(--muted); font-weight: 500; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 22px 4px 6px; font-weight: 600; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- herói: fatura atual */
.hero .label { font-size: 15px; color: var(--text-2); }
.hero .value { font-size: 46px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; margin: 4px 0 6px; }
.hero .meta { font-size: 14px; color: var(--text-2); }
.hero-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.tile .t-label { font-size: 13px; color: var(--text-2); }
.tile .t-value { font-size: 19px; font-weight: 650; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .t-delta { font-size: 12.5px; margin-top: 2px; color: var(--text-2); }

/* ---------- medidor (meta) */
.meter { margin-top: 16px; }
.meter-track { position: relative; height: 10px; border-radius: 999px; background: var(--meter-track); overflow: visible; }
.meter-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--accent); }
.meter-fill.warn { background: var(--warning); }
.meter-fill.bad { background: var(--critical); }
.meter-proj { position: absolute; top: 0; bottom: 0; background: var(--accent); opacity: 0.35; border-radius: 0 999px 999px 0; }
.meter-proj.warn { background: var(--warning); }
.meter-proj.bad { background: var(--critical); }
.meter-key { display: inline-block; width: 14px; height: 6px; border-radius: 3px; background: var(--accent); opacity: 0.35; margin-right: 6px; vertical-align: 1px; }
.meter-mark { position: absolute; top: -4px; width: 2px; height: 18px; background: var(--text); border-radius: 1px; }
.meter-legend { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-2); margin-top: 8px; gap: 8px; }

/* ---------- estado (ícone + texto) */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.status.good { color: var(--good-ink); }
.status.good::before { background: var(--good); }
.status.warn { color: var(--text); }
.status.warn::before { background: var(--warning); }
.status.bad { color: var(--danger-ink); }
.status.bad::before { background: var(--critical); }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--surface-2); margin-top: 8px; font-size: 14.5px; }
.alert .ic { font-size: 18px; line-height: 1.2; }
.alert b { font-weight: 650; }
.alert a, .alert button.link { margin-left: auto; white-space: nowrap; }

/* ---------- listas */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--hairline); }
.list > li:first-child { border-top: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 11px 0; width: 100%; background: none; border: 0; text-align: left; cursor: pointer; color: inherit; }
.item .ic { width: 38px; height: 38px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-size: 19px; flex: none; }
.item .body { flex: 1; min-width: 0; display: block; }
.item .title, .item .desc { display: block; }
.item .title { font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .desc .badge { margin-right: 4px; }
.item .desc { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .amt { flex: none; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }
.item .amt .sub { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.item .chev { color: var(--muted); font-size: 20px; }
.date-head { font-size: 13px; color: var(--muted); font-weight: 600; padding: 14px 0 2px; }
.date-head::first-letter { text-transform: uppercase; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 650; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); vertical-align: 1px; }
.badge.accent { background: var(--accent-wash); color: var(--accent-ink); }
.badge.bad { background: rgba(208, 59, 59, 0.14); color: var(--danger-ink); }
.badge.good { background: rgba(12, 163, 12, 0.14); color: var(--good-ink); }
.empty { text-align: center; color: var(--text-2); padding: 28px 12px; }
.empty .big { font-size: 34px; margin-bottom: 6px; }

/* ---------- barras horizontais (categorias) */
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { padding: 7px 0; }
.bars .bar-row { display: flex; justify-content: space-between; gap: 8px; font-size: 14.5px; }
.bars .bar-row .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .bar-row .val { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text); font-weight: 560; }
.bars .bar-row .val small { color: var(--muted); font-weight: 500; }
.bars .track { height: 8px; margin-top: 5px; border-radius: 0 4px 4px 0; position: relative; }
.bars .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.bars .budget { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); border-radius: 1px; }

/* ---------- barra segmentada (pessoas) */
.seg { display: flex; gap: 2px; height: 8px; border-radius: 999px; overflow: hidden; margin: 4px 0 12px; }
.seg span { display: block; height: 100%; }
.seg span:first-child { border-radius: 999px 0 0 999px; }
.seg span:last-child { border-radius: 0 999px 999px 0; }
.seg span:only-child { border-radius: 999px; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 14.5px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .lv { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 560; }
.legend.inline { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 8px; }
.legend.inline li { font-size: 13px; color: var(--text-2); }

/* ---------- gráfico de colunas */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--hairline); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .xl { fill: var(--muted); font-size: 11px; }
.chart .xl.cur { fill: var(--text); font-weight: 650; }
.chart .col-a { fill: var(--series-1); }
.chart .col-b { fill: var(--series-1-soft); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit.on { fill: var(--accent-wash); }
.tooltip { position: absolute; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18); border-radius: 10px; padding: 8px 10px; font-size: 13px; min-width: 150px; transform: translateX(-50%); white-space: nowrap; z-index: 5; }
.tooltip b { display: block; margin-bottom: 4px; }
.tooltip .tr { display: flex; align-items: center; gap: 6px; }
.tooltip .tr span:last-child { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }

/* ---------- seletor de fatura e filtros */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin: 8px 0; }
.month-nav button { background: none; border: 0; font-size: 22px; width: 44px; height: 40px; border-radius: 10px; cursor: pointer; color: var(--accent-ink); }
.month-nav button:active { background: var(--surface-2); }
.month-nav .mid { text-align: center; }
.month-nav .mid b { display: block; }
.month-nav .mid span { font-size: 12.5px; color: var(--text-2); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 13px; font-size: 14px; white-space: nowrap; cursor: pointer; }
.chip.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.search { width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 10px 12px; font-size: 16px; }

/* ---------- formulários */
.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 5px; font-weight: 560; }
.field .hint { display: block; font-size: 12.5px; color: var(--muted); margin-top: 4px; font-weight: 400; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; appearance: none; -webkit-appearance: none;
}
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
textarea.input { min-height: 96px; resize: vertical; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.input.money { font-size: 30px; font-weight: 650; padding: 10px 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-2 .field { margin: 6px 0; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; font-size: 15px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 12px 18px; font-size: 16px; font-weight: 600; cursor: pointer; background: var(--surface-2); color: var(--text); text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: var(--danger-ink); }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: 0.55; }
.btn:active { transform: scale(0.98); }
.actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.actions .btn { flex: 1; }
button.link { background: none; border: 0; color: var(--accent-ink); padding: 0; font-size: inherit; cursor: pointer; font-weight: 560; }
.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; word-break: break-all; display: block; }
.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row .code { flex: 1; }
.steps { padding-left: 20px; margin: 8px 0; }
.steps li { margin: 8px 0; }
.steps b { font-weight: 650; }
.raw { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border-radius: 8px; padding: 8px; white-space: pre-wrap; word-break: break-word; margin: 6px 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-weight: 560; word-break: break-word; }

/* ---------- auth */
.auth { max-width: 420px; margin: 0 auto; padding-top: 6vh; }
.auth .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 12px; }
.auth h1 { text-align: center; font-size: 26px; margin: 0 0 4px; }
.auth p.lead { text-align: center; color: var(--text-2); margin: 0 0 18px; }
.error { color: var(--danger-ink); font-size: 14px; margin-top: 8px; }

/* ---------- barra de abas */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around;
  padding: 6px 4px calc(var(--safe-b) + 6px); background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--border);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 560; padding: 4px 0; position: relative; }
.tabbar a .ti { font-size: 21px; line-height: 1.1; filter: grayscale(1); opacity: 0.75; }
.tabbar a.on { color: var(--accent-ink); }
.tabbar a.on .ti { filter: none; opacity: 1; }
.tabbar .dot { position: absolute; top: 0; left: calc(50% + 8px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; background: var(--critical); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

/* ---------- botão flutuante */
.fab { position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px); width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 30px; line-height: 1; box-shadow: 0 6px 20px rgba(42, 120, 214, 0.35); z-index: 15; cursor: pointer; }

/* ---------- folha (modal de baixo para cima) */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 40; animation: fade 0.18s ease; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92dvh; overflow-y: auto; background: var(--surface); border-radius: 18px 18px 0 0; padding: 8px 16px calc(var(--safe-b) + 20px); max-width: 640px; margin: 0 auto; animation: up 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); -webkit-overflow-scrolling: touch; }
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--hairline); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.sheet-head h3 { margin: 0; font-size: 18px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + var(--safe-b) + 86px); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 12px; font-size: 14.5px; z-index: 60; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); text-align: center; }

details.more summary { cursor: pointer; color: var(--accent-ink); font-weight: 560; list-style: none; padding: 6px 0; }
details.more summary::-webkit-details-marker { display: none; }

@media (min-width: 700px) {
  .hero-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
@media (forced-colors: active) {
  .bars .fill, .meter-fill, .seg span, .chart .col-a, .chart .col-b { forced-color-adjust: none; }
}
