/* ============================================================
   SpendWise — light theme
   White surfaces, real elevation, brand gradient as the only
   loud color. Material's structural sense (cards, hierarchy,
   motion) with a futuristic edge: glassy nav, gradient hero
   number, color-railed rows that softly tint by category.
   ============================================================ */

:root {
  /* ---------- base palette ---------- */
  --bg-0: #f6f8fc;
  --bg-1: #ffffff;
  --surface-0: #ffffff;
  --surface-1: #ffffff;
  --surface-2: #f1f3f9;
  --surface-3: #e6eaf2;
  --border-soft: rgba(15, 19, 32, 0.06);
  --border: rgba(15, 19, 32, 0.10);
  --border-strong: rgba(15, 19, 32, 0.18);

  --text: #0f1320;
  --text-2: #4a5061;
  --text-3: #6c7280;
  --text-4: #9ca3af;

  /* ---------- brand accents ---------- */
  --c-magenta: #ff3c8e;
  --c-magenta-deep: #ed1a78;
  --c-violet: #9b7bff;
  --c-violet-deep: #7b53f8;
  --c-cyan: #2bb8e0;

  /* ---------- semantic ---------- */
  --c-spend: #f25e36;
  --c-positive: #18b070;
  --c-warning: #e89c0c;
  --c-danger: #e53e60;

  /* ---------- category jewel tones (tuned for light bg) ---------- */
  --cat-sapphire: #3f78e4;
  --cat-amethyst: #8e3eee;
  --cat-magenta:  #e63d8a;
  --cat-citrine:  #d99416;
  --cat-jade:     #15a575;
  --cat-ruby:     #d83838;
  --cat-topaz:    #d96d18;
  --cat-peridot:  #6fa824;
  --cat-default:  var(--c-violet);

  /* ---------- type ---------- */
  --font-display: "Bricolage Grotesque", "Geist", system-ui, sans-serif;
  --font-body: "Geist", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", "JetBrains Mono", ui-monospace, "SF Mono", monospace;

  /* ---------- shape ---------- */
  --r-sm: 10px;
  --r:    14px;
  --r-lg: 22px;
  --r-xl: 28px;

  /* ---------- shadow (Material-style elevation) ---------- */
  --shadow-sm: 0 1px 2px rgba(15, 19, 32, 0.04), 0 1px 3px rgba(15, 19, 32, 0.05);
  --shadow:    0 4px 12px rgba(15, 19, 32, 0.05), 0 2px 4px rgba(15, 19, 32, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 19, 32, 0.08), 0 4px 12px rgba(15, 19, 32, 0.06);
  --shadow-elevated: 0 24px 48px -12px rgba(15, 19, 32, 0.14), 0 8px 16px rgba(15, 19, 32, 0.05);
  --glow-primary: 0 8px 24px -6px rgba(255, 60, 142, 0.45);
  --focus-ring: 0 0 0 3px rgba(155, 123, 255, 0.25);

  /* ---------- aurora background (pastel wash) ---------- */
  --aurora:
    radial-gradient(60% 50% at 16% 8%,  rgba(155, 123, 255, 0.12) 0%, transparent 65%),
    radial-gradient(55% 45% at 88% 0%,  rgba(255, 60, 142, 0.10)  0%, transparent 60%),
    radial-gradient(70% 55% at 50% 100%, rgba(91, 213, 255, 0.06) 0%, transparent 65%);
}

/* ============================================================
   Reset + base
   ============================================================ */

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

html, body {
  margin: 0;
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--font-body);
  font-feature-settings: "ss01", "cv11";
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  background:
    var(--aurora),
    var(--bg-0);
  background-attachment: fixed;
}

::selection {
  background: rgba(255, 60, 142, 0.2);
  color: var(--text);
}

a {
  color: var(--c-violet-deep);
  text-decoration: none;
  transition: color 120ms ease;
}
a:hover { color: var(--c-magenta-deep); }

hr {
  border: 0;
  border-top: 1px solid var(--border-soft);
  margin: 1.25rem 0;
}

code, kbd, pre, samp {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--surface-2);
  padding: 0.05rem 0.35rem;
  border-radius: 5px;
}

