/* ========================================================================
   Cash Flow Engine by CY Academy
   Design system: Modern fintech, Robinhood/Revolut inspired
   ======================================================================== */

:root {
  /* Light theme (default) — zinc neutral (shadcn-inspired) */
  --bg-page: #FAFAFA;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F4F4F5;
  --bg-inverse: #18181B;
  --text-primary: #18181B;
  --text-secondary: #52525B;
  --text-tertiary: #71717A;
  --text-inverse: #FAFAFA;
  --border: #E4E4E7;
  --border-subtle: #F1F1F3;
  --badge-bg: #E4E4E7;
  --badge-fg: #3F3F46;

  --brand: #18181B;
  --ring: rgba(24,24,27,0.45);
  --success: #16A34A;
  --success-bg: rgba(22,163,74,0.10);
  --warning: #D97706;
  --warning-bg: rgba(217,119,6,0.10);
  --danger: #DC2626;
  --danger-bg: rgba(220,38,38,0.10);
  --info: #0A63D2;
  --info-bg: rgba(10,99,210,0.10);
  --purple: #7C3AED;

  --shadow-sm: 0 1px 2px rgba(24,24,27,0.04);
  --shadow-md: 0 1px 3px rgba(24,24,27,0.06), 0 1px 2px rgba(24,24,27,0.04);
  --shadow-lg: 0 12px 32px -12px rgba(24,24,27,0.18);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-height: calc(64px + var(--safe-bottom));

  /* One standard content width, centered within the canvas on every desktop size. */
  --content-max: 1200px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-page: #09090B;
    --bg-surface: #18181B;
    --bg-subtle: #27272A;
    --bg-inverse: #FAFAFA;
    --text-primary: #FAFAFA;
    --text-secondary: #A1A1AA;
    --text-tertiary: #8A8A93;
    --text-inverse: #18181B;
    --border: #27272A;
    --border-subtle: #1F1F23;
    --badge-bg: #3F3F46;
    --badge-fg: #E4E4E7;
    --brand: #FAFAFA;
    --ring: rgba(250,250,250,0.35);
    --success: #22C55E;
    --success-bg: rgba(34,197,94,0.15);
    --warning: #F59E0B;
    --warning-bg: rgba(245,158,11,0.15);
    --danger: #F87171;
    --danger-bg: rgba(248,113,113,0.15);
    --info: #5AA8FF;
    --info-bg: rgba(90,168,255,0.16);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 1px 3px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 32px -12px rgba(0,0,0,0.7);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* shadcn-style focus ring: 2px ring with a bg-colored offset halo */
*:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--bg-page), 0 0 0 4px var(--ring); border-radius: var(--radius-sm); }
input:focus-visible, textarea:focus-visible, .search:focus-within { box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--ring); }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

body {
  padding-bottom: var(--tabbar-height);
  min-height: 100vh;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input {
  font-family: inherit;
  font-size: inherit;
}

.hidden { display: none !important; }

/* ---------- Layout container (mobile-first) ---------- */
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg-page);
  position: relative;
}

/* ---------- Loading state ---------- */
.loader {
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.loader-logo {
  animation: pulse 1.5s ease-in-out infinite;
}
.loader-logo img {
  width: 200px;
  max-width: 62vw;
  height: auto;
  display: block;
}
/* Sidebar brand shows only in the desktop sidebar layout (see min-width media). */
.sidebar-brand { display: none; }
.loader-text {
  color: var(--text-secondary);
  font-size: 14px;
}
@keyframes pulse {
  0%, 100% { opacity: 0.5; transform: scale(0.95); }
  50% { opacity: 1; transform: scale(1); }
}

/* ---------- Data freshness indicator ---------- */
.freshness { display:inline-flex; align-items:center; gap:6px; font-size:11px; font-weight:500; color:var(--text-secondary); background:var(--bg-subtle); border:1px solid var(--border); padding:3px 10px; border-radius:999px; cursor:default; }
.freshness .dot { width:6px; height:6px; border-radius:50%; background:var(--success); }
.freshness.stale { color:var(--warning); }
.freshness.stale .dot { background:var(--warning); }
@keyframes freshness-pulse { 0%{box-shadow:0 0 0 0 rgba(16,185,129,.5);} 70%{box-shadow:0 0 0 6px rgba(16,185,129,0);} 100%{box-shadow:0 0 0 0 rgba(16,185,129,0);} }
#refresh-btn.spinning svg { animation:spin .8s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }

/* ---------- Top bar ---------- */
.topbar {
  padding: 20px 20px 4px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.topbar .greet {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 2px;
  letter-spacing: 0.2px;
}
.topbar h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.6px;
  color: var(--text-primary);
}
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 999px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-primary);
  transition: all 0.15s ease;
}
.icon-btn:hover { background: var(--bg-subtle); }
.icon-btn:active { transform: scale(0.95); }

