/* Reset & app shell */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  margin: 0; height: 100%;
  font-family: var(--font); font-size: var(--fs); line-height: 1.4;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  /* app feel: no text selection / callouts / drag on chrome; inputs stay editable */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  position: fixed; inset: 0; width: 100%;
}
input, textarea, [contenteditable], .selectable { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
a, img, svg, button { -webkit-user-drag: none; user-drag: none; }
button, a { touch-action: manipulation; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
svg { display: block; }
[hidden] { display: none !important; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.income { color: var(--income); }
.expense { color: var(--expense); }
.transfer { color: var(--transfer); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- App shell ---------- */
#app {
  position: fixed; inset: 0;
  height: 100%;
  display: grid;
  grid-template-rows: 1fr;
  grid-template-areas: "view";
}
.sidebar { display: none; }
#view {
  grid-area: view;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--sat) + 28px) var(--gutter) calc(var(--space-6) + 80px);
  scroll-behavior: smooth;
}
.screen { max-width: 520px; margin: 0 auto; min-width: 0; animation: screen-in var(--dur) var(--ease); }
@keyframes screen-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.screen-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  min-height: 44px; margin-bottom: var(--space-4);
}
.screen-head h1 { font-size: var(--fs-l); font-weight: 700; letter-spacing: -0.01em; }
.screen-head .actions { display: flex; gap: var(--space-2); align-items: center; }
.screen-head .icon-btn { width: 40px; height: 40px; }

/* Tab bar (mobile): slim floating glass pill, icons only */
.tabbar {
  position: fixed; left: 50%; bottom: max(calc(var(--sab) - 6px), 10px); transform: translateX(-50%); z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  height: var(--tabbar-h);
  width: min(320px, calc(100% - 48px));
  padding: 0 6px;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  backdrop-filter: blur(28px) saturate(1.7); -webkit-backdrop-filter: blur(28px) saturate(1.7);
  border: 1px solid color-mix(in srgb, var(--border) 60%, transparent); border-radius: 999px;
  box-shadow: 0 12px 30px -10px rgba(15, 23, 42, .25), inset 0 1px 0 rgba(255,255,255,.4);
  isolation: isolate;
}
:root[data-theme="dark"] .tabbar { box-shadow: 0 12px 30px -10px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.07); }
#app { background: var(--bg); position: fixed; inset: 0; }
/* status-bar fade: content scrolling under the notch/status bar fades out only inside that strip, never over the title */
#app::before { content: ''; position: fixed; top: 0; left: 0; right: 0; height: var(--sat); background: linear-gradient(to bottom, var(--bg) 40%, transparent); z-index: 15; pointer-events: none; }
#app .glow { position: fixed; inset: -20% -20% auto -20%; height: 60vh; background: radial-gradient(60% 60% at 30% 0%, color-mix(in srgb, var(--brand) 14%, transparent), transparent 70%); pointer-events: none; z-index: 0; view-transition-name: glow; }
#view { position: relative; z-index: 1; padding-bottom: calc(var(--tabbar-h) + var(--sab) + 40px); }
.tabbar a {
  display: flex; align-items: center; justify-content: center; height: 44px; border-radius: 999px;
  color: var(--text-2); transition: color var(--dur), transform 140ms var(--ease);
}
.tabbar a span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.tabbar a .ic { width: 24px; height: 24px; stroke-width: 1.9; }
.tabbar a.active { color: var(--text); }
.tabbar a.active .ic { stroke-width: 2.4; }
.tabbar a:active { transform: scale(.9); }
.tabbar.scrolling { transform: translateX(-50%); }
.tabbar .fab-slot { display: flex; align-items: center; justify-content: center; }
.fab {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--text); color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: transform 120ms var(--ease), box-shadow 120ms;
}
.fab:active { transform: scale(.92); }
.fab .ic { width: 22px; height: 22px; stroke-width: 2.4; }
.tabbar .indicator { position: absolute; top: 6px; bottom: 6px; width: 0; border-radius: 999px; background: color-mix(in srgb, var(--text) 8%, transparent); transition: left 320ms var(--ease), width 320ms var(--ease); pointer-events: none; z-index: -1; }
.tabbar.scrolling { background: color-mix(in srgb, var(--surface) 28%, transparent); border-color: color-mix(in srgb, var(--border) 35%, transparent); }
.tabbar.scrolling a, .tabbar.scrolling .fab { opacity: .8; }