/* ============================================================
   Type
   ============================================================ */

h1, h2, h3, h4, h5, h6,
.display-1, .display-2, .display-3, .display-4, .display-5, .display-6 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.1;
  color: var(--text);
  margin: 0;
}

h1, .display-5 { font-size: 2.5rem; font-weight: 600; }
.display-6 { font-size: 2rem; font-weight: 600; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.4rem; }
h4 { font-size: 1.15rem; }
h5 { font-size: 1rem; font-weight: 600; }
h6 { font-size: 0.9rem; font-weight: 600; letter-spacing: 0; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-3);
}

.tabnum, .font-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.text-secondary { color: var(--text-2) !important; }
.text-muted { color: var(--text-3) !important; }
.text-spend { color: var(--c-spend); }
.text-positive { color: var(--c-positive); }
.text-warning { color: var(--c-warning); }
.text-danger { color: var(--c-danger); }

/* ============================================================
   Layout
   ============================================================ */

.app-main {
  max-width: 1240px;
  margin: 0 auto;
  padding: calc(64px + 2rem) 1.25rem 6rem;
}

@media (min-width: 768px) {
  .app-main { padding-left: 2rem; padding-right: 2rem; }
}

.pagehead { margin-bottom: 2rem; }

/* ============================================================
   Navbar — glassy on light
   ============================================================ */

.app-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1030;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border-soft);
}

.app-nav-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

@media (min-width: 768px) {
  .app-nav-inner { padding-left: 2rem; padding-right: 2rem; }
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.025em;
  background: linear-gradient(135deg, var(--c-magenta) 0%, var(--c-violet) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-decoration: none;
}
.brand:hover { filter: brightness(1.05); }

.brand-dot {
  width: 10px; height: 10px; border-radius: 999px;
  background: linear-gradient(135deg, var(--c-magenta), var(--c-violet));
  box-shadow: 0 0 14px rgba(255, 60, 142, 0.5);
  -webkit-text-fill-color: initial;
}

.app-nav-links {
  display: none;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
}
@media (min-width: 820px) { .app-nav-links { display: flex; } }

.nav-link {
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  color: var(--text-2);
  font-weight: 500;
  font-size: 0.95rem;
  transition: background 120ms, color 120ms;
  text-decoration: none;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active {
  background: var(--text);
  color: #ffffff;
}

.app-nav-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* mobile menu */
.nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  color: var(--text);
  cursor: pointer;
}
@media (min-width: 820px) { .nav-toggle { display: none; } }

.app-nav-mobile {
  display: none;
  padding: 0.5rem 1.25rem 1rem;
  border-top: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.92);
}
.app-nav-mobile.open { display: block; }
.app-nav-mobile .nav-link { display: block; margin: 0.25rem 0; }

/* ============================================================
   Cards
   ============================================================ */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  position: relative;
  transition: box-shadow 160ms ease, transform 160ms ease;
}

.card-glass {
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-soft);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.card-hero {
  background:
    radial-gradient(120% 100% at 0% 0%, rgba(155, 123, 255, 0.13) 0%, transparent 60%),
    radial-gradient(80% 100% at 100% 100%, rgba(255, 60, 142, 0.10) 0%, transparent 65%),
    #ffffff;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.card-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--r-lg);
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.55) 0%, transparent 40%);
}

.card-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.95rem;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: transform 80ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.btn-pill { border-radius: 999px; }
.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.85rem; }
.btn-lg { padding: 0.75rem 1.4rem; font-size: 1rem; }
.btn-block { display: flex; width: 100%; }

.btn-primary {
  background: linear-gradient(135deg, var(--c-magenta) 0%, var(--c-violet) 100%);
  color: #ffffff;
  border: 0;
  box-shadow: var(--glow-primary);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--c-magenta-deep) 0%, var(--c-violet-deep) 100%);
  color: #ffffff;
  box-shadow: 0 12px 28px -6px rgba(255, 60, 142, 0.55);
}

