/* =====================================================================
   Finance App — design system
   Mobile-first. Light theme. Premium SaaS look.
   ===================================================================== */

:root {
  --bg:        #f7f8fb;
  --bg-elev:   #ffffff;
  --bg-side:   #0b1020;
  --bg-side-2: #131a36;
  --text:      #0f172a;
  --text-mut:  #64748b;
  --text-side: #cbd5e1;
  --text-side-mut: #8a93b3;
  --border:    #e6e8ef;
  --border-strong: #cdd2dc;
  --primary:   #4f46e5;
  --primary-600:#4338ca;
  --primary-50: #eef2ff;
  --success:   #16a34a;
  --success-50:#dcfce7;
  --danger:    #dc2626;
  --danger-50: #fee2e2;
  --warning:   #ea580c;
  --warning-50:#ffedd5;
  --info:      #2563eb;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
  --shadow:    0 4px 16px rgba(15,23,42,.08);
  --shadow-lg: 0 12px 40px rgba(15,23,42,.14);
  --radius:    14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --sidebar-w: 260px;
  --topbar-h:  64px;
  --bottomnav-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
.muted { color: var(--text-mut); }

/* ==================== AUTH SHELL ==================== */
.auth-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  position: relative;
  overflow: hidden;
}
.auth-bg {
  position: absolute; inset: 0; z-index: -1;
  background:
    radial-gradient(700px 400px at 10% -10%, #c7d2fe55 0%, transparent 70%),
    radial-gradient(700px 400px at 110% 30%, #a7f3d055 0%, transparent 70%),
    linear-gradient(180deg, #f8fafc, #eef2ff);
}
.auth-container { width: 100%; max-width: 460px; }
.auth-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.auth-card-wide { max-width: 600px; margin-inline: auto; }
.auth-brand {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.auth-logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff; font-weight: 700; font-size: 22px;
  display: grid; place-items: center;
  box-shadow: 0 8px 18px rgba(79,70,229,.35);
}
.auth-brand-text strong { display: block; font-size: 1.05rem; }
.auth-brand-text span { color: var(--text-mut); font-size: .85rem; }
.auth-alt { text-align: center; margin: 18px 0 0; color: var(--text-mut); }
.auth-footer { color: var(--text-mut); text-align: center; margin: 18px 0 0; font-size: .85rem; }

/* ==================== APP SHELL ==================== */
.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
}
.app-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: var(--bottomnav-h);
}

/* ==================== SIDEBAR ==================== */
.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: 86%;
  max-width: 320px;
  background: linear-gradient(180deg, var(--bg-side), var(--bg-side-2));
  color: var(--text-side);
  z-index: 50;
  transform: translateX(-105%);
  transition: transform .22s ease;
  display: flex; flex-direction: column;
}
.sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow-lg); }
.sidebar-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(2,6,23,.55);
  border: 0;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid #ffffff14;
}
.sidebar-logo, .sidebar-logo-fallback {
  width: 40px; height: 40px; border-radius: 10px;
  object-fit: cover; background: #1f2747;
  display: grid; place-items: center;
  color: #fff; font-weight: 700;
}
.sidebar-logo-fallback { background: linear-gradient(135deg, #4f46e5, #7c3aed); }
.sidebar-brand-text strong { color: #fff; display: block; }
.sidebar-brand-text span { color: var(--text-side-mut); font-size: .8rem; }
.sidebar-nav {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px;
  overflow-y: auto;
  flex: 1;
}
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 10px;
  color: var(--text-side);
  font-weight: 500;
}
.nav-link:hover { background: #ffffff10; color: #fff; text-decoration: none; }
.nav-link.is-active { background: #ffffff18; color: #fff; }
.nav-icon { width: 20px; height: 20px; flex: 0 0 20px; opacity: .9; }
.nav-sep { height: 1px; background: #ffffff14; margin: 8px 6px; }
.sidebar-foot {
  border-top: 1px solid #ffffff14;
  padding: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.user-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  color: #fff; font-weight: 700;
  display: grid; place-items: center;
}
.user-meta { min-width: 0; }
.user-meta strong { display: block; color: #fff; font-size: .9rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.user-meta span { color: var(--text-side-mut); font-size: .75rem; }
.btn-logout {
  background: #ffffff10; color: #fff; border: 0; cursor: pointer;
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
}
.btn-logout:hover { background: #ffffff20; }

/* ==================== TOPBAR ==================== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px;
}
.hamburger {
  background: transparent; border: 0; cursor: pointer;
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; gap: 4px; align-content: center; justify-items: center;
}
.hamburger:hover { background: #00000008; }
.hamburger span { display: block; width: 20px; height: 2px; background: var(--text); border-radius: 2px; }
.topbar-title { font-weight: 600; font-size: 1rem; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: none; }
.topbar-company strong { font-weight: 600; }

/* ==================== CONTENT ==================== */
.app-content { padding: 16px 16px 24px; }
.page-head {
  display: flex; align-items: end; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}

/* ==================== CARDS ==================== */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.cards-grid {
  display: grid; gap: 12px;
  grid-template-columns: 1fr;
  margin-bottom: 14px;
}
.stat-card { padding: 18px; }
.stat-label { color: var(--text-mut); font-size: .85rem; }
.stat-value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; }
.stat-income { border-left: 4px solid var(--success); }
.stat-expense { border-left: 4px solid var(--danger); }
.is-positive { border-left: 4px solid var(--success); }
.is-positive .stat-value { color: var(--success); }
.is-negative { border-left: 4px solid var(--danger); }
.is-negative .stat-value { color: var(--danger); }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: -4px 0 10px;
}
.card-action { color: var(--primary); font-weight: 500; font-size: .9rem; }
.two-col { display: grid; grid-template-columns: 1fr; gap: 12px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "txt amt" "txt date";
  align-items: start;
  gap: 2px 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.list li:last-child { border-bottom: 0; }
.list li > div:first-child { grid-area: txt; min-width: 0; }
.list li > div:first-child strong { display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list li > div:first-child span { color: var(--text-mut); font-size: .85rem; }
.list-amount { grid-area: amt; font-weight: 700; white-space: nowrap; }
.list-amount.positive { color: var(--success); }
.list-amount.negative { color: var(--danger); }
.list-date { grid-area: date; color: var(--text-mut); font-size: .8rem; text-align: right; }

.empty { padding: 18px; text-align: center; color: var(--text-mut); }
.empty p { margin: 0 0 10px; }

.phase-note { margin-top: 14px; background: var(--primary-50); border-color: #c7d2fe; }

/* ==================== PLACEHOLDER ==================== */
.placeholder-card { padding: 28px 22px; text-align: center; }
.placeholder-card h2 { font-size: 1.3rem; margin: 8px 0 6px; }
.placeholder-card p  { max-width: 540px; margin: 0 auto 18px; }
.placeholder-badge {
  display: inline-block;
  background: var(--primary-50);
  color: var(--primary-600);
  font-size: .8rem; font-weight: 700;
  padding: 4px 10px; border-radius: 999px;
}
.placeholder-list {
  list-style: none; padding: 0; margin: 0 auto 22px;
  max-width: 580px; text-align: left;
}
.placeholder-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px;
  font-size: .92rem; color: var(--text-mut);
}
.placeholder-list li.is-current {
  background: var(--primary-50); color: var(--primary-600); font-weight: 600;
}
.placeholder-list .check {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--success); color: #fff;
  display: grid; place-items: center; font-size: .8rem; font-weight: 700;
  flex-shrink: 0;
}
.placeholder-list .dot {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border-strong);
  flex-shrink: 0;
}
.placeholder-list li.is-current .dot {
  border-color: var(--primary); background: var(--primary);
}

/* ==================== FORMS ==================== */
.form { display: grid; gap: 14px; }
.row {
  display: grid; gap: 14px;
  grid-template-columns: 1fr;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .85rem; color: var(--text-mut); font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px #c7d2fe66;
}
.field textarea { resize: vertical; min-height: 80px; }
.field .hint { color: var(--text-mut); font-size: .8rem; }
.field .err { color: var(--danger); font-size: .8rem; }

.input-icon { position: relative; }
.input-icon input { padding-right: 44px; }
.icon-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: transparent; border: 0; cursor: pointer;
  color: var(--text-mut); width: 36px; height: 36px;
  display: grid; place-items: center; border-radius: 8px;
}
.icon-btn:hover { background: #00000008; color: var(--text); }

.checkbox { display: flex; align-items: center; gap: 8px; color: var(--text); }
.checkbox input { width: 18px; height: 18px; }

/* ==================== BUTTONS ==================== */
.btn {
  -webkit-appearance: none; appearance: none;
  border: 1px solid var(--border-strong);
  background: #fff; color: var(--text);
  font: inherit; font-weight: 600;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform .04s, background .15s, border-color .15s, box-shadow .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { background: #f1f5f9; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--primary); color: #fff;
  border-color: var(--primary);
  box-shadow: 0 6px 16px rgba(79,70,229,.25);
}
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: .9rem; }

/* ==================== FLASH ==================== */
.flash-stack { display: grid; gap: 8px; margin-bottom: 12px; }
.flash {
  display: flex; align-items: start; justify-content: space-between; gap: 8px;
  padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: .92rem;
}
.flash-success { background: var(--success-50); border-color: #bbf7d0; color: #14532d; }
.flash-error   { background: var(--danger-50);  border-color: #fecaca; color: #7f1d1d; }
.flash-info    { background: #dbeafe;          border-color: #bfdbfe; color: #1e3a8a; }
.flash-warning { background: var(--warning-50); border-color: #fed7aa; color: #7c2d12; }
.flash-close { background: transparent; border: 0; color: inherit; cursor: pointer; font-size: 1.2rem; line-height: 1; }

/* ==================== TOAST ==================== */
.toast-host {
  position: fixed; right: 12px; bottom: calc(var(--bottomnav-h) + 12px); z-index: 80;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: #0f172a; color: #fff;
  padding: 10px 14px; border-radius: 10px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  font-size: .9rem;
  animation: toastIn .18s ease both;
}
.toast.success { background: #166534; }
.toast.error   { background: #991b1b; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ==================== BOTTOM NAV ==================== */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: var(--bottomnav-h);
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(10px);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottomnav a {
  display: grid; place-items: center; gap: 2px;
  color: var(--text-mut); font-size: .72rem;
  text-decoration: none;
}
.bottomnav a svg { width: 22px; height: 22px; }
.bottomnav a.is-active { color: var(--primary); }

/* ==================== TABLE (used in Phase 3+) ==================== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
.table {
  width: 100%; border-collapse: collapse;
  background: #fff;
}
.table th, .table td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { background: #f8fafc; color: var(--text-mut); font-weight: 600; font-size: .85rem; }
.table tr:last-child td { border-bottom: 0; }

/* ==================== RESPONSIVE ==================== */
@media (min-width: 720px) {
  .row { grid-template-columns: 1fr 1fr; }
  .cards-grid { grid-template-columns: repeat(3, 1fr); }
  .two-col { grid-template-columns: 1fr 1fr; }
  .topbar-actions { display: flex; align-items: center; gap: 12px; }
}

@media (min-width: 1024px) {
  .app-shell { grid-template-columns: var(--sidebar-w) 1fr; }
  .sidebar {
    position: sticky; top: 0; height: 100dvh;
    transform: none !important;
    width: var(--sidebar-w); max-width: var(--sidebar-w);
    box-shadow: none;
  }
  .sidebar-overlay { display: none; }
  .hamburger { display: none; }
  .bottomnav { display: none; }
  .app-main { padding-bottom: 0; }
  .app-content { padding: 22px 28px; }
}

/* ==================== SETTINGS ==================== */
.settings-nav {
  display: flex; gap: 6px;
  overflow-x: auto;
  margin: 0 -4px 16px;
  padding: 4px;
  scrollbar-width: none;
}
.settings-nav::-webkit-scrollbar { display: none; }
.settings-nav a {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  background: #fff; border: 1px solid var(--border);
  color: var(--text-mut);
  font-weight: 500; font-size: .9rem;
  white-space: nowrap;
  text-decoration: none;
}
.settings-nav a:hover { color: var(--text); border-color: var(--border-strong); }
.settings-nav a.is-active {
  background: var(--primary); color: #fff;
  border-color: var(--primary);
  box-shadow: 0 4px 14px rgba(79,70,229,.25);
}
.settings-nav-ico { font-size: 1rem; line-height: 1; }

.settings-grid {
  display: grid; gap: 12px;
  grid-template-columns: 1fr;
}
.settings-tile {
  display: block;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-decoration: none;
  color: var(--text);
  transition: transform .12s, box-shadow .15s, border-color .15s;
}
.settings-tile:hover {
  text-decoration: none;
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.settings-tile-ico {
  font-size: 1.6rem; margin-bottom: 8px;
}
.settings-tile h3 { font-size: 1rem; margin: 0 0 4px; }
.settings-tile p { margin: 0 0 4px; color: var(--text); font-weight: 600; }
.settings-tile small { color: var(--text-mut); }

/* Logo upload row */
.logo-row {
  display: grid; gap: 16px;
  grid-template-columns: 1fr;
  align-items: start;
  padding: 6px 0 14px;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 14px;
}
.logo-preview {
  width: 100px; height: 100px; border-radius: 14px;
  background: #f1f5f9; overflow: hidden;
  display: grid; place-items: center;
  border: 1px solid var(--border);
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }
.logo-empty { font-size: 2rem; color: var(--text-mut); }
.logo-actions { display: flex; flex-direction: column; gap: 8px; }
.logo-actions .btn { align-self: start; }

.form-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  padding-top: 6px;
}

/* Inline forms used inside settings */
.inline-form {
  display: flex; gap: 12px; align-items: end;
  flex-wrap: wrap;
}
.inline-form .field { margin: 0; }
.flex-grow { flex: 1; min-width: 200px; }
.field-btn { padding-bottom: 0; }
.field-btn .btn { white-space: nowrap; }

.inline-edit { display: inline-flex; align-items: center; gap: 6px; }
.inline-edit input {
  font: inherit;
  border: 1px solid transparent;
  background: transparent;
  padding: 4px 6px;
  border-radius: 6px;
  width: 100%;
  min-width: 120px;
}
.inline-edit input:hover { border-color: var(--border); }
.inline-edit input:focus {
  background: #fff; border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px #c7d2fe66;
}
.inline-edit-row { display: inline-block; }
.inline-edit-row select { padding: 4px 6px; border-radius: 6px; }

.inline-form-tight { display: inline-block; }

.btn-link {
  background: transparent; border: 0; cursor: pointer;
  padding: 6px 8px; border-radius: 6px;
  color: var(--text-mut);
  font-size: 1rem;
}
.btn-link:hover { background: #00000008; color: var(--text); }
.btn-danger-link:hover { color: var(--danger); background: var(--danger-50); }

/* Pills */
.pill {
  display: inline-block;
  font-size: .72rem; font-weight: 600;
  padding: 3px 8px; border-radius: 999px;
  background: #f1f5f9; color: var(--text-mut);
  vertical-align: middle;
}
.pill-active   { background: var(--success-50); color: #14532d; }
.pill-inactive { background: #f1f5f9; color: var(--text-mut); }
.pill-system   { background: #e0e7ff; color: #3730a3; }
.pill-self     { background: #fef3c7; color: #92400e; }

.text-right { text-align: right; }

/* Category cards */
.category-card { padding: 16px 18px; }
.category-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
  margin-bottom: 8px;
}
.category-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.category-title h3 { margin: 0; font-size: 1.05rem; }
.category-edit input { font-weight: 600; font-size: 1.05rem; min-width: 200px; }
.subcat-list { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 4px; }
.subcat-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 10px;
  background: #f8fafc; border-radius: 8px;
}
.subcat-add { display: flex; gap: 8px; margin-top: 8px; }
.subcat-add input {
  flex: 1; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px; font: inherit;
}

/* Plan bar (users page) */
.plan-bar {
  display: grid; gap: 8px;
  grid-template-columns: 1fr;
  align-items: center;
}
.progress-bar { height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, #6366f1, #06b6d4); transition: width .25s; }

/* Plan cards */
.current-plan-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.current-plan-head h2 { margin: 0; }
.usage-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(2, 1fr);
}
.usage-grid > div { padding: 10px; background: #f8fafc; border-radius: 10px; }

.plans-grid {
  display: grid; gap: 12px;
  grid-template-columns: 1fr;
  margin-top: 14px;
}
.plan-card { padding: 22px; }
.plan-card header { margin-bottom: 12px; }
.plan-card h3 { margin: 0 0 4px; }
.plan-price strong { font-size: 1.4rem; }
.plan-features {
  list-style: none; padding: 0; margin: 0 0 16px;
  display: grid; gap: 6px;
}
.plan-features li {
  padding: 6px 10px;
  background: #f8fafc; border-radius: 8px;
  font-size: .92rem;
}
.plan-card.is-current {
  border-color: var(--primary);
  box-shadow: 0 8px 30px rgba(79,70,229,.18);
}

@media (min-width: 720px) {
  .settings-grid { grid-template-columns: repeat(2, 1fr); }
  .logo-row { grid-template-columns: 120px 1fr; }
  .plan-bar { grid-template-columns: 1fr 240px auto; }
  .usage-grid { grid-template-columns: repeat(4, 1fr); }
  .plans-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1024px) {
  .settings-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ==================== PERIOD SELECTOR ==================== */
.period-bar {
  display: grid; gap: 10px;
  margin-bottom: 14px;
}
.period-chips {
  display: flex; gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: -2px;
  padding: 2px;
}
.period-chips::-webkit-scrollbar { display: none; }
.period-chip {
  display: inline-flex; align-items: center;
  padding: 7px 14px; border-radius: 999px;
  background: #f1f5f9; color: var(--text-mut);
  border: 1px solid transparent;
  font-weight: 500; font-size: .88rem;
  white-space: nowrap;
  text-decoration: none;
  transition: background .12s, color .12s, border-color .12s;
}
.period-chip:hover { background: #e2e8f0; color: var(--text); text-decoration: none; }
.period-chip.is-active {
  background: var(--primary); color: #fff;
  border-color: var(--primary);
}
.period-custom {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.period-custom input[type=date] {
  padding: 6px 10px; border: 1px solid var(--border-strong);
  border-radius: 8px; font: inherit;
}
.period-range { color: var(--text-mut); font-size: .85rem; }

/* ==================== DELTA INDICATORS ==================== */
.stat-delta {
  font-size: .85rem; margin-top: 6px;
  font-weight: 600;
}
.delta-up   { color: var(--success); }
.delta-down { color: var(--danger); }

.head-actions { display: flex; gap: 8px; }

/* ==================== FILTERS BAR ==================== */
.filter-bar {
  display: grid; gap: 10px;
  grid-template-columns: 1fr;
  align-items: end;
  margin-bottom: 14px;
}
.filter-bar .field { margin: 0; }
.filter-actions {
  grid-column: 1 / -1;
  display: flex; gap: 8px;
}

/* ==================== TABLE TWEAKS ==================== */
.nowrap   { white-space: nowrap; }
.small    { font-size: .82rem; }
.amt-pos  { color: var(--success); font-weight: 700; }
.amt-neg  { color: var(--danger);  font-weight: 700; }
.entry-link { color: var(--text); text-decoration: none; }
.entry-link:hover { color: var(--primary); text-decoration: none; }

.table-condensed th, .table-condensed td { padding: 7px 10px; font-size: .9rem; }
.cash-table { margin-top: 12px; }

.pager {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 12px;
}
.pager-info { color: var(--text-mut); font-size: .9rem; }

/* ==================== DETAIL VIEWS ==================== */
.detail-card { padding: 22px; }
.detail-card h2 { margin: 4px 0 8px; font-size: 1.4rem; }
.detail-amount {
  font-size: 1.8rem; font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.detail-grid {
  display: grid; gap: 6px 16px;
  grid-template-columns: 1fr;
  margin: 16px 0 8px;
}
.detail-grid dt { color: var(--text-mut); font-size: .82rem; }
.detail-grid dd { margin: 0 0 4px; font-weight: 500; }
.notes-block {
  background: #f8fafc; padding: 12px; border-radius: 10px;
  border-left: 3px solid var(--border-strong);
  margin: 6px 0 0;
}
.delete-form { margin-top: 12px; text-align: right; }

/* ==================== CHART WRAPPERS ==================== */
.chart-card { padding: 16px; }
.chart-wrap {
  position: relative;
  width: 100%;
  height: 280px;
}
.chart-wrap-pie { height: 240px; }

@media (min-width: 720px) {
  .filter-bar { grid-template-columns: repeat(3, 1fr); }
  .filter-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .detail-grid { grid-template-columns: max-content 1fr; }
  .detail-grid dt { padding-right: 12px; }
  .chart-wrap { height: 320px; }
  .chart-wrap-pie { height: 280px; }
}
@media (min-width: 1024px) {
  .filter-bar { grid-template-columns: 2fr 1fr 1fr 1fr 1fr; }
  .filter-actions { grid-column: 1 / -1; }
}

/* ==================== ANALYTICS / P&L / REPORTS ==================== */
.three-col {
  display: grid; gap: 12px;
  grid-template-columns: 1fr;
  margin-bottom: 14px;
}
@media (min-width: 720px)  { .three-col { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .three-col { grid-template-columns: repeat(3, 1fr); } }

.compare-bar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin-top: -8px;
}
.compare-chips { gap: 6px; }

/* Profit & Loss hero */
.pl-hero {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 14px;
  padding: 22px 24px;
  border-left: 6px solid var(--border-strong);
}
.pl-hero.pl-profit { border-left-color: var(--success); background: linear-gradient(180deg, #f0fdf4, #fff); }
.pl-hero.pl-loss   { border-left-color: var(--danger);  background: linear-gradient(180deg, #fef2f2, #fff); }
.pl-status { display: inline-block; font-size: .85rem; font-weight: 600; }
.pl-amount {
  font-size: 2.4rem; font-weight: 800; letter-spacing: -0.02em;
  margin: 6px 0 4px;
}
.pl-profit .pl-amount { color: var(--success); }
.pl-loss   .pl-amount { color: var(--danger); }
.pl-margin { display: grid; gap: 4px; text-align: right; }
.pl-margin strong { font-size: 1.6rem; font-weight: 800; color: var(--primary-600); }

.row-total td { font-weight: 700; background: #f8fafc; }

/* Reports */
.report-header {
  display: grid; gap: 14px;
  grid-template-columns: 1fr;
  padding: 18px 20px;
}
.report-meta strong { font-size: 1.1rem; }
.report-summary {
  display: grid; gap: 12px;
  grid-template-columns: repeat(2, 1fr);
}
.report-summary-item {
  background: #f8fafc; border-radius: 10px;
  padding: 10px 12px;
  display: grid; gap: 2px;
}
.report-summary-item strong { font-size: 1.1rem; }

.export-bar {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 8px;
  padding: 14px;
  background: #f8fafc;
  border-radius: var(--radius);
  margin-top: 14px;
}

@media (min-width: 720px) {
  .report-header { grid-template-columns: 1fr 2fr; align-items: center; }
  .report-summary { grid-template-columns: repeat(4, 1fr); }
}

/* ==================== PRINT ==================== */
@media print {
  body { background: #fff !important; }
  .sidebar, .topbar, .bottomnav, .toast-host, .hide-print, .flash-stack { display: none !important; }
  .app-shell { display: block !important; }
  .app-content { padding: 0 !important; }
  .card {
    box-shadow: none !important;
    border: 1px solid #ddd !important;
    page-break-inside: avoid;
  }
  .pl-hero { background: #fff !important; }
  .table th { background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { color: inherit; text-decoration: none; }
  .page-head { border-bottom: 2px solid #333; padding-bottom: 8px; margin-bottom: 16px; }
  /* Page-break friendly section spacing */
  section.card { margin-bottom: 12px; }
}