/* ---------- Search ---------- */
.search-wrap { padding: 12px 20px 0; }
.search {
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.search svg { color: var(--text-tertiary); flex-shrink: 0; }
.search input {
  flex: 1;
  border: none; outline: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  /* Vertical padding lives on the input (not the box) so the whole row height
     is a tappable focus target on touch screens. */
  padding: 13px 0;
}
.search input::placeholder { color: var(--text-tertiary); }

/* ---------- Filter chips ---------- */
.filters {
  display: flex; gap: 8px;
  padding: 12px 20px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }

.chip {
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
  transition: all 0.15s ease;
}
.chip:hover { background: var(--bg-subtle); }
.chip.active {
  background: var(--text-primary);
  color: var(--text-inverse);
  border-color: var(--text-primary);
}
.filters-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.filters-caret { font-size: 10px; opacity: 0.7; }

/* Segmented control (mutually-exclusive groups: market / type) */
.scope-filters { gap: 10px; overflow-x: visible; flex-wrap: wrap; align-items: center; row-gap: 8px; }
.segmented {
  display: inline-flex;
  flex: 0 0 auto;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}
.segmented .seg {
  border: none;
  background: transparent;
  border-radius: calc(var(--radius) - 4px);
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.segmented .seg:hover:not(.active) { color: var(--text-primary); }
.segmented .seg.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ---------- Section header ---------- */
.section-head {
  padding: 18px 20px 10px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.section-head h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
}
.section-head .action {
  font-size: 13px;
  color: var(--info);
  font-weight: 500;
  cursor: pointer;
}
.section-actions {
  display: flex;
  gap: 16px;
  align-items: baseline;
}

/* ---------- REIT list rows ---------- */
.reit-list {
  padding: 0 12px 20px;
}
.reit-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background 0.15s ease;
}
.reit-row:hover { background: var(--bg-subtle); }
.reit-row:active { transform: scale(0.99); }

.ticker-badge {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--badge-fg);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.3px;
  flex: 0 0 auto;
  text-transform: uppercase;
}

