﻿:root {
  --bg: #f6f7f5; --card: #ffffff; --ink: #1c2321; --muted: #66726e; --line: #e2e6e3;
  --brand: #0f766e; --brand-ink: #ffffff; --good: #15803d; --bad: #b91c1c; --warn: #b45309;
  --bubble-me: #d7efe9; --bubble-bot: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615; --card: #1b2120; --ink: #e8eeeb; --muted: #94a19c; --line: #2c3532;
    --brand: #2dd4bf; --brand-ink: #062b27; --good: #4ade80; --bad: #f87171; --warn: #fbbf24;
    --bubble-me: #164e47; --bubble-bot: #1b2120;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 18px; margin: 0; color: var(--brand); letter-spacing: .3px; }
.month { display: flex; align-items: center; gap: 4px; font-weight: 600; }
.month button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 20px; cursor: pointer; }
#monthLabel { min-width: 96px; text-align: center; text-transform: capitalize; }

main { max-width: 960px; margin: 0 auto; padding: 16px; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 50; }
.tabs a { flex: 1; display: block; padding: 15px 4px; text-align: center; color: var(--muted); text-decoration: none;
  font-weight: 600; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.tabs a.on { color: var(--brand); box-shadow: inset 0 3px 0 var(--brand); }

button, input, select { font: inherit; color: inherit; }
input, select { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; min-width: 0; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn { background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 8px; padding: 10px 16px;
  font-weight: 600; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--line); }
.btn.small { padding: 6px 10px; font-size: 14px; }

/* chat */
.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 80px; }
.msg { max-width: 92%; padding: 10px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--bubble-bot); }
.msg.me { align-self: flex-end; background: var(--bubble-me); border-color: transparent; }
.msg.warn { border-color: var(--warn); }
.msg.bad { border-color: var(--bad); }
.msg p { margin: 0 0 4px; }
.msg ul { margin: 4px 0 0; padding-left: 18px; }
.composer { z-index: 10; position: fixed; left: 0; right: 0; bottom: calc(52px + env(safe-area-inset-bottom)); background: var(--bg);
  padding: 8px 12px; border-top: 1px solid var(--line); }
.composer form { max-width: 960px; margin: 0 auto; display: flex; gap: 8px; }
.composer input { flex: 1; }

.draft { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; min-width: min(78vw, 420px); }
.draft label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 2px; }
.draft .wide { grid-column: 1 / -1; }
.draft .need input, .draft .need select { border-color: var(--bad); }
.draft .check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }
.draft .actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.hide { display: none !important; }

/* planilha */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.tile .t { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.tile .v { font-size: 22px; font-weight: 700; }
.tile .s { font-size: 13px; color: var(--muted); }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }

section.block { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 16px; overflow: hidden; }
section.block h2 { font-size: 14px; margin: 0; padding: 10px 12px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); border-bottom: 1px solid var(--line); }
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 12px; }
.tbl td { padding: 8px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
.tbl .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tfoot td { font-weight: 700; }
.tbl input.est { width: 96px; text-align: right; }
.scroll { overflow-x: auto; }
.empty { padding: 16px 12px; color: var(--muted); }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--brand); }
.bar i.over { background: var(--bad); }

