:root {
  --bg: #08080a;
  --panel: #0d0d10;
  --panel-2: #121216;
  --panel-3: #17171d;
  --line: #1d1d23;
  --line-2: #2b2b34;
  --ink: #f6f6f8;
  --ink-2: #bcbcc8;
  --ink-3: #8c8c99;
  --accent: #5b9dfa;
  --pos: #5b9dfa;
  --neg: #ff7a5c;
  --info: #7fb8f0;
  --warn: #f5c451;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* film grain — kills the flat gradient look */
body::after {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.mono, .num, .stat-value, .hero-value, .tick-value, td.num, th.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

#app { display: flex; min-height: 100vh; }

/* ══ Rail (left nav) ══════════════════ */
.rail {
  width: 214px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 0 0 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  background: #0a0a0c;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px 22px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--ink);
  color: #08080a;
  display: grid; place-items: center;
  font-family: var(--mono);
  font-weight: 700; font-size: 15px;
  letter-spacing: -1px;
  flex-shrink: 0;
}
.brand-name {
  font-size: 14px; font-weight: 650; letter-spacing: -0.2px;
  display: flex; align-items: baseline; gap: 4px;
}
.brand-name .x {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

#nav { flex: 1; padding: 0 10px; overflow-y: auto; }
.nav-group + .nav-group { margin-top: 20px; }
.nav-group-label {
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.7px; text-transform: uppercase;
  color: var(--ink-3);
  padding: 0 8px 8px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 9px 9px;
  border: none; background: none;
  color: var(--ink-2);
  font-family: inherit; font-size: 14px;
  text-align: left; cursor: pointer;
  border-radius: 7px;
  position: relative;
  transition: color 0.1s, background 0.1s;
}
.nav-item:hover { color: var(--ink); background: rgba(255,255,255,0.035); }
.nav-item.active { color: var(--ink); font-weight: 600; background: rgba(255,255,255,0.055); }
.nav-item.active::after {
  content: "";
  position: absolute; right: 8px; top: 50%;
  width: 4px; height: 4px; margin-top: -2px;
  border-radius: 50%;
  background: var(--accent);
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }

.rail-foot { padding: 12px 14px 0; margin-top: 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.user-avatar {
  width: 24px; height: 24px; border-radius: 6px;
  background: var(--accent); color: #08080a;
  font-family: var(--mono); font-weight: 700; font-size: 11px;
  display: grid; place-items: center; flex-shrink: 0;
}
.user-email { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.logout-btn { background: none; border: none; color: var(--ink-3); cursor: pointer; padding: 3px; border-radius: 5px; display: grid; place-items: center; }
.logout-btn:hover { color: var(--neg); }
.logout-btn svg { width: 14px; height: 14px; }

.lang-switch { display: flex; gap: 14px; padding: 0 2px; }
.lang-btn {
  border: none; background: none; padding: 0;
  color: var(--ink-3); cursor: pointer;
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.5px;
}
.lang-btn.active { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }

.sync-status { font-size: 10.5px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; letter-spacing: 0.2px; }
.sync-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--ink-3); flex-shrink: 0; }
.sync-dot.on { background: var(--accent); }
.sync-dot.err { background: var(--neg); }
.sync-dot.pulse { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ══ Content ══════════════════════════ */
.content { flex: 1; min-width: 0; }

.page-head {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; flex-wrap: wrap;
  padding: 18px 34px 17px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
  background: rgba(8, 8, 10, 0.78);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
}
.page-title { font-size: 24px; font-weight: 650; letter-spacing: -0.5px; line-height: 1.2; }
.page-sub { color: var(--ink-3); font-size: 13px; margin-top: 3px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
/* a hairline between the period control and the page's primary action */
.page-actions > .segmented + .btn::before {
  content: "";
  width: 1px; height: 20px;
  background: var(--line-2);
  margin-right: 4px;
}

#view > *:not(.page-head) { margin-left: 34px; margin-right: 34px; }
#view { padding-bottom: 70px; }

/* ══ Period control ═══════════════════ */
.segmented { display: inline-flex; gap: 0; border: 1px solid var(--line-2); border-radius: 7px; overflow: hidden; }
.seg-btn {
  border: none; background: none;
  color: var(--ink-3);
  font-family: var(--mono); font-size: 12.5px; font-weight: 600;
  letter-spacing: 0.2px;
  padding: 7px 13px;
  cursor: pointer; white-space: nowrap;
  border-right: 1px solid var(--line-2);
  transition: color 0.1s, background 0.1s;
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { color: var(--ink); background: rgba(255,255,255,0.04); }
.seg-btn.active { background: var(--ink); color: #08080a; }

/* ══ Buttons ══════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px;
  border-radius: 7px;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--ink);
  font-size: 13.5px; font-weight: 600; font-family: inherit;
  cursor: pointer; white-space: nowrap;
  transition: background 0.1s, border-color 0.1s, transform 0.06s;
}
.btn:hover { background: rgba(255,255,255,0.05); border-color: #3a3a45; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); color: #08080a; border-color: var(--ink); }
.btn-primary:hover { background: #ffffff; border-color: #ffffff; }
.btn-danger { color: var(--neg); border-color: rgba(255,122,92,0.3); }
.btn-danger:hover { background: rgba(255,122,92,0.1); border-color: rgba(255,122,92,0.5); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-lg { width: 100%; padding: 11px; font-size: 13.5px; }
.btn-ghost { border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { color: var(--ink); }
.btn:disabled { opacity: 0.45; cursor: default; }

/* ══ Hero ═════════════════════════════ */
.hero {
  display: grid;
  grid-template-columns: minmax(240px, 0.85fr) 1.15fr;
  gap: 24px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--panel), #0a0a0d);
  padding: 24px 26px;
  margin-bottom: 20px;
}
.hero-label {
  font-family: var(--mono);
  font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.9px; text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 14px;
}
.hero-value {
  font-size: 46px; font-weight: 600;
  letter-spacing: -2px; line-height: 1;
  margin-bottom: 12px;
}
.hero-value.pos { color: var(--accent); }
.hero-value.neg { color: var(--neg); }
.hero-meta {
  font-family: var(--mono);
  font-size: 13px; color: var(--ink-3);
  margin-top: 16px; line-height: 1.9;
}
.hero-meta b { color: var(--ink-2); font-weight: 600; }
.hero-chart { display: flex; align-items: flex-end; min-width: 0; }

.delta {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono);
  font-size: 12px; font-weight: 700;
  padding: 4px 9px; border-radius: 5px;
  width: fit-content;
  letter-spacing: 0.2px;
}
.delta.up { color: var(--accent); background: rgba(91,157,250,0.1); }
.delta.down { color: var(--neg); background: rgba(255,122,92,0.1); }
.delta.flat { color: var(--ink-3); background: rgba(255,255,255,0.05); }

/* ══ Ticker strip ═════════════════════ */
.ticker {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 20px;
  background: var(--panel);
}
.tick {
  flex: 1 1 134px;
  min-width: 0;
  padding: 16px 18px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 5px;
}
.tick-label {
  font-family: var(--mono);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.6px; text-transform: uppercase;
  color: var(--ink-3);
}
.tick-value { font-size: 21px; font-weight: 600; letter-spacing: -0.6px; }
.tick-value.pos { color: var(--accent); }
.tick-value.neg { color: var(--neg); }
.tick-sub { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }

/* ══ Panels ═══════════════════════════ */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}
.panel-title {
  font-family: var(--mono);
  font-size: 11.5px; font-weight: 700;
  letter-spacing: 0.8px; text-transform: uppercase;
  color: var(--ink-2);
}
.panel-body { padding: 18px; }
.panel-body.flush { padding: 0; }

.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 18px 20px;
}
.card-title {
  font-family: var(--mono);
  font-size: 11.5px; font-weight: 700;
  letter-spacing: 0.8px; text-transform: uppercase;
  color: var(--ink-2);
  margin-bottom: 14px;
}
.stat-tile { display: flex; flex-direction: column; gap: 6px; }
.stat-label {
  font-family: var(--mono);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.6px; text-transform: uppercase;
  color: var(--ink-3);
}
.stat-value { font-size: 24px; font-weight: 600; letter-spacing: -0.8px; }
.stat-value.pos { color: var(--accent); }
.stat-value.neg { color: var(--neg); }
.stat-sub { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }

/* ══ Tables ═══════════════════════════ */
.table-wrap { border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left;
  padding: 11px 16px;
  font-family: var(--mono);
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.6px; text-transform: uppercase;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td {
  padding: 13px 16px;
  border-bottom: 1px solid rgba(29,29,35,0.7);
  vertical-align: middle;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.08s; }
tbody tr:hover { background: rgba(255,255,255,0.022); }
td.num, th.num { text-align: right; }
.td-main { font-weight: 550; }
.td-sub { color: var(--ink-3); font-size: 12.5px; }
.profit-pos { color: var(--accent); font-weight: 600; }
.profit-neg { color: var(--neg); font-weight: 600; }

/* row actions appear on hover */
.row-actions { display: flex; gap: 2px; justify-content: flex-end; opacity: 0; transition: opacity 0.1s; }
tbody tr:hover .row-actions { opacity: 1; }
@media (hover: none) { .row-actions { opacity: 1; } }

.rank {
  font-family: var(--mono); font-size: 10.5px;
  color: var(--ink-3); width: 22px; display: inline-block;
}

.summary-strip {
  display: flex; gap: 26px; flex-wrap: wrap;
  padding: 11px 16px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--ink-2);
  letter-spacing: 0.2px;
}
.summary-strip b { color: var(--ink); font-weight: 600; }
.summary-strip .pos { color: var(--accent); }
.summary-strip .neg { color: var(--neg); }

.empty-state { text-align: center; padding: 46px 20px; color: var(--ink-3); font-size: 13px; }
.empty-state .big { font-size: 28px; margin-bottom: 10px; opacity: 0.7; }

/* ══ Badges ═══════════════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.3px; text-transform: uppercase;
  padding: 4px 9px; border-radius: 5px;
  border: 1px solid var(--line-2);
  color: var(--ink-2);
}
.badge-dot { width: 5px; height: 5px; border-radius: 50%; }
.badge.stock .badge-dot { background: var(--info); }
.badge.listed .badge-dot { background: var(--warn); }
.badge.sold .badge-dot { background: var(--accent); }

/* ══ Forms ════════════════════════════ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12.5px; font-weight: 600;
  letter-spacing: 0;
  color: var(--ink-2);
}
input, select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 7px;
  color: var(--ink);
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: inherit;
  width: 100%;
  transition: border-color 0.1s;
}
input[type="text"][inputmode="decimal"], input[type="date"] { font-family: var(--mono); }
input:focus, select:focus, textarea:focus { outline: none; border-color: #4a4a58; }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235f5f6b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
  padding-right: 28px;
}
textarea { resize: vertical; min-height: 58px; }
.input-group { display: flex; }
.input-group input { border-radius: 7px 0 0 7px; border-right: none; }
.input-group select { width: 86px; flex-shrink: 0; border-radius: 0 7px 7px 0; font-family: var(--mono); font-size: 11.5px; }

.filter-row { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.filter-row input[type="search"] { max-width: 230px; }
.filter-row select { width: auto; }
.filter-row .spacer { flex: 1; }

/* ══ Modal ════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(4,4,6,0.78);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  z-index: 100; padding: 20px;
}
.modal {
  background: #101014;
  border: 1px solid var(--line-2);
  border-radius: 14px;
  width: 100%; max-width: 580px;
  max-height: 90vh; overflow-y: auto;
  padding: 24px;
  animation: modalIn 0.14s ease-out;
  box-shadow: 0 30px 90px -20px #000;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(8px); } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.modal-title { font-size: 15px; font-weight: 650; letter-spacing: -0.2px; }
.modal-close { background: none; border: none; color: var(--ink-3); font-size: 19px; cursor: pointer; padding: 2px 7px; line-height: 1; border-radius: 6px; }
.modal-close:hover { color: var(--ink); background: var(--panel-3); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

.profit-readout {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 20px; padding: 13px 16px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--panel-2);
}
.profit-readout .stat-label { margin: 0; }

/* ══ Charts ═══════════════════════════ */
.chart-box { position: relative; }
.chart-box svg { display: block; width: 100%; height: auto; }
.chart-tooltip {
  position: fixed;
  background: #1c1c22;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  padding: 7px 11px;
  font-family: var(--mono);
  font-size: 11.5px;
  pointer-events: none;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}
.bar-hover:hover path.bar, .bar-hover:hover rect.bar { opacity: 0.75; }

/* HTML horizontal bars */
.hbars { display: flex; flex-direction: column; gap: 2px; }
.hbar-row {
  display: grid;
  grid-template-columns: clamp(64px, 26%, 130px) 1fr clamp(34px, 12%, 52px);
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border-radius: 5px;
}
.hbar-row:hover { background: rgba(255,255,255,0.025); }
.hbar-label {
  font-size: 13px; color: var(--ink-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hbar-track { height: 14px; display: flex; align-items: center; }
.hbar-fill {
  height: 100%;
  flex: 0 0 auto;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
  min-width: 2px;
  transition: width 0.25s ease-out;
}
.hbar-fill.neg { background: var(--neg); }
.hbar-value {
  font-family: var(--mono);
  font-size: 11.5px; color: var(--ink-3);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ══ Toast ════════════════════════════ */
#toastRoot { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast {
  background: var(--ink); color: #08080a;
  padding: 10px 16px; border-radius: 8px;
  font-size: 12.5px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  animation: toastIn 0.18s ease-out;
}
.toast.error { background: var(--neg); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ══ Auth ═════════════════════════════ */
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 372px;
  border: 1px solid var(--line-2);
  border-radius: 14px;
  background: var(--panel);
  padding: 30px 28px 22px;
}
.auth-brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 24px; }
.auth-title { font-size: 17px; font-weight: 650; text-align: center; margin-bottom: 5px; letter-spacing: -0.2px; }
.auth-sub { font-size: 12.5px; color: var(--ink-3); text-align: center; margin-bottom: 22px; line-height: 1.5; }
.auth-msg {
  font-size: 12px; line-height: 1.5;
  background: rgba(91,157,250,0.08);
  color: var(--accent);
  border: 1px solid rgba(91,157,250,0.2);
  padding: 9px 12px; border-radius: 7px; margin-bottom: 16px;
}
.auth-msg.err { background: rgba(255,122,92,0.08); color: var(--neg); border-color: rgba(255,122,92,0.25); }
.auth-switch {
  display: block; width: 100%; margin-top: 16px;
  background: none; border: none;
  color: var(--ink-3); font-size: 12px; font-family: inherit;
  cursor: pointer; text-align: center; padding: 6px;
}
.auth-switch:hover { color: var(--ink); }

/* ══ Onboarding ═══════════════════════ */
.ob-screen { min-height: 100vh; display: grid; place-items: center; padding: 26px 20px; }
.ob-card {
  width: 100%; max-width: 560px;
  border: 1px solid var(--line-2);
  border-radius: 16px;
  background: var(--panel);
  padding: 22px 30px 24px;
  display: flex; flex-direction: column;
}
.ob-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.ob-skip { background: none; border: none; color: var(--ink-3); font-family: inherit; font-size: 13px; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.ob-skip:hover { color: var(--ink); background: var(--panel-2); }

.ob-body { padding: 26px 0 4px; min-height: 290px; }
.ob-hero { font-size: 40px; text-align: center; margin-bottom: 14px; }
.ob-title { font-size: 22px; font-weight: 650; letter-spacing: -0.4px; margin-bottom: 9px; }
.ob-sub { font-size: 14px; color: var(--ink-2); line-height: 1.6; margin-bottom: 22px; }
.ob-note {
  font-size: 12.5px; color: var(--ink-3); line-height: 1.6;
  margin-top: 18px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2);
}

.ob-list { list-style: none; display: flex; flex-direction: column; gap: 13px; }
.ob-list li { display: flex; align-items: flex-start; gap: 12px; font-size: 14px; color: var(--ink-2); line-height: 1.5; }
.ob-bullet { font-size: 17px; flex-shrink: 0; line-height: 1.3; }

.ob-fields { display: flex; flex-direction: column; gap: 16px; }
.ob-fields .field label { font-size: 13px; }

.ob-toggle {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 17px; margin-bottom: 18px;
  border: 1px solid var(--line-2); border-radius: 10px;
  background: var(--panel-2);
  font-size: 14px; font-weight: 550; color: var(--ink-2);
  cursor: pointer;
}
.ob-toggle:hover { border-color: #3a3a45; }
.ob-toggle.on { border-color: var(--accent); background: rgba(91,157,250,0.07); color: var(--ink); }
.ob-toggle input { width: 18px; height: 18px; flex-shrink: 0; }

.ob-presets { display: flex; gap: 7px; margin-top: 9px; flex-wrap: wrap; }
.ob-preset {
  border: 1px solid var(--line-2); background: none;
  color: var(--ink-3);
  font-family: var(--mono); font-size: 12px; font-weight: 600;
  padding: 5px 11px; border-radius: 6px; cursor: pointer;
}
.ob-preset:hover { color: var(--ink); border-color: #3a3a45; }
.ob-preset.active { background: var(--accent); border-color: var(--accent); color: #08080a; }

.ob-choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 20px; }
.ob-choice {
  border: 1px solid var(--line-2); border-radius: 11px;
  background: var(--panel-2); cursor: pointer;
  padding: 16px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  font-family: inherit;
}
.ob-choice:hover { border-color: #3a3a45; }
.ob-choice.active { border-color: var(--accent); background: rgba(91,157,250,0.08); }
.ob-choice-num { font-family: var(--mono); font-size: 22px; font-weight: 700; color: var(--ink); }
.ob-choice.active .ob-choice-num { color: var(--accent); }
.ob-choice-label { font-size: 11.5px; color: var(--ink-3); text-align: center; line-height: 1.4; }

.ob-steps { display: flex; flex-direction: column; gap: 14px; }
.ob-stepcard {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 15px 16px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--panel-2);
}
.ob-stepnum { font-size: 20px; flex-shrink: 0; line-height: 1.2; }
.ob-stepttl { font-size: 14px; font-weight: 650; margin-bottom: 4px; }
.ob-stepdesc { font-size: 13px; color: var(--ink-3); line-height: 1.55; }

.ob-summary { display: flex; flex-direction: column; gap: 1px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.ob-summary > div {
  display: flex; justify-content: space-between; align-items: center; gap: 14px;
  padding: 12px 16px; background: var(--panel-2);
  font-size: 13.5px;
}
.ob-summary span { color: var(--ink-3); }
.ob-summary b { font-family: var(--mono); color: var(--ink); }

.ob-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 20px; border-top: 1px solid var(--line); }
.ob-dots { display: flex; gap: 6px; }
.ob-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line-2); transition: background 0.15s, width 0.15s; }
.ob-dot.done { background: var(--ink-3); }
.ob-dot.active { background: var(--accent); width: 20px; border-radius: 4px; }
.ob-nav { display: flex; gap: 8px; }

@media (max-width: 560px) {
  .ob-card { padding: 18px 18px 20px; }
  .ob-body { min-height: 0; padding: 20px 0 4px; }
  .ob-choices { grid-template-columns: 1fr; }
  .ob-choice { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 13px 15px; }
}

/* ══ Terms gate ═══════════════════════ */
.terms-screen { min-height: 100vh; display: grid; place-items: center; padding: 28px 20px; }
.terms-card {
  width: 100%; max-width: 620px;
  border: 1px solid var(--line-2);
  border-radius: 14px;
  background: var(--panel);
  padding: 30px 30px 24px;
}
.terms-body {
  max-height: 42vh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0a0a0c;
  padding: 20px 22px;
  margin-bottom: 18px;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink-2);
}
.terms-body h3 {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
  margin: 22px 0 7px;
}
.terms-body h3:first-child { margin-top: 0; }
.terms-body p { margin-bottom: 11px; }
.terms-body p:last-child { margin-bottom: 0; }
.terms-body b { color: var(--ink); }
.terms-todo {
  color: #08080a;
  background: var(--warn);
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 12px;
}
.terms-version {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 20px !important;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.terms-check {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 13px; line-height: 1.5;
  color: var(--ink-2);
  cursor: pointer;
  margin-bottom: 18px;
  padding: 13px 15px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--panel-2);
}
.terms-check:hover { border-color: #3a3a45; }
.terms-check input { width: 17px; height: 17px; flex-shrink: 0; margin-top: 1px; }
.terms-langs { display: flex; justify-content: center; gap: 18px; margin-top: 16px; }

/* ══ Settings ═════════════════════════ */
.hint { font-size: 12.5px; color: var(--ink-3); margin-top: 6px; line-height: 1.6; }
.hint code {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 5px;
  font-family: var(--mono); font-size: 11px;
}
.rate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 11px; }
.mode-banner {
  font-size: 12.5px; line-height: 1.6;
  padding: 12px 15px; border-radius: 8px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--ink-2);
}
.mode-banner.ok { border-color: rgba(91,157,250,0.22); background: rgba(91,157,250,0.05); }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.settings-section { margin-bottom: 16px; }

.icon-btn {
  background: none; border: none; color: var(--ink-3);
  cursor: pointer; padding: 5px; border-radius: 6px;
  display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--panel-3); color: var(--ink); }
.icon-btn.danger:hover { color: var(--neg); }
.icon-btn svg { width: 14px; height: 14px; }

/* ══ Command palette ══════════════════ */
.cmd-trigger {
  display: flex; align-items: center; gap: 8px;
  margin: 0 10px 16px;
  padding: 7px 10px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink-3);
  font-family: inherit; font-size: 12.5px;
  cursor: pointer; width: calc(100% - 20px);
}
.cmd-trigger:hover { border-color: #3a3a45; color: var(--ink-2); }
.cmd-trigger svg { width: 14px; height: 14px; flex-shrink: 0; }
.cmd-trigger span { flex: 1; text-align: left; }
.cmd-trigger kbd {
  font-family: var(--mono); font-size: 10px;
  border: 1px solid var(--line-2); border-radius: 4px;
  padding: 1px 5px; color: var(--ink-3);
}

.palette-overlay {
  position: fixed; inset: 0;
  background: rgba(4,4,6,0.72);
  backdrop-filter: blur(3px);
  z-index: 400;
  display: flex; justify-content: center;
  padding: 12vh 20px 20px;
}
.palette {
  width: 100%; max-width: 560px;
  height: fit-content; max-height: 62vh;
  background: #121216;
  border: 1px solid var(--line-2);
  border-radius: 13px;
  box-shadow: 0 30px 90px -20px #000;
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.12s ease-out;
}
.palette-input-wrap {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-3);
}
.palette-input-wrap svg { width: 16px; height: 16px; flex-shrink: 0; }
.palette-input-wrap input {
  border: none; background: none; padding: 0;
  font-size: 14.5px; color: var(--ink);
}
.palette-input-wrap input:focus { outline: none; border: none; box-shadow: none; }
.palette-list { overflow-y: auto; padding: 6px; flex: 1; }
.palette-group {
  font-family: var(--mono);
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.6px; text-transform: uppercase;
  color: var(--ink-3);
  padding: 10px 10px 5px;
}
.palette-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px;
  border: none; background: none;
  color: var(--ink-2);
  font-family: inherit; font-size: 14px;
  text-align: left; cursor: pointer;
  border-radius: 7px;
}
.palette-item.active { background: rgba(255,255,255,0.07); color: var(--ink); }
.palette-icon { display: grid; place-items: center; flex-shrink: 0; opacity: 0.7; }
.palette-icon svg { width: 15px; height: 15px; }
.palette-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-hint { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); flex-shrink: 0; }
.palette-empty { padding: 26px; text-align: center; color: var(--ink-3); font-size: 13px; }
.palette-foot {
  padding: 9px 16px;
  border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 10px;
  color: var(--ink-3); letter-spacing: 0.3px;
}

