/* ==========================================================================
   FinMate — "Paper White" High-Contrast Theme
   Light · White & Gray · Mobile Top Nav
   ==========================================================================
   Contents
   1.  Design tokens
   2.  Reset & base
   3.  Typography
   4.  Layout shell
   5.  Sidebar (desktop) + Top nav (mobile)
   6.  Cards & grids
   7.  Stat tiles
   8.  Buttons
   9.  Forms
   10. Tables
   11. Badges
   12. Progress bars
   13. Details / summary
   14. Flash messages
   15. Utilities
   16. Animations
   17. Responsive (mobile top nav)
   18. Print
   ========================================================================== */


/* ==========================================================================
   1. DESIGN TOKENS — High contrast white & gray
   ========================================================================== */
:root {
  /* — Neutrals — */
  --bg:             #f4f6f9;   /* page backdrop */
  --bg-2:           #ffffff;   /* input backgrounds */
  --surface:        #ffffff;   /* cards */
  --surface-2:      #f8fafc;   /* elevated / hover */
  --surface-3:      #eef2f7;   /* deeper inset */
  --border:         #e2e8f0;
  --border-strong:  #cbd5e1;

  /* — Text: near-black for max contrast — */
  --text:           #0b1220;
  --text-2:         #1e293b;
  --muted:          #64748b;
  --faint:          #94a3b8;

  /* — Emerald accent (deeper shade for contrast on white) — */
  --primary:        #059669;
  --primary-2:      #10b981;
  --primary-3:      #34d399;
  --primary-deep:   #047857;
  --primary-soft:   rgba(5, 150, 105, 0.10);

  /* — Supporting accents — */
  --cyan:           #0891b2;
  --cyan-soft:      rgba(8, 145, 178, 0.10);
  --amber:          #b45309;
  --amber-soft:     rgba(180, 83, 9, 0.10);
  --danger:         #dc2626;
  --danger-soft:    rgba(220, 38, 38, 0.09);

  /* — Gradients (deeper for contrast on light) — */
  --grad-primary:   linear-gradient(135deg, #059669 0%, #0891b2 100%);
  --grad-primary-r: linear-gradient(135deg, #10b981 0%, #34d399 100%);
  --grad-danger:    linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  --grad-surface:   linear-gradient(180deg, rgba(15,23,42,0.012), transparent);

  /* — Soft background glows on white — */
  --aura-1: radial-gradient(1100px 700px at 92% -8%, rgba(16,185,129,0.05), transparent 55%);
  --aura-2: radial-gradient(900px 600px at -10% 105%, rgba(8,145,178,0.04), transparent 60%);

  /* — Radii — */
  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-xl:   20px;
  --r-full: 999px;

  /* — Elevation (soft, tinted) — */
  --shadow-1:    0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-2:    0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-3:    0 12px 24px -8px rgba(15, 23, 42, 0.12),
                 0 4px 8px -4px rgba(15, 23, 42, 0.06);
  --shadow-glow: 0 0 0 3px rgba(5, 150, 105, 0.18);
  --shadow-topnav: 0 1px 2px rgba(15, 23, 42, 0.04),
                   0 8px 24px -12px rgba(15, 23, 42, 0.08);

  /* — Spacing — */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px;
  --s-4: 16px; --s-5: 20px; --s-6: 24px;
  --s-7: 32px; --s-8: 40px; --s-9: 56px;

  /* — Motion — */
  --t-fast: 140ms cubic-bezier(.2,.8,.2,1);
  --t-base: 220ms cubic-bezier(.2,.8,.2,1);
  --t-slow: 320ms cubic-bezier(.2,.8,.2,1);

  /* — Type — */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system,
               "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo,
               Consolas, "Liberation Mono", monospace;

  --sidebar-w: 252px;
  --z-sidebar: 50;
  --z-toast: 90;
}


/* ==========================================================================
   2. RESET & BASE
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  font-weight: 400;
  color: var(--text);
  background: var(--aura-1), var(--aura-2), var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg { display: block; max-width: 100%; height: auto; }

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--t-fast);
  font-weight: 500;
}
a:hover { color: var(--primary-deep); }

::selection { background: rgba(16,185,129,.22); color: var(--text); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: var(--r-full);
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}


/* ==========================================================================
   3. TYPOGRAPHY
   ========================================================================== */
h1, h2, h3, h4, h5 {
  font-weight: 700;
  line-height: 1.22;
  letter-spacing: -0.015em;
  color: var(--text);
}
h1 { font-size: clamp(24px, 2.4vw, 30px); margin-bottom: var(--s-6); font-weight: 800; }
h2 { font-size: clamp(19px, 2vw, 22px); margin-bottom: var(--s-5); }
h3 { font-size: 16px; margin-bottom: var(--s-4); font-weight: 700; }
h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  font-weight: 600;
}

p { color: var(--text-2); }
small { color: var(--muted); font-size: 13px; }
code, pre { font-family: var(--font-mono); font-size: 13px; }


/* ==========================================================================
   4. LAYOUT SHELL
   ========================================================================== */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.main {
  padding: var(--s-7) clamp(16px, 3vw, 40px) var(--s-9);
  max-width: 1400px;
  width: 100%;
  animation: fadeUp 360ms ease-out both;
}


/* ==========================================================================
   5a. SIDEBAR — desktop
   ========================================================================== */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  padding: var(--s-6) var(--s-3);
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfd 100%);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: var(--z-sidebar);
}

