/* Design tokens. Light by default; dark follows the system setting
   (prefers-color-scheme). Colors meet WCAG AA on --surface and --bg. */
:root {
  color-scheme: light dark;

  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --text: #0f172a;
  --muted: #586174;
  --border: #e2e7ef;
  --border-strong: #cdd5e1;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --success: #157f3d;
  --success-soft: #e7f6ed;
  --warning: #9a5b06;
  --warning-soft: #fff5e1;
  --danger: #c0262d;
  --danger-soft: #fdeeee;
  --error-bg: var(--danger-soft);
  --flash-bg: var(--success-soft);
  --focus: #4f46e5;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.14);
  --header-bg: rgba(255, 255, 255, 0.85);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --surface: #131a2b;
    --surface-2: #1a2236;
    --text: #e7eaf3;
    --muted: #9aa3b8;
    --border: #252e45;
    --border-strong: #34405c;
    --accent: #8f8ff9;
    --accent-hover: #a9a9fb;
    --accent-soft: #23264a;
    --accent-text: #0b1020;
    --success: #4ade80;
    --success-soft: #11301f;
    --warning: #fbbf24;
    --warning-soft: #36280b;
    --danger: #f87171;
    --danger-soft: #3a1619;
    --focus: #a9a9fb;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
    --header-bg: rgba(19, 26, 43, 0.85);
  }
}

* {
  box-sizing: border-box;
}

/* Components below set display; the hidden attribute must still win
   (e.g. the phone Menu button, which nav.js reveals). */
[hidden] {
  display: none !important;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  line-height: 1.25;
  letter-spacing: -0.015em;
}

h1 {
  font-size: 1.85rem;
  font-weight: 750;
  letter-spacing: -0.025em;
}

h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
}

h3 {
  font-size: 1rem;
  font-weight: 650;
}

/* Links in running text keep a soft underline (not color alone);
   menus, tables, buttons and cards drop it below. */
a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

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

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
  background: var(--surface);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 100;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Icons: inline SVG from icon() in helpers.php; inherit the text color. */
.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  vertical-align: -0.2em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Header / nav */

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.site-nav {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
}

.site-nav .brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6 55%, #ec4899);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.35);
}

.brand-mark .icon {
  width: 1.1rem;
  height: 1.1rem;
  vertical-align: 0;
}

/* Main menu: groups with drop-down links. Without JavaScript the
   drop-downs open on hover and keyboard focus (wide screens) and phones
   show every group expanded; public/js/nav.js adds click/tap toggles,
   Escape, and a "Menu" button on phones (html.js). */
.nav-menu {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-menu ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-menu a {
  text-decoration: none;
}

.nav-top {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--muted);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
}

.nav-top:hover {
  color: var(--text);
  background: var(--surface-2);
}

/* Current group: filled pill + bold, not color alone. */
.nav-item.is-current > .nav-top,
.nav-top[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}

.nav-sub a {
  color: var(--text);
}

.nav-sub .link-button {
  color: var(--text);
  text-decoration: none;
  font-size: inherit;
}

.nav-sub a[aria-current="page"] {
  font-weight: 700;
  color: var(--accent);
}

.nav-sub-toggle,
.nav-toggle {
  font: inherit;
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
}

.nav-sub-toggle {
  padding: 0.2rem 0.35rem;
  margin-left: -0.35rem;
  font-size: 0.8rem;
}

.nav-sub-toggle:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-color: var(--border-strong);
  color: var(--text);
  font-weight: 600;
  padding: 0.35rem 0.9rem;
}

/* Phones: one column of groups. */
@media (max-width: 47.99rem) {
  .nav-menu {
    flex-basis: 100%;
  }

  .nav-item {
    padding: 0.35rem 0;
    border-top: 1px solid var(--border);
  }

  .nav-top {
    padding-left: 0.5rem;
  }

  .nav-sub {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    padding: 0.25rem 0 0.35rem 1.25rem !important;
  }

  .nav-sub-toggle {
    display: none;
  }

  /* With the script: the whole menu collapses behind "Menu". */
  html.js .nav-menu:not(.nav-plain) {
    display: none;
  }

  html.js .nav-menu.menu-open {
    display: block;
  }
}

