/* Finance Dashboard — dark by default, light via data-theme. */
:root,
[data-theme="dark"] {
  --bg: #14171c;
  --bg-card: #1e232b;
  --bg-inset: #262d38;
  --text: #eef1f5;
  --text-dim: #9aa4b2;
  --line: #323b48;
  --accent: #5aa9ff;
  --income: #4ade80;
  --spend: #f87171;
  --warn: #fbbf24;
}

[data-theme="light"] {
  --bg: #f4f6f9;
  --bg-card: #ffffff;
  --bg-inset: #eef1f5;
  --text: #1c2430;
  --text-dim: #5b6675;
  --line: #d4dae3;
  --accent: #2563eb;
  --income: #15803d;
  --spend: #dc2626;
  --warn: #b45309;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a {
  color: var(--accent);
  text-decoration: none;
}

/* Top bar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
  padding: 16px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  flex: 1;
}

.nav a {
  color: var(--text-dim);
  padding: 4px 2px;
}

.nav a.active {
  color: var(--text);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 6px;
}

/* Segmented scope control */
.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.segmented button {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  font: inherit;
  font-size: 16px;
  padding: 8px 14px;
  cursor: pointer;
}

.segmented button + button {
  border-left: 1px solid var(--line);
}

.segmented button.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* Buttons */
.btn {
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 16px;
  padding: 10px 16px;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Page + cards */
.page {
  max-width: 1000px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

h1 {
  font-size: 30px;
  margin: 0 0 24px;
}

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

.login-card {
  max-width: 420px;
  margin: 12vh auto 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--text-dim);
  font-size: 15px;
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Forms */
label {
  display: block;
  color: var(--text-dim);
  font-size: 16px;
}

label input,
input,
select {
  width: 100%;
  margin-top: 6px;
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 18px;
  padding: 10px 12px;
}

/* Progress bar */
.progress {
  height: 14px;
  background: var(--bg-inset);
  border-radius: 7px;
  overflow: hidden;
}

.progress .fill {
  height: 100%;
  background: var(--income);
  border-radius: 7px 0 0 7px;
}

.progress .fill.warn {
  background: var(--warn);
}

.progress .fill.over {
  background: var(--spend);
}

/* Money colors */
.income {
  color: var(--income);
}

.spend {
  color: var(--spend);
}

.error {
  color: var(--spend);
  margin: 0;
}

/* Badges */
.badge {
  display: inline-block;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 14px;
  color: var(--text-dim);
  text-transform: capitalize;
  vertical-align: middle;
}

.badge.joint {
  border-color: var(--accent);
  color: var(--accent);
}

.badge.personal {
  border-color: var(--warn);
  color: var(--warn);
}

/* Account cards */
.account-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

.account-head h2 {
  margin: 0;
  font-size: 22px;
}

.dim {
  color: var(--text-dim);
  margin: 0 0 12px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.actions .btn {
  font-size: 15px;
  padding: 8px 12px;
}

.btn.danger {
  border-color: var(--spend);
  color: var(--spend);
}

.btn.danger:hover {
  background: var(--spend);
  color: #fff;
}

.result {
  margin: 12px 0 0;
}

.result p {
  margin: 0 0 8px;
}

.result details ul {
  margin: 8px 0;
}

label.check {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

label.check input {
  width: auto;
  margin: 0;
}

/* Transactions page */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  align-items: end;
}

.filters .chips {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 15px;
  border: 1px dashed var(--line);
  color: var(--text-dim);
  background: transparent;
}

.chip.active {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
}

td.desc {
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 12px;
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  background: transparent;
}

.pill-auto {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.75;
}

.pill-select {
  width: auto;
  margin: 0;
  padding: 6px 10px;
}

.btn.small {
  font-size: 14px;
  padding: 5px 10px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.pager .btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 10;
}

/* Dialogs */
dlg.dlg,
dialog.dlg {
  width: min(92vw, 480px);
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
}

.dlg::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.dlg h2 {
  font-size: 22px;
  margin: 0 0 16px;
}

.dlg form .actions {
  justify-content: flex-end;
}

/* Home page */
.range-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.range-custom {
  display: flex;
  align-items: end;
  gap: 10px;
}

.range-custom label {
  font-size: 15px;
}

.range-custom input {
  width: auto;
  margin-top: 0;
  font-size: 16px;
  padding: 8px 10px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-label {
  font-size: 14px;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  font-size: 14px;
  color: var(--text-dim);
}

.review-link {
  margin: -12px 0 24px;
}

.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

.view-seg {
  margin-bottom: 16px;
}

.chart-wrap {
  position: relative;
  height: 340px;
}

tr.clickable {
  cursor: pointer;
}

tr.clickable:hover td {
  background: var(--bg-inset);
}

.dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.card-head h2 {
  margin: 0;
  font-size: 22px;
}

/* Budget page */
.month-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.month-bar h2 {
  flex: 1;
  margin: 0;
  font-size: 24px;
  text-align: center;
}

.month-nav {
  font-size: 22px;
  line-height: 1;
  padding: 8px 18px;
}

.month-bar .note {
  width: 100%;
  margin: 6px 0 0;
  color: var(--warn);
  font-size: 16px;
}

.budget-cell {
  min-width: 260px;
}

.budget-line {
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}

.over {
  margin-top: 6px;
  color: var(--spend);
  font-weight: 600;
  font-size: 15px;
}

.limit-edit {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 4px;
  font-variant-numeric: tabular-nums;
}

.limit-input {
  width: 120px;
  margin: 0;
  text-align: right;
  font-size: 16px;
  padding: 6px 10px;
}

/* Goals page */
.card-head .note {
  margin: 0;
  color: var(--warn);
  font-size: 16px;
}

.goal-card .budget-line {
  margin-top: 8px;
  margin-bottom: 6px;
}

.alloc-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.alloc-row .error {
  width: 100%;
}

.alloc-label {
  color: var(--text-dim);
  font-size: 15px;
}

.sim-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 14px;
  margin-bottom: 16px;
}

.sim-form select {
  width: auto;
}

.sim-form input {
  width: 160px;
  margin-top: 0;
}

.sim-result .sim-text {
  white-space: pre-wrap;
}

.sim-result table {
  margin-top: 12px;
}

/* Forecast page */
.fc-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.fc-inputs select {
  width: auto;
}

.fc-inputs input {
  width: 160px;
  margin-top: 0;
}

.fc-verdict {
  margin: 12px 0 0;
  font-size: 18px;
  font-weight: 600;
}

.event-groups h2 {
  font-size: 18px;
  margin: 18px 0 6px;
}

.event-groups h2:first-child {
  margin-top: 0;
}

.event-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.event-row:last-child {
  border-bottom: 0;
}

.event-name {
  font-weight: 600;
}

.event-desc {
  flex: 1;
  min-width: 200px;
  color: var(--text-dim);
  font-size: 15px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}

/* Rules page */
.form-flex {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin-top: 16px;
}

.form-flex .btn {
  white-space: nowrap;
  margin-left: auto;
}

.form-flex label {
  flex: 1 1 150px;
}

.f-num {
  width: 120px;
  text-align: right;
}

.form-flex .swatch {
  width: 44px;
}

.cat-out p {
  margin: 12px 0 0;
}

.cat-offline {
  color: var(--warn);
  font-weight: 600;
}

.editable {
  border-bottom: 1px dotted var(--line);
  cursor: pointer;
  min-height: 1.3em;
  display: inline-block;
  padding: 0 2px;
}

.editable:hover {
  border-bottom-color: var(--accent);
}

.editable.empty {
  color: var(--text-dim);
  font-style: italic;
}

.inline-input {
  width: 100%;
  max-width: 360px;
  margin-top: 0;
  font-size: 16px;
  padding: 6px 10px;
}

.swatch {
  width: 34px;
  height: 34px;
  padding: 2px;
  margin-top: 0;
  cursor: pointer;
}

.dlg h3 {
  font-size: 17px;
  margin: 14px 0 4px;
}

/* Phone widths */
@media (max-width: 640px) {
  body {
    font-size: 17px;
  }

  .topbar {
    padding: 12px 16px;
  }

  .nav {
    order: 3;
    width: 100%;
  }

  .page {
    padding: 20px 16px 48px;
  }

  .card {
    padding: 16px;
  }

  td.desc {
    max-width: 200px;
  }

  .home-grid {
    grid-template-columns: 1fr;
  }

  .chart-wrap {
    height: 280px;
  }
}
