:root {
  --bg: #f6f4ef; --surface: #fffdf9; --ink: #1f2421; --muted: #6b716c; --line: #e4dfd5;
  --accent: #0f6b5c; --accent-ink: #ffffff; --accent-soft: #e2f0ec;
  --cost: #b4432f; --income: #0f6b5c; --warn: #8a5a08; --warn-soft: #f6ead0;
  --radius: 12px; --shadow: 0 1px 2px rgba(31, 36, 33, .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
:root { color-scheme: light; }
/* Escuro automático (segue o sistema), a menos que o usuário tenha escolhido "claro" */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #131614; --surface: #1b1f1d; --ink: #ecebe6; --muted: #9aa19b; --line: #2b312e;
    --accent: #3fb59f; --accent-ink: #06120f; --accent-soft: #1a2f2a;
    --cost: #e58a76; --income: #3fb59f; --warn: #dcae52; --warn-soft: #2f2712;
    --shadow: none;
  }
}
/* Escuro escolhido manualmente */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131614; --surface: #1b1f1d; --ink: #ecebe6; --muted: #9aa19b; --line: #2b312e;
  --accent: #3fb59f; --accent-ink: #06120f; --accent-soft: #1a2f2a;
  --cost: #e58a76; --income: #3fb59f; --warn: #dcae52; --warn-soft: #2f2712;
  --shadow: none;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }

/* Layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.nav { position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; font-size: 1.1rem; padding: 4px 10px 16px; letter-spacing: -.01em; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 9px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.nav a:hover { background: var(--bg); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .tag { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.nav .live { color: var(--accent); }
.nav .foot { margin-top: auto; padding: 10px; font-size: .8rem; color: var(--muted); }
.nav .foot button { margin-top: 6px; }
main { padding: 28px clamp(16px, 4vw, 40px) 64px; max-width: 1120px; width: 100%; }
.page-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.lead { color: var(--muted); margin: 6px 0 0; max-width: 60ch; }

/* Componentes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card > h3 { margin-bottom: 12px; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge.soft { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.banner { background: var(--warn-soft); color: var(--warn); padding: 10px 14px; border-radius: 10px; margin-bottom: 18px; font-size: .9rem; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn.danger { color: var(--cost); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 4px 12px; font-size: .85rem; }
button.chip { cursor: pointer; }
button.chip:hover { border-color: var(--accent); color: var(--accent); }
.muted { color: var(--muted); }
.neg { color: var(--cost); }
.pos { color: var(--income); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi span { display: block; color: var(--muted); font-size: .8rem; }
.kpi strong { display: block; font-size: 1.45rem; letter-spacing: -.01em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: .78rem; }

/* Formulário */
.form .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 14px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; padding: 7px 18px; }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 14px; }
.span2 { grid-column: span 2; }
.fld { display: flex; flex-direction: column; gap: 4px; }
.fld > span { font-size: .8rem; color: var(--muted); }
.fld input, .fld select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); min-width: 0; }
.fld input:focus, .fld select:focus, .btn:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.quick { margin-bottom: 14px; }
.quick p { margin: 0 0 8px; font-size: .85rem; color: var(--muted); }

/* Tabela */
.tools { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.tools input, .tools select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.tools .grow { flex: 1; min-width: 160px; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td small { display: block; color: var(--muted); font-size: .78rem; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }

/* Gráficos */
.split { display: grid; grid-template-columns: 3fr 2fr; gap: 18px; }
.months { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 150px; }
.mcol { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.mbars { display: flex; align-items: flex-end; gap: 2px; height: 122px; width: 100%; justify-content: center; }
.mbars i { display: block; width: 42%; max-width: 14px; border-radius: 3px 3px 0 0; min-height: 1px; }
.mbars .c { background: var(--cost); } .mbars .r { background: var(--income); }
.mcol span { font-size: .7rem; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }
.cat { margin-bottom: 10px; font-size: .9rem; }
.cat .top { display: flex; justify-content: space-between; gap: 8px; }
.cat .bar { height: 6px; background: var(--bg); border-radius: 4px; margin-top: 4px; overflow: hidden; }
.cat .bar i { display: block; height: 100%; background: var(--cost); }

/* Máscaras das outras telas */
.kanban { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 12px; overflow-x: auto; }
.kcol { background: var(--bg); border-radius: 10px; padding: 10px; min-height: 160px; }
.kcol h4 { margin: 0 0 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kcard { background: var(--surface); border: 1px dashed var(--line); border-radius: 8px; padding: 9px 10px; font-size: .88rem; margin-bottom: 8px; }
.kcard small { display: block; color: var(--muted); }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.day { background: var(--bg); border-radius: 10px; padding: 8px; min-height: 130px; font-size: .82rem; }
.day b { display: block; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.pill { background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 3px 6px; margin-bottom: 4px; display: block; }
.gantt { display: grid; grid-template-columns: 150px repeat(12, 1fr); gap: 6px 0; align-items: center; font-size: .85rem; }
.gantt .h { color: var(--muted); font-size: .7rem; text-align: center; }
.gantt .bar { background: var(--accent-soft); border: 1px dashed var(--accent); border-radius: 6px; height: 20px; }
.pcards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.pcard { border: 1px dashed var(--line); border-radius: 10px; padding: 14px; background: var(--surface); }
.pcard h4 { margin: 0 0 4px; }
.ctxlist { list-style: none; padding: 0; margin: 0; }
.ctxlist li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.ctxlist code { background: var(--bg); padding: 1px 6px; border-radius: 5px; font-size: .85rem; }
.mock { opacity: .92; }

/* Seletor de tema */
.theme-btn { position: fixed; right: 16px; bottom: 16px; z-index: 9; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 8px 14px; font-size: .85rem; cursor: pointer; box-shadow: 0 2px 8px rgba(0, 0, 0, .12); }
.theme-btn:hover { border-color: var(--accent); }
.theme-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Login e toast */
.login { max-width: 380px; margin: 12vh auto; padding: 0 16px; }
.login .card { padding: 24px; }
.login h1 { margin-bottom: 4px; }
.login .fld { margin-bottom: 12px; }
.err { color: var(--cost); font-size: .88rem; min-height: 1.2em; margin: 4px 0 10px; }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 10; }
#toast.on { opacity: 1; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; flex-direction: row; overflow-x: auto; padding: 10px; border-right: 0; border-bottom: 1px solid var(--line); align-items: center; }
  .nav a { white-space: nowrap; } .nav .tag, .nav .foot, .brand { display: none; }
  .split { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; } .span2 { grid-column: auto; }
  .week { grid-template-columns: repeat(2, 1fr); }
  .gantt { grid-template-columns: 110px repeat(12, 1fr); }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