/* Wider screens: one row; links drop down under their group. */
@media (min-width: 48rem) {
  .nav-menu {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.35rem;
  }

  .nav-toggle {
    display: none;
  }

  .nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0;
    /* Room below the name, so the pointer can reach the drop-down. */
    padding: 0.35rem 0;
  }

  html:not(.js) .has-sub > .nav-top::after {
    content: " ▾";
    font-size: 0.8em;
  }

  .nav-sub {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 40;
    min-width: 13rem;
    padding: 0.4rem !important;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
  }

  .nav-sub li > a,
  .nav-sub .link-button {
    display: block;
    padding: 0.45rem 0.75rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
  }

  .nav-sub li > a:hover,
  .nav-sub .link-button:hover {
    background: var(--surface-2);
  }

  .nav-sub .link-button {
    width: 100%;
    text-align: left;
    color: var(--text);
    text-decoration: none;
  }

  html.js .has-sub > .nav-top {
    padding-right: 0.3rem;
    border-radius: 999px 0 0 999px;
  }

  html.js .has-sub > .nav-sub-toggle {
    align-self: stretch;
    display: inline-flex;
    align-items: center;
    margin: 0;
    padding: 0 0.6rem 0 0.2rem;
    border: 0;
    border-radius: 0 999px 999px 0;
  }

  .nav-item:hover > .nav-top,
  .nav-item:hover > .nav-sub-toggle {
    color: var(--text);
    background: var(--surface-2);
  }

  .nav-item.is-current > .nav-sub-toggle,
  .nav-item.is-current:hover > .nav-top,
  .nav-item.is-current:hover > .nav-sub-toggle {
    color: var(--accent);
    background: var(--accent-soft);
  }

  .nav-item:hover > .nav-sub,
  .nav-item.open > .nav-sub,
  html:not(.js) .nav-item:focus-within > .nav-sub {
    display: block;
  }
}

main {
  max-width: 72rem;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

/* Buttons */

.inline-form {
  display: inline;
}

.button,
button {
  font: inherit;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-text);
}

.button-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.button-secondary:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}