/* ══ Photos ═══════════════════════════ */
.hidden-el { display: none !important; }
.photo-field {
  display: flex; align-items: center; gap: 16px;
  padding: 14px; margin-bottom: 18px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2);
}
.photo-preview {
  width: 84px; height: 84px; flex-shrink: 0;
  border-radius: 8px;
  border: 1px dashed var(--line-2);
  display: grid; place-items: center;
  color: var(--ink-3);
  overflow: hidden;
}
.photo-preview.has { border-style: solid; }
.photo-preview svg { width: 24px; height: 24px; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-actions { display: flex; flex-direction: column; gap: 7px; align-items: flex-start; }

.cell-check { width: 34px; }
.cell-thumb { width: 46px; padding-right: 0; }
.thumb { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; display: block; }
.thumb-empty {
  display: grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--line);
  color: var(--ink-3);
}
.thumb-empty svg { width: 14px; height: 14px; }
tbody tr.sel { background: rgba(91,157,250,0.05); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); cursor: pointer; }
.age-warn { color: var(--warn) !important; font-weight: 600; }

/* ══ Gallery ══════════════════════════ */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 14px;
}
.gcard {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  overflow: hidden;
  position: relative;
  display: flex; flex-direction: column;
}
.gcard.sel { border-color: var(--accent); }
.gcard-check { position: absolute; top: 9px; left: 9px; z-index: 2; }
.gcard-photo { aspect-ratio: 1; background: var(--panel-2); cursor: pointer; }
.gphoto { width: 100%; height: 100%; object-fit: cover; display: block; }
.gphoto-empty { display: grid; place-items: center; color: var(--ink-3); }
.gphoto-empty svg { width: 26px; height: 26px; }
.gcard-body { padding: 11px 12px; display: flex; flex-direction: column; gap: 5px; flex: 1; }
.gcard-name { font-size: 13px; font-weight: 600; line-height: 1.3; }
.gcard-meta { font-size: 11.5px; color: var(--ink-3); }
.gcard-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
.gcard-row .num { font-size: 13px; font-weight: 600; }
.gcard-loc { font-family: var(--mono); font-size: 10px; color: var(--ink-3); }
.gcard-age {
  position: absolute; top: 9px; right: 9px;
  font-family: var(--mono); font-size: 10px;
  background: rgba(8,8,10,0.75); color: var(--ink-2);
  padding: 2px 6px; border-radius: 4px;
}
.gcard-actions { display: flex; gap: 6px; padding: 0 12px 12px; align-items: center; }
.gcard-actions .btn { flex: 1; }