/* ---------- Desktop / tablet: app layout with sidebar ---------- */
@media (min-width: 768px) {
  #app {
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: 1fr;
    grid-template-areas: "sidebar view";
  }
  .tabbar { display: none; }
  .sidebar {
    grid-area: sidebar;
    display: flex; flex-direction: column;
    background: var(--surface); border-right: 1px solid var(--border);
    padding: var(--space-5) var(--space-4);
    overflow-y: auto;
  }
  .sidebar .logo { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; font-weight: 800; font-size: 19px; letter-spacing: -0.02em; }
  .sidebar .logo .mark { width: 36px; height: 36px; border-radius: 12px; background: linear-gradient(140deg, var(--brand), #2563eb); color: #fff; display: grid; place-items: center; }
  .sidebar .logo .mark .ic { width: 20px; height: 20px; }
  .sidebar nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: var(--radius-s);
    color: var(--text-2); font-weight: 500;
    transition: background var(--dur), color var(--dur);
  }
  .sidebar nav a .ic { width: 21px; height: 21px; }
  .sidebar nav a:hover { background: var(--surface-2); color: var(--text); }
  .sidebar nav a.active { background: var(--brand-100); color: var(--brand-600); }
  .sidebar .side-add {
    margin: 18px 0 22px; display: flex; align-items: center; justify-content: center; gap: 8px;
    height: 46px; border-radius: 14px; background: linear-gradient(140deg, var(--brand), color-mix(in srgb, var(--brand) 70%, #2563eb)); color: #fff; font-weight: 600;
    box-shadow: 0 10px 22px -8px color-mix(in srgb, var(--brand) 70%, transparent);
  }
  .sidebar .side-add .ic { width: 20px; height: 20px; }
  .sidebar .side-add kbd { font-size: 11px; opacity: .7; border: 1px solid currentColor; border-radius: 4px; padding: 0 5px; }
  .sidebar .side-section { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 8px 12px; }
  .sidebar .side-wallets a { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-radius: var(--radius-s); color: var(--text); }
  .sidebar .side-wallets a:hover { background: var(--surface-2); }
  .sidebar .side-wallets .w-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .sidebar .side-wallets .w-name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar .side-wallets .ci { width: 26px; height: 26px; border-radius: 8px; }
  .sidebar .side-wallets .ci .ic { width: 14px; height: 14px; }
  .sidebar .side-wallets .num { font-size: var(--fs-s); color: var(--text-2); }
  .sidebar .side-foot { margin-top: auto; padding-top: 16px; font-size: var(--fs-xs); color: var(--text-3); }

  #view { padding: var(--space-6) var(--space-8) var(--space-8); }
  .screen { max-width: var(--content-max); }
  .screen-head h1 { font-size: 26px; }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); align-items: start; }
  .grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-5); }
  .desktop-only { display: initial; }
  .mobile-only { display: none !important; }
}
@media (max-width: 767.98px) {
  .desktop-only { display: none !important; }
}

/* Portrait-only on phones: overlay when rotated to landscape (iOS ignores manifest orientation) */
#rotate-overlay { display: none; position: fixed; inset: 0; z-index: 100; background: var(--bg); color: var(--text); align-items: center; justify-content: center; flex-direction: column; gap: 18px; text-align: center; padding: 24px; font-weight: 600; }
#rotate-overlay .ro-phone { width: 34px; height: 60px; border: 3px solid var(--brand); border-radius: 8px; position: relative; animation: ro-rotate 1.6s ease-in-out infinite; }
#rotate-overlay .ro-phone::after { content: ""; position: absolute; bottom: 5px; left: 50%; width: 10px; height: 3px; margin-left: -5px; border-radius: 2px; background: var(--brand); }
@keyframes ro-rotate { 0%, 20% { transform: rotate(90deg); } 60%, 100% { transform: rotate(0deg); } }
@media (orientation: landscape) and (max-height: 520px) and (pointer: coarse) { #rotate-overlay { display: flex; } }

/* iOS auto-zooms on focus when an input's font is < 16px; keep all fields at 16px on touch devices */
@media (pointer: coarse) {
  input, select, textarea, .input, .pick-row input, .pick-row select { font-size: 16px !important; }
}