/* Brand wordmark */
.sidebar::before {
  content: "MoneyMap";
  display: block;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -.03em;
  margin-bottom: var(--s-6);
  padding: 0 var(--s-3);
  background: var(--grad-primary);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 10px 12px;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  position: relative;
  transition:
    background var(--t-fast),
    color var(--t-fast),
    transform var(--t-fast);
}

.sidebar a:hover {
  background: var(--surface-2);
  color: var(--text);
  transform: translateX(2px);
}

.sidebar a.active {
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-weight: 600;
}

.sidebar a.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 22%;
  bottom: 22%;
  width: 3px;
  background: var(--grad-primary);
  border-radius: var(--r-full);
}

.sidebar form { margin-top: var(--s-5) !important; }
.sidebar form button {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  width: 100%;
}


/* ==========================================================================
   6. CARDS & GRIDS
   ========================================================================== */
.grid {
  display: grid;
  gap: var(--s-5);
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.card {
  position: relative;
  background: var(--grad-surface), var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-2);
  transition:
    transform var(--t-base),
    box-shadow var(--t-base),
    border-color var(--t-base);
}

.card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-3);
}

.card h1, .card h2, .card h3 { color: var(--text); }


/* ==========================================================================
   7. STAT TILES
   ========================================================================== */
.stat {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.stat::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg,
    rgba(16,185,129,.045) 0%,
    rgba(8,145,178,.03) 100%);
  opacity: 0;
  transition: opacity var(--t-base);
  z-index: -1;
}

.stat:hover::after { opacity: 1; }

.stat h4 { margin-bottom: var(--s-2); }