.btn-secondary {
  background: var(--text);
  color: #ffffff;
  border: 1px solid var(--text);
}
.btn-secondary:hover { background: #232838; border-color: #232838; color: #ffffff; }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }

.btn-danger {
  background: transparent;
  color: var(--c-danger);
  border: 1px solid rgba(229, 62, 96, 0.35);
}
.btn-danger:hover {
  background: rgba(229, 62, 96, 0.08);
  border-color: rgba(229, 62, 96, 0.55);
  color: var(--c-danger);
}

.btn-icon {
  width: 36px; height: 36px;
  padding: 0;
  border-radius: 10px;
}
.btn-icon.btn-sm { width: 30px; height: 30px; }

/* ============================================================
   Form controls — Material-inspired outlined
   ============================================================ */

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 0.4rem;
}

.form-text {
  font-size: 0.82rem;
  color: var(--text-3);
  margin-top: 0.35rem;
}

.form-control, .form-select {
  display: block;
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
  color-scheme: light;
}
.form-control::placeholder { color: var(--text-4); }
.form-control:hover, .form-select:hover {
  border-color: var(--border-strong);
}
.form-control:focus, .form-select:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--c-violet);
  box-shadow: var(--focus-ring);
}
.form-control[readonly] { background: var(--surface-2); color: var(--text-2); }
.form-control:disabled { opacity: 0.6; cursor: not-allowed; }

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'><path fill='%234a5061' d='M3 6l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2.25rem;
}

/* Native popup dropdown options — keep readable on every OS */
.form-select option {
  background-color: #ffffff;
  color: var(--text);
  padding: 0.5rem;
}

input[type="file"].form-control {
  padding: 0.45rem 0.55rem;
}

input[type="date"].form-control { color-scheme: light; }

.input-group {
  display: flex;
  align-items: stretch;
  width: 100%;
}
.input-group > .form-control,
.input-group > .form-select {
  flex: 1;
  border-radius: 0;
}
.input-group > :first-child { border-top-left-radius: var(--r-sm); border-bottom-left-radius: var(--r-sm); }
.input-group > :last-child  { border-top-right-radius: var(--r-sm); border-bottom-right-radius: var(--r-sm); }
.input-group > .btn {
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.input-group > .btn:hover { background: var(--surface-3); }
.input-group > .form-control + .btn { border-left: 0; }

/* ============================================================
   Badge / pill
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border-soft);
}

.badge-soft {
  background: rgba(155, 123, 255, 0.10);
  color: var(--c-violet-deep);
  border: 1px solid rgba(155, 123, 255, 0.30);
}

.badge-spend  { background: rgba(242, 94, 54, 0.10); color: var(--c-spend);    border-color: rgba(242, 94, 54, 0.28); }
.badge-positive { background: rgba(24, 176, 112, 0.10); color: var(--c-positive); border-color: rgba(24, 176, 112, 0.28); }

/* category pill — colored by --cat-color inline */
.cat-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  background: color-mix(in oklab, var(--cat-color, var(--cat-default)) 12%, white);
  color: var(--cat-color, var(--cat-default));
  border: 1px solid color-mix(in oklab, var(--cat-color, var(--cat-default)) 28%, transparent);
  text-decoration: none;
  white-space: nowrap;
}
.cat-dot {
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--cat-color, var(--cat-default));
}

/* ============================================================
   Expense list — color rail + subtle category tint
   ============================================================ */

.expense-list { display: grid; gap: 0.5rem; }

.expense-list-scroll {
  max-height: 580px;
  overflow-y: auto;
  padding-right: 4px;
  margin-right: -4px;
}
.expense-list-scroll::-webkit-scrollbar { width: 6px; }
.expense-list-scroll::-webkit-scrollbar-track { background: transparent; }
.expense-list-scroll::-webkit-scrollbar-thumb {
  background: rgba(15, 19, 32, 0.15);
  border-radius: 3px;
}
.expense-list-scroll::-webkit-scrollbar-thumb:hover { background: rgba(15, 19, 32, 0.28); }
.expense-list-scroll { scrollbar-width: thin; scrollbar-color: rgba(15, 19, 32, 0.18) transparent; }