/* ══ Bulk bar ═════════════════════════ */
.bulk-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 14px;
  border: 1px solid rgba(91,157,250,0.3);
  border-radius: 9px;
  background: rgba(91,157,250,0.06);
}
.bulk-count {
  font-family: var(--mono); font-size: 11.5px; font-weight: 700;
  color: var(--accent); letter-spacing: 0.3px;
  margin-right: 4px;
}
.bulk-bar select { width: auto; padding: 5px 26px 5px 10px; font-size: 12px; }

/* ══ Goal panel ═══════════════════════ */
.goal-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 16px 20px;
  margin-bottom: 20px;
}
.goal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 11px; flex-wrap: wrap; }
.goal-nums { font-family: var(--mono); font-size: 13.5px; color: var(--ink-3); }
.goal-nums b { color: var(--ink); font-size: 15px; }
.goal-nums b.pos { color: var(--accent); }
.goal-track { height: 8px; background: var(--panel-3); border-radius: 4px; overflow: hidden; }
.goal-fill {
  height: 100%;
  background: linear-gradient(90deg, rgba(91,157,250,0.55), var(--accent));
  border-radius: 4px;
  transition: width 0.4s ease-out;
}
.goal-fill.done { background: var(--accent); }
.goal-foot {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-top: 10px;
  font-family: var(--mono); font-size: 12px; color: var(--ink-3);
}