.stat .v {
  font-size: clamp(22px, 2.4vw, 28px);
  font-weight: 800;
  letter-spacing: -.025em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.stat.income .v {
  background: linear-gradient(135deg, #047857 0%, #059669 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stat.expense .v {
  background: linear-gradient(135deg, #b91c1c 0%, #dc2626 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}


/* ==========================================================================
   8. BUTTONS
   ========================================================================== */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 11px 18px;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  color: #ffffff;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--r-md);
  cursor: pointer;
  white-space: nowrap;
  transition:
    transform var(--t-fast),
    box-shadow var(--t-fast),
    filter var(--t-fast),
    background var(--t-fast),
    color var(--t-fast),
    border-color var(--t-fast);
  box-shadow: var(--shadow-1);
}

button:hover, .btn:hover {
  background: var(--primary-deep);
  border-color: var(--primary-deep);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px -4px rgba(5, 150, 105, 0.35);
}

button:active, .btn:active {
  transform: translateY(0) scale(.985);
  filter: brightness(.96);
}

button:disabled, .btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

.btn-ghost {
  background: #ffffff;
  color: var(--text-2);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-1);
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--primary-deep);
  border-color: var(--primary-2);
  box-shadow: var(--shadow-2);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

.btn-icon { padding: 8px 10px; border-radius: var(--r-md); }


/* ==========================================================================
   9. FORMS
   ========================================================================== */
label {
  display: block;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  margin-bottom: var(--s-2);
  letter-spacing: .005em;
}

input, select, textarea {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition:
    border-color var(--t-fast),
    box-shadow var(--t-fast),
    background var(--t-fast);
}

input::placeholder, textarea::placeholder { color: var(--faint); }

input:hover, select:hover, textarea:hover { border-color: #94a3b8; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: var(--shadow-glow);
}

input[type="checkbox"], input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

input[type="file"] {
  padding: 9px 13px;
  cursor: pointer;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 34px;
  background-color: #ffffff;
}

input:invalid:not(:placeholder-shown) {
  border-color: rgba(220, 38, 38, .55);
}


/* ==========================================================================
   10. TABLES
   ========================================================================== */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

thead th {
  padding: 12px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th:first-child { border-top-left-radius: var(--r-md); }
thead th:last-child  { border-top-right-radius: var(--r-md); }

tbody td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
  transition: background var(--t-fast);
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); color: var(--text); }

tbody td strong { color: var(--text); font-weight: 600; }
tbody td[style*="text-align:right"] { font-variant-numeric: tabular-nums; }


/* ==========================================================================
   11. BADGES
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .01em;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge.ok     { background: var(--primary-soft); color: var(--primary-deep); border-color: rgba(5, 150, 105, .22); }
.badge.warn   { background: var(--amber-soft);   color: var(--amber);         border-color: rgba(180, 83, 9, .22); }
.badge.danger { background: var(--danger-soft);  color: var(--danger);        border-color: rgba(220, 38, 38, .22); }
.badge.info   { background: var(--cyan-soft);    color: var(--cyan);          border-color: rgba(8, 145, 178, .22); }


/* ==========================================================================
   12. PROGRESS BARS
   ========================================================================== */
.progress {
  position: relative;
  height: 10px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
  margin: var(--s-3) 0;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
}

.progress span {
  display: block;
  height: 100%;
  border-radius: var(--r-full);
  background: var(--grad-primary);
  transition: width 600ms cubic-bezier(.2,.8,.2,1);
  position: relative;
  overflow: hidden;
}

.progress span::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255,255,255,.45) 50%,
    transparent 100%);
  animation: shimmer 2.4s infinite;
}

.progress.over span {
  background: linear-gradient(90deg, #d97706 0%, #dc2626 100%);
}


/* ==========================================================================
   13. DETAILS / SUMMARY
   ========================================================================== */
details {
  margin-top: var(--s-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-2);
}

summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--primary-deep);
  padding: var(--s-2) 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  user-select: none;
}
summary::-webkit-details-marker { display: none; }

summary::before {
  content: "▸";
  display: inline-block;
  transition: transform var(--t-fast);
  color: var(--muted);
}

details[open] summary::before { transform: rotate(90deg); }

details > table {
  margin-top: var(--s-3);
  font-size: 13px;
}
details > table thead th { background: #eef2f7; }


/* ==========================================================================
   14. FLASH MESSAGES
   ========================================================================== */
.card[style*="border-left:4px solid #22c55e"],
.card[style*="border-left:4px solid var(--success)"] {
  background: linear-gradient(90deg, rgba(16,185,129,.08), #ffffff);
  border-color: rgba(5, 150, 105, .30) !important;
  color: var(--primary-deep);
}

.card[style*="border-left:4px solid #ef4444"],
.card[style*="border-left:4px solid var(--danger)"] {
  background: linear-gradient(90deg, rgba(220,38,38,.06), #ffffff);
  border-color: rgba(220, 38, 38, .30) !important;
  color: #b91c1c;
}


/* ==========================================================================
   15. UTILITIES
   ========================================================================== */
.flex          { display: flex; gap: var(--s-3); }
.flex-between  { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); }
.flex-center   { display: flex; justify-content: center; align-items: center; }
.flex-wrap     { flex-wrap: wrap; }

.gap-1 { gap: var(--s-1); } .gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); } .gap-4 { gap: var(--s-4); }

.mt-1 { margin-top: var(--s-1); } .mt-2 { margin-top: var(--s-2); }
.mt-3 { margin-top: var(--s-3); } .mt-4 { margin-top: var(--s-4); }
.mt-5 { margin-top: var(--s-5); } .mt-6 { margin-top: var(--s-6); }