.expense-row {
  display: grid;
  grid-template-columns: 4px minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
  padding: 0.85rem 1rem 0.85rem 0;
  background:
    linear-gradient(90deg,
      color-mix(in oklab, var(--cat-color, var(--cat-default)) 6%, white) 0%,
      #ffffff 40%,
      #ffffff 100%);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
  overflow: hidden;
}
.expense-row:hover {
  border-color: color-mix(in oklab, var(--cat-color, var(--cat-default)) 20%, var(--border));
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.expense-row .rail {
  align-self: stretch;
  background: var(--cat-color, var(--cat-default));
}

.expense-body { min-width: 0; padding-left: 0.5rem; display: flex; flex-direction: column; gap: 0.4rem; }

/* Description sits on its own line and may use the full width */
.expense-desc {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  line-height: 1.3;
}
.expense-desc.empty { color: var(--text-3); font-weight: 400; font-style: italic; }

/* Row of tags: category pill + payment badge, evenly spaced */
.expense-tags {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.expense-meta {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.8rem;
  color: var(--text-3);
  font-family: var(--font-mono);
  flex-wrap: wrap;
}
.expense-meta .dot { width: 3px; height: 3px; border-radius: 999px; background: var(--text-4); flex-shrink: 0; }

.expense-tail {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-right: 1rem;
}

.expense-amount {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  color: var(--text);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-3);
}
.empty-state .icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  background: linear-gradient(135deg, var(--c-violet), var(--c-magenta));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.empty-state .title { color: var(--text); font-weight: 600; margin-bottom: 0.25rem; }

/* ============================================================
   Hero number — dramatic gradient on light
   ============================================================ */

.hero-eyebrow { color: var(--text-3); font-size: 0.85rem; margin-bottom: 0.4rem; }

.hero-amount {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-size: clamp(3.5rem, 9vw, 5.5rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  background: linear-gradient(135deg, #1a1f33 0%, #5b3da0 55%, #c41e7e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}
.hero-amount .currency {
  font-size: 0.42em;
  font-weight: 500;
  color: var(--text-2);
  vertical-align: 0.6em;
  margin-right: 0.1em;
  -webkit-text-fill-color: var(--text-2);
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-top: 1.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-soft);
}
.hero-stat-label {
  font-size: 0.8rem;
  color: var(--text-3);
  margin-bottom: 0.25rem;
}
.hero-stat-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  font-size: 1.1rem;
  color: var(--text);
}

/* ============================================================
   Tables
   ============================================================ */

.table-glass {
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface-0);
}
.table-glass table {
  width: 100%;
  border-collapse: collapse;
}
.table-glass th, .table-glass td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
}
.table-glass thead th {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  background: var(--surface-2);
}
.table-glass tbody tr:last-child td { border-bottom: 0; }
.table-glass tbody tr:hover { background: var(--surface-2); }
.text-end { text-align: right; }
.text-nowrap { white-space: nowrap; }

/* ============================================================
   Category tiles
   ============================================================ */

.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.85rem;
}

.cat-tile {
  position: relative;
  padding: 1rem 1.1rem;
  background: var(--surface-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}
.cat-tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(80% 100% at 0% 0%, color-mix(in oklab, var(--cat-color, var(--cat-default)) 16%, transparent) 0%, transparent 60%);
  pointer-events: none;
}
.cat-tile:hover {
  border-color: color-mix(in oklab, var(--cat-color, var(--cat-default)) 40%, var(--border));
  transform: translateY(-2px);
  box-shadow: 0 16px 32px -16px color-mix(in oklab, var(--cat-color, var(--cat-default)) 40%, rgba(15, 19, 32, 0.18));
}
.cat-tile .name {
  display: flex; align-items: center; gap: 0.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  font-size: 1rem;
}
.cat-tile .swatch {
  width: 14px; height: 14px;
  border-radius: 999px;
  background: var(--cat-color, var(--cat-default));
  flex-shrink: 0;
}
.cat-tile .meta {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-3);
}
.cat-tile .actions {
  margin-top: 0.85rem;
  display: flex; gap: 0.4rem;
}

/* ============================================================
   Alerts / flash messages
   ============================================================ */

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-soft);
  background: var(--surface-1);
  color: var(--text);
  font-size: 0.92rem;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}