.reit-meta {
  flex: 1;
  min-width: 0;
}
.reit-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reit-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.type-badge { font-size:10px; font-weight:600; padding:1px 6px; border-radius:6px; text-transform:uppercase; letter-spacing:.3px; }
.type-badge.reit { background:var(--info-bg); color:var(--info); }
.type-badge.bank { background:var(--purple); color:#fff; opacity:.85; }

.reit-right {
  text-align: right;
  flex: 0 0 auto;
}
.yield-val {
  font-size: 15px;
  font-weight: 600;
}
.yield-val.high { color: var(--success); }
.yield-val.mid { color: var(--warning); }
.yield-val.low { color: var(--danger); }
.yield-val.unk { color: var(--text-tertiary); }

.price-sub {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.star-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--text-tertiary);
  min-width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  cursor: pointer;
}
.star-btn.on { color: #F5A623; }

/* ---------- Watchlist ---------- */
.wl-intro {
  padding: 0 20px 4px;
  max-width: 680px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.wl-list {
  padding: 12px;
  max-width: 680px;
}
/* Use desktop width: two columns of watchlist cards.
   Width/centering come from the shared content-container media queries below. */
@media (min-width: 1024px) {
  .wl-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .wl-card { margin-bottom: 0; }
}
.wl-card {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
}
.wl-add-btn { width: 100%; margin-top: 12px; }
.wl-card.wl-hit {
  border-color: var(--success);
  background: var(--success-bg);
}
.wl-card-star {
  position: absolute;
  top: 12px; right: 10px;
  font-size: 20px;
}
.wl-card .reit-name {
  white-space: normal;
  padding-right: 30px;
  font-size: 15px;
}
.wl-facts {
  display: flex;
  gap: 24px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.wl-fact-label {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.wl-fact-val {
  font-size: 16px;
  font-weight: 600;
  margin-top: 3px;
  color: var(--text-primary);
}
.wl-fact-val.high { color: var(--success); }
.wl-fact-val.mid { color: var(--warning); }
.wl-fact-val.low { color: var(--danger); }
.wl-fact-val.unk { color: var(--text-tertiary); }
.wl-fact-sub { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }

/* Detail: real distributions (ex-date / payment date / amount) */
.dist-table { display: flex; flex-direction: column; }
.dist-head { display: flex; gap: 12px; padding: 0 6px 8px; }
.dist-head .dist-cell { font-size: 11px; text-transform: uppercase; letter-spacing: 0.3px; color: var(--text-tertiary); font-weight: 600; }
.dist-row { display: flex; gap: 12px; padding: 11px 6px; border-top: 1px solid var(--border-subtle); font-size: 14px; font-weight: 600; color: var(--text-primary); align-items: center; }
.dist-upcoming { background: var(--info-bg); border-radius: var(--radius-sm); }
.dist-cell { flex: 1; min-width: 0; white-space: nowrap; }
.dist-amt { text-align: right; flex: 0 0 auto; }
.dist-badge { background: var(--info-bg); color: var(--info); font-size: 9px; font-weight: 600; padding: 1px 5px; border-radius: 4px; text-transform: uppercase; letter-spacing: 0.3px; margin-left: 4px; }
.wl-hit-label { color: var(--success); font-weight: 600; }
.wl-distance { color: var(--text-secondary); font-weight: 500; font-size: 14px; }
.wl-range { margin-top: 16px; }
.wl-range-track {
  position: relative;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}
.wl-range-dot {
  position: absolute;
  top: -3px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-primary);
  transform: translateX(-50%);
}
.wl-range-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 7px;
  font-size: 11px;
  color: var(--text-tertiary);
}
.wl-targets {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.wl-field {
  flex: 1;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.wl-field-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}
.wl-target-price, .wl-target-yield {
  width: 100%;
  font-size: 14px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-page);
  color: var(--text-primary);
}

/* ---------- Portfolio hero card ---------- */
.hero {
  margin: 16px 20px 8px;
  padding: 24px 22px;
  border-radius: var(--radius-lg);
  background: #18181B;
  color: #FAFAFA;
  position: relative;
  overflow: hidden;
}
.hero .label {
  font-size: 11px;
  opacity: 0.7;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.hero .value {
  font-size: 36px;
  font-weight: 600;
  letter-spacing: -1.2px;
  margin-top: 6px;
  line-height: 1.1;
  display: flex;
  flex-wrap: wrap;
  gap: 0 10px;
}
.hero .value small {
  font-size: 20px;
  opacity: 0.7;
  margin-right: 4px;
  font-weight: 600;
}
.hero .change-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  font-size: 12px;
  padding: 4px 10px;
  background: rgba(16,185,129,0.2);
  color: #10D394;
  border-radius: 999px;
  font-weight: 600;
}
.hero-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.hero-grid .k {
  font-size: 10px;
  opacity: 0.65;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.hero-grid .v {
  font-size: 14px;
  font-weight: 600;
  margin-top: 4px;
  white-space: nowrap;
}

/* ---------- Holdings ---------- */
.holding {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background 0.15s ease;
}
.holding:hover { background: var(--bg-surface); }
.holding:last-child { border-bottom: none; }

.holding-mid { flex: 1; min-width: 0; }
.holding-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.holding-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.holding-right { text-align: right; flex-shrink: 0; }
.holding-income {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.holding-yoc {
  font-size: 12px;
  color: var(--success);
  margin-top: 2px;
  font-weight: 500;
}

/* ---------- Detail page ---------- */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 20px;
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}
.detail-hero {
  margin: 4px 20px 12px;
  padding: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.detail-title-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.detail-title-info { flex: 1; min-width: 0; }
.detail-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.4px;
  color: var(--text-primary);
}
.detail-ticker {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 2px;
}
.badge-inline {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-subtle);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-left: 6px;
}

.hero-price-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.hero-price-row .num {
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -1.5px;
  line-height: 1;
  color: var(--text-primary);
}
.hero-yields {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.ychip {
  background: var(--bg-subtle);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
.ychip b { color: var(--text-primary); font-weight: 600; }
.ychip-fwd { cursor: help; }
.ychip-fwd b { color: var(--success); }
.ychip-mut { color: var(--text-tertiary); font-weight: 400; }
.hero-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 12px;
}
.hero-sub-mut { opacity: 0.7; }
.hero-sub-warn { color: var(--warning); }
.hero-sub-warn b { font-weight: 600; }

.chart-card {
  margin: 12px 20px;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.chart-card .chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chart-card canvas { max-height: 200px !important; }
.chart-tabs {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  padding: 4px;
  background: var(--bg-subtle);
  border-radius: 8px;
}
.chart-tab {
  flex: 1;
  padding: 6px;
  font-size: 11px;
  color: var(--text-secondary);
  border-radius: 6px;
  font-weight: 500;
}
.chart-tab.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* YA2026 tax-treatment disclosure under income projections */
.tax-note { font-size: 11px; color: var(--text-secondary); line-height: 1.5; margin-top: 8px; opacity: 0.9; }
.hero .tax-note { color: rgba(255,255,255,0.6); margin-top: 12px; }

/* Dividend chart view toggle (Yearly / Per payout) */
.chart-card .chart-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.seg-toggle { display: inline-flex; background: var(--bg-subtle); border-radius: 8px; padding: 2px; gap: 2px; flex: 0 0 auto; }
.seg-toggle .seg { font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 6px; color: var(--text-secondary); white-space: nowrap; }
.seg-toggle .seg.active { background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-sm); }

/* Right-rail metrics panel — frames the KPI grid as one shadcn card. */
.metrics-card {
  margin: 12px 20px;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.metrics-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 0;
}
/* Very narrow phones: 3 columns get too cramped, drop to 2. */
@media (max-width: 430px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}
.kpi {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.kpi .k {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.kpi .v {
  font-size: 17px;
  font-weight: 600;
  margin-top: 4px;
  color: var(--text-primary);
  /* Flex lets the .tag qualifier wrap onto its own line in narrow tiles
     (detail side rail, small phones) instead of spilling into the next tile —
     the markup has no whitespace before the tag, so text wrapping can't. */
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 5px;
}
.kpi .v.pos { color: var(--success); }
.kpi .v.neg { color: var(--danger); }
.kpi .v.warn { color: var(--warning); }
.kpi .v.v--sm { font-size: 15px; }
.kpi .v .tag { font-size: 11px; font-weight: 600; color: var(--text-tertiary); }
.kpi[title]:not([title=""]) { cursor: help; }
/* Inside the metrics card, tiles read as filled chips (no border) — shadcn stat style. */
.metrics-card .kpi {
  background: var(--bg-subtle);
  border-color: transparent;
  padding: 10px 12px;
}
.kpi-section {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-tertiary);
  margin-top: 10px;
  padding-left: 2px;
}
.kpi-section:first-child { margin-top: 0; }

/* ---------- Buttons ---------- */
.cta-row {
  display: flex;
  gap: 10px;
  padding: 12px 20px 20px;
  position: sticky;
  bottom: var(--tabbar-height);
  background: linear-gradient(to top, var(--bg-page) 60%, transparent);
  z-index: 5;
}
.btn {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  transition: transform 0.1s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--brand);
  color: var(--text-inverse);
}
.btn-primary:hover { opacity: 0.90; }
.btn-ghost {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
}
.btn-ghost:hover { background: var(--bg-subtle); }
.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

/* ---------- Modal / bottom sheet ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-page);
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: -8px auto 16px;
}
.modal h3 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
  margin-bottom: 4px;
}
.modal p.sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 18px;
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.field-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.field-prefix {
  position: absolute;
  left: 14px;
  font-size: 16px;
  color: var(--text-tertiary);
  font-weight: 500;
  pointer-events: none;
}
.field input {
  width: 100%;
  padding: 14px 14px 14px 44px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s ease;
}
.field input:focus { border-color: var(--text-primary); }
.field input.no-prefix { padding-left: 14px; }
.field .hint {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
}
.field .error {
  font-size: 11px;
  color: var(--danger);
  margin-top: 4px;
}

.preview-box {
  background: var(--success-bg);
  border: 1px solid rgba(16,185,129,0.25);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
}
.preview-box .k {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.preview-box .v {
  font-size: 22px;
  font-weight: 600;
  color: var(--success);
  margin-top: 2px;
}
.preview-box .sub-detail {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ---------- Empty states ---------- */
.empty-state {
  padding: 60px 40px;
  text-align: center;
}
.empty-icon {
  font-size: 48px;
  opacity: 0.5;
  margin-bottom: 12px;
}
.empty-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}
.empty-msg {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 20px;
}

/* ---------- Onboarding ---------- */
.onboard {
  min-height: calc(100vh - var(--tabbar-height));
  padding: 40px 24px 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--bg-page);
}
.onboard-hero {
  width: 88px; height: 88px;
  margin: 20px auto 0;
  border-radius: var(--radius-xl);
  background: var(--brand);
  color: var(--text-inverse);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg);
}
.onboard h2 {
  margin: 24px 0 8px;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.6px;
  text-align: center;
  line-height: 1.2;
}
.onboard > div:first-child > p {
  margin: 0 auto;
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 320px;
  line-height: 1.5;
  text-align: center;
}
.feature-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  margin-bottom: 10px;
}
.feature-ico {
  width: 40px; height: 40px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-subtle);
  color: var(--text-primary);
  flex: 0 0 auto;
}
.feature-title { font-size: 14px; font-weight: 600; }
.feature-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ---------- Bottom Tab Bar ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--tabbar-height);
  padding-bottom: var(--safe-bottom);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  z-index: 50;
  max-width: 480px;
  margin: 0 auto;
}
.tabbar .tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px;
  font-size: 10px;
  color: var(--text-tertiary);
  font-weight: 500;
  transition: color 0.15s ease;
}
.tabbar .tab.active { color: var(--text-primary); }
.tabbar .tab:active { transform: scale(0.95); }
/* Sign out lives in the desktop sidebar only (mobile uses Settings → Sign out).
   Scoped to .tabbar so it beats the .tabbar .tab display:flex above. */
