/* =====================================================================
   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); }

/* ==================== BULK ACTIONS ==================== */
.bulk-cell {
  width: 36px;
  text-align: center;
  padding: 8px 4px !important;
}
.bulk-cell input[type=checkbox] {
  width: 16px; height: 16px;
  cursor: pointer;
  accent-color: var(--primary, #2563eb);
}
.bulk-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #eff6ff, #ede9fe);
  border: 1px solid #c7d2fe;
  border-radius: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  position: sticky; top: 60px; z-index: 5;
  animation: bulk-slide-in .15s ease-out;
}
@keyframes bulk-slide-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.bulk-count {
  font-size: .92rem; color: #1e40af;
}
.bulk-action-select, .bulk-value-select {
  padding: 6px 10px;
  font-size: .9rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.bulk-bar #bulk-clear { margin-left: auto; }

/* ==================== 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; }

/* ==================== INLINE QUICK-ADD ==================== */
.inline-qa {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.inline-qa[open] {
  border-color: var(--primary, #2563eb);
  box-shadow: 0 4px 16px -4px rgba(37,99,235,.18);
}
.inline-qa-summary {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.inline-qa-summary::-webkit-details-marker { display: none; }
.inline-qa-summary::before {
  content: '▸';
  color: var(--text-mut);
  transition: transform .15s;
  flex: 0 0 auto;
}
.inline-qa[open] .inline-qa-summary::before { transform: rotate(90deg); }
.inline-qa-icon { font-size: 1.2rem; }
.inline-qa-label strong { color: var(--primary, #2563eb); }
.inline-qa-hint { margin-left: auto; }
@media (max-width: 640px) {
  .inline-qa-hint { display: none; }
}
.inline-qa-form {
  padding: 0 18px 18px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.inline-qa-grid {
  display: grid; gap: 10px;
  grid-template-columns: 1fr;
  padding-top: 14px;
}
@media (min-width: 720px) {
  .inline-qa-grid { grid-template-columns: 1.4fr .8fr 1fr 1fr 1fr; }
}
.inline-qa-grid .field { margin: 0; }
.inline-qa-actions {
  display: flex; gap: 8px; align-items: center;
  margin-top: 12px;
  flex-wrap: wrap;
}
.inline-qa-status { flex: 1; }
.inline-qa-spinner { display: inline-block; }

/* ==================== 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; }
}

/* ==================== FLOATING ACTION BUTTON ==================== */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--bottomnav-h) + 18px);
  z-index: 60;
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 0; cursor: pointer;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  font-size: 30px; font-weight: 300; line-height: 1;
  box-shadow: 0 12px 30px rgba(79,70,229,.45), 0 4px 10px rgba(15,23,42,.18);
  display: grid; place-items: center;
  transition: transform .12s, box-shadow .15s;
}
.fab:hover  { transform: translateY(-2px); }
.fab:active { transform: translateY(0); box-shadow: 0 6px 16px rgba(79,70,229,.45); }
@media (min-width: 1024px) {
  .fab { bottom: 24px; right: 24px; }
}
@media print { .fab { display: none !important; } }

/* ==================== QUICK-ADD MODAL ==================== */
.qa-modal {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: end center;
}
.qa-modal[hidden] { display: none; }
@media (min-width: 720px) { .qa-modal { place-items: center; } }

.qa-backdrop {
  position: absolute; inset: 0;
  background: rgba(2, 6, 23, .55);
  backdrop-filter: blur(2px);
  animation: qaFade .18s ease both;
}
@keyframes qaFade { from { opacity: 0; } to { opacity: 1; } }

.qa-dialog {
  position: relative;
  width: 100%; max-width: 540px;
  background: #fff;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -20px 60px rgba(15,23,42,.25);
  padding: 18px 18px calc(env(safe-area-inset-bottom, 0) + 18px);
  max-height: 92dvh;
  overflow-y: auto;
  animation: qaSlide .22s ease both;
}
@media (min-width: 720px) {
  .qa-dialog {
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(15,23,42,.30);
    margin: 0 16px;
    max-height: 88dvh;
  }
}
@keyframes qaSlide { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.qa-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 0 12px;
}
.qa-head h2 { font-size: 1.15rem; margin: 0; }
.qa-x {
  background: transparent; border: 0; cursor: pointer;
  font-size: 28px; line-height: 1;
  width: 36px; height: 36px; border-radius: 50%;
  color: var(--text-mut);
}
.qa-x:hover { background: #00000008; color: var(--text); }

.qa-toggle {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #f1f5f9;
  border-radius: 12px;
  padding: 4px;
  margin: 0 0 14px;
}
.qa-tab {
  border: 0; cursor: pointer;
  background: transparent; color: var(--text-mut);
  padding: 10px 12px; border-radius: 10px;
  font: inherit; font-weight: 600; font-size: .95rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .12s, color .12s, box-shadow .12s;
}
.qa-tab:hover { color: var(--text); }
.qa-tab.is-active {
  background: #fff; color: var(--text);
  box-shadow: 0 1px 3px rgba(15,23,42,.08);
}
.qa-tab[data-qa-type="income"].is-active  { color: var(--success); }
.qa-tab[data-qa-type="expense"].is-active { color: var(--danger); }
.qa-tab-ico {
  width: 22px; height: 22px; border-radius: 50%;
  background: #e2e8f0; color: var(--text-mut);
  display: grid; place-items: center; font-size: 14px;
}
.qa-tab.is-active .qa-tab-ico {
  color: #fff;
}
.qa-tab[data-qa-type="income"].is-active .qa-tab-ico  { background: var(--success); }
.qa-tab[data-qa-type="expense"].is-active .qa-tab-ico { background: var(--danger); }

.qa-form { gap: 12px; }
.qa-form .row { gap: 12px; }
.qa-form select, .qa-form input { font-size: 16px; /* iOS no-zoom */ }
/* `.field` uses display:flex, which overrides the browser's default
   `[hidden] { display:none }`. Force-hide so the income/expense toggle works. */
.qa-form .field[hidden] { display: none !important; }

body.qa-open { overflow: hidden; }

/* =====================================================================
   MOBILE RESPONSIVE SAFETY NETS
   Common cause of horizontal scrollbars in PHP/Bootstrap-style layouts:
     1. Flex/grid children inherit `min-width: auto` which means "don't
        shrink below my content" — long text or wide tables blow past the
        viewport. Fix by setting `min-width: 0` on the children we want to
        be shrinkable.
     2. `white-space: nowrap` on text inside narrow flex columns chops words.
        On phones, prefer wrapping over ellipsis.
   ===================================================================== */

/* Hard floor: never let the document scroll horizontally. */
html, body { overflow-x: hidden; max-width: 100%; }

/* Top-level shell containers can shrink to viewport. */
.app-shell, .app-main, .app-content { min-width: 0; max-width: 100%; }
.app-content { overflow-x: hidden; }

/* All grid/flex item containers — let children shrink. */
.cards-grid > *, .two-col > *, .three-col > *,
.settings-grid > *, .plans-grid > *, .row > * { min-width: 0; }

/* Page header — title block shrinks, action buttons wrap to next line. */
.page-head > div:first-child { min-width: 0; flex: 1 1 auto; }
.head-actions { flex-wrap: wrap; }
.form-actions { flex-wrap: wrap; }

/* Topbar — title shrinks instead of forcing horizontal scroll. */
.topbar { min-width: 0; }
.topbar-title { min-width: 0; flex: 1 1 0%; }

/* Sidebar brand text */
.sidebar-brand-text { min-width: 0; flex: 1; }
.sidebar-brand-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* List rows — first column shrinkable. */
.list li > div:first-child { min-width: 0; }

/* Tables — wrap container fills card width, table can scroll inside. */
.card > .table-wrap, .table-wrap { width: 100%; max-width: 100%; }

/* Long text ought to break, not overflow */
.stat-value, .detail-card h2, .pl-amount,
.entry-link, .qa-head h2,
.list li > div:first-child strong,
.detail-card p, .notes-block {
  overflow-wrap: anywhere;
  word-break: normal;
}

/* Period/settings/compare chip rows — keep their width contained. The chips
   themselves use overflow-x: auto on desktop and flex-wrap on mobile (see
   media query below), so the bar wrapper doesn't need overflow:hidden. */
.period-bar, .compare-bar { min-width: 0; }
.period-chips, .settings-nav { max-width: 100%; }

/* Filter bar grid items can shrink */
.filter-bar > * { min-width: 0; }

/* Compare-bar wraps neatly */
.compare-bar { flex-wrap: wrap; }

/* ---------- Phone screens (≤ 720px) ---------- */
@media (max-width: 720px) {
  /* Period / compare / settings chip rows wrap into multiple lines instead
     of horizontal scroll — easier to discover & tap, no off-screen items. */
  .period-chips, .compare-chips, .settings-nav {
    flex-wrap: wrap;
    overflow-x: visible;
  }
  .period-chip, .settings-nav a { font-size: .82rem; padding: 6px 10px; }

  /* Show full names/descriptions on phones — wrap, don't truncate. */
  .list li > div:first-child strong {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }
  .list li {
    grid-template-columns: 1fr auto;
    grid-template-areas: "txt amt" "txt date";
    gap: 4px 12px;
  }
  .list-amount { font-size: .95rem; white-space: nowrap; }

  /* Page-head action row goes below title on phones */
  .page-head { flex-direction: column; align-items: stretch; }
  .head-actions { width: 100%; }

  /* Smaller body padding so content uses full width */
  .app-content { padding: 12px; }
  .card { padding: 14px; }
  .stat-card { padding: 14px; }

  /* Page title slightly smaller so big company names don't crash */
  h1 { font-size: 1.25rem; }
  .stat-value { font-size: 1.4rem; }

  /* Detail/PL hero amounts */
  .detail-amount { font-size: 1.5rem; }
  .pl-amount { font-size: 1.9rem; }
  .pl-margin { text-align: left; }
  .pl-margin strong { font-size: 1.3rem; }

  /* Tile titles + reports */
  .settings-tile h3 { font-size: .95rem; }
  .report-summary { grid-template-columns: 1fr 1fr; }
  .report-summary-item strong { font-size: 1rem; }

  /* Tables on mobile — slightly tighter */
  .table th, .table td { padding: 8px 8px; font-size: .9rem; }

  /* Forms in cards — stack rows */
  .row { grid-template-columns: 1fr; }
  .form-actions .btn { flex: 1 1 auto; }
  .form-actions .btn-primary { flex: 1 1 100%; order: -1; }

  /* ============================================================
     Mobile table → card-list transformation
     Tables with 5–6 columns are unreadable on phones (horizontal
     scroll required). Convert each row into a stacked card.
     Layout per card:
        [date]              [amount]
        [name + description]
        [meta]              [actions]
     The 4th column (payment method on income/expense lists,
     payment on report tables) is hidden on phones to keep cards
     compact — full info is still on the detail page.
     Targets `.table-wrap > .table` only, so it doesn't affect
     small condensed inline tables (e.g. P&L summary).
     ============================================================ */
  .card > .table-wrap { overflow-x: visible; }
  .table-wrap > .table,
  .table-wrap > .table > thead,
  .table-wrap > .table > tbody,
  .table-wrap > .table > tfoot { display: block; background: transparent; }
  .table-wrap > .table { border: 0; }
  .table-wrap > .table > thead { display: none; }

  .table-wrap > .table > tbody > tr,
  .table-wrap > .table > tfoot > tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "date    amount"
      "name    name"
      "meta    actions";
    gap: 4px 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    align-items: center;
  }
  .table-wrap > .table > tbody > tr:last-child,
  .table-wrap > .table > tfoot > tr:last-child { margin-bottom: 0; }

  .table-wrap > .table td {
    display: block;
    padding: 0;
    border: 0;
    text-align: left;
  }
  .table-wrap > .table td:nth-child(1) {
    grid-area: date;
    color: var(--text-mut);
    font-size: .78rem;
    align-self: start;
  }
  .table-wrap > .table td:nth-child(2) {
    grid-area: name;
    align-self: start;
  }
  .table-wrap > .table td:nth-child(3) {
    grid-area: meta;
    color: var(--text-mut);
    font-size: .82rem;
  }
  /* Hide the 4th column (payment method) on phones — secondary info,
     visible on the detail page when the user taps the row. */
  .table-wrap > .table td:nth-child(4) { display: none; }
  .table-wrap > .table td:nth-child(5) {
    grid-area: amount;
    text-align: right;
    align-self: center;
    font-size: 1rem;
    white-space: nowrap;
  }
  .table-wrap > .table td:nth-child(6) {
    grid-area: actions;
    text-align: right;
    align-self: center;
    white-space: nowrap;
  }

  /* Footer rows (totals) — slightly different style; first td may have
     colspan=4 so we let it span the meta side and align the amount right. */
  .table-wrap > .table > tfoot > tr {
    grid-template-areas: "label amount";
    background: #f1f5f9;
    font-weight: 700;
  }
  .table-wrap > .table > tfoot > tr td:first-child {
    grid-area: label;
    align-self: center;
  }
  .table-wrap > .table > tfoot > tr td:last-child {
    grid-area: amount;
    text-align: right;
    white-space: nowrap;
  }
  /* For Reports tables: their rows have only 5 cols (no actions). Adjust:
     since td:nth-child(5) is the amount, that already maps correctly. The
     row's "actions" grid area is empty — fine, grid just skips it. */
}

/* ---------- Tiny screens (≤ 380px) ---------- */
@media (max-width: 380px) {
  .stat-value { font-size: 1.25rem; }
  .pl-amount { font-size: 1.6rem; }
  .topbar { padding: 0 8px; }
  .app-content { padding: 10px; }

  /* Hide topbar's company name on very small screens — the sidebar shows it */
  .topbar-company { display: none; }
}

/* ==================== SUBSCRIPTION BANNER ==================== */
.sub-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  margin-bottom: 12px;
  font-size: .92rem;
}
.sub-banner-icon { font-size: 1.2rem; line-height: 1; }
.sub-banner-text { flex: 1; min-width: 0; }
.sub-banner-warn   { background: var(--warning-50); border-color: #fed7aa; color: #7c2d12; }
.sub-banner-urgent { background: var(--danger-50);  border-color: #fecaca; color: #7f1d1d; }

/* =====================================================================
 * Daily entry spreadsheet (income/expense) — partials/entry_sheet.php
 * ===================================================================== */
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 14px;
}
.sheet-head h1 { margin: 0; }
.sheet-datebar {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 8px; box-shadow: var(--shadow-sm);
}
.sheet-datebar-label { font-weight: 600; color: var(--text-mut); font-size: .85rem; margin-right: 2px; }
.sheet-datebar input[type=date] {
  border: 1px solid var(--border); border-radius: var(--radius-xs);
  padding: 6px 8px; font: inherit; color: var(--text); background: #fff;
}
.sheet-nav { min-width: 32px; text-align: center; font-weight: 700; }

.sheet-wrap {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  overflow-x: auto;
}
table.sheet {
  width: 100%; border-collapse: collapse; font-size: .92rem;
  min-width: 720px;
}
table.sheet col.col-num    { width: 40px; }
table.sheet col.col-amount { width: 130px; }
table.sheet col.col-pm,
table.sheet col.col-src,
table.sheet col.col-cat,
table.sheet col.col-sub    { width: 170px; }
table.sheet col.col-act    { width: 64px; }

table.sheet thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg-side); color: #fff;
  text-align: left; font-weight: 600; font-size: .78rem;
  letter-spacing: .02em; text-transform: uppercase;
  padding: 10px 10px; white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,.08);
}
table.sheet thead th.th-amount { text-align: right; }
table.sheet thead th:last-child { border-right: 0; }

table.sheet td.sheet-cell,
table.sheet td.sheet-num,
table.sheet td.sheet-actions {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0;
}
table.sheet td.sheet-actions { border-right: 0; }
.sheet-num {
  text-align: center; color: var(--text-mut);
  font-variant-numeric: tabular-nums; font-size: .8rem; width: 40px;
}

/* Borderless cell inputs — the cell IS the input, Excel-style. */
.cell-input {
  width: 100%; border: 0; background: transparent; outline: none;
  padding: 9px 10px; font: inherit; color: var(--text);
  border-radius: 0;
}
.cell-input:focus { background: var(--primary-50); box-shadow: inset 0 0 0 2px var(--primary); }
select.cell-input { cursor: pointer; appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-mut) 50%),
                    linear-gradient(135deg, var(--text-mut) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 26px;
}
.cell-amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* Row save state cues */
.sheet-row.is-saving  td.sheet-cell { background: #fffbeb; }
.sheet-row.is-saved   td.sheet-cell { background: var(--success-50); transition: background .4s; }
.sheet-row.is-error   td.sheet-cell { background: var(--danger-50); }
.sheet-row:hover      td.sheet-cell { background: #fafbff; }
.sheet-row.is-saved:hover td.sheet-cell,
.sheet-row.is-error:hover td.sheet-cell { background: inherit; }

.sheet-actions { text-align: center; white-space: nowrap; }
.sheet-state { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.sheet-row.is-saving .sheet-state { background: var(--warning); }
.sheet-row.is-saved  .sheet-state { background: var(--success); }
.sheet-row.is-error  .sheet-state { background: var(--danger); }
.row-del {
  border: 0; background: transparent; cursor: pointer; color: var(--text-mut);
  font-size: 1rem; line-height: 1; padding: 6px 8px; border-radius: var(--radius-xs);
}
.row-del:hover { background: var(--danger-50); color: var(--danger); }

table.sheet tfoot .sheet-foot td {
  padding: 12px 10px; border-top: 2px solid var(--border-strong); background: #fbfcfe;
}
.sheet-foot-label { text-align: right; font-weight: 700; letter-spacing: .03em; color: var(--text-mut); }
.sheet-foot-total {
  text-align: right; font-size: 1.15rem; font-weight: 800;
  font-variant-numeric: tabular-nums; color: var(--primary-600);
}
.sheet-hint { padding: 10px 12px; margin: 0; }
.sheet-hint kbd {
  background: var(--bg); border: 1px solid var(--border-strong);
  border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; font-size: .8em;
}

/* Scope bar (Ημέρα / Εβδομάδα / Μήνας / Διάστημα / Όλα) */
.sheet-scopebar {
  display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap;
}
.scope-chips { display: inline-flex; gap: 2px; background: var(--bg); padding: 3px;
  border: 1px solid var(--border); border-radius: 999px; }
.scope-chip {
  display: inline-block; padding: 5px 13px; border-radius: 999px;
  font-size: .85rem; font-weight: 600; color: var(--text-mut); text-decoration: none;
  white-space: nowrap;
}
.scope-chip:hover { color: var(--text); background: #fff; }
.scope-chip.is-active { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.scope-nav {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 5px 7px; box-shadow: var(--shadow-sm);
}
.scope-nav input[type=date] {
  border: 1px solid var(--border); border-radius: var(--radius-xs);
  padding: 5px 7px; font: inherit; color: var(--text); background: #fff;
}
.scope-label { color: var(--text-mut); font-size: .85rem; font-weight: 600; white-space: nowrap; }
table.sheet col.col-date { width: 140px; }
.sheet-cell-date .cell-date { color: var(--text-mut); }

/* Summary breakdown panels (ανά τρόπο πληρωμής / ανά προέλευση-κατηγορία) */
.sheet-breakdowns {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px; margin-top: 16px;
}
.breakdown-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 14px 16px;
}
.breakdown-card h3 {
  margin: 0 0 10px; font-size: .8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-mut);
}
.breakdown-list { list-style: none; margin: 0; padding: 0; }
.breakdown-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 7px 0; border-bottom: 1px dashed var(--border);
}
.breakdown-list li:last-child { border-bottom: 0; }
.bd-label { color: var(--text); }
.bd-total { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--primary-600); white-space: nowrap; }
.bd-empty { color: var(--text-mut); }