.alert.alert-success { background: #ebfaf3; border-color: rgba(24, 176, 112, 0.30); color: #0d5d3a; }
.alert.alert-warning { background: #fdf6e7; border-color: rgba(232, 156, 12, 0.30); color: #7a4d05; }
.alert.alert-danger  { background: #fceaef; border-color: rgba(229, 62, 96, 0.30); color: #8d1f33; }
.alert.alert-info    { background: #ebf6fd; border-color: rgba(43, 184, 224, 0.30); color: #0c4862; }

.flash-stack {
  position: fixed;
  top: calc(64px + 12px);
  right: 1.25rem;
  z-index: 1080;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 380px;
  pointer-events: none;
}
.flash-stack .alert {
  pointer-events: auto;
  box-shadow: var(--shadow-lg);
}

/* ============================================================
   Auth layout
   ============================================================ */

.auth-shell {
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 2rem;
  background: var(--surface-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-elevated);
  position: relative;
}
.auth-card::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: var(--r-lg);
  padding: 1px;
  background: linear-gradient(135deg, rgba(255, 60, 142, 0.45) 0%, transparent 35%, transparent 65%, rgba(155, 123, 255, 0.45) 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
}
.auth-title { margin-bottom: 0.5rem; }
.auth-sub { color: var(--text-2); margin-bottom: 1.5rem; }

/* ============================================================
   Receipt preview
   ============================================================ */

.modal-glass {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-elevated);
  color: var(--text);
}
.receipt-modal-body {
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: var(--r);
  overflow: hidden;
}
.receipt-modal-body img { max-width: 100%; max-height: 70vh; display: block; }
.receipt-modal-body iframe { width: 100%; height: 70vh; border: 0; background: #fff; }

/* ============================================================
   Utilities
   ============================================================ */

.row { display: flex; flex-wrap: wrap; gap: 1rem; }
.col-12 { flex: 0 0 100%; max-width: 100%; }
@media (min-width: 768px) {
  .col-md-6 { flex: 0 0 calc(50% - 0.5rem); max-width: calc(50% - 0.5rem); }
}
@media (min-width: 992px) {
  .col-lg-5 { flex: 0 0 calc(41.6667% - 0.6rem); max-width: calc(41.6667% - 0.6rem); }
  .col-lg-7 { flex: 0 0 calc(58.3333% - 0.4rem); max-width: calc(58.3333% - 0.4rem); }
  .col-lg-6 { flex: 0 0 calc(50% - 0.5rem); max-width: calc(50% - 0.5rem); }
  .col-lg-4 { flex: 0 0 calc(33.3333% - 0.67rem); max-width: calc(33.3333% - 0.67rem); }
  .col-lg-8 { flex: 0 0 calc(66.6667% - 0.33rem); max-width: calc(66.6667% - 0.33rem); }
}

.d-flex { display: flex; }
.d-inline-flex { display: inline-flex; }
.d-grid { display: grid; }
.d-none { display: none; }
.flex-wrap { flex-wrap: wrap; }
.flex-column { flex-direction: column; }
.align-items-center { align-items: center; }
.align-items-end { align-items: flex-end; }
.justify-content-between { justify-content: space-between; }
.justify-content-end { justify-content: flex-end; }
.justify-content-center { justify-content: center; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }

.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 0.25rem; } .mb-2 { margin-bottom: 0.5rem; } .mb-3 { margin-bottom: 0.75rem; } .mb-4 { margin-bottom: 1rem; } .mb-5 { margin-bottom: 1.5rem; }
.mt-0 { margin-top: 0; } .mt-2 { margin-top: 0.5rem; } .mt-3 { margin-top: 0.75rem; } .mt-4 { margin-top: 1rem; } .mt-5 { margin-top: 1.5rem; }
.me-2 { margin-right: 0.5rem; } .me-3 { margin-right: 0.75rem; }
.ms-auto { margin-left: auto; }
.p-3 { padding: 0.75rem; } .p-4 { padding: 1rem; } .p-5 { padding: 1.5rem; }
.py-5 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.w-100 { width: 100%; }

.fw-500 { font-weight: 500; } .fw-600 { font-weight: 600; } .fw-semibold { font-weight: 600; } .fw-700 { font-weight: 700; }
.small { font-size: 0.85rem; }

/* ============================================================
   Animations
   ============================================================ */

@media (prefers-reduced-motion: no-preference) {
  .fade-in { animation: fadeIn 380ms cubic-bezier(0.22, 1, 0.36, 1) both; }
  .fade-in-delay-1 { animation-delay: 60ms; }
  .fade-in-delay-2 { animation-delay: 120ms; }
  .fade-in-delay-3 { animation-delay: 180ms; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Mobile tweaks
   ============================================================ */

@media (max-width: 640px) {
  .app-main { padding-top: 5rem; padding-bottom: 3rem; }
  .card, .card-glass { padding: 1.15rem; }
  .card-hero { padding: 1.5rem 1.25rem; }
  .hero-amount { font-size: 3rem; }
  .flash-stack { right: 0.75rem; left: 0.75rem; max-width: none; }
  .expense-row { grid-template-columns: 4px minmax(0,1fr) auto; }
  .expense-meta { font-size: 0.72rem; }
  .expense-list-scroll { max-height: 460px; }
}

/* ============================================================
   Calendar
   ============================================================ */

.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.cal-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  min-width: 220px;
}
.cal-title .muted { color: var(--text-3); font-weight: 500; }
.cal-nav { display: flex; align-items: center; gap: 0.5rem; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-dow {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 0.4rem 0;
}

.cal-cell {
  position: relative;
  min-height: 92px;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  padding: 0.5rem 0.55rem;
  cursor: pointer;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease, background 140ms ease;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  overflow: hidden;
}
.cal-cell:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.cal-cell.is-empty {
  background: transparent;
  border-color: transparent;
  cursor: default;
}
.cal-cell.is-empty:hover { box-shadow: none; transform: none; }
.cal-cell.is-other { opacity: 0.4; }
.cal-cell.is-today { border-color: var(--c-violet); box-shadow: 0 0 0 1px var(--c-violet); }
.cal-cell.is-selected {
  border-color: var(--c-magenta);
  box-shadow: 0 0 0 2px rgba(255, 60, 142, 0.35);
}

.cal-daynum {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-2);
}
.cal-cell.is-today .cal-daynum {
  color: #fff;
  background: var(--c-violet);
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
}

.cal-amount {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  margin-top: auto;
  line-height: 1.1;
}
.cal-count { font-size: 0.7rem; color: var(--text-3); font-family: var(--font-mono); }

.cal-dots { display: flex; gap: 3px; flex-wrap: wrap; }
.cal-dots .d {
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--c, var(--cat-default));
}

@media (max-width: 640px) {
  .cal-cell { min-height: 68px; padding: 0.35rem 0.4rem; }
  .cal-amount { font-size: 0.8rem; }
  .cal-count { display: none; }
  .cal-daynum { font-size: 0.72rem; }
}

/* Day panel */
.day-panel { margin-top: 1.5rem; }
.day-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.day-panel-total {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 1.25rem;
}

/* ============================================================
   Modal (edit expense)
   ============================================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1090;
  background: rgba(15, 19, 32, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}
.modal-backdrop.open { display: flex; }

.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface-1);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-elevated);
  padding: 1.5rem;
  position: relative;
  animation: modalIn 200ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.modal-close {
  width: 34px; height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border-soft);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--surface-3); color: var(--text); }

/* ============================================================
   Payment type badge
   ============================================================ */

.pay-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  font-family: var(--font-body);
  border: 1px solid var(--border-soft);
  white-space: nowrap;
}
.pay-badge.cash {
  background: rgba(24, 176, 112, 0.10);
  color: #0d7a4d;
  border-color: rgba(24, 176, 112, 0.28);
}
.pay-badge.online {
  background: rgba(43, 130, 224, 0.10);
  color: #1d5fa8;
  border-color: rgba(43, 130, 224, 0.28);
}

/* Segmented toggle for payment type in forms */
.pay-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 3px;
  gap: 3px;
}
.pay-toggle label {
  position: relative;
  cursor: pointer;
}
.pay-toggle input {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
}
.pay-toggle .seg {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-2);
  transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease;
}
.pay-toggle input:checked + .seg {
  background: #fff;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.pay-toggle input:focus-visible + .seg {
  box-shadow: var(--focus-ring);
}