.tabbar .tab-signout { display: none; }

/* ---------- Payout cards ---------- */
.month-card {
  margin: 12px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.month-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-subtle);
}
.month-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.month-total {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.payout-row {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.payout-row + .payout-row {
  border-top: 1px solid var(--border-subtle);
}
.payout-date {
  width: 48px;
  text-align: center;
  padding: 6px 0;
  border-radius: 10px;
  background: var(--bg-subtle);
  flex: 0 0 auto;
}
.payout-date .d {
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
}
.payout-date .m {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-top: 2px;
}
.payout-mid { flex: 1; min-width: 0; }
.payout-title {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.payout-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.payout-amt {
  font-size: 15px;
  font-weight: 600;
  color: var(--success);
  flex: 0 0 auto;
}
.status-pill {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.status-pill.upcoming { background: var(--info-bg); color: var(--info); }
.status-pill.predicted { background: var(--warning-bg); color: var(--warning); }

/* ---------- Settings ---------- */
.settings-section {
  margin: 16px 20px;
}
.settings-section h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding-left: 4px;
}
.settings-item {
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-bottom: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.settings-item:first-of-type { border-top-left-radius: var(--radius-lg); border-top-right-radius: var(--radius-lg); }
.settings-item:last-of-type { border-top-right-radius: 0; border-top-left-radius: 0; border-bottom-left-radius: var(--radius-lg); border-bottom-right-radius: var(--radius-lg); border-bottom: 1px solid var(--border); }
/* A lone item (also matches :only-child) — full radius; beats the first/last rules. */
.settings-item:first-of-type:last-of-type { border-radius: var(--radius-lg); border-bottom: 1px solid var(--border); }
.settings-item-label { font-size: 14px; font-weight: 500; }
.settings-item-value { font-size: 13px; color: var(--text-secondary); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(var(--tabbar-height) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--text-inverse);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: toastSlide 3s ease forwards;
}
@keyframes toastSlide {
  0% { opacity: 0; transform: translateX(-50%) translateY(20px); }
  10%, 90% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(20px); }
}

/* ---------- Warning banner ---------- */
.warning-banner {
  margin: 12px 20px;
  padding: 12px 14px;
  background: var(--warning-bg);
  border-radius: 12px;
  font-size: 12px;
  color: var(--warning);
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.warning-banner strong { color: var(--warning); font-weight: 600; }

/* ---------- Sort menu ---------- */
.sort-menu {
  position: absolute;
  top: 100%;
  right: 20px;
  margin-top: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 20;
  overflow: hidden;
  min-width: 200px;
}
.sort-item {
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sort-item:last-child { border-bottom: none; }
.sort-item:hover { background: var(--bg-subtle); }
.sort-item.active { color: var(--info); font-weight: 600; }
.sort-item .check { opacity: 0; margin-left: auto; }
.sort-item.active .check { opacity: 1; }

/* ============================================================
   RESPONSIVE LAYOUT — Tablet, Laptop, Desktop
   ============================================================ */

/* ---------- Touch viewports (<768px): comfortable tap targets ---------- */
@media (max-width: 767px) {
  /* Text-link actions (Sort, Backtest →, Income calendar →): grow the hit
     area with padding + negative margin so layout doesn't shift. */
  .section-head .action,
  .section-actions .action {
    padding: 12px 8px;
    margin: -12px -8px;
  }
  /* Chart view toggle (Yearly / Per payout) */
  .seg-toggle .seg { padding: 9px 12px; }
}

/* ---------- Tablet (768px+): Two-column layout ---------- */
@media (min-width: 768px) {
  :root {
    --tabbar-height: 0px;  /* Hide bottom tabbar, use sidebar instead */
    --sidebar-width: 240px;
  }
  body {
    background: var(--bg-subtle);
    padding-bottom: 0;
    padding-left: var(--sidebar-width);
  }
  #app {
    max-width: none;
    margin: 0;
    background: var(--bg-page);
    min-height: 100vh;
  }
  /* Bottom tabbar becomes vertical sidebar */
  .tabbar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    height: 100vh;
    padding: 32px 16px 24px;
    padding-bottom: 24px;
    border-top: none;
    border-right: 1px solid var(--border-subtle);
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    max-width: none;
    margin: 0;
    background: var(--bg-page);
    z-index: 40;
  }
  /* App logo + wordmark at top of sidebar */
  .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 4px 12px 14px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-subtle);
  }
  .sidebar-brand img { height: 36px; width: auto; flex: 0 0 auto; }
  .sidebar-brand-text strong {
    display: block; font-size: 15px; font-weight: 600;
    letter-spacing: -0.3px; line-height: 1.15; color: var(--text-primary);
  }
  .sidebar-brand-text span {
    display: block; font-size: 11px; color: var(--text-secondary);
  }
  .tabbar .tab {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 10px;
    margin-bottom: 4px;
    color: var(--text-secondary);
  }
  .tabbar .tab:hover {
    background: var(--bg-subtle);
  }
  .tabbar .tab.active {
    background: var(--bg-subtle);
    color: var(--text-primary);
    font-weight: 600;
  }
  .tabbar .tab .ico,
  .tabbar .tab svg {
    width: 20px;
    height: 20px;
    margin-bottom: 0;
  }
  /* Sign out: shown in the sidebar, pinned to the bottom, danger on hover. */
  .tabbar .tab-signout {
    display: flex;
    margin-top: auto;
    color: var(--text-tertiary);
  }
  .tabbar .tab-signout:hover {
    background: var(--danger-bg);
    color: var(--danger);
  }

  /* Content container padding */
  .topbar {
    padding: 32px 40px 8px;
    max-width: 1200px;
  }
  .topbar h1 {
    font-size: 32px;
  }
  .topbar,
  .search-wrap,
  .filters,
  .section-head,
  .reit-list,
  .cta-row,
  .metrics-card,
  .chart-card,
  .month-card,
  .settings-section,
  .warning-banner,
  .detail-hero,
  .back-btn,
  .wl-intro,
  .wl-list,
  .members-list,
  .screen {
    max-width: var(--content-max);
    margin-left: auto;
    margin-right: auto;
    padding-left: 40px;
    padding-right: 40px;
  }
  .reit-list {
    padding-left: 40px;
    padding-right: 40px;
  }
  /* Chip rows h-scroll on touch, but mice have no affordance for a hidden
     scrollbar — wrap the sector/advanced filter chips instead. */
  .filters {
    flex-wrap: wrap;
    overflow-x: visible;
  }
  .hero {
    margin: 20px 40px 12px;
    max-width: 1120px;
    padding: 28px 32px;
  }
  .hero .value {
    font-size: 42px;
  }

  /* Portfolio holdings full-width but padded */
  .holding {
    padding: 16px 40px;
    max-width: var(--content-max);
    margin-left: auto;
    margin-right: auto;
  }

  /* Empty state */
  .empty-state {
    max-width: 500px;
    margin: 0 auto;
  }

  /* Modal centered instead of bottom sheet */
  .modal-backdrop {
    align-items: center;
    justify-content: center;
    padding: 24px;
  }
  .modal {
    max-width: 480px;
    border-radius: var(--radius-lg);
    padding: 28px;
    padding-bottom: 28px;
    animation: modalPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  }
  @keyframes modalPop {
    from { opacity: 0; transform: translateY(20px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
  }
  .modal-handle {
    display: none;
  }

  /* Toast repositioned above content */
  .toast {
    bottom: 32px;
    left: calc(50% + var(--sidebar-width) / 2);
  }
}

/* ---------- Tablet Portrait & Landscape (768–1279px): Enhanced spacing ---------- */
@media (min-width: 768px) and (max-width: 1279px) {
  /* Portfolio KPI grid tightens to 2 columns on tablet */
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .hero-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

/* ---------- Laptop (1024px+): Two-column dashboard for Portfolio + Detail ---------- */
@media (min-width: 1024px) {
  /* Detail page: chart card + KPI grid side-by-side */
  .detail-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    max-width: var(--content-max);
    padding: 0 40px;
    margin: 0 auto;
  }
  .detail-layout .col-main > * {
    padding-left: 0;
    padding-right: 0;
    margin-left: 0;
    margin-right: 0;
    max-width: none;
  }
  .detail-layout .col-side > * {
    padding-left: 0;
    padding-right: 0;
    margin-left: 0;
    margin-right: 0;
    max-width: none;
  }
  /* Right rail is narrow (≈1/3 width minus sidebar) — 2 columns read cleaner than 3. */
  .detail-layout .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 0;
  }
  /* Keep the card's own padding (the col-side reset zeroes horizontal padding). */
  .detail-layout .col-side .metrics-card {
    padding: 16px;
    margin-bottom: 16px;
  }
  .detail-layout .cta-row {
    padding: 0;
    position: static;
    background: none;
  }
}

/* ---------- Desktop (1280px+): Wider content, better use of space ---------- */
@media (min-width: 1280px) {
  :root {
    --sidebar-width: 260px;
  }
  .topbar {
    padding: 36px 40px 12px;
  }
  .topbar h1 {
    font-size: 36px;
    letter-spacing: -0.8px;
  }
  .search-wrap,
  .filters,
  .section-head,
  .reit-list,
  .cta-row,
  .metrics-card,
  .chart-card,
  .month-card,
  .settings-section,
  .warning-banner,
  .detail-hero,
  .back-btn,
  .wl-intro,
  .wl-list,
  .members-list,
  .screen {
    padding-left: 40px;
    padding-right: 40px;
  }
  .reit-list {
    padding-left: 28px;
    padding-right: 28px;
  }
  .hero {
    margin: 24px 40px 16px;
    max-width: 1120px;
  }
  .holding {
    padding-left: 40px;
    padding-right: 40px;
  }

  /* Two-column REIT grid for desktop — rows become bordered cards */
  .reit-list.grid-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding-left: 36px;
    padding-right: 36px;
  }
  .reit-list.grid-view .reit-row {
    border: 1px solid var(--border);
    background: var(--bg-surface);
  }
  .reit-list.grid-view .reit-row:hover {
    background: var(--bg-subtle);
    box-shadow: var(--shadow-sm);
  }

  /* Portfolio: hero + chart in two columns */
  .portfolio-top {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 20px;
    align-items: start;  /* don't stretch — let each card be its natural height */
    max-width: var(--content-max);
    margin: 24px auto 16px;
    padding: 0 40px;
  }
  .portfolio-top .hero,
  .portfolio-top .chart-card {
    margin: 0;
    max-width: none;
  }
  .portfolio-top .chart-card {
    padding: 20px;
  }
}

/* ---------- Wide Desktop (1600px+): Cap content width ---------- */
@media (min-width: 1600px) {
  .topbar,
  .search-wrap,
  .filters,
  .section-head,
  .reit-list,
  .cta-row,
  .metrics-card,
  .chart-card,
  .month-card,
  .settings-section,
  .warning-banner,
  .detail-hero,
  .back-btn,
  .holding,
  .wl-intro,
  .wl-list,
  .members-list,
  .screen {
    max-width: var(--content-max);
    margin-left: auto;
    margin-right: auto;
  }
  .hero {
    max-width: var(--content-max);
    margin-left: auto;
    margin-right: auto;
  }
  .portfolio-top {
    max-width: var(--content-max);
    margin-left: auto;
    margin-right: auto;
  }
  .detail-layout {
    max-width: var(--content-max);
  }
}

/* .back-btn is inline-flex (shrink-to-fit), so the auto margins set by the
   centering lists above resolve to 0; align its left edge to the centered
   container explicitly. Placed after those lists so it wins at every width. */
@media (min-width: 768px) {
  .back-btn {
    margin-left: max(0px, calc(50% - var(--content-max) / 2));
  }
}

/* ---------- Chart heights on larger screens ---------- */
@media (min-width: 768px) {
  .chart-card canvas {
    max-height: 260px !important;
  }
}
@media (min-width: 1280px) {
  .chart-card canvas {
    max-height: 320px !important;
  }
}

/* ---------- Hover-capable devices: Show sort menu on right ---------- */
@media (min-width: 768px) {
  .sort-menu {
    right: 40px;
  }
}
@media (min-width: 1280px) {
  .sort-menu {
    right: 48px;
  }
}

/* ---------- Onboarding on large screens ---------- */
@media (min-width: 768px) {
  .onboard {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    padding: 60px 40px;
  }
}

/* ---------- Final polish ---------- */
/* Fix hero card height on desktop - avoid empty bottom space */
@media (min-width: 768px) {
  .hero {
    padding-bottom: 24px;
  }
  .hero-grid {
    margin-top: 20px;
    padding-top: 18px;
  }
}

/* Sticky CTA row shouldn't be sticky on desktop */
@media (min-width: 768px) {
  .cta-row {
    position: static;
    background: none;
    padding: 20px 40px;
    max-width: 800px;
  }
  .cta-row .btn {
    max-width: 240px;
  }
}

/* Detail hero: larger price on desktop */
@media (min-width: 1024px) {
  .hero-price-row .num {
    font-size: 46px;
  }
}

/* Holdings rows on desktop: subtle border, hover background */
@media (min-width: 768px) {
  .holding {
    border-bottom: 1px solid var(--border-subtle);
    padding: 16px 40px;
    margin: 0 auto;
    max-width: var(--content-max);
  }
  .holding:last-child { border-bottom: none; }
  .holding:hover {
    background: var(--bg-subtle);
  }
}

/* Section heads on desktop have subtle divider */
@media (min-width: 768px) {
  .section-head {
    padding-top: 28px;
    padding-bottom: 14px;
  }
  .section-head h2 {
    font-size: 20px;
  }
}

/* ---------- Backtest tab ---------- */
/* Backtest screen container — mobile padding; desktop width caps come from the
   shared centering media queries (the .screen selector is added to those lists). */
.screen { padding: 16px 20px 40px; }
.screen-head h1 { margin-bottom: 2px; }
.bt-inputs label { display:block; font-size:12px; color:var(--text-secondary); margin-bottom:12px; }
.bt-inputs input, .bt-inputs select { width:100%; margin-top:4px; padding:10px 12px; border-radius:10px; border:1px solid var(--border); background:var(--bg-surface); color:var(--text-primary); font-size:15px; }
/* min-width:0 lets fields shrink below the intrinsic width of type="month"
   inputs — without it the Start/End row overflows narrow phone viewports. */
.bt-row { display:flex; gap:12px; } .bt-row label { flex:1; min-width:0; }
.bt-inputs input, .bt-inputs select { min-width:0; }
.bt-toggles { display:flex; flex-direction:column; gap:8px; margin-bottom:12px; }
.bt-toggles .switch { display:flex; align-items:center; gap:8px; font-size:14px; color:var(--text-primary); min-height:32px; }
.bt-toggles .switch input { width:18px; height:18px; margin:0; accent-color:var(--brand); }
.bt-stats { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin:16px 0; }
.bt-stat { background:var(--bg-surface); border:1px solid var(--border); border-radius:var(--radius-lg); padding:14px; }
.bt-stat .k { font-size:11px; color:var(--text-secondary); } .bt-stat .v { font-size:22px; font-weight:600; margin-top:4px; }
.bt-stat .v.pos { color:var(--success); } .bt-stat .v.neg { color:var(--danger); }
.bt-substats { display:flex; flex-wrap:wrap; gap:14px; font-size:12px; color:var(--text-secondary); margin-bottom:12px; }
.bt-flag { background:rgba(245,158,11,.12); color:var(--warning); border-radius:10px; padding:10px 12px; font-size:13px; margin-bottom:12px; }
.bt-note { font-size:11px; color:var(--text-secondary); line-height:1.5; margin-top:10px; }
#bt-run.btn-primary { width:100%; padding:14px; border:none; border-radius:12px; background:var(--success); color:#fff; font-size:16px; font-weight:600; cursor:pointer; }

/* Full-viewport overlay: fixed + inset:0 so it ignores the desktop sidebar
   gutter (body padding-left) and stays perfectly centered on every screen. */
.auth-screen { position: fixed; inset: 0; z-index: 100; background: var(--bg-page);
  display: flex; align-items: center; justify-content: center; padding: 24px; overflow-y: auto; }
.auth-screen.hidden { display: none; }
.auth-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px;
  background: var(--bg-surface); color: var(--text-primary); padding: 28px; border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); }
