:root {
  --bg: #F7F9FC;
  --surface: #FFFFFF;
  --text: #1A2332;
  --text-secondary: #6B7684;
  --accent: #1B4B7A;
  --accent-light: rgba(27, 75, 122, 0.08);
  --accent-border: rgba(27, 75, 122, 0.35);
  --gold: #E3A72F;
  --stock-green: #34C759;
  --gold-orange: #FF9500;
  --up-green: #2E7D32;
  --up-green-bg: rgba(46, 125, 50, 0.1);
  --down-red: #D32F2F;
  --down-red-bg: rgba(211, 47, 47, 0.1);
  --border: #E5E9F0;
  --card: #F2F4F8;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.06), 0 1px 2px rgba(20, 30, 50, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-variant-numeric: tabular-nums;
}

.app-shell {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  flex: 1;
}
.topbar button.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 18px;
  line-height: 1;
}
.topbar button.icon-btn:hover { background: var(--card); }
.back-btn { font-size: 20px; }

/* Content */
.content {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

/* Bottom nav */
.bottom-nav {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  bottom: 0;
}
.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 4px 8px;
  cursor: pointer;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.bottom-nav button.active { color: var(--accent); font-weight: 600; }
.bottom-nav button .nav-icon { font-size: 20px; }

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.field label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
input, select {
  font-family: inherit;
  font-size: 15px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

.btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 13px 20px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-primary { background: var(--accent); color: white; width: 100%; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }
.btn-outline { background: var(--surface); color: var(--accent); border: 1px solid var(--accent-border); }
.btn-text { background: none; color: var(--accent); padding: 8px; width: 100%; }
.btn-danger { background: none; color: var(--down-red); }
.btn-sm { font-size: 13px; padding: 8px 14px; }

.error-text { color: var(--down-red); font-size: 13px; margin: -8px 0 12px; }
.info-text { color: var(--accent); font-size: 13px; margin: -8px 0 12px; }
.muted { color: var(--text-secondary); font-size: 13px; }
.disclaimer {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 16px;
  line-height: 1.5;
}

/* Login screen */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 32px 24px;
}
.login-card { width: 100%; max-width: 380px; }
.login-title { font-size: 30px; font-weight: 800; margin: 0 0 6px; letter-spacing: -0.02em; }
.login-subtitle { color: var(--text-secondary); font-size: 14px; margin: 0 0 24px; }

/* Search */
.search-box {
  position: relative;
  margin-bottom: 16px;
}
.search-box input { width: 100%; padding-left: 40px; }
.search-box .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
}

/* Ticker list */
.ticker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  font-size: 14px;
}
.ticker-row:hover { background: var(--card); }
.ticker-row .chevron { color: var(--text-secondary); font-family: inherit; }

.welcome-block {
  text-align: center;
  padding: 60px 20px;
}
.welcome-icon {
  width: 64px; height: 64px;
  border-radius: 18px;
  background: var(--accent-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  margin: 0 auto 16px;
}
.welcome-title { font-weight: 700; font-size: 18px; margin: 0 0 8px; }
.welcome-desc { color: var(--text-secondary); font-size: 13px; max-width: 320px; margin: 0 auto; line-height: 1.5; }

/* Cards */
.card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}
.card-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 0 0 10px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 7px 0;
}
.info-row .label { color: var(--text-secondary); font-size: 14px; }
.info-row .value { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 15px; }
.info-divider { height: 1px; background: var(--border); margin: 10px 0; }

/* Today banner */
.today-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--accent-light);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}

.stale-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 193, 7, 0.25);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-weight: 700;
  font-size: 13px;
  color: #6B5300;
}

/* Holding badge */
.holding-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.holding-badge {
  display: inline-flex;
  align-items: center;
  color: white;
  font-weight: 800;
  font-size: 26px;
  padding: 12px 22px;
  border-radius: 14px;
}
.holding-badge.stock { background: var(--stock-green); }
.holding-badge.gold { background: var(--gold-orange); }
.new-tag {
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 8px;
}
.holding-sub { color: var(--text-secondary); font-size: 13px; margin: 0 0 20px; }

