:root {
  color-scheme: light;
  --surface-0: #f3f2ee;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e1dfd8;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77756f;
  --series-1: #2a78d6;
  --track: #e8e6e0;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --warning: #fab219;
  --critical: #d03b3b;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #262624;
    --border: #33332f;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9a998f;
    --series-1: #3987e5;
    --track: #2c2c29;
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --critical: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #262624;
  --border: #33332f;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #9a998f;
  --series-1: #3987e5;
  --track: #2c2c29;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --critical: #e66767;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, p { margin: 0; }
h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1rem; font-weight: 650; }
button, input, select, textarea { font: inherit; color: inherit; }

.topo {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: color-mix(in srgb, var(--surface-0) 88%, transparent);
  backdrop-filter: blur(10px);
}
.sobretitulo { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
main { max-width: 720px; margin: 0 auto; padding: 0 16px 32px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }

.cartao {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; min-width: 0;
}
.cab-secao { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.cartao > h2 { margin-bottom: 12px; }
.rotulo { color: var(--text-secondary); font-size: .9rem; }
.sub { color: var(--text-secondary); font-size: .88rem; }
.vazio { text-align: center; padding: 24px 0 8px; }

.hero { display: grid; gap: 6px; }
.numero-hero { font-size: clamp(2.2rem, 11vw, 3.2rem); font-weight: 750; letter-spacing: -0.03em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.barra-orc { height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; margin-top: 8px; }
.barra-orc span { display: block; height: 100%; border-radius: 999px; background: var(--series-1); width: 0; transition: width .4s; }
.aviso-pendente {
  justify-self: start; margin-top: 6px; border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 999px; padding: 6px 12px; font-size: .88rem; cursor: pointer;
}

/* barras horizontais por etapa */
.barras-h { display: grid; gap: 12px; }
.barra-linha { display: grid; gap: 4px; cursor: pointer; border-radius: 8px; padding: 2px 0; }
.barra-linha:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.barra-cab { display: flex; justify-content: space-between; gap: 8px; font-size: .92rem; }
.barra-cab strong { font-variant-numeric: tabular-nums; font-weight: 650; }
.barra-trilho { height: 10px; background: var(--track); border-radius: 4px; }
.barra-trilho span { display: block; height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 0; transition: width .4s; }
.barra-pe { font-size: .8rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.barra-linha.vazia .barra-cab { color: var(--text-muted); }

/* barras verticais por mês */
.barras-v { display: flex; align-items: flex-end; gap: 2px; height: 140px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.coluna { flex: 1 0 28px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; cursor: pointer; padding: 0 2px; }
.coluna span { width: 100%; max-width: 36px; background: var(--series-1); border-radius: 4px 4px 0 0; min-height: 2px; }
.coluna.ativa span { outline: 2px solid var(--text-primary); outline-offset: 1px; }
.eixo-meses { display: flex; gap: 2px; overflow: hidden; }
.eixo-meses small { flex: 1 0 28px; text-align: center; color: var(--text-muted); font-size: .72rem; padding-top: 4px; }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.tile p:first-child { font-size: .82rem; color: var(--text-secondary); }
.tile p:nth-child(2) { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.tile p:nth-child(3) { font-size: .8rem; color: var(--text-muted); }

.tabela { width: 100%; border-collapse: collapse; font-size: .88rem; margin-top: 12px; font-variant-numeric: tabular-nums; }
.tabela th, .tabela td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); }
.tabela td:not(:first-child), .tabela th:not(:first-child) { text-align: right; }

/* filtros e lista */
input[type=search], .cartao input, dialog input, dialog select, dialog textarea {
  width: 100%; border: 1px solid var(--border); background: var(--surface-1);
  border-radius: 10px; padding: 10px 12px; min-width: 0;
}
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface-1); border-radius: 999px;
  padding: 6px 12px; font-size: .85rem; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--text-primary); color: var(--surface-1); border-color: var(--text-primary); }

.lista { list-style: none; margin: 8px 0 0; padding: 0; display: grid; }
.item {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 12px 4px;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 8px; }
.item .desc { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .valor { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.item .meta { grid-column: 1 / -1; color: var(--text-secondary); font-size: .84rem; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.tag { border: 1px solid var(--border); border-radius: 6px; padding: 0 6px; font-size: .78rem; color: var(--text-secondary); }
.tag.pendente { border-color: var(--warning); }
.item.destaque { background: var(--surface-2); border-radius: 8px; }

.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: .88rem; text-decoration: none; }
.icone { background: none; border: 0; cursor: pointer; padding: 8px; border-radius: 10px; color: var(--text-secondary); line-height: 0; }
.icone:hover { background: var(--surface-2); }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--text-primary); color: var(--surface-1);
  padding: 6px 10px; border-radius: 8px; font-size: .82rem; max-width: 240px; font-variant-numeric: tabular-nums;
}

/* diálogos */
dialog {
  width: min(560px, 100vw); max-height: 92dvh; margin: auto auto 0; border: 0; padding: 0;
  border-radius: 18px 18px 0 0; background: var(--surface-1); color: var(--text-primary);
}
@media (min-width: 600px) { dialog { margin: auto; border-radius: 18px; } }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { display: grid; gap: 10px; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
dialog label { display: grid; gap: 4px; font-size: .84rem; color: var(--text-secondary); min-width: 0; }
.duas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cab-dialogo { display: flex; justify-content: space-between; align-items: center; }
#dlg-anexo img { width: 100%; max-height: 260px; object-fit: contain; background: var(--surface-2); border-radius: 10px; }
.itens { margin: 6px 0 0; padding-left: 18px; font-size: .85rem; color: var(--text-secondary); }
.acoes { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; }
.primario, .perigo { border: 0; border-radius: 10px; padding: 11px 18px; font-weight: 650; cursor: pointer; }
.primario { background: var(--accent); color: var(--accent-ink); flex: 1; }
.perigo { background: none; color: var(--critical); border: 1px solid var(--border); }

.login { max-width: 380px; margin: 12vh auto 0; display: grid; gap: 12px; width: calc(100% - 32px); }
.login label { display: grid; gap: 4px; font-size: .84rem; color: var(--text-secondary); }
.login input { width: 100%; border: 1px solid var(--border); background: var(--surface-1); border-radius: 10px; padding: 12px; font-size: 1rem; }
.erro { background: var(--surface-1); border: 1px solid var(--critical); border-radius: var(--radius); padding: 12px 16px; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text-primary); color: var(--surface-1); padding: 10px 16px; border-radius: 10px; z-index: 30;
  display: flex; gap: 12px; align-items: center; font-size: .9rem; max-width: calc(100vw - 32px);
}
.toast button { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }

@media (forced-colors: active) {
  .barra-trilho span, .coluna span, .barra-orc span { background: CanvasText; }
}