.auth-brand { font-weight: 600; font-size: 22px; text-align: center; margin-bottom: 8px; color: var(--text-primary); }
.auth-brand span { display: block; font-size: 13px; font-weight: 500; opacity: .6; }
.auth-card input { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg-page); color: var(--text-primary); font-size: 15px; }
.auth-card input::placeholder { color: var(--text-tertiary); }
.auth-card h2 { color: var(--text-primary); }
.auth-card p { color: var(--text-secondary); font-size: 14px; }
.auth-error { color: var(--danger, #dc2626); font-size: 13px; min-height: 16px; }
.auth-divider { text-align: center; opacity: .5; font-size: 12px; }
.auth-link { background: none; border: none; color: var(--info); font-size: 13px; font-weight: 600; padding: 10px; min-height: 44px; align-self: center; cursor: pointer; }
.change-pw { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.change-pw input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); font-size: 14px; background: var(--bg-surface); color: var(--text-primary); }

/* Admin: Members page */
.members-list { padding: 0 20px 24px; }
.members-loading { color: var(--text-secondary); font-size: 14px; padding: 24px 0; text-align: center; }
.members-count { font-size: 13px; color: var(--text-secondary); font-weight: 600; margin: 4px 0 12px; }
.member-row { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: center; justify-content: space-between;
  padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-surface); margin-bottom: 10px; }