/* Comparison tiles */
.compare-row { display: flex; gap: 12px; margin-bottom: 16px; }
.compare-tile {
  flex: 1;
  border-radius: 14px;
  padding: 16px;
  border: 1.5px solid transparent;
}
.compare-tile .name { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.compare-tile .pct { font-weight: 800; font-size: 22px; margin-top: 8px; }
.compare-tile.up { background: var(--up-green-bg); }
.compare-tile.down { background: var(--down-red-bg); }
.compare-tile.recommended.up { border-color: rgba(46,125,50,0.5); }
.compare-tile.recommended.down { border-color: rgba(211,47,47,0.5); }
.check-badge { color: var(--accent); }

/* Benefit banner */
.benefit-banner {
  display: flex;
  gap: 12px;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}
.benefit-banner.up { background: var(--up-green-bg); }
.benefit-banner.down { background: var(--down-red-bg); }
.benefit-banner .icon { font-size: 22px; }
.benefit-banner .title { font-weight: 700; font-size: 14px; margin: 0 0 3px; }
.benefit-banner .desc { color: var(--text-secondary); font-size: 12px; margin: 0; }

/* Lists screen */
.list-card {
  display: block;
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
}
.list-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.list-card-since {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.list-card:hover { filter: brightness(0.97); }
.list-card .name { font-weight: 700; font-size: 15px; }
.list-card .count { font-size: 12px; color: var(--text-secondary); }
.fab {
  position: fixed;
  bottom: 84px;
  right: max(20px, calc(50% - 320px + 20px));
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 24px;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 5;
}

/* Ticker chips in a list */
.chip-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ticker-status-row {
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.ticker-status-row .ticker-name { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 14px; }
.ticker-status-row .sub { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }
.badge-pill {
  display: inline-flex;
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
}
.remove-x { color: var(--text-secondary); cursor: pointer; font-size: 16px; padding: 4px; }

.date-row { display: flex; gap: 12px; margin-bottom: 16px; }
.date-row .btn-outline { flex: 1; }

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin: 8px 0 12px;
}
.progress-bar .fill {
  height: 100%;
  width: 40%;
  background: var(--accent);
  animation: indeterminate 1.2s infinite ease-in-out;
}
@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

.result-tile {
  flex: 1;
  border-radius: 14px;
  padding: 14px;
}
.result-tile .rlabel { font-size: 12px; color: var(--text-secondary); }
.result-tile .rpct { font-weight: 800; font-size: 18px; margin-top: 4px; }

.ticker-result-card {
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.ticker-result-card .thead { font-weight: 700; font-family: 'JetBrains Mono', monospace; font-size: 14px; margin-bottom: 4px; }
.pct-pair { display: flex; flex-wrap: wrap; gap: 16px 24px; margin-top: 6px; }
.pct-pair .plabel { font-size: 11px; color: var(--text-secondary); }
.pct-pair .pval { font-weight: 700; font-size: 14px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 30, 50, 0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  max-width: 380px;
  width: 100%;
}
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
}
.checkbox-row input { width: 18px; height: 18px; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
.spinner.dark { border-color: rgba(27,75,122,0.25); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.center-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-size: 13px;
}
.center-loading .spinner.dark { width: 28px; height: 28px; border-width: 3px; }

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.admin-row .email { font-weight: 700; font-size: 14px; }
.admin-row .created { font-size: 11px; color: var(--text-secondary); }
.admin-actions { display: flex; gap: 6px; }
.admin-actions button {
  border: none; background: var(--surface); border-radius: 8px;
  width: 34px; height: 34px; cursor: pointer; font-size: 15px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161F;
    --surface: #1A1F2B;
    --text: #EAEDF2;
    --text-secondary: #8993A4;
    --accent-light: rgba(90, 150, 210, 0.15);
    --accent-border: rgba(90, 150, 210, 0.4);
    --border: #2A3040;
    --card: #202634;
  }
}
