:root {
  color-scheme: light;
  --page-plane:      #f9f9f7;
  --surface-1:       #fcfcfb;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #73726d; /* darkened from palette's #898781 to clear 4.5:1 at body-text sizes */
  --gridline:        #e1e0d9;
  --border:          rgba(11, 11, 11, 0.10);

  --series-gold:     #2a78d6; /* categorical slot 1 */
  --series-oil:      #eb6834; /* categorical slot 2 */
  --series-fed:      #1baf7a; /* categorical slot 3 */

  /* one step darker than --series-gold so white button text clears 4.5:1 in both themes */
  --accent-primary:  #1c5cab;

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;

  --diverging-pos:   #2a78d6;
  --diverging-neg:   #e34948;
  --diverging-mid:   #f0efec;

  --seq-100: #cde2fb;
  --seq-300: #6da7ec;
  --seq-500: #256abf;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page-plane:      #0d0d0d;
    --surface-1:       #1a1a19;
    --text-primary:    #ffffff;
    --text-secondary:  #c3c2b7;
    --text-muted:      #898781;
    --gridline:        #2c2c2a;
    --border:          rgba(255, 255, 255, 0.10);

    --series-gold:     #3987e5;
    --series-oil:      #d95926;
    --series-fed:      #199e70;

    --status-good:     #0ca30c;
    --status-warning:  #fab219;
    --status-serious:  #ec835a;
    --status-critical: #e66767;

    --diverging-pos:   #3987e5;
    --diverging-neg:   #e66767;
    --diverging-mid:   #383835;

    --seq-100: #184f95;
    --seq-300: #2a78d6;
    --seq-500: #86b6ef;
  }
}

* { box-sizing: border-box; }

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

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 20px;
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.92rem;
  max-width: 56ch;
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.generated-at {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.55; cursor: progress; }

.banner {
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.86rem;
  margin-bottom: 18px;
  border: 1px solid var(--border);
}

.banner code {
  background: rgba(127, 127, 127, 0.18);
  padding: 1px 5px;
  border-radius: 4px;
}

.banner-warning {
  background: color-mix(in srgb, var(--status-warning) 14%, var(--surface-1));
  color: var(--text-primary);
}

.banner-critical {
  background: color-mix(in srgb, var(--status-critical) 12%, var(--surface-1));
  color: var(--text-primary);
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.category-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.category-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.category-card-header h2 {
  margin: 0;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

.sentiment-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.sentiment-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.sentiment-bullish { background: color-mix(in srgb, var(--status-good) 16%, transparent); color: var(--status-good); }
.sentiment-bullish .dot { background: var(--status-good); }
.sentiment-bearish { background: color-mix(in srgb, var(--status-critical) 16%, transparent); color: var(--status-critical); }
.sentiment-bearish .dot { background: var(--status-critical); }
.sentiment-neutral { background: rgba(137, 135, 129, 0.18); color: var(--text-secondary); }
.sentiment-neutral .dot { background: var(--text-muted); }

.score-bar-track {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--gridline);
  overflow: hidden;
}

.score-bar-mid {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--text-muted);
}

.score-bar-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 999px;
}

.score-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.card-summary {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.45;
  margin: 0;
}

.card-subheading {
  margin: 0 0 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.chip {
  background: rgba(127, 127, 127, 0.14);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.driver-list {
  margin: 0;
  padding-left: 18px;
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.article-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  border-top: 1px solid var(--gridline);
  padding-top: 8px;
}

.article-item + .article-item {
  border-top: 1px solid var(--gridline);
  padding-top: 8px;
  margin-top: 8px;
}

.article-title {
  color: var(--text-primary);
  font-size: 0.85rem;
  text-decoration: none;
  line-height: 1.35;
  display: block;
}

.article-title:hover { text-decoration: underline; }

.article-meta {
  display: flex;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.86rem;
  padding: 16px 0;
}

.macro-section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.macro-section h2 {
  margin: 0 0 12px;
  font-size: 1.15rem;
}

.macro-narrative {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.55;
  margin: 0 0 18px;
}

.correlation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.correlation-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.correlation-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.correlation-pair {
  font-weight: 700;
  font-size: 0.88rem;
}

.correlation-relationship {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.strength-track {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.strength-step {
  height: 6px;
  flex: 1;
  border-radius: 999px;
  background: var(--gridline);
}

.strength-step.filled { background: var(--seq-500); }

.strength-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.correlation-explanation {
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.45;
  margin: 0;
}

.risk-watch h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
}

.risk-watch ul {
  margin: 0;
  padding-left: 18px;
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.55;
}

.app-footer {
  margin-top: 24px;
  text-align: center;
  font-size: 0.76rem;
  color: var(--text-muted);
}

@media (max-width: 560px) {
  .app-header { flex-direction: column; align-items: flex-start; }
  .app-header-actions { width: 100%; justify-content: space-between; }
}