.button-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.button-danger:hover {
  background: color-mix(in srgb, var(--danger) 85%, #000000);
  border-color: color-mix(in srgb, var(--danger) 85%, #000000);
  color: #ffffff;
}

@media (prefers-color-scheme: dark) {
  .button-danger,
  .button-danger:hover {
    color: #1a0b0c;
  }
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
  text-underline-offset: 0.2em;
  cursor: pointer;
}

.link-button:hover {
  text-decoration-color: currentColor;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem 1rem;
  margin-bottom: 1.5rem;
}

.page-head h1,
.page-head h2 {
  margin: 0;
}

.page-head > p {
  margin: 0;
}

/* Messages */

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

.flash,
.error-summary,
.alert-panel {
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem 0.9rem 3rem;
  position: relative;
}

/* Status icon, drawn with a mask so it takes the text color. */
.flash::before,
.error-summary::before,
.alert-panel::before {
  content: "";
  position: absolute;
  left: 1.05rem;
  top: 1.05rem;
  width: 1.25rem;
  height: 1.25rem;
  background: currentColor;
  -webkit-mask: var(--status-icon) center / contain no-repeat;
  mask: var(--status-icon) center / contain no-repeat;
}

.flash {
  --status-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9.5'/%3E%3Cpath d='m8 12.5 2.7 2.7L16.2 9.5'/%3E%3C/svg%3E");
  background: var(--success-soft);
  border: 1px solid color-mix(in srgb, var(--success) 25%, transparent);
  margin: 0 0 1.25rem;
}

.flash::before {
  color: var(--success);
}

.error-summary,
.alert-panel {
  --status-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.3 3.9 2.4 17.6A2 2 0 0 0 4.1 20.6h15.8a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z'/%3E%3Cpath d='M12 9v4.5M12 17h.01'/%3E%3C/svg%3E");
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
}

.error-summary::before,
.alert-panel::before {
  color: var(--danger);
}

.error-summary {
  margin-bottom: 1.5rem;
}

.error-summary p {
  margin: 0 0 0.25rem;
  font-weight: 700;
}

.error-summary ul {
  margin: 0.25rem 0 0;
  padding-left: 1.1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.4;
  vertical-align: middle;
  padding: 0.12rem 0.6rem;
  border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 10%, transparent);
  color: var(--success);
}

.badge-danger {
  color: var(--danger);
}

/* "Bills 3" count in the top menu; red when something is overdue. */
.nav-count {
  display: inline-block;
  min-width: 1.35rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.35rem;
  text-align: center;
  text-decoration: none;
}

.nav-count-alert {
  background: var(--danger);
  color: #ffffff;
}

@media (prefers-color-scheme: dark) {
  .nav-count-alert {
    color: #1a0b0c;
  }
}

.badge-muted {
  color: var(--muted);
}

.badge-highlight {
  color: var(--accent);
  margin-left: 0.25rem;
}

/* Account types (accounts list). */
.badge-type {
  color: var(--muted);
}

.badge-type-credit_card {
  color: var(--accent);
}

.badge-type-loan {
  color: var(--warning);
}

.badge-type-personal {
  color: var(--success);
}

section {
  margin-bottom: 2.25rem;
}

.hint {
  color: var(--muted);
}

/* Tables: a rounded card with a soft header row. */

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.table-wrap > .data-table {
  margin-bottom: 0;
  border: 0;
  box-shadow: none;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1.5rem;
}

.data-table caption {
  text-align: left;
  font-weight: 700;
  font-size: 1rem;
  padding: 0.9rem 1rem 0.6rem;
  background: var(--surface);
}

.data-table th,
.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.data-table thead th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
}

.data-table tbody tr:last-child > * {
  border-bottom: 0;
}

.data-table tbody tr:hover > * {
  background: color-mix(in srgb, var(--surface-2) 60%, transparent);
}

.data-table tbody th {
  font-weight: 400;
}

.data-table tbody th a {
  font-weight: 650;
  color: var(--text);
  text-decoration: none;
}