.member-info { min-width: 0; flex: 1 1 200px; }
.member-email { font-size: 14px; font-weight: 600; color: var(--text-primary); overflow-wrap: anywhere; }
.member-you { font-size: 11px; font-weight: 600; color: var(--text-tertiary); }
.member-sub { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.member-status { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; padding: 2px 8px; border-radius: 999px; }
.member-status.s-pending { background: var(--warning-bg); color: var(--warning); }
.member-status.s-active { background: var(--success-bg); color: var(--success); }
.member-status.s-deactivated, .member-status.s-expired { background: var(--danger-bg); color: var(--danger); }
.member-role { font-size: 12px; color: var(--text-secondary); }
.member-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.member-actions .btn { padding: 8px 12px; font-size: 13px; border-radius: 10px; min-height: 40px; }
.member-expiry { font-size: 11px; color: var(--text-tertiary); display: inline-flex; align-items: center; gap: 4px; }
.member-expiry-input { font-family: inherit; font-size: 12px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-page); color: var(--text-primary); }

/* Backtest: resolved month-end date under the Start/End month pickers */
.bt-datehint { display: block; margin-top: 4px; font-size: 11px; color: var(--text-secondary); }

/* Backtest: duration preset toggle (auto-fills Start/End) */
.bt-duration-wrap { display: flex; flex-direction: column; gap: 6px; }
.bt-field-label { font-size: 13px; color: var(--text-secondary); }
.bt-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  margin: 6px 0 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}
.bt-duration { display: flex; gap: 6px; }
.bt-duration button { flex: 1; min-width: 44px; padding: 9px 6px; font-size: 12px; font-weight: 600;
  border-radius: 10px; border: 1px solid var(--border); background: var(--bg-surface); color: var(--text-secondary); cursor: pointer; transition: all .15s ease; }