.mb-1 { margin-bottom: var(--s-1); } .mb-2 { margin-bottom: var(--s-2); }
.mb-3 { margin-bottom: var(--s-3); } .mb-4 { margin-bottom: var(--s-4); }
.mb-5 { margin-bottom: var(--s-5); } .mb-6 { margin-bottom: var(--s-6); }

.text-muted   { color: var(--muted); }
.text-success { color: var(--primary-deep); }
.text-danger  { color: var(--danger); }
.text-warn    { color: var(--amber); }

.text-center { text-align: center; }
.text-right  { text-align: right; }

.mono    { font-family: var(--font-mono); }
.tabular { font-variant-numeric: tabular-nums; }

.hidden { display: none !important; }


/* ==========================================================================
   16. ANIMATIONS
   ========================================================================== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.grid > .card { animation: fadeUp 360ms ease-out both; }
.grid > .card:nth-child(1) { animation-delay:  15ms; }
.grid > .card:nth-child(2) { animation-delay:  45ms; }
.grid > .card:nth-child(3) { animation-delay:  75ms; }
.grid > .card:nth-child(4) { animation-delay: 105ms; }
.grid > .card:nth-child(5) { animation-delay: 135ms; }
.grid > .card:nth-child(6) { animation-delay: 165ms; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}


/* ==========================================================================
   17. RESPONSIVE — mobile top navigation
   ========================================================================== */
@media (max-width: 1024px) {
  :root { --sidebar-w: 220px; }
}