.cardbox { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.cardbox h3 { margin: 0 0 2px; }
.cardbox .sub { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 130px; background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: 90vw; }

/* config */
.hint { margin: 0; padding: 10px 12px 0; color: var(--muted); font-size: 14px; }
.item { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; padding: 12px; border-top: 1px solid var(--line); }
.section-first, section.block h2 + .item { border-top: 0; }
.item label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.item label input, .item label select { font-weight: 400; color: var(--ink); font-size: 16px; width: 100%; }
.item small { font-weight: 400; font-size: 12px; }
.item .wide { grid-column: 1 / -1; }
.item .btns { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
section.block.add { border-color: var(--brand); }
section.block.add h2 { color: var(--brand); }
@media (min-width: 720px) { .item { grid-template-columns: repeat(4, minmax(0, 1fr)); } .item .wide { grid-column: span 2; } }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; color: var(--brand); font-size: 26px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; }
.login-card input { font-size: 16px; font-weight: 400; }
.login-card .btn { padding: 12px; }
.login-card p { margin: 0; }
#loginError { min-height: 1.4em; font-size: 14px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
.top { gap: 8px; }

/* menu com ícones */
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 4px 8px; font-size: 12px; }
.tabs a svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* config: abas, itens recolhíveis */
.seg { display: flex; gap: 4px; padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 16px; }
.seg button { flex: 1; padding: 10px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
details.acc { border-top: 1px solid var(--line); }
details.acc > summary { list-style: none; cursor: pointer; padding: 13px 12px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary::after { content: "›"; font-size: 22px; color: var(--muted); transition: transform .15s; }
details.acc[open] > summary::after { transform: rotate(90deg); }
details.acc[open] > summary { color: var(--brand); }
details.acc > .item { border-top: 0; padding-top: 4px; background: var(--bg); }
section.block h2 + details.acc { border-top: 0; }

/* gráficos (cores validadas: azul, laranja, verde-água — ordem fixa) */
:root { --v1: #2a78d6; --v2: #eb6834; --v3: #1baf7a; }
@media (prefers-color-scheme: dark) { :root { --v1: #3987e5; --v2: #d95926; --v3: #199e70; } }
.c1 { --fill: var(--v1); } .c2 { --fill: var(--v2); } .c3 { --fill: var(--v3); }
.viz-grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 16px; }
@media (min-width: 720px) { .viz-grid { grid-template-columns: 1fr 1fr; } .viz.wide { grid-column: 1 / -1; } }
.viz-grid section.block { margin-bottom: 0; }
.viz-body { padding: 12px; }
.viz-sub { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.viz-empty { color: var(--muted); margin: 8px 0; }
.viz-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.viz-legend.col { flex-direction: column; gap: 4px; list-style: none; padding: 0; margin: 10px 0 0; }
.viz-legend li { display: flex; align-items: center; }
.viz-legend li span { margin-left: auto; color: var(--ink); font-variant-numeric: tabular-nums; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; background: var(--fill, var(--ink)); }
.sw.est { background: var(--ink); opacity: .3; } .sw.real { background: var(--ink); }
.pb { margin-bottom: 14px; } .pb-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.pb-line { display: grid; grid-template-columns: 3.8em 1fr 7.8em; gap: 8px; align-items: center; margin-bottom: 4px; }
.pb-tag { font-size: 12px; color: var(--muted); }
.pb-val { font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pb-val small { color: var(--muted); }
.trk { position: relative; height: 12px; background: color-mix(in srgb, var(--line) 60%, transparent); border-radius: 6px; }
.trk i { position: absolute; top: 1px; bottom: 1px; border-radius: 4px; background: var(--fill, var(--v1)); }
.trk i.est { opacity: .35; }
.trk .zero { position: absolute; top: -2px; bottom: -2px; width: 1px; background: var(--muted); }
.rank .rk { display: grid; grid-template-columns: minmax(70px, 8.5em) 1fr 9.6em; gap: 8px; align-items: center; margin-bottom: 9px; }
.rk-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comp { display: flex; gap: 2px; height: 22px; }
.comp i { border-radius: 4px; background: var(--fill); }
svg.year { width: 100%; height: auto; display: block; }
svg .grid { stroke: var(--line); stroke-width: 1; }
svg .ax { fill: var(--muted); font-size: 12px; } svg .ax.on { fill: var(--ink); font-weight: 700; }
svg .sel { fill: var(--line); opacity: .5; }
svg path.c1, svg path.c2 { fill: var(--fill); }
.astable { margin-top: 8px; } .astable summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.viz-tip { position: fixed; z-index: 100; background: var(--ink); color: var(--bg); padding: 6px 10px; border-radius: 8px;
  font-size: 13px; pointer-events: none; max-width: 80vw; }
@media (max-width: 640px) {
  .tbl { font-size: 14px; }
  .tbl th, .tbl td { padding: 8px 6px; }
  .tbl input.est { width: 78px; padding: 7px 6px; }
}
