:root {
  color-scheme: light;
  --page:            #f9f9f7;
  --surface:         #fcfcfb;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --muted:           #898781;
  --gridline:        #e1e0d9;
  --border:          rgba(11, 11, 11, 0.10);
  --good:            #0ca30c;
  --critical:        #d03b3b;
  --sequential:      #2a78d6;
  --sequential-track:#e1e0d9;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page:            #0d0d0d;
    --surface:         #1a1a19;
    --text-primary:    #ffffff;
    --text-secondary:  #c3c2b7;
    --muted:           #898781;
    --gridline:        #2c2c2a;
    --border:          rgba(255, 255, 255, 0.10);
    --good:            #0ca30c;
    --critical:        #d03b3b;
    --sequential:      #3987e5;
    --sequential-track:#2c2c2a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
}

.hidden { display: none !important; }

.muted { color: var(--text-secondary); }

/* ---- topbar ---- */

.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { font-weight: 600; }
.guest-badge {
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* ---- landing ---- */

.landing {
  max-width: 640px;
  margin: 10vh auto;
  padding: 0 20px;
}
.landing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  text-align: center;
}
.landing-card h1 {
  font-size: 22px;
  margin: 0 0 12px;
}
.landing-card p {
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 20px;
}

/* ---- buttons / inputs ---- */

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  padding: 10px 18px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary {
  background: var(--sequential);
  color: #ffffff;
}
.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
}
.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:disabled {
  opacity: 0.6;
  cursor: default;
}
.btn-link {
  background: none;
  border: none;
  color: var(--sequential);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

input, select, textarea {
  font: inherit;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
textarea { resize: vertical; }

/* ---- app layout ---- */

.app {
  max-width: 1000px;
  margin: 24px auto 60px;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
}
.panel h2 {
  font-size: 15px;
  margin: 0 0 16px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.build-form {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.field-wide { grid-column: 1 / -1; }
.build-actions { display: flex; align-items: center; gap: 12px; }
.build-status { font-size: 13px; color: var(--text-secondary); }

.error {
  color: var(--critical);
  font-size: 13px;
  margin-top: 12px;
}
.warning {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 8px;
}

/* ---- results ---- */

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}
.analyst-export-row {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  justify-content: flex-start;
}
.filter-input { min-width: 200px; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  border-bottom: 1px solid var(--gridline);
  padding: 8px 10px;
}
td {
  padding: 10px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}
tr:last-child td { border-bottom: none; }

.ticker-cell { font-weight: 600; }

.trend-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}
.trend-up    { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.trend-down  { color: var(--critical); background: color-mix(in srgb, var(--critical) 14%, transparent); }
.trend-neutral { color: var(--text-secondary); background: color-mix(in srgb, var(--muted) 16%, transparent); }

.prediction-cell { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.meter-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--sequential-track);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  background: var(--sequential);
  border-radius: 999px;
}
.prediction-value { font-size: 12px; color: var(--text-secondary); width: 42px; text-align: right; }

.cluster-chip {
  display: inline-block;
  font-size: 11px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
  margin: 1px;
}

/* ---- clusters panel ---- */

.clusters-list { display: flex; flex-direction: column; gap: 10px; }
.cluster-row { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.cluster-row-head { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }

/* ---- landing admin login ---- */

.landing-admin {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.admin-login {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}
.admin-login input { min-width: 200px; }

/* ---- account auth (login / register tabs) ---- */

.auth-tabs {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 16px;
}
.tab-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 16px;
  cursor: pointer;
}
.tab-btn.active {
  color: #ffffff;
  background: var(--sequential);
  border-color: var(--sequential);
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.auth-form-row { display: flex; gap: 10px; }
.auth-form-row input { flex: 1; min-width: 0; }
.auth-form input { width: 100%; }

.password-field { position: relative; }
.password-field input { padding-right: 56px; }
.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--sequential);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 6px;
}

/* ---- guest picker + stock card ---- */

.dataset-info { font-size: 13px; margin: 0 0 14px; }
.quota-info { font-size: 13px; margin: 0 0 14px; }
.quota-info.quota-empty { color: var(--critical); }
.tendency-description { font-size: 13px; margin: 10px 0 0; line-height: 1.5; }

.picker-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.picker-row .field { min-width: 160px; }
.picker-action { justify-content: flex-end; }

.stock-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.stock-card-ticker { font-size: 28px; font-weight: 700; letter-spacing: 0.01em; }

.stock-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
/* Price and Current Change are their own tiles (plain market facts); the
   Prediction tile spans the full width since it carries the probability
   readout for the predicted direction. */
.stat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--page);
}
.stat-wide { grid-column: 1 / -1; }
.stat-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.stat-value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-value.pos { color: var(--good); }
.stat-value.neg { color: var(--critical); }

.card-note { font-size: 12px; margin: 16px 0 0; }

/* ---- loading spinner, shown while a selection is in flight ---- */

.spinner {
  width: 18px;
  height: 18px;
  margin-top: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--sequential);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- panel header row (title + a right-aligned corner label) ---- */

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.panel-head h2 { margin: 0; }
.last-updated {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.prediction-headline { font-size: 20px; font-weight: 600; }
.prediction-meter { margin: 10px 0 8px; height: 8px; }
.prediction-breakdown { font-size: 12px; font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  .build-form { grid-template-columns: 1fr 1fr; }
}