.bt-duration button:hover { background: var(--bg-subtle); }
.bt-duration button.active { background: var(--text-primary); color: var(--text-inverse); border-color: var(--text-primary); }

/* Backtest: Discover-style instrument picker */
.bt-instr-trigger { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-surface);
  color: var(--text-primary); cursor: pointer; text-align: left; }
.bt-instr-trigger:hover { background: var(--bg-subtle); }
.bt-instr-summary { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bt-instr-badge { width: 38px; height: 38px; flex: 0 0 auto; border-radius: 10px; color: var(--badge-fg); font-weight: 600;
  font-size: 12px; display: flex; align-items: center; justify-content: center; text-transform: uppercase; }
.bt-instr-text { min-width: 0; display: flex; flex-direction: column; }
.bt-instr-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bt-instr-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.bt-instr-caret { color: var(--text-tertiary); flex: 0 0 auto; }

.bt-picker { position: fixed; inset: 0; z-index: 120; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.bt-picker.hidden { display: none; }
.bt-picker-panel { width: 100%; max-width: 520px; max-height: 84vh; display: flex; flex-direction: column;
  background: var(--bg-surface); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); overflow: hidden; }
.bt-picker-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; font-size: 16px; font-weight: 600; color: var(--text-primary); }
.bt-picker-close { font-size: 18px; line-height: 1; color: var(--text-secondary); background: none; border: none; cursor: pointer; padding: 4px 8px; }
.bt-picker-search { padding: 4px 18px 8px; }
.bt-picker-search input { width: 100%; padding: 11px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg-page); color: var(--text-primary); font-size: 14px; }
/* flex:0 0 auto stops the flex column from collapsing these rows to ~0 —
   .filters' overflow-x:auto otherwise makes them min-height:0 scroll containers. */
.bt-picker-chips { padding: 4px 18px; flex: 0 0 auto; }
.bt-picker-list { flex: 1; overflow-y: auto; padding: 6px 10px 14px; }
.bt-picker-empty { color: var(--text-secondary); font-size: 14px; text-align: center; padding: 28px 0; }

/* Settings sections span the standard content container like every other
   screen; only the password form fields stay capped for usable line length. */
@media (min-width: 768px) {
  .change-pw { max-width: 480px; }
}