/* ══ Dead stock ═══════════════════════ */
.dead-panel { border-color: rgba(245,196,81,0.28); }
.dead-panel .panel-title { color: var(--warn); }
.dead-stats { display: flex; gap: 40px; flex-wrap: wrap; }
.dead-stats > div { display: flex; flex-direction: column; gap: 5px; }

/* ══ Report ═══════════════════════════ */
.report-sheet {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 30px 32px;
}
.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding-bottom: 18px; border-bottom: 2px solid var(--line-2); margin-bottom: 24px; flex-wrap: wrap; }
.report-brand { font-size: 15px; font-weight: 700; letter-spacing: -0.2px; }
.report-brand .x { color: var(--accent); font-family: var(--mono); }
.report-title { font-size: 22px; font-weight: 650; letter-spacing: -0.5px; margin-top: 5px; }
.report-meta { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); text-align: right; line-height: 1.7; }
.report-section-title {
  font-family: var(--mono);
  font-size: 11.5px; font-weight: 700;
  letter-spacing: 0.8px; text-transform: uppercase;
  color: var(--ink-3);
  margin: 26px 0 10px;
}
.report-scroll { overflow-x: auto; }
.report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-table th {
  background: none; padding: 7px 10px;
  border-bottom: 1px solid var(--line-2);
}
.report-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.report-table td.num, .report-table th.num { font-family: var(--mono); text-align: right; }
.report-table tfoot td {
  font-weight: 700; border-top: 2px solid var(--line-2); border-bottom: none;
  font-family: var(--mono);
}
.report-table tfoot td:first-child { font-family: var(--sans); }
.report-empty { font-size: 12.5px; color: var(--ink-3); padding: 12px 10px; }

