:root {
  --ink-rgb: 28,26,22;
  --bg: #e9e4d9;
  --bg-panel: #faf8f4;
  --bg-panel-2: #f2ece0;
  --bg-inset: #efe9dd;
  --border: rgba(var(--ink-rgb),.10);
  --border-strong: rgba(var(--ink-rgb),.18);
  --text: #1c1a16;
  --text-dim: rgba(var(--ink-rgb),.55);
  --text-faint: rgba(var(--ink-rgb),.42);
  --primary: #a8542f;
  --primary-dark: #8a4224;
  --primary-tint: rgba(168,84,47,.12);
  --green: #3f6b38;
  --green-tint: rgba(95,154,85,.18);
  --red: #c05f5f;
  --red-tint: rgba(192,95,95,.14);
  --yellow: #8a6c10;
  --yellow-tint: rgba(201,162,39,.16);
  --ink: #1c1a16;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 14px rgba(var(--ink-rgb),.06);
  --font-body: 'Hanken Grotesk', system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 15px;
}

/* Dark theme — "Mesmo mês, escuro" from the design (screen 1b): near-black
   background with luminous cream text. Applied via [data-theme=dark] (explicit
   choice, saved per user); with no explicit choice ("system"), falls back to
   the OS preference instead. */
:root[data-theme="dark"] {
  --ink-rgb: 244,241,234;
  --bg: #141311;
  --bg-panel: #1f1d19;
  --bg-panel-2: #26231e;
  --bg-inset: #26231e;
  --text: #f4f1ea;
  --primary: #c9713f;
  --primary-dark: #a8542f;
  --primary-tint: rgba(201,113,63,.18);
  --green: #6fa864;
  --green-tint: rgba(111,168,100,.2);
  --red: #d97a7a;
  --red-tint: rgba(217,122,122,.18);
  --yellow: #d4ab3a;
  --yellow-tint: rgba(212,171,58,.2);
  --ink: #f4f1ea;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --ink-rgb: 244,241,234;
    --bg: #141311;
    --bg-panel: #1f1d19;
    --bg-panel-2: #26231e;
    --bg-inset: #26231e;
    --text: #f4f1ea;
    --primary: #c9713f;
    --primary-dark: #a8542f;
    --primary-tint: rgba(201,113,63,.18);
    --green: #6fa864;
    --green-tint: rgba(111,168,100,.2);
    --red: #d97a7a;
    --red-tint: rgba(217,122,122,.18);
    --yellow: #d4ab3a;
    --yellow-tint: rgba(212,171,58,.2);
    --ink: #f4f1ea;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
}