/* ---------- Tablet / Mobile: sidebar becomes sticky top bar ---------- */
@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    /* Reserve space for the sticky top bar */
    padding-top: calc(58px + env(safe-area-inset-top, 0px));
  }

  /* ---- Top bar container ---- */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: auto;
    height: calc(58px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 8px 0 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    box-shadow: var(--shadow-topnav);
    z-index: var(--z-sidebar);
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }

  /* ---- Brand: pinned left, solid white backdrop ---- */
  .sidebar::before {
    content: "FinMate";
    position: sticky;
    left: 0;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 14px 0 6px;
    margin-right: 4px;
    border-right: 1px solid var(--border);
    background: #ffffff;
    -webkit-background-clip: unset;
    background-clip: unset;
    color: var(--primary);
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -0.03em;
    z-index: 2;
    pointer-events: none;
  }

  /* ---- Nav items: compact pill tabs ---- */
  .sidebar a {
    flex-shrink: 0;
    height: 38px;
    padding: 0 14px;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    border-radius: var(--r-full);
    color: var(--text-2);
    background: transparent;
    transition: background var(--t-fast), color var(--t-fast);
  }
  .sidebar a:hover {
    background: var(--surface-2);
    color: var(--text);
    transform: none;
  }
  .sidebar a.active {
    background: var(--primary-soft);
    color: var(--primary-deep);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px rgba(5, 150, 105, .22);
  }
  .sidebar a.active::before { display: none; }

  /* ---- Logout: pinned right ---- */
  .sidebar form {
    position: sticky;
    right: 0;
    margin: 0 0 0 4px !important;
    flex-shrink: 0;
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 6px 0 10px;
    border-left: 1px solid var(--border);
    background: #ffffff;
    z-index: 2;
  }
  .sidebar form button {
    height: 38px;
    width: 38px;
    padding: 0;
    border-radius: var(--r-full);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-2);
    font-size: 14px;
    box-shadow: none;
  }
  .sidebar form button::before {
    content: "⏻";
    font-size: 15px;
    display: block;
  }
  .sidebar form button:hover {
    background: var(--surface-2);
    color: var(--danger);
    border-color: rgba(220, 38, 38, .30);
    transform: none;
  }

  /* ---- Main content: remove big top padding (top bar has its own) ---- */
  .main {
    padding: 20px 16px 32px;
    max-width: none;
  }

  h1 { font-size: 22px; font-weight: 800; margin-bottom: 16px; letter-spacing: -0.02em; }
  h2 { font-size: 18px; margin-bottom: 14px; }
  h3 { font-size: 15px; margin-bottom: 12px; }
  h4 { font-size: 10px; }
  p  { font-size: 14px; }
  small { font-size: 12px; }

  /* ---- Cards & grids ---- */
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .card { padding: 16px; border-radius: 14px; }
  .grid > .card { animation-duration: 220ms; }

  /* ---- Compact 2-up stat tiles ---- */
  .grid:has(.stat) {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .grid:has(.stat) > .card:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .stat { padding: 14px !important; }
  .stat h4 { font-size: 10px; margin-bottom: 4px; }
  .stat .v { font-size: 20px; letter-spacing: -0.02em; }

  /* ---- Forms: single column, big taps ---- */
  form[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  form[style*="display:flex"] { flex-wrap: wrap; }
  form[style*="display:flex"] > input { flex: 1 1 100%; min-width: 0; }

  input, select, textarea {
    font-size: 16px;          /* prevents iOS auto-zoom */
    padding: 12px 14px;
    min-height: 46px;
    border-radius: 10px;
  }
  select { padding-right: 36px; }

  label { font-size: 13px; margin-bottom: 6px; font-weight: 500; }

  button, .btn {
    min-height: 46px;
    padding: 12px 18px;
    font-size: 14px;
    border-radius: 10px;
  }

  /* ---- Compact buttons inside tables ---- */
  td button, td .btn {
    width: auto;
    min-height: 34px;
    padding: 7px 12px;
    font-size: 12px;
    border-radius: 8px;
  }
  td form[style*="display:flex"] { gap: 4px; flex-wrap: nowrap; }
  td select {
    min-height: 34px;
    padding: 6px 28px 6px 10px;
    font-size: 12px;
  }

  /* ---- Tables: horizontal scroll with edge hints ---- */
  .card > table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    border-radius: 10px;
    background:
      linear-gradient(to right, #ffffff 30%, transparent) left center / 20px 100% no-repeat local,
      linear-gradient(to left,  #ffffff 30%, transparent) right center / 20px 100% no-repeat local,
      radial-gradient(farthest-side at 0 50%,  rgba(15,23,42,.10), transparent) left center  / 12px 100% no-repeat scroll,
      radial-gradient(farthest-side at 100% 50%, rgba(15,23,42,.10), transparent) right center / 12px 100% no-repeat scroll;
  }
  .card > table::-webkit-scrollbar { height: 4px; }
  .card > table::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 2px;
  }
  thead th { padding: 10px 12px; font-size: 10px; letter-spacing: .06em; }
  tbody td { padding: 11px 12px; font-size: 13px; }

  /* ---- Progress & badges ---- */
  .progress { height: 8px; margin: 8px 0; }
  .badge { font-size: 10px; padding: 3px 8px; }
  .badge::before { width: 5px; height: 5px; }

  /* ---- Details / loan schedule ---- */
  details { padding: 10px 12px; margin-top: 10px; }
  summary { font-size: 13px; padding: 6px 0; }
  details > table { font-size: 12px; }
}

/* ---- Small phones (iPhone SE ~375px) ---- */
@media (max-width: 380px) {
  .grid:has(.stat) { grid-template-columns: 1fr; }
  .stat .v { font-size: 22px; }
  .main { padding-left: 12px; padding-right: 12px; }
  h1 { font-size: 20px; }
  .sidebar::before { font-size: 15px; padding: 0 10px 0 4px; }
  .sidebar a { padding: 0 12px; font-size: 12px; }
}

/* ---- Extra-tight phones (≤340px) ---- */
@media (max-width: 340px) {
  .main { padding-left: 10px; padding-right: 10px; }
  .card { padding: 12px; }
  .sidebar a { padding: 0 10px; font-size: 11.5px; }
}


/* ==========================================================================
   18. PRINT
   ========================================================================== */
@media print {
  :root {
    --bg: #fff; --bg-2: #fff; --surface: #fff; --surface-2: #f5f5f5;
    --text: #111; --text-2: #333; --muted: #555; --border: #ddd;
  }
  body { background: #fff; color: #111; }
  .sidebar, .sidebar form, button, .btn, .btn-ghost { display: none !important; }
  .shell { display: block; padding-top: 0; }
  .main { padding: 0; max-width: none; }
  .card {
    border: 1px solid #ddd;
    box-shadow: none;
    page-break-inside: avoid;
    background: #fff;
  }
  .progress { background: #eee; }
  .progress span { background: #333; }
  .progress span::after { display: none; }
  table { font-size: 11px; }
  thead th { background: #f0f0f0; color: #333; }
  a { color: #111; text-decoration: underline; }
}