/* ============ Tokens ============ */
:root {
  color-scheme: light;
  --page: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e3eefb;
  --series-1: #2a78d6; /* receitas / valores */
  --series-2: #eb6834; /* despesas */
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-ink: #b42a2a;
  --shadow: 0 1px 2px rgba(11, 11, 11, .04), 0 4px 16px rgba(11, 11, 11, .04);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --line: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-soft: #17283d;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good-ink: #0ca30c;
    --critical-ink: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242422;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --line: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-soft: #17283d;
  --series-1: #3987e5;
  --series-2: #d95926;
  --good-ink: #0ca30c;
  --critical-ink: #e66767;
  --shadow: none;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  background: var(--page);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.hint { font-size: 12px; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ============ Layout ============ */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 24px;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand strong { display: block; font-size: 16px; }
.brand small { color: var(--muted); font-size: 12px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: conic-gradient(from 210deg, var(--series-1), #1baf7a, var(--series-2), var(--series-1));
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.nav a svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.sidebar-foot .btn { justify-content: flex-start; }
.sidebar-foot .hint { padding: 6px 10px 0; }

.main { padding: 28px 32px 64px; max-width: 1240px; width: 100%; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { color: var(--ink-2); margin-top: 4px; }

.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head .hint { font-size: 13px; }

/* ============ KPI tiles ============ */
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .label { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 650; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* ============ Buttons & forms ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 8px 14px; font-weight: 550; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { background: var(--surface-2); filter: none; }
.btn.ghost { background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); filter: none; }
.btn.danger { background: transparent; color: var(--critical-ink); }
.btn.danger:hover { background: color-mix(in srgb, var(--critical) 12%, transparent); filter: none; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 5px 8px; }
.file-btn { cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
input[type="text"], input[type="number"], input[type="date"], input[type="month"], input[type="search"], select, textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  min-height: 38px;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .nav a:focus-visible, .check:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent;
}
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }

.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: 10px; gap: 2px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 6px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 550; color: var(--ink-2); cursor: pointer; }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--ring); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  padding: 5px 11px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.chip:hover { color: var(--ink); }
.chip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 550; color: var(--ink-2);
  background: var(--surface-2); padding: 2px 9px; border-radius: 999px;
}
.status { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; }
.status svg { width: 13px; height: 13px; fill: currentColor; }
.status.ok { color: var(--good-ink); }
.status.bad { color: var(--critical-ink); }
.status.warn { color: var(--ink-2); }
.status.warn svg { fill: var(--warning); }

/* ============ Month switcher ============ */
.month-nav { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 4px; }
.month-nav strong { min-width: 150px; text-align: center; font-weight: 600; }

/* ============ Lists / tables ============ */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 550; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.val-in { color: var(--good-ink); font-weight: 600; }
.val-out { color: var(--ink); font-weight: 600; }
.empty { padding: 26px 12px; text-align: center; color: var(--muted); font-size: 14px; }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.list-item.done .title { text-decoration: line-through; color: var(--muted); }

.check {
  width: 20px; height: 20px; flex: none; border-radius: 6px;
  border: 1.5px solid var(--axis); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; padding: 0;
}
.check svg { width: 13px; height: 13px; fill: none; stroke: #fff; stroke-width: 3; opacity: 0; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on svg { opacity: 1; }

/* ============ Progress ============ */
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.progress.done > i { background: var(--good); }

/* ============ Budget bars ============ */
.budget { display: flex; flex-direction: column; gap: 14px; }
.budget-row { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; align-items: center; }
.budget-row .name { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.budget-row .meta { grid-column: 2; display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-2); }
.track { position: relative; height: 14px; }
.track .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; background: var(--series-1); min-width: 2px; }
.track .fill.over { background: var(--critical); }
.track .base { position: absolute; left: 0; top: -2px; bottom: -2px; width: 1px; background: var(--axis); }
.track .mark { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); border-radius: 1px; box-shadow: 0 0 0 2px var(--surface); }
.track .hit { position: absolute; inset: -6px 0; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend .sw.line { width: 2px; height: 12px; border-radius: 1px; background: var(--ink); }

/* ============ SVG chart ============ */
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 12px; }
.chart .bar-in { fill: var(--series-1); }
.chart .bar-out { fill: var(--series-2); }
.chart .col-hit { fill: transparent; }
.chart .col-hit:hover { fill: var(--ink); fill-opacity: .04; }
details.table-view { margin-top: 10px; font-size: 13px; }
details.table-view summary { cursor: pointer; color: var(--ink-2); }

/* ============ Metas ============ */
.goal-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.goal { display: flex; flex-direction: column; gap: 12px; }
.goal.concluida { opacity: .75; }
.goal-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.goal h3 { font-size: 16px; }
.goal .why { font-size: 13.5px; color: var(--ink-2); }
.goal-progress { display: flex; flex-direction: column; gap: 6px; }
.goal-progress .row { justify-content: space-between; font-size: 13px; }
.milestones .list-item { padding: 6px 0; font-size: 14px; }
.inline-add { display: flex; gap: 6px; }
.inline-add input { min-height: 34px; padding: 6px 10px; }

/* ============ Organização ============ */
.kanban { display: grid; gap: 16px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kanban .col-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.list-item { position: relative; }
.task-move {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  display: inline-flex; gap: 2px; padding-left: 10px;
  background: linear-gradient(to right, transparent, var(--surface) 10px);
  opacity: 0; pointer-events: none; transition: opacity .12s;
}
.list-item:hover .task-move, .list-item:focus-within .task-move { opacity: 1; pointer-events: auto; }
.prio { width: 4px; align-self: stretch; border-radius: 2px; flex: none; }
.prio.alta { background: var(--critical); }
.prio.media { background: var(--warning); }
.prio.baixa { background: var(--axis); }


.notes { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.note { display: flex; flex-direction: column; gap: 6px; padding: 14px; }
.note input { border: 0; padding: 0; min-height: 0; font-weight: 600; background: transparent; }
.note textarea { border: 0; padding: 0; background: transparent; min-height: 120px; font-size: 14px; color: var(--ink-2); }
.note input:focus, .note textarea:focus { outline: none; }
.note:focus-within { border-color: var(--accent); }
.note .row { font-size: 11.5px; }

/* ============ Modal, tooltip, toast ============ */
.modal {
  border: 1px solid var(--ring); border-radius: 16px; padding: 0;
  background: var(--surface); color: var(--ink);
  width: min(560px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.modal::backdrop { background: rgba(10, 10, 10, .45); }
.modal form { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.tip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--ink); color: var(--surface);
  font-size: 12.5px; padding: 7px 10px; border-radius: 8px;
  white-space: pre-line; max-width: 260px; line-height: 1.4;
  font-variant-numeric: tabular-nums;
}
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--surface);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
}

/* ============ Responsive ============ */
@media (max-width: 1100px) {
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .cols-2, .cols-3, .kanban { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; z-index: 20;
    flex-direction: row; padding: 6px; gap: 0; border-right: 0; border-top: 1px solid var(--line);
  }
  .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; flex: 1; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 8px; }
  .main { padding: 18px 14px 96px; }
  .kpi .value { font-size: 20px; }
  .card { padding: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .budget-row { grid-template-columns: 1fr; }
  .budget-row .meta { grid-column: 1; }
  .table .hide-sm { display: none; }
  .task-move { position: static; transform: none; background: none; opacity: 1; pointer-events: auto; }
}
@media (forced-colors: active) {
  .track .fill, .progress > i, .chart rect, .chart path { forced-color-adjust: none; }
}