h1 { font: 600 1.5rem/1.2 var(--font-body); margin: 0 0 4px 0; letter-spacing: -.01em; }
h3 { margin: 0 0 12px 0; font: 600 1.05rem var(--font-body); color: var(--text); }
p.subtitle { color: var(--text-dim); margin: 0 0 20px 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 700; font-size: 1.1rem; letter-spacing: -.01em; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.period-label { color: var(--text-dim); font-size: 0.9rem; }

select, input[type=text], input[type=date], input[type=number], input[type=file], input[type=password] {
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 9px;
  font-size: 0.92rem;
  font-family: var(--font-body);
}
select:focus, input:focus { outline: 2px solid var(--primary-tint); border-color: var(--primary); }

.btn {
  border: none;
  padding: 8px 15px;
  border-radius: 10px;
  font: 600 0.88rem var(--font-body);
  cursor: pointer;
}
.btn-primary { background: var(--ink); color: var(--bg-panel); }
.btn-primary:hover { background: #000; }
.btn-ghost { background: transparent; border: 1px solid var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--bg-panel-2); }
.btn-danger { background: var(--red); color: white; }
.btn-small { padding: 5px 11px; font-size: 0.8rem; }
.btn-icon { background: transparent; border: none; color: var(--text-faint); cursor: pointer; font-size: 1rem; padding: 2px 6px; }
.btn-icon:hover { color: var(--text); }

.layout { display: flex; min-height: calc(100vh - 53px); }

.sidebar {
  width: 220px;
  background: var(--bg-panel-2);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.navbtn {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 10px 12px;
  border-radius: 9px;
  cursor: pointer;
  font: 400 0.92rem var(--font-body);
}
.navbtn:hover { background: rgba(var(--ink-rgb),.05); color: var(--text); }
.navbtn.active { background: var(--bg-panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(var(--ink-rgb),.1); }

.content { flex: 1; padding: 24px 32px; max-width: 1200px; }
.view.hidden, .hidden { display: none; }
.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin: 16px 0 24px; }
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.card .label { font: 500 .68rem var(--font-mono); letter-spacing: .07em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 8px; }
.card .value { font: 600 1.6rem var(--font-body); letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.card .value.green { color: var(--green); }
.card .value.red { color: var(--red); }
.card .value.yellow { color: var(--primary); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; color: var(--text-faint); font: 500 .68rem var(--font-mono); padding: 8px 10px; border-bottom: 1px solid var(--border); letter-spacing: .06em; text-transform: uppercase; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: none; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--border-strong); border-bottom: none; }
.table tr:hover td { background: rgba(var(--ink-rgb),.02); }

.category-card { margin-bottom: 20px; }
.category-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.category-card-head .name-edit { display: flex; align-items: center; gap: 8px; }
.category-total { font: 600 1.05rem var(--font-body); font-variant-numeric: tabular-nums; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 100px; font: 600 .72rem var(--font-body); }
.pill.paid { background: var(--green-tint); color: var(--green); }
.pill.pendente, .pill.pending { background: var(--yellow-tint); color: var(--yellow); }
.pill.cobrado { background: rgba(79,124,172,.16); color: #2f5a86; }
.pill.pago { background: var(--green-tint); color: var(--green); }
.pill.fixed { background: var(--primary-tint); color: var(--primary); }
.pill.variable { background: rgba(var(--ink-rgb),.07); color: var(--text-dim); }

/* avatar initials circle (reembolsos/eventos) */
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--bg-inset); display: flex; align-items: center; justify-content: center; font: 600 .68rem var(--font-body); color: var(--text-dim); flex: none; }
.avatar.sm { width: 22px; height: 22px; font-size: .6rem; }

/* filter pill row (Gastos view: Todos/Fixos/Variáveis/A reembolsar) */
.filter-pills { display: flex; gap: 7px; flex-wrap: wrap; }
.filter-pill { padding: 6px 13px; border-radius: 999px; border: 1px solid var(--border-strong); font: 400 .72rem var(--font-body); color: var(--text-dim); background: transparent; cursor: pointer; }
.filter-pill.active { background: var(--ink); color: var(--bg-panel); border-color: var(--ink); font-weight: 600; }

/* segmented toggle (Gasto/Entrada, Fixo/Variável) */
.segmented { display: flex; gap: 8px; }
.segmented .seg-btn { flex: 1; text-align: center; padding: 11px; border-radius: 12px; border: 1px solid var(--border-strong); font: 400 .82rem var(--font-body); color: var(--text-dim); background: transparent; cursor: pointer; }
.segmented .seg-btn.active { border: 1.5px solid var(--ink); color: var(--ink); font-weight: 600; }
.segmented.tabs { padding: 4px; background: var(--bg-panel-2); border-radius: 12px; }
.segmented.tabs .seg-btn { border: none; padding: 9px; border-radius: 9px; }
.segmented.tabs .seg-btn.active { background: var(--bg-panel); box-shadow: 0 1px 2px rgba(var(--ink-rgb),.08); }

/* big value display for the quick-entry form */
.big-value { text-align: center; }
.big-value .lbl { font: 500 .68rem var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--text-faint); }
.big-value input { border: none; background: transparent; text-align: center; font: 600 2.6rem var(--font-body); letter-spacing: -.02em; width: 100%; padding: 6px 0 0; font-variant-numeric: tabular-nums; }
.big-value input:focus { outline: none; }

