/* Finanças: tokens de cor em :root. Escuro é o padrão; [data-theme=light] e "sistema" (sem atributo) trocam. */

:root,
[data-theme="dark"] {
  --bg: #14161c;
  --surface: #1d2028;
  --surface-2: #262a34;
  --line: #313643;
  --text: #e9ebf1;
  --muted: #9aa1b0;
  --accent: #6c8cff;
  --accent-text: #0e1220;
  --expense: #ff6b6b;
  --income: #3ddc97;
  --transfer: #5ab0f0;
  --warn: #f5b84a;
  --danger: #ff6b6b;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #eceef3;
  --line: #d9dce4;
  --text: #1b1e26;
  --muted: #626a7a;
  --accent: #3556d8;
  --accent-text: #ffffff;
  --expense: #d63c3c;
  --income: #13945e;
  --transfer: #1f7cc0;
  --warn: #b7791f;
  --danger: #d63c3c;
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #eceef3;
    --line: #d9dce4;
    --text: #1b1e26;
    --muted: #626a7a;
    --accent: #3556d8;
    --accent-text: #ffffff;
    --expense: #d63c3c;
    --income: #13945e;
    --transfer: #1f7cc0;
    --warn: #b7791f;
    --danger: #d63c3c;
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 96px max(16px, env(safe-area-inset-left));
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}

/* ---------- botões ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-danger { color: var(--danger); }
.btn-wide { width: 100%; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- formulários ---------- */

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.field-error { color: var(--danger); font-size: .85rem; margin: 4px 0 0; }
.field.has-error input { border-color: var(--danger); }

.alert { padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; background: var(--surface-2); }
.alert-error { color: var(--danger); border: 1px solid var(--danger); background: transparent; }
.alert-ok { color: var(--income); border: 1px solid var(--income); background: transparent; }

/* ---------- login e erro ---------- */

.auth-page { max-width: 400px; margin: 12vh auto 0; }
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-brand strong { font-size: 1.6rem; }

.error-page { text-align: center; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--muted); margin: 0; }

/* ---------- ícones ---------- */

.icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- casca: barra de baixo no celular, menu lateral no computador ---------- */

.sidebar { display: none; }

.bottom-nav {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 10;
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 48px;
  justify-content: center;
  color: var(--muted);
  text-decoration: none;
  font-size: .75rem;
}
.bottom-nav a[aria-current="page"] { color: var(--accent); }

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}
.nav-link[aria-current="page"] { background: var(--surface-2); color: var(--accent); }
.nav-button { width: 100%; border: 0; background: none; font: inherit; cursor: pointer; }
.list-nav { padding: 6px; }

@media (min-width: 900px) {
  .bottom-nav { display: none; }
  .has-shell .sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    width: 240px;
    padding: 20px 12px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    overflow-y: auto;
  }
  .has-shell { padding-left: 240px; }
  .has-shell .wrap { padding-bottom: 32px; max-width: 960px; }
  .sidebar .theme-switch span { display: none; }
  .sidebar-brand { font-size: 1.3rem; font-weight: 800; padding: 0 12px 16px; }
  .sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
  .sidebar-foot { margin-top: auto; padding-top: 16px; }
  .sidebar-user { color: var(--muted); font-size: .9rem; padding: 0 12px; margin: 12px 0 0; }
}

/* ---------- tema ---------- */

.theme-switch { display: flex; gap: 4px; background: var(--bg); border-radius: 10px; padding: 4px; }
.theme-switch button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.theme-switch .icon { width: 18px; height: 18px; }
.theme-switch button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }

/* ---------- navegação por mês ---------- */

.month-nav { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 12px; }
.month-label {
  min-width: 160px;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}
.month-arrow {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--text);
}
.month-arrow:hover { background: var(--surface-2); }

/* ---------- páginas ---------- */

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.page-links { text-align: center; color: var(--muted); }
.small { font-size: .85rem; }
.neg { color: var(--expense); }
.empty { text-align: center; }
.badge {
  font-size: .75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent);
}
.dot { flex-shrink: 0; display: block; }

.row { display: grid; gap: 0 12px; grid-template-columns: 1fr 1fr; }
.field-hint { color: var(--muted); font-size: .8rem; margin: 4px 0 0; }
fieldset.field { border: 0; padding: 0; margin: 0 0 14px; }
fieldset.field legend { font-size: .9rem; color: var(--muted); margin-bottom: 6px; padding: 0; }
.colors { display: flex; flex-wrap: wrap; gap: 8px; }
.color-option { position: relative; cursor: pointer; }
.color-option input { position: absolute; opacity: 0; }
.color-option svg { border-radius: 50%; outline: 2px solid transparent; outline-offset: 2px; }
.color-option input:checked + svg { outline-color: var(--text); }
.color-option input:focus-visible + svg { outline-color: var(--accent); }
.checks { display: grid; gap: 10px; margin-bottom: 18px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); }
.check small { display: block; color: var(--muted); font-size: .8rem; }
.field select { appearance: auto; }

.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.totals div { display: flex; flex-direction: column; }
.totals strong { font-size: 1.25rem; }