@media print {
  @page { margin: 14mm; }
  body { background: #fff !important; color: #000 !important; }
  body::after { display: none !important; }
  .rail, .page-head, #toastRoot, .palette-overlay, .modal-overlay { display: none !important; }
  #view > *:not(.page-head) { margin: 0 !important; }
  #view { padding: 0 !important; }
  .report-sheet { border: none !important; background: #fff !important; padding: 0 !important; }
  .report-brand, .report-title, .report-table td, .report-table th { color: #000 !important; }
  .report-brand .x { color: #6a7f1a !important; }
  .report-meta, .report-section-title, .report-empty { color: #555 !important; }
  .report-table td, .report-table th { border-color: #ccc !important; }
  .report-table tfoot td, .report-head { border-color: #000 !important; }
  .report-table thead { display: table-header-group; }
  .report-table tr { break-inside: avoid; }
  .report-scroll { overflow: visible !important; }
}

/* ══ Toast undo ═══════════════════════ */
.toast { display: flex; align-items: center; gap: 14px; }
.toast-undo {
  background: none; border: none;
  color: inherit; opacity: 0.72;
  font-family: inherit; font-size: 12px; font-weight: 700;
  text-decoration: underline; text-underline-offset: 2px;
  cursor: pointer; padding: 0;
}
.toast-undo:hover { opacity: 1; }

/* ══ More sheet (phone) ═══════════════ */
.nav-more { display: none; }
.more-list { display: flex; flex-direction: column; gap: 2px; }
.more-item {
  display: flex; align-items: center; gap: 13px;
  width: 100%; padding: 14px 14px;
  border: none; background: var(--panel-2);
  border-radius: 10px;
  color: var(--ink);
  font-family: inherit; font-size: 15px;
  text-align: left; cursor: pointer;
}
.more-item:hover { background: var(--panel-3); }
.more-item svg { width: 19px; height: 19px; flex-shrink: 0; opacity: 0.8; }
.more-item > span:first-of-type { flex: 1; }
.more-chev { color: var(--ink-3); font-size: 19px; line-height: 1; }
.more-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.more-foot .lang-switch { gap: 16px; }

/* search button in the page header (phone only) */
.page-head-main { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.head-search {
  display: none;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  color: var(--ink-2);
  width: 40px; height: 40px;
  place-items: center; cursor: pointer;
  flex-shrink: 0;
}
.head-search svg { width: 18px; height: 18px; }

/* ══ Notice banner ════════════════════ */
.notice {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 18px; margin-bottom: 16px;
  border: 1px solid rgba(245,196,81,0.3);
  border-radius: 12px;
  background: rgba(245,196,81,0.06);
  font-size: 13.5px; line-height: 1.5;
  color: var(--ink-2);
}
.notice b { color: var(--warn); }
.notice-icon { font-size: 19px; flex-shrink: 0; }
.notice .btn { margin-left: auto; }

/* ══ Returns ══════════════════════════ */
.row-returned td:not(.cell-actions) { opacity: 0.45; }
.badge-return { border-color: rgba(255,122,92,0.45); color: var(--neg); }

/* ══ Switch row (settings) ════════════ */
.switch-row {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 15px;
  border: 1px solid var(--line-2); border-radius: 9px;
  background: var(--panel-2);
  font-size: 13.5px; font-weight: 550; color: var(--ink-2);
  cursor: pointer;
  text-transform: none; letter-spacing: 0;
}
.switch-row:hover { border-color: #3a3a45; }
.switch-row.on { border-color: var(--accent); background: rgba(91,157,250,0.07); color: var(--ink); }
.switch-row input { width: 17px; height: 17px; flex-shrink: 0; }

/* ══ Compare picker ═══════════════════ */
.cmp-picks { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cmp-picks > div { display: flex; flex-direction: column; gap: 6px; }

/* ══ Quick add ════════════════════════ */
.quick-photo {
  width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 20px;
  margin-bottom: 20px;
  border: 1px dashed var(--line-2);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--ink-3);
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  cursor: pointer;
}
.quick-photo:hover { border-color: var(--accent); color: var(--ink-2); }
.quick-photo-inner {
  width: 110px; height: 110px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: var(--panel-3);
  overflow: hidden;
}
.quick-photo-inner svg { width: 34px; height: 34px; }
.quick-photo-inner img { width: 100%; height: 100%; object-fit: cover; }
.quick-fields { display: flex; flex-direction: column; gap: 15px; }
.quick-fields input, .quick-fields select { font-size: 16px; padding: 12px 13px; }
.quick-fields label { font-size: 13px; }

/* ══ Floating quick-add button ════════ */
.fab {
  position: fixed;
  right: 22px; bottom: 22px;
  width: 54px; height: 54px;
  border-radius: 50%;
  border: none;
  background: var(--ink);
  color: #08080a;
  display: none;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 8px 26px rgba(0,0,0,0.6);
  z-index: 60;
}
.fab:active { transform: scale(0.94); }
.fab svg { width: 24px; height: 24px; }

/* ══ Responsive ═══════════════════════ */

/* Tablet and phone: stack wide tables into readable cards */
@media (max-width: 780px) {
  .table-wrap { border-radius: 12px; overflow: hidden; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    padding: 13px 15px;
    border-bottom: 1px solid var(--line);
    position: relative;
  }
  .table-wrap tr:last-child { border-bottom: none; }
  .table-wrap td {
    border: none;
    padding: 4px 0;
    display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
    white-space: normal;
    text-align: right;
  }
  .table-wrap td::before {
    content: attr(data-label);
    color: var(--ink-3);
    font-size: 12px;
    font-family: var(--sans);
    text-align: left;
    flex-shrink: 0;
  }
  .table-wrap td:not([data-label]) { display: none; }
  .table-wrap td.cell-check,
  .table-wrap td.cell-thumb,
  .table-wrap td.cell-actions { display: block; }
  .table-wrap td.cell-check { position: absolute; top: 12px; right: 12px; padding: 0; width: auto; }
  .table-wrap td.cell-thumb { padding: 0 0 10px; }
  .table-wrap td.cell-thumb .thumb { width: 56px; height: 56px; }
  .table-wrap td.cell-actions { padding-top: 12px; }
  .table-wrap td.cell-actions .row-actions { opacity: 1; justify-content: flex-start; gap: 6px; }
  .table-wrap td.cell-actions .icon-btn { border: 1px solid var(--line-2); padding: 8px; }
  /* the item name reads as the card heading */
  .table-wrap td.cell-title { display: block; text-align: left; padding: 0 0 9px; }
  .table-wrap td.cell-title::before { display: none; }
  .table-wrap td.cell-title .td-main, .table-wrap td.cell-title { font-size: 15.5px; font-weight: 650; }

  .report-table, .report-table thead, .report-table tbody, .report-table tr, .report-table td { display: revert; }
  .report-table thead { display: table-header-group; }
}

@media (max-width: 860px) {
  #app { flex-direction: column; }
  .rail {
    width: 100%; height: auto; position: static;
    flex-direction: row; align-items: center;
    padding: 0 12px; gap: 10px;
    border-right: none; border-bottom: 1px solid var(--line);
  }
  .brand { border-bottom: none; margin: 0; padding: 12px 8px 12px 0; }
  .brand-name { display: none; }
  #nav { display: flex; overflow-x: auto; padding: 0; flex: 1; }
  .nav-group { display: flex; }
  .nav-group + .nav-group { margin: 0; }
  .nav-group-label { display: none; }
  .nav-item span { display: none; }
  .nav-item.active::after { display: none; }
  .rail-foot { flex-direction: row; align-items: center; border-top: none; margin: 0; padding: 0; }
  .user-email, .sync-status { display: none; }
  .cmd-trigger { width: auto; margin: 0; padding: 7px; }
  .cmd-trigger span, .cmd-trigger kbd { display: none; }
  .palette-overlay { padding: 6vh 12px 12px; }
  .dead-stats { gap: 22px; }
  .report-sheet { padding: 20px 16px; }
  .cmp-picks { grid-template-columns: 1fr; }
}

/* ══ Phone ════════════════════════════ */
@media (max-width: 620px) {
  /* nav moves to a thumb-reachable bottom bar */
  .rail {
    position: fixed; bottom: 0; left: 0; right: 0;
    top: auto; width: 100%; height: auto;
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    border-bottom: none;
    border-top: 1px solid var(--line);
    background: rgba(10,10,12,0.96);
    backdrop-filter: blur(12px);
    z-index: 50;
  }
  .brand, .rail-foot .lang-switch, .rail-foot .sync-status, .rail-foot .user-chip { display: none; }
  #nav {
    display: flex; justify-content: space-around;
    padding: 6px 2px calc(6px + env(safe-area-inset-bottom));
    gap: 2px;
    overflow: visible;
  }
  .nav-group { display: contents; }
  /* only the five core sections live in the bottom bar */
  .nav-item[data-view="report"],
  .nav-item[data-view="import"],
  .nav-item[data-view="settings"],
  .nav-item[data-view="expenses"] { display: none; }
  .nav-more { display: flex; }
  .cmd-trigger { display: none; }
  .head-search { display: grid; }
  .page-head-main { width: 100%; }
  .nav-item {
    flex: 1 1 0;
    width: auto;
    flex-direction: column; gap: 4px;
    padding: 7px 2px 5px;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    min-width: 0;
  }
  .nav-item span {
    display: block;
    font-size: 9px;
    line-height: 1.2;
    letter-spacing: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .nav-item svg { width: 20px; height: 20px; opacity: 1; }
  .nav-item.active { background: none; color: var(--accent); }
  .nav-item.active svg { color: var(--accent); }
  .nav-item.active::after { display: none; }
  .rail-foot { border: none; margin: 0; padding: 0; position: absolute; top: -9999px; }

  .content { padding-bottom: 78px; }
  #app { display: block; }

  /* header: title, then controls on their own line */
  .page-head { padding: 16px 16px 13px; margin-bottom: 18px; gap: 12px; }
  .page-title { font-size: 22px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; justify-content: center; }
  .segmented { width: 100%; overflow-x: auto; }
  .seg-btn { flex: 1; padding: 8px 10px; }

  #view > *:not(.page-head) { margin-left: 14px; margin-right: 14px; }

  .hero { padding: 20px 18px; gap: 18px; }
  .hero-value { font-size: 40px; }
  .ticker { grid-template-columns: 1fr 1fr; }
  .tick { padding: 14px 15px; }
  .tick-value { font-size: 18px; }

  .filter-row { gap: 7px; }
  .filter-row input[type="search"] { max-width: none; flex: 1 1 100%; }
  .filter-row select { flex: 1; }
  .filter-row .spacer { display: none; }

  .gallery { grid-template-columns: 1fr 1fr; gap: 11px; }
  .gcard-body { padding: 10px; }
  .gcard-name { font-size: 12.5px; }

  /* full-height sheets instead of floating dialogs */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: none;
    max-height: 92vh;
    border-radius: 18px 18px 0 0;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
    animation: sheetIn 0.18s ease-out;
  }
  @keyframes sheetIn { from { transform: translateY(28px); opacity: 0; } }
  .modal-actions { position: sticky; bottom: 0; background: #101014; padding-top: 14px; margin-top: 18px; }
  .modal-actions .btn { flex: 1; padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  /* comfortable tap targets and no iOS zoom-on-focus */
  input, select, textarea { font-size: 16px; padding: 11px 12px; }
  .field label { font-size: 12.5px; }

  .fab { display: grid; bottom: calc(76px + env(safe-area-inset-bottom)); }

  .bulk-bar { position: sticky; top: 0; z-index: 20; }
  .bulk-bar .btn { flex: 1; }

  .palette-overlay { padding: 0; }
  .palette { max-width: none; max-height: 100vh; height: 100vh; border-radius: 0; }
  .palette-input-wrap input { font-size: 16px; }

  .notice { padding: 13px 15px; }
  .notice .btn { margin-left: 0; width: 100%; }

  .goal-panel, .card, .panel-body { padding-left: 16px; padding-right: 16px; }
  .ob-card, .terms-card, .auth-card { border: none; border-radius: 0; min-height: 100vh; padding: 20px 18px 26px; }
  .ob-screen, .terms-screen, .auth-screen { padding: 0; }
  .terms-body { max-height: 38vh; }
  .page-head { padding: 18px 16px 14px; margin-bottom: 18px; }
  #view > *:not(.page-head) { margin-left: 16px; margin-right: 16px; }
  .hero { grid-template-columns: 1fr; }
  .hero-value { font-size: 38px; }
  .form-grid { grid-template-columns: 1fr; }
}