.data-table tbody th a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.data-table tbody th .muted {
  display: block;
  font-size: 0.85rem;
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.data-table td.num {
  font-weight: 550;
}

.data-table td .muted {
  font-weight: 400;
}

.data-table td a {
  text-decoration: none;
}

.data-table td a:hover {
  text-decoration: underline;
}

/* A lone short link in the last cell (e.g. "View plan") stays on one line. */
.data-table td:last-child > a:only-child {
  white-space: nowrap;
}

/* Row actions: small outlined pills that never wrap mid-label. */
.data-table td[data-label="Actions"] a,
.data-table td[data-label="Actions"] .link-button,
.data-table td[data-label="Pay"] a {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.4;
  text-decoration: none;
  white-space: nowrap;
}

.data-table td[data-label="Actions"] a:hover,
.data-table td[data-label="Actions"] .link-button:hover,
.data-table td[data-label="Pay"] a:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.data-table td[data-label="Actions"] a[href*="/delete/"]:hover {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.data-table td[data-label="Actions"] .actions {
  flex-wrap: nowrap;
  gap: 0.35rem;
}

.data-table td[data-label="Actions"],
.data-table td[data-label="Pay"] {
  text-align: right;
  white-space: nowrap;
}

details.archived summary {
  cursor: pointer;
  margin-bottom: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

details > summary {
  cursor: pointer;
}

details > summary:hover {
  color: var(--text);
}

/* Details list */

.details {
  display: grid;
  grid-template-columns: minmax(10rem, max-content) 1fr;
  gap: 0.65rem 1.5rem;
  background: var(--surface);
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.details dt {
  font-weight: 600;
  color: var(--muted);
}

.details dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.details .notes {
  white-space: pre-line;
}

/* Forms */

.stacked-form {
  max-width: 36rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.stacked-form p:first-of-type {
  margin-top: 0;
}

.stacked-form > :last-child {
  margin-bottom: 0;
}

.field {
  margin-bottom: 1.25rem;
}

.field label {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.3rem;
}

.field .hint {
  margin: 0 0 0.35rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.field .error {
  margin: 0 0 0.35rem;
  color: var(--danger);
  font-weight: 600;
  font-size: 0.9rem;
}

.field input,
.field select,
.field textarea,
.select-inline {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.55rem 0.75rem;
}

.field input:hover,
.field select:hover,
.field textarea:hover,
.select-inline:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border-strong));
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.select-inline:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
  outline: none;
}

.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible,
.select-inline:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.field.has-error input,
.field.has-error select,
.field.has-error textarea {
  border: 2px solid var(--danger);
}

.field-checkbox {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 0.6rem;
  align-items: start;
}

.field-checkbox label {
  margin-bottom: 0;
  font-weight: 500;
}

.field-checkbox input {
  width: 1.2rem;
  height: 1.2rem;
  min-height: 0;
  margin-top: 0.2rem;
  padding: 0;
  accent-color: var(--accent);
}

.field-checkbox .hint {
  grid-column: 2;
}

input[type="radio"],
input[type="checkbox"] {
  accent-color: var(--accent);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.filters .field {
  margin: 0;
}

.filters .field input,
.filters .field select {
  width: auto;
  min-width: 9rem;
  height: 2.5rem;
  min-height: 0;
}

/* Filter-as-you-type above list tables (public/js/table-filter.js):
   a slim search bar rather than a boxed form. */

.table-filter {
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  align-items: center;
}

.table-filter .field label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.table-filter .field input {
  min-width: 18rem;
  height: 2.6rem;
  padding-left: 2.4rem;
  border-radius: 999px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888fa0' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 0.85rem center / 1.05rem;
  box-shadow: var(--shadow-sm);
}

.filter-empty {
  margin: 0;
  padding: 1rem;
  text-align: center;
}

.table-filter-status {
  margin: 0;
  align-self: center;
  font-size: 0.9rem;
}

/* Rows hidden by the filter must stay hidden in the stacked phone layout,
   where table rows are display: block. */
.data-table tr[hidden],
.data-table tfoot[hidden] {
  display: none;
}

.select-inline {
  height: 2.5rem;
  padding: 0 0.6rem;
  max-width: 100%;
}

.totals-row th,
.totals-row td {
  font-weight: 750;
  border-top: 2px solid var(--border-strong);
  background: var(--surface-2);
}

fieldset.field {
  border: 0;
  padding: 0;
  margin: 0 0 1.25rem;
}

fieldset.field legend {
  font-weight: 600;
  margin-bottom: 0.5rem;
}

fieldset .field-checkbox {
  margin-bottom: 0.5rem;
}

/* A titled group of optional fields inside a form (e.g. Subscription details). */
fieldset.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 0.9rem 1.1rem 0.25rem;
  margin: 0 0 1.25rem;
}

fieldset.form-section legend {
  font-weight: 700;
  padding: 0 0.35rem;
}

/* Dashboard */

/* At-a-glance row at the top of the dashboard. */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem 1.2rem;
  overflow: hidden;
}

.stat-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.stat-icon {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
}

.stat-icon .icon {
  vertical-align: 0;
}

.stat-danger .stat-icon {
  background: var(--danger-soft);
  color: var(--danger);
}

.stat-success .stat-icon {
  background: var(--success-soft);
  color: var(--success);
}

.stat-warning .stat-icon {
  background: var(--warning-soft);
  color: var(--warning);
}

.stat-value {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 750;
  letter-spacing: -0.025em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.stat-value-muted {
  font-size: 1.15rem;
  color: var(--muted);
}

.stat-sub {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.stat-meter {
  height: 6px;
  margin-top: 0.75rem;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.stat-meter > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--success);
}

/* Meter widths in 10% steps (CSP allows no inline style). */
.meter-0 { width: 0; }
.meter-10 { width: 10%; }
.meter-20 { width: 20%; }
.meter-30 { width: 30%; }
.meter-40 { width: 40%; }
.meter-50 { width: 50%; }
.meter-60 { width: 60%; }
.meter-70 { width: 70%; }
.meter-80 { width: 80%; }
.meter-90 { width: 90%; }
.meter-100 { width: 100%; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}

.card-label {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--muted);
}

.card-value {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.card-value-muted {
  font-size: 1.05rem;
  color: var(--muted);
}

.card .hint {
  font-size: 0.85rem;
  margin: 0.25rem 0 0;
}

.card-definition {
  margin-top: 0.6rem;
  font-size: 0.8rem;
}

.card-definition summary {
  cursor: pointer;
  color: var(--muted);
}

.card-definition summary:hover {
  color: var(--accent);
}

.card-definition p {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.alert-panel {
  margin-bottom: 1.5rem;
}

.alert-panel h2 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  color: var(--danger);
}

.alert-panel .hint {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}

.alert-panel .plain-list li {
  padding: 0.45rem 0;
  border-top: 1px solid color-mix(in srgb, var(--danger) 15%, transparent);
}

.plain-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.plain-list li {
  padding: 0.35rem 0;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 1rem;
}

.two-col > div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}

.two-col h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.two-col p {
  margin: 0;
}

.progress-list li {
  padding: 0.6rem 0;
}

.progress-list label {
  display: block;
  margin-bottom: 0.35rem;
}

.progress-list progress {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  max-width: 32rem;
  height: 0.6rem;
  border: 0;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--success);
  overflow: hidden;
}

.progress-list progress::-webkit-progress-bar {
  background: var(--surface-2);
  border-radius: 999px;
}

.progress-list progress::-webkit-progress-value {
  background: var(--success);
  border-radius: 999px;
}

.progress-list progress::-moz-progress-bar {
  background: var(--success);
  border-radius: 999px;
}

.chart-figure {
  margin: 0 0 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}

.chart-figure details > summary {
  font-size: 0.9rem;
  color: var(--muted);
}

.chart-figure details .data-table {
  margin-top: 0.75rem;
}

.chart {
  width: 100%;
  height: auto;
  display: block;
  margin: 0.75rem 0;
}

.chart-bar {
  fill: var(--accent);
  rx: 3px;
}

.chart-bar:hover {
  fill: var(--accent-hover);
}

.chart-axis {
  stroke: var(--border-strong);
  stroke-width: 1;
}

/* Sizes are in chart units (the SVG scales with the card), so phones need
   bigger numbers to stay readable. */
.chart-label {
  fill: var(--muted);
  font-size: 13px;
}

@media (max-width: 40rem) {
  .chart-label {
    font-size: 34px;
  }
}

.compact-table {
  max-width: 24rem;
}

/* Planner */

.planner-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 0 2rem;
  align-items: start;
}

