/* CliBank — Soft app shell. Light + Dark via [data-theme] */
:root {
  --font-sans: "Heebo", "Assistant", -apple-system, "Segoe UI", system-ui, sans-serif;
  --font-display: "Heebo", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, monospace;

  /* tweakable */
  --accent: #0a84ff;
  --accent-ink: #0070e0;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --density: 1;
}

[data-theme="light"] {
  --bg: #fafafa;
  --bg-deep: #f2f2f4;
  --surface: #ffffff;
  --surface-2: #f7f7f9;
  --ink: #0b0b0f;
  --ink-2: #3a3a45;
  --ink-soft: #86868b;
  --ink-faint: #c5c5cc;
  --rule: #ececef;
  --rule-strong: #dcdce0;
  --positive: #30a46c;
  --alert: #d83a3a;
  --warn: #cc7a00;
  --shadow-sm: 0 0 0 0.5px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
  --shadow-md: 0 0 0 0.5px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03), 0 8px 24px -8px rgba(0,0,0,0.06);
  --shadow-lg: 0 0 0 0.5px rgba(0,0,0,0.05), 0 4px 16px rgba(0,0,0,0.06), 0 20px 50px -16px rgba(0,0,0,0.18);
}

[data-theme="dark"] {
  --bg: #0a0a0c;
  --bg-deep: #08080a;
  --surface: #16161a;
  --surface-2: #1d1d22;
  --ink: #f5f5f7;
  --ink-2: #d2d2d6;
  --ink-soft: #86868b;
  --ink-faint: #48484a;
  --rule: #26262a;
  --rule-strong: #36363a;
  --positive: #30d158;
  --alert: #ff453a;
  --warn: #ff9f0a;
  --shadow-sm: 0 0 0 0.5px rgba(255,255,255,0.05), 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 0 0 0.5px rgba(255,255,255,0.05), 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px -8px rgba(0,0,0,0.6);
  --shadow-lg: 0 0 0 0.5px rgba(255,255,255,0.06), 0 4px 16px rgba(0,0,0,0.5), 0 20px 50px -16px rgba(0,0,0,0.8);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  /* Block horizontal scroll caused by stray-wide elements (charts, long
     descriptions, etc) — common cause of broken-looking mobile layouts. */
  overflow-x: hidden;
  /* Prevent iOS pinch-zoom from leaving the layout in a weird scaled state */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv01";
  transition: background .25s, color .25s;
}
/* No global img rule — too easy to interact badly with explicit width/height.
   Each component is expected to pin its own dimensions via class or attr. */