/* flat gastos table: Data / Descrição / Etiqueta / Tipo / Reembolso / Valor
   Cells carry stable .c-* classes and are placed by named grid-area, so the
   mobile breakpoint can reflow them into a 2-line card without touching the DOM. */
.gastos-table-head {
  display: grid; grid-template-columns: 74px minmax(0,1fr) 130px 78px 130px 100px;
  gap: 8px; align-items: center;
  font: 500 .62rem var(--font-mono); letter-spacing: .07em; text-transform: uppercase; color: var(--text-faint);
  padding: 0 12px 9px; border-bottom: 1px solid var(--border-strong);
}
.gastos-table-row {
  display: grid; gap: 8px; align-items: center;
  grid-template-columns: 74px minmax(0,1fr) 130px 78px 130px 100px auto;
  grid-template-areas: "date desc tag tipo reemb valor edit";
  padding: 11px 12px; border-bottom: 1px solid var(--border); font: 400 .85rem var(--font-body);
}
.gastos-table-row.fixos-row { grid-template-columns: 74px minmax(0,1fr) 130px 100px auto; grid-template-areas: "date desc tag valor actions"; }
.gastos-table-row .meta-wrap { display: contents; }
.gastos-table-row .c-date { grid-area: date; font-family: var(--font-mono); font-size: .78rem; color: var(--text-dim); }
.gastos-table-row .c-desc { grid-area: desc; min-width: 0; }
.gastos-table-row .c-tag { grid-area: tag; }
.gastos-table-row .c-tipo { grid-area: tipo; color: var(--text-dim); font-size: .8rem; }
.gastos-table-row .c-reemb { grid-area: reemb; display: flex; align-items: center; gap: 6px; }
.gastos-table-row .c-reemb.no-reembolso { color: var(--text-faint); font-size: .8rem; display: block; }
.gastos-table-row .c-valor { grid-area: valor; text-align: right; font-family: var(--font-mono); font-size: .8rem; font-weight: 500; }
.gastos-table-row .c-edit { grid-area: edit; justify-self: end; }
.gastos-table-row .c-actions { grid-area: actions; display: flex; gap: 2px; justify-self: end; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; }
.toggle-row + .toggle-row { border-top: 1px solid var(--border); }
.toggle-switch { width: 42px; height: 24px; border-radius: 12px; position: relative; flex: none; border: none; cursor: pointer; background: rgba(var(--ink-rgb),.18); }
.toggle-switch.on { background: var(--primary); }
.toggle-switch .knob { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s ease; }
.toggle-switch.on .knob { left: 21px; }

/* per-tag colored chip — background/border/color set inline via UI.tagChipStyle() */
.tag-chip { display: inline-block; padding: 3px 10px; border-radius: 8px; font: 600 .72rem var(--font-body); border: 1px solid transparent; }

/* dashboard "dot + bar + value" category row (mirrors the design's summary rows) */
.cat-row { display: flex; align-items: center; gap: 11px; }
.cat-row .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.cat-row .name { font: 400 .88rem var(--font-body); flex: 1; }
.cat-row .bar { width: 96px; height: 6px; border-radius: 3px; background: rgba(var(--ink-rgb),.08); position: relative; overflow: hidden; flex: none; }
.cat-row .bar > span { position: absolute; inset: 0 auto 0 0; border-radius: 3px; }
.cat-row .amount { font: 500 .8rem var(--font-mono); width: 78px; text-align: right; }

.checkbox-toggle { cursor: pointer; width: 17px; height: 17px; accent-color: var(--primary); }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border-strong); }
.inline-form input, .inline-form select { flex: 1; min-width: 100px; }
.inline-form input[data-f=description] { flex: 2; min-width: 160px; }