.planner-form .button {
  justify-self: start;
}

.planner-form .field input[type="text"] {
  max-width: 12rem;
}

.selected-row th,
.selected-row td {
  background: var(--accent-soft);
}

.data-table tbody tr.selected-row:hover > * {
  background: var(--accent-soft);
}

.note-row td {
  padding-top: 0;
  font-size: 0.9rem;
}

.paid-off-note {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--success);
}

.schedule-year {
  margin-bottom: 0.5rem;
}

.schedule-year summary {
  cursor: pointer;
  padding: 0.5rem 0;
  font-weight: 600;
}

.assumptions {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 0.75rem 1.25rem;
}

.assumptions h2 {
  font-size: 1.05rem;
}

/* Tabs (link-based): a segmented control. */

.tabs {
  margin: 0.5rem 0 1.75rem;
  overflow-x: auto;
}

.tabs ul {
  list-style: none;
  margin: 0;
  padding: 0.25rem;
  display: inline-flex;
  gap: 0.25rem;
  white-space: nowrap;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.tabs a {
  display: block;
  padding: 0.45rem 1.1rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
}

.tabs a:hover {
  color: var(--text);
}

/* Active tab: raised pill + bold, not color alone. */
.tabs a.active {
  color: var(--text);
  font-weight: 750;
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* Small screens: stack table rows into labeled cards */

@media (max-width: 40rem) {
  h1 {
    font-size: 1.55rem;
  }

  main {
    padding-top: 1.25rem;
  }

  .data-table thead {
    position: absolute;
    left: -9999px;
  }

  .data-table tr {
    display: block;
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 0;
  }

  .data-table tbody tr:last-child {
    border-bottom: 0;
  }

  .data-table th,
  .data-table td {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    border: none;
    padding: 0.25rem 1rem;
  }

  .data-table tbody th {
    display: block;
  }

  .data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    text-align: left;
  }

  .data-table td[data-label="Actions"],
  .data-table td[data-label="Pay"] {
    padding-top: 0.5rem;
  }

  .data-table td[data-label="Actions"]::before,
  .data-table td[data-label="Pay"]::before {
    content: none;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .stat {
    padding: 0.9rem 1rem;
  }

  .stat-value {
    font-size: 1.3rem;
  }

  .stat-sub {
    font-size: 0.8rem;
  }

  .table-filter .field,
  .table-filter .field input {
    width: 100%;
    min-width: 0;
  }

  .stacked-form {
    padding: 1.1rem;
  }

  .details {
    grid-template-columns: 1fr;
    gap: 0.1rem;
  }

  .details dd {
    margin-bottom: 0.5rem;
  }
}

/* Inline warning text, e.g. a price increase. */
.text-danger {
  color: var(--danger);
}

/* Short action links in table rows stay on one line each. */
.data-table .actions a {
  white-space: nowrap;
}

/* Spending suggestions: quick-add chips and "make it a subscription?" banners. */
.quick-add {
  margin: 0 0 1.25rem;
}

.quick-add-title {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 0.5rem;
}

.quick-add ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  display: inline-block;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 550;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}

.chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.suggestion,
.insight {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem 1rem 1.4rem;
  position: relative;
  overflow: hidden;
}

/* Accent stripe on the left edge. */
.suggestion::before,
.insight::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, #6366f1, #a855f7);
}