.tnum { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

.thin-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.thin-scroll::-webkit-scrollbar-thumb { background: var(--ink-faint); border-radius: 4px; }
.thin-scroll::-webkit-scrollbar-thumb:hover { background: var(--ink-soft); }
.thin-scroll { scrollbar-width: thin; scrollbar-color: var(--ink-faint) transparent; }

button { font-family: inherit; }
input, select, textarea { font-family: inherit; color: inherit; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slide-in-end { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: calc(200px + 100%) 0; }
}

.skeleton {
  background: linear-gradient(90deg, var(--rule) 0%, var(--surface-2) 50%, var(--rule) 100%);
  background-size: 200px 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: 6px;
}

.fade-in { animation: fade-in .25s ease-out both; }
.slide-up { animation: slide-up .35s cubic-bezier(.2,.7,.3,1) both; }

/* Focus rings */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ───────────────────────────────────────────────────────────────────
   App shell — desktop sidebar; mobile gets iOS-style tab bar
   ─────────────────────────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.app-main { flex: 1; min-width: 0; overflow-x: hidden; }
.app-sidebar {
  background: var(--bg-deep);
  border-inline-end: 0.5px solid var(--rule);
  padding: 22px 14px;
  display: flex; flex-direction: column; gap: 22px;
  width: 220px; flex-shrink: 0;
}

/* Mobile-only chrome — hidden by default on desktop */
.mobile-topbar  { display: none; }
.tab-bar        { display: none; }
.sheet-backdrop { display: none; }
.sheet          { display: none; }

/* ───────────────────────────────────────────────────────────────────
   Mobile (≤ 1024px) — covers phones + small tablets in portrait.
   Pattern: sticky glass top bar + bottom tab bar + bottom-up "More" sheet
   ─────────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {

  /* Hide the desktop sidebar entirely — mobile uses tab bar */
  .app-sidebar { display: none !important; }

  /* ── Top bar (sticky, glass) ────────────────────────────────── */
  .mobile-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 80;
    height: calc(52px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 16px 0;
    display: flex; align-items: center; gap: 12px;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(20px);
    backdrop-filter: saturate(1.4) blur(20px);
    border-bottom: 0.5px solid color-mix(in srgb, var(--rule) 80%, transparent);
  }
  .mobile-topbar-title {
    flex: 1;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.012em;
    color: var(--ink);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .topbar-action {
    width: 38px; height: 38px;
    border: none; background: transparent;
    color: var(--ink); font-size: 17px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    border-radius: 10px;
    padding: 0;
    transition: background .12s, transform .08s;
  }
  .topbar-action:active { background: var(--bg-deep); transform: scale(0.94); }

  /* ── Bottom tab bar (the primary nav on mobile) ─────────────── */
  .tab-bar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 80;
    height: calc(56px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(22px);
    backdrop-filter: saturate(1.4) blur(22px);
    border-top: 0.5px solid color-mix(in srgb, var(--rule) 80%, transparent);
    align-items: stretch;
    justify-content: space-around;
  }
  .tab-item {
    flex: 1;
    border: none; background: transparent;
    color: var(--ink-soft);
    cursor: pointer;
    padding: 7px 4px 6px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 2px;
    font-family: inherit;
    font-size: 10.5px; font-weight: 500;
    transition: color .12s, transform .08s;
    position: relative;
    min-height: 56px;
    -webkit-tap-highlight-color: transparent;
  }
  .tab-item-icon { font-size: 22px; line-height: 1; transition: transform .12s; }
  .tab-item.active { color: var(--ink); }
  .tab-item.active .tab-item-icon { transform: translateY(-1px); }
  .tab-item:active .tab-item-icon { transform: scale(0.85); }
  .tab-item-badge {
    position: absolute;
    top: 4px; inset-inline-end: calc(50% - 22px);
    min-width: 16px; height: 16px;
    padding: 0 5px;
    border-radius: 8px;
    background: var(--alert);
    color: #fff;
    font-size: 10px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
  }

  /* ── More sheet (bottom-up modal) ───────────────────────────── */
  .sheet-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0);
    z-index: 90;
    pointer-events: none;
    transition: background .2s;
  }
  .sheet-backdrop.open {
    background: rgba(0,0,0,0.42);
    pointer-events: auto;
  }
  .sheet {
    display: block;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 91;
    background: var(--surface);
    border-radius: 18px 18px 0 0;
    padding: 6px 8px calc(20px + env(safe-area-inset-bottom));
    box-shadow: var(--shadow-lg);
    transform: translateY(100%);
    transition: transform .28s cubic-bezier(.2,.8,.25,1);
    max-height: 78vh;
    overflow-y: auto;
  }
  .sheet.open { transform: translateY(0); }
  .sheet-handle {
    width: 36px; height: 5px;
    background: var(--ink-faint);
    border-radius: 3px;
    margin: 8px auto 14px;
  }
  .sheet-title {
    font-size: 12px; font-weight: 600;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 4px 16px 8px;
  }
  .sheet-item {
    display: flex; align-items: center; gap: 14px;
    padding: 13px 16px;
    border: none; background: transparent;
    color: var(--ink); font-size: 15px; font-weight: 500;
    font-family: inherit;
    width: 100%;
    text-align: start;
    cursor: pointer;
    border-radius: 12px;
    transition: background .12s;
    -webkit-tap-highlight-color: transparent;
  }
  .sheet-item:active { background: var(--bg-deep); }
  .sheet-item-icon {
    width: 28px; text-align: center; font-size: 17px;
    color: var(--ink-soft);
    flex-shrink: 0;
  }
  .sheet-item-label { flex: 1; }
  .sheet-item-count {
    font-size: 11.5px; font-weight: 500;
    color: var(--ink-soft);
    background: var(--bg-deep);
    padding: 2px 7px; border-radius: 8px;
  }
  .sheet-item.danger { color: var(--alert); }
  .sheet-item.danger .sheet-item-icon { color: var(--alert); }

  /* ── Layout — content scrolls between top + tab bar ─────────── */
  .app-shell {
    padding-top: calc(52px + env(safe-area-inset-top));
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
  }
  .app-main { width: 100%; min-width: 0; }

  /* Page wrappers — each page renders <div class="fade-in"
     style="padding 32px 40px 60px"> — override to mobile rhythm. */
  .app-main > .fade-in {
    padding: 12px 16px 24px !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  /* Typography hierarchy on mobile */
  .app-main h1 {
    font-size: 26px !important;
    line-height: 1.2 !important;
    letter-spacing: -0.022em !important;
    margin: 4px 0 12px !important;
  }
  .app-main h2 { font-size: 20px !important; }

  /* Page-header rows: stack title + controls vertically */
  .app-main .fade-in > div[style*="space-between"] {
    flex-wrap: wrap !important;
    gap: 10px !important;
    align-items: stretch !important;
    margin-bottom: 14px !important;
  }
  .app-main .fade-in > div[style*="space-between"] > div:first-child { width: 100% !important; }
  .app-main .fade-in > div[style*="space-between"] > div:last-child {
    width: 100% !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    scrollbar-width: none;
  }
  .app-main .fade-in > div[style*="space-between"] > div:last-child::-webkit-scrollbar {
    display: none;
  }

  /* Cards — full bleed on mobile, tighter radius */
  .app-main [class*="Surface"], .app-main .surface { border-radius: 14px !important; }

  /* ── Multi-column grids → single column on mobile ─────────────
     The dashboard and other pages use inline-style CSS Grid with
     `grid-template-columns: 1.6fr 1fr` etc. On a phone these crush
     each column to ~150px, which makes Hebrew text wrap one
     character per line ("דוח Cai עוד לא נוצר…").

     Match the multi-fr patterns we know about by attribute and
     collapse them. Single-fr or auto-column "row" grids (lists
     with ID + label + amount) stay multi-column. */
  .app-main div[style*="1.6fr 1fr"],
  .app-main div[style*="1.2fr 1fr"],
  .app-main div[style*="1fr 1.2fr"],
  .app-main div[style*="1.4fr 1fr 1fr"],
  .app-main div[style*="1.5fr 1fr 1fr"],
  .app-main div[style*="repeat(3, 1fr)"],
  .app-main div[style*="repeat(2, 1fr)"],
  .app-main div[style*="1fr 1fr 1fr"],
  .app-main div[style*="repeat(auto-fit, minmax(280px"],
  .app-main div[style*="1fr 1fr"]:not([style*="auto"]) {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* iOS won't auto-zoom on focus when input font-size >= 16px */
  .app-main input, .app-main select, .app-main textarea {
    font-size: 16px !important;
  }

  .app-main button { -webkit-tap-highlight-color: transparent; }
}