/* clickable tag chip picker used in add/edit forms instead of a plain <select> */
.chip-picker { display: flex; flex-wrap: wrap; gap: 7px; }
.chip-picker .chip-btn { cursor: pointer; padding: 6px 12px; border-radius: 9px; font: 500 .78rem var(--font-body); border: 1px solid transparent; background: rgba(var(--ink-rgb),.05); color: var(--text-dim); }
.chip-picker .chip-btn.selected { font-weight: 600; }

.empty-state { color: var(--text-dim); text-align: center; padding: 20px; font-size: 0.9rem; }

/* modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20,19,17,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-box {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 26px; min-width: 320px; max-width: 90vw; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(var(--ink-rgb),.25);
}
.modal-box h3 { margin-bottom: 16px; }
.modal-box .modal-row { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.modal-box .modal-row label { font: 500 .7rem var(--font-mono); text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); }
.modal-box .modal-row input, .modal-box .modal-row select { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.list-manage-item { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); }
.list-manage-item:last-child { border-bottom: none; }

.import-block { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; background: var(--bg-panel-2); }
.import-block-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.import-block-head select { min-width: 160px; }
.badge { font: 500 .68rem var(--font-mono); padding: 2px 8px; border-radius: 100px; background: var(--bg-panel-2); color: var(--text-dim); border: 1px solid var(--border); }
.period-import-group { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.period-import-group > h3 { display: flex; align-items: center; gap: 10px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------------------------------------------------
   Mobile layout — bottom tab bar instead of the sidebar, single-column
   views, cards reflow into a 2-line layout. Mirrors the phone screens
   ("1a"/"1c"/"1d") from the design instead of squeezing the desktop one.
--------------------------------------------------------------------- */
.bottom-nav { display: none; }

@media (max-width: 760px) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  .topbar { flex-wrap: wrap; row-gap: 8px; padding: 10px 14px; }
  .topbar-right { flex-wrap: wrap; gap: 6px; }
  .period-label { display: none; }

  .sidebar { display: none; }
  .content { padding: 16px 14px calc(84px + env(safe-area-inset-bottom)); max-width: 100%; }

  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--bg-panel); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-between; align-items: center;
    box-shadow: 0 -2px 14px rgba(var(--ink-rgb),.06);
  }
  .bottom-nav .bn-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    background: transparent; border: none; color: var(--text-faint);
    font: 500 .62rem var(--font-body); padding: 4px 0; cursor: pointer;
  }
  .bottom-nav .bn-item.active { color: var(--ink); font-weight: 600; }
  .bottom-nav .bn-icon { font-size: 1.2rem; line-height: 1; }
  .bottom-nav .bn-add {
    width: 46px; height: 46px; border-radius: 50%; background: var(--ink); color: var(--bg-panel);
    display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
    margin-top: -20px; box-shadow: 0 4px 14px rgba(var(--ink-rgb),.3); border: 3px solid var(--bg);
  }

  .cards { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
  .card { padding: 13px 14px; }
  .card .value { font-size: 1.25rem; }

  .view-header { flex-wrap: wrap; gap: 10px; }
  .view-header > div:last-child { width: 100%; }

  /* Gastos: drop the desktop right rail (chart + fixed-costs + a-receber quick lists) */
  #view-gastos > div { flex-direction: column; }
  #view-gastos aside { display: none !important; }
  .filter-pills { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }

  .gastos-table-head { display: none; }
  .gastos-table-row, .gastos-table-row.fixos-row {
    grid-template-columns: 1fr auto !important;
    row-gap: 6px;
  }
  .gastos-table-row { grid-template-areas: "desc valor" "meta edit"; }
  .gastos-table-row.fixos-row { grid-template-areas: "desc valor" "meta actions"; }
  .gastos-table-row .meta-wrap {
    display: flex; grid-area: meta; flex-wrap: wrap; gap: 8px; align-items: center;
    font-size: .78rem; color: var(--text-dim);
  }

  #reembolsosCards { grid-template-columns: 1fr 1fr !important; }

  .modal-box { min-width: 0; width: 92vw; padding: 20px; }
}