.suggestion {
  margin: 0 0 1rem;
}

.suggestion p {
  margin: 0 0 0.6rem;
}

/* Insights: short cards with the numbers and an action. */
.insight-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.insight-title {
  font-weight: 700;
  margin: 0 0 0.25rem;
}

.insight-detail {
  margin: 0 0 0.6rem;
  color: var(--muted);
}

.insight .actions {
  gap: 0.35rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.insight .actions a,
.insight .actions .link-button {
  text-decoration: none;
}

.insight .actions a:hover,
.insight .actions .link-button:hover {
  text-decoration: underline;
}

/* Signed-out pages: a centered card. */
.auth-card {
  max-width: 26rem;
  margin: 2rem auto;
}

.auth-card h1 {
  text-align: center;
  margin: 0 0 1.25rem;
}

.auth-card .stacked-form {
  max-width: none;
}

/* Plain forms written as <p><label>Name<br><input></label></p> with a bare
   submit button (auth and account pages): same look as .field forms. */
main form p > label {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
}

main form p > label > br {
  display: none;
}

main form p > label > input:not([type="checkbox"]):not([type="radio"]),
main form p > label > select,
main form p > label > textarea {
  display: block;
  width: 100%;
  min-height: 2.75rem;
  margin-top: 0.3rem;
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
}

main form p > label > input:focus,
main form p > label > select:focus,
main form p > label > textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
  outline: none;
}

main form p > label > input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

main form button[type="submit"]:not([class]) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.6rem;
  padding: 0.5rem 1.25rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

main form button[type="submit"]:not([class]):hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.auth-card .stacked-form button[type="submit"] {
  width: 100%;
  margin-top: 0.25rem;
}

.auth-card > p {
  text-align: center;
  font-size: 0.92rem;
}

ul.error-summary {
  list-style: none;
}