.account-head { display: flex; align-items: center; gap: 10px; }
.account-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.account-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-name span { font-size: .85rem; }
.account-values { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 12px 0 0; }
.account-values dt { font-size: .8rem; color: var(--muted); }
.account-values dd { margin: 0; font-weight: 600; }

.menu { position: relative; }
.menu summary {
  list-style: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--muted);
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover { background: var(--surface-2); }
.menu-panel {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 20;
  min-width: 200px;
  padding: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .3);
}
.menu-panel a, .menu-panel button {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu-panel a:hover, .menu-panel button:hover { background: var(--surface); }
.menu-panel .danger { color: var(--danger); }

.type-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.inline-form { flex: 1; display: flex; gap: 8px; }
.inline-form input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

/* ---------- abas, categorias ---------- */

.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.tabs a {
  flex: 1;
  text-align: center;
  padding: 10px 8px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}
.tabs a[aria-current="page"] { background: var(--surface-2); color: var(--text); }

.btn-small { min-height: 32px; padding: 0 10px; font-size: .85rem; }
.list { padding: 4px 16px; }
.cat-row { display: flex; align-items: center; gap: 10px; min-height: 52px; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.cat-icon { font-size: 1.3rem; width: 28px; text-align: center; }
.cat-name { flex: 1; color: var(--text); text-decoration: none; padding: 12px 0; }
.cat-sub { padding-left: 38px; min-height: 44px; }
.cat-sub .cat-name { color: var(--muted); }

.icons { display: flex; flex-wrap: wrap; gap: 6px; }
.icon-option { position: relative; cursor: pointer; }
.icon-option input { position: absolute; opacity: 0; }
.icon-option span {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  font-size: 1.3rem;
  border: 2px solid transparent;
  background: var(--bg);
}
.icon-option input:checked + span { border-color: var(--accent); }
.icon-option input:focus-visible + span { outline: 2px solid var(--accent); }
.btn-danger.btn-wide { margin-top: 4px; background: transparent; }

/* ---------- lançamentos e transações ---------- */

.value-expense { color: var(--expense); }
.value-income { color: var(--income); }
.value-transfer { color: var(--transfer); }
.kind-title.kind-expense { color: var(--expense); }
.kind-title.kind-income { color: var(--income); }
.kind-title.kind-transfer { color: var(--transfer); }

.nav-add {
  flex: 0 0 auto !important;
  width: 56px;
  height: 56px;
  margin-top: -18px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text) !important;
  box-shadow: 0 4px 14px rgb(0 0 0 / .35);
}
.nav-add .icon { width: 28px; height: 28px; stroke-width: 2.2; }
.sidebar-add { margin: 0 4px 16px; }

.choose { display: grid; gap: 12px; }
.choose-item {
  display: block;
  padding: 22px 18px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 1.15rem;
  font-weight: 700;
  text-decoration: none;
}
.choose-item.kind-expense { color: var(--expense); }
.choose-item.kind-income { color: var(--income); }
.choose-item.kind-transfer { color: var(--transfer); }

.field textarea { resize: vertical; min-height: 80px; }
.more { margin: 4px 0 16px; }
.more summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 8px 0; }
.more[open] summary { margin-bottom: 8px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.form-actions .btn { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; }
.chip span { display: inline-block; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.filters summary, .breakdown summary { cursor: pointer; font-weight: 600; }
.filters[open] summary, .breakdown[open] summary { margin-bottom: 12px; }
.filter-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.filter-form .form-actions { grid-column: 1 / -1; }
.totals-3 { grid-template-columns: repeat(3, 1fr); }
.totals-3 strong { font-size: 1.05rem; }

.day-title { font-size: .85rem; color: var(--muted); font-weight: 600; margin: 16px 4px 6px; text-transform: capitalize; }
.tx-list { list-style: none; padding: 0 12px; margin: 0 0 8px; }
.tx-row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.tx-row:last-child { border-bottom: 0; }
.tx-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 10px 0; color: var(--text); text-decoration: none; }
.tx-icon { font-size: 1.25rem; width: 28px; text-align: center; }
.tx-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tx-text strong, .tx-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-text small { font-size: .8rem; }
.tx-value { font-weight: 700; white-space: nowrap; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.status-paid { background: var(--income); }
.status-near { background: var(--warn); }
.status-overdue { background: var(--danger); }
.status-far { background: var(--muted); }
.day-balance { display: flex; justify-content: space-between; padding: 10px 0; color: var(--muted); font-size: .9rem; }
.day-balance strong { color: var(--text); }
.account-pick { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.account-pick select {
  flex: 1;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.detail h1 { margin-bottom: 4px; }
.detail-value { font-size: 1.8rem; font-weight: 800; margin: 0 0 8px; }
.status { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; color: #10131a; }
.detail-list { margin: 12px 0 0; display: grid; gap: 8px; }
.detail-list div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; text-align: right; }
.notes { white-space: pre-wrap; margin-top: 12px; color: var(--muted); }
.detail-actions { display: grid; gap: 8px; }
form > .check { margin-bottom: 16px; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.install-btn { margin-bottom: 12px; }
.error-page img { margin: 0 auto 12px; display: block; }
