:root {
  --navy: #0f172a;
  --gold: #f1b811;
  --blue: #2563eb;
  --light-bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #ea580c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--light-bg);
  color: var(--text);
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

/* ── Skip navigation link (screen readers + keyboard users) ──────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 8px;
  background: var(--gold);
  color: var(--navy);
  padding: 8px 16px;
  border-radius: 0 0 8px 8px;
  font-weight: 700;
  font-size: 14px;
  z-index: 9999;
  text-decoration: none;
}
.skip-link:focus { top: 0; }

/* ── Visible focus ring for keyboard navigation ───────────────────────────── */
:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  border-radius: 4px;
}
/* Remove outline for mouse users */
:focus:not(:focus-visible) { outline: none; }

/* ── Screen-reader-only utility ──────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Respect user's reduced-motion preference ────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── NAV ──────────────────────────────────────────────────────────────────── */
.topnav {
  background: var(--navy);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topnav .logo {
  color: var(--gold);
  font-weight: 700;
  font-size: 18px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topnav .logo span { color: #fff; }
.nav-links a {
  color: #cbd5e1;
  text-decoration: none;
  margin-left: 20px;
  font-size: 14px;
  white-space: nowrap;
}
.nav-links a:hover { color: var(--gold); }

/* ── SEARCH BAR ───────────────────────────────────────────────────────────── */
.search-bar {
  background: var(--navy);
  padding: 10px 16px 14px;
}
.search-bar form { display: flex; gap: 8px; }
.search-bar input {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  border-radius: 8px;
  border: none;
  font-size: 16px; /* 16px prevents iOS zoom */
  background: #1e293b;
  color: #fff;
}
.search-bar input::placeholder { color: #64748b; }
.search-bar button {
  background: var(--gold);
  color: var(--navy);
  border: none;
  border-radius: 8px;
  padding: 11px 18px;
  font-weight: 700;
  cursor: pointer;
  font-size: 15px;
  white-space: nowrap;
  min-height: 44px;
}

/* ── LAYOUT ───────────────────────────────────────────────────────────────── */
.main { padding: 16px; max-width: 900px; margin: 0 auto; }

/* ── CARDS ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── BUTTONS ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  min-height: 44px;
  white-space: nowrap;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-gold    { background: var(--gold); color: var(--navy); }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 36px; }

/* ── FORMS ────────────────────────────────────────────────────────────────── */
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px; /* prevent iOS zoom */
  outline: none;
  transition: border 0.2s;
  -webkit-appearance: none;
}
.form-input:focus { border-color: var(--blue); }
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

/* ── ALERT BANNERS ────────────────────────────────────────────────────────── */
.alert-banner {
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 14px;
  margin-bottom: 14px;
  line-height: 1.5;
}
.alert-green  { background: #dcfce7; color: #15803d; }
.alert-red    { background: #fee2e2; color: var(--red); }
.alert-orange { background: #ffedd5; color: #9a3412; }

/* ── WATCHLIST ────────────────────────────────────────────────────────────── */
.watchlist-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  min-height: 56px;
}
.watchlist-item:last-child { border-bottom: none; }
.ticker { font-weight: 700; font-size: 16px; }
.company-name { font-size: 13px; color: var(--muted); }
.price { font-weight: 600; font-size: 16px; }
.change.up   { color: var(--green); font-size: 13px; }
.change.down { color: var(--red);   font-size: 13px; }
.ai-flag {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  margin-left: 8px;
}
.flag-buy  { background: #dcfce7; color: var(--green); }
.flag-sell { background: #fee2e2; color: var(--red); }
.flag-watch { background: #fef9c3; color: #a16207; }
.flag-hold { background: #e0e7ff; color: #3730a3; }

/* ── PORTFOLIO CARDS ──────────────────────────────────────────────────────── */
.position-card { padding: 14px 16px; }
.position-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.position-ticker {
  font-size: 20px;
  font-weight: 800;
  color: var(--navy);
  text-decoration: none;
}
.position-ticker:hover { color: var(--blue); }
.position-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.pstat {
  background: #f8fafc;
  border-radius: 8px;
  padding: 8px 10px;
}
.pstat-label { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.pstat-val   { font-size: 14px; font-weight: 600; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-top: 4px;
}
.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.stat-value { font-size: 22px; font-weight: 800; }

/* ── ALERTS ───────────────────────────────────────────────────────────────── */
.alert-item {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.alert-item:last-child { border-bottom: none; }
.alert-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.dot-red    { background: var(--red); }
.dot-orange { background: var(--orange); }
.dot-blue   { background: var(--blue); }
.alert-source { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── CONGRESS FEED ────────────────────────────────────────────────────────── */
.congress-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.congress-item:last-child { border-bottom: none; }
.congress-tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
  background: #dbeafe;
  color: #1d4ed8;
  margin-bottom: 4px;
}
.congress-impact { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── GRID ─────────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── BOTTOM NAV (mobile) ──────────────────────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--navy);
  border-top: 1px solid #1e293b;
  padding: 6px 0 env(safe-area-inset-bottom, 6px);
  z-index: 100;
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #64748b;
  text-decoration: none;
  font-size: 10px;
  gap: 3px;
  padding: 4px 0;
  min-height: 44px;
  justify-content: center;
}
.bottom-nav a.active, .bottom-nav a:hover { color: var(--gold); }
.bottom-nav svg { width: 22px; height: 22px; }

/* ── EMPTY STATE ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
}
.empty-state p { margin-top: 8px; font-size: 14px; }

/* ── RESPONSIVE ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Layout */
  .grid-2           { grid-template-columns: 1fr; }
  .form-grid-2      { grid-template-columns: 1fr; }
  .nav-links        { display: none; }
  .bottom-nav       { display: flex; }
  .main             { padding: 12px 12px 80px; }

  /* Summary grid → 2×2 on mobile */
  .summary-grid     { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-value       { font-size: 18px; }

  /* Position cards */
  .position-stats   { grid-template-columns: repeat(2, 1fr); }
  .position-header  { flex-direction: column; gap: 6px; }

  /* Chart range toggles — make them scroll horizontally */
  #range-btns       { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  #range-btns button { flex-shrink: 0; }

  /* Schwab/Settings card full width */
  .card             { border-radius: 10px; }
}

@media (max-width: 380px) {
  .position-stats   { grid-template-columns: 1fr 1fr; }
  .summary-grid     { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  #ai-grid      { grid-template-columns: 1fr !important; }
  #futures-grid { grid-template-columns: repeat(2, 1fr) !important; }
}