/* Category detail header */
.cat-detail-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.cat-detail-swatch {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: var(--cat-color, var(--cat-default));
  box-shadow: 0 6px 16px -6px color-mix(in oklab, var(--cat-color, var(--cat-default)) 70%, transparent);
  flex-shrink: 0;
}
.cat-tile-link { text-decoration: none; color: inherit; display: block; }
.cat-tile .view-hint {
  margin-top: 0.6rem;
  font-size: 0.78rem;
  color: var(--text-3);
  display: flex; align-items: center; gap: 0.3rem;
}

/* ============================================================
   Payments overview
   ============================================================ */

.scope-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 3px;
  gap: 3px;
}
.scope-toggle a {
  padding: 0.4rem 1rem;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-2);
  text-decoration: none;
  transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease;
}
.scope-toggle a.active {
  background: #fff;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.pay-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.pay-card {
  display: block;
  text-decoration: none;
  color: inherit;
  position: relative;
  padding: 1.5rem;
  border-radius: var(--r-lg);
  border: 1px solid var(--border-soft);
  background: var(--surface-1);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}
.pay-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  color: inherit;
}
.pay-card::before {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(90% 100% at 0% 0%, var(--accent-wash) 0%, transparent 60%);
  pointer-events: none;
}
.pay-card.cash   { --accent: #15a575; --accent-wash: rgba(24,176,112,0.12); }
.pay-card.online { --accent: #2bb8e0; --accent-wash: rgba(43,130,224,0.12); }

.pay-card-head {
  display: flex; align-items: center; gap: 0.6rem;
  margin-bottom: 1rem;
}
.pay-card-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 6px 16px -6px var(--accent);
}
.pay-card-label { font-weight: 600; font-size: 1.05rem; }
.pay-card-amount {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 2.4rem;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--text);
}
.pay-card-sub {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-3);
  font-family: var(--font-mono);
  display: flex; align-items: center; gap: 0.5rem;
}
.pay-card-bar {
  margin-top: 1rem;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.pay-card-bar > span {
  display: block; height: 100%;
  background: var(--accent);
  border-radius: 999px;
}
.pay-card .go {
  margin-top: 1rem;
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 500;
  display: flex; align-items: center; gap: 0.3rem;
}

/* split bar inside category table */
.split-bar {
  display: flex;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-3);
  min-width: 80px;
}
.split-bar .cash   { background: #15a575; }
.split-bar .online { background: #2bb8e0; }

.legend-row {
  display: flex; gap: 1.25rem; flex-wrap: wrap;
  font-size: 0.8rem; color: var(--text-2);
  margin-top: 0.25rem;
}
.legend-row .key { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend-row .key .sw { width: 10px; height: 10px; border-radius: 3px; }
.legend-row .key .sw.cash { background: #15a575; }
.legend-row .key .sw.online { background: #2bb8e0; }

/* Calendar month total pill (next to the month/year title) */
.cal-total {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  white-space: nowrap;
}

/* ============================================================
   Dashboard: match "This month" card height to the Quick add card
   ------------------------------------------------------------
   On desktop the left (Quick add) card defines the row height; the
   entries card absolutely fills its column so both cards are exactly
   the same height, and the list scrolls within the leftover space.
   On mobile the columns stack, so the capped scroll height applies.
   ============================================================ */

@media (min-width: 992px) {
  .entries-col {
    position: relative;
    /* Safety floor so the entries card never collapses if the
       Quick add card ever renders unusually short. */
    min-height: 480px;
  }
  .entries-card {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .entries-card .card-section-title { flex-shrink: 0; }
  .entries-card .expense-list-scroll {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;   /* height now comes from the flex fill, not a cap */
    /* Use block flow (not grid) inside the flex-filled scroller: block
       children can never be compressed, so each row keeps its natural
       height exactly as before and the container simply scrolls. */
    display: block;
  }
  .entries-card .expense-list-scroll > .expense-row { margin-bottom: 0.5rem; }
  .entries-card .expense-list-scroll > .expense-row:last-child { margin-bottom: 0; }
  .entries-card .empty-state { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: center; }
}
