:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --green: #16a34a;
  --yellow: #d97706;
  --red: #dc2626;
  --blue: #2563eb;
  --accent: #2563eb;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; }
.tagline { color: var(--muted); font-size: 0.875rem; margin-top: 0.15rem; }

.btn-primary {
  background: var(--blue);
  color: white;
  border: none;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.875rem;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:disabled { opacity: 0.5; cursor: wait; }

.container { max-width: 1280px; margin: 0 auto; padding: 1.5rem 2rem 3rem; }

.status-msg { text-align: center; padding: 3rem; color: var(--muted); }
.status-msg.error { color: var(--red); }

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.hidden { display: none !important; }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}
.stat .num { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.stat .label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 0.25rem; }

.markets { display: grid; gap: 0.75rem; }

.market-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  border-left: 4px solid var(--border);
}
.market-card.signal-GREEN { border-left-color: var(--green); }
.market-card.signal-YELLOW { border-left-color: var(--yellow); }
.market-card.signal-RED { border-left-color: var(--red); }

.market-summary {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  padding: 1rem 1.25rem;
  cursor: pointer;
  list-style: none;
  align-items: center;
}
.market-summary::-webkit-details-marker { display: none; }

.market-title { font-size: 1.1rem; font-weight: 600; }
.market-meta { color: var(--muted); font-size: 0.8rem; margin-top: 0.2rem; }
.market-message { font-size: 0.9rem; margin-top: 0.35rem; color: var(--text); }
.tier-label { font-size: 0.8rem; margin-top: 0.25rem; }
.tier-1 { color: var(--muted); }
.tier-2 { color: var(--yellow); }
.tier-3 { color: var(--green); }

.badge {
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.badge-GREEN { background: rgba(22, 163, 74, 0.12); color: var(--green); }
.badge-YELLOW { background: rgba(217, 119, 6, 0.12); color: var(--yellow); }
.badge-RED { background: rgba(220, 38, 38, 0.12); color: var(--red); }

.card-body {
  padding: 0 1.25rem 1.25rem;
  border-top: 1px solid var(--border);
}

.section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 1.25rem 0 0.75rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.6rem;
}

.metric-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}
.metric-box .label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.metric-box .value { font-size: 1.1rem; font-weight: 600; margin-top: 0.2rem; }
.metric-box .delta { font-size: 0.75rem; margin-top: 0.15rem; }
.delta-down { color: var(--green); }
.delta-up { color: var(--red); }
.delta-neutral { color: var(--muted); }

.reasons { list-style: none; margin-top: 0.5rem; }
.reasons li {
  padding: 0.45rem 0.65rem;
  margin-bottom: 0.35rem;
  border-radius: 6px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.reasons li.pass { border-color: rgba(22, 163, 74, 0.35); background: #f0fdf4; color: #15803d; }
.reasons li.fail { color: var(--muted); background: var(--surface-2); }
.reasons li.info { border-color: rgba(217, 119, 6, 0.35); background: #fffbeb; color: #b45309; }

.charts-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1rem;
  margin-top: 0.5rem;
}
@media (max-width: 900px) {
  .charts-row { grid-template-columns: 1fr; }
}

.chart-box {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 0.5rem 0.65rem 0.35rem;
  min-height: 320px;
  overflow: visible;
}
.chart-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: #374151;
  margin: 0 0 0.35rem 0.1rem;
}
.chart-plot {
  width: 100%;
  min-height: 300px;
}

.sparkline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}
.spark-box {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 0.5rem 0.75rem 0.5rem;
  overflow: visible;
}
.spark-box h5 { font-size: 0.75rem; color: #555; margin-bottom: 0.15rem; font-weight: 600; }
.spark-chart {
  width: 100%;
  height: 165px;
}

.history-section {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.history-summary {
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
}
.history-summary::-webkit-details-marker { display: none; }
.history-body { padding: 0 1rem 1rem; }
.history-loading { color: var(--muted); font-size: 0.85rem; padding: 1rem 0; }

.site-footer {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}
.site-footer .muted { margin-top: 0.35rem; font-size: 0.75rem; opacity: 0.7; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.user-label {
  font-size: 0.8rem;
  color: var(--muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.65rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.875rem;
}
.btn-secondary:hover { background: var(--surface-2); }

.btn-danger {
  background: #fef2f2;
  color: var(--red);
  border: 1px solid #fecaca;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.75rem;
}
.btn-sm { padding: 0.35rem 0.65rem; }
.btn-block { width: 100%; }

.link-btn {
  background: none;
  border: none;
  color: var(--blue);
  cursor: pointer;
  font-weight: 600;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
}

.guest-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: #1e40af;
}

.manage-panel {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem 1.25rem;
}
.manage-panel-inner { max-width: 1280px; margin: 0 auto; }
.manage-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.75rem;
}
.manage-header h2 { font-size: 1rem; font-weight: 700; }
.market-count { font-size: 0.8rem; color: var(--muted); }

.add-market-form {
  display: grid;
  grid-template-columns: 100px 1fr 120px auto;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
@media (max-width: 700px) {
  .add-market-form { grid-template-columns: 1fr 1fr; }
  .add-market-form button { grid-column: 1 / -1; }
}

.add-market-form input,
.add-market-form select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font-size: 0.875rem;
}

.watchlist {
  list-style: none;
  display: grid;
  gap: 0.4rem;
}
.watchlist-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}
.watchlist-meta {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

.manage-msg, .auth-msg {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  color: var(--green);
}
.manage-msg.error, .auth-msg.error { color: var(--red); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}
.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}
.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
}
.modal-card h2 { font-size: 1.15rem; margin-bottom: 0.25rem; }
.modal-sub { font-size: 0.85rem; color: var(--muted); margin-bottom: 1rem; }
.modal-card label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.modal-card input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
}
.auth-toggle { text-align: center; margin-top: 0.75rem; font-size: 0.85rem; }
