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

:root {
  --bg: #0c0f14;
  --surface: #141922;
  --surface-2: #1a2030;
  --border: #252d3d;
  --text: #e8ecf4;
  --muted: #8892a4;
  --bull: #22c55e;
  --bull-bg: rgba(34, 197, 94, 0.12);
  --bear: #ef4444;
  --bear-bg: rgba(239, 68, 68, 0.12);
  --neutral: #94a3b8;
  --neutral-bg: rgba(148, 163, 184, 0.1);
  --accent: #3b82f6;
  --radius: 12px;
  --font: 'DM Sans', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(59, 130, 246, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(34, 197, 94, 0.06), transparent);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
  width: 100%;
  overflow-x: hidden;
}

.header {
  margin-bottom: 2rem;
}

.header__top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.eyebrow {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

h1 {
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header__actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.updated {
  font-size: 0.8125rem;
  color: var(--muted);
  font-family: var(--mono);
}

.intro {
  margin-bottom: 1.25rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
}

.intro p {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--muted);
}

.intro p + p {
  margin-top: 0.625rem;
}

.intro__lead {
  color: var(--text);
}

.intro strong {
  color: var(--text);
  font-weight: 600;
}

.intro__example {
  padding-top: 0.625rem;
  border-top: 1px solid var(--border);
}

.btn {
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.controls-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.control-section {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  padding: 1rem 0;
}

.control-section:first-child {
  padding-top: 0;
}

.control-section:last-child {
  padding-bottom: 0;
}

.control-section + .control-section {
  border-top: 1px solid var(--border);
}

.control-section__label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.control-section__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.625rem;
}

.filter-group {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
  flex-wrap: wrap;
}

.filter-btn {
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.375rem 0.75rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.filter-btn:hover {
  color: var(--text);
}

.filter-btn--active {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.filter-btn--active.filter-btn--financial_conditions { color: #38bdf8; }
.filter-btn--active.filter-btn--business_activity { color: #fbbf24; }
.filter-btn--active.filter-btn--consumers { color: #a78bfa; }

.year-range {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.year-range__sep {
  color: var(--muted);
  font-size: 0.875rem;
}

.year-select {
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.year-select:focus {
  outline: none;
  border-color: var(--accent);
}

.btn--sm {
  font-size: 0.75rem;
  padding: 0.375rem 0.75rem;
}

.range-preset {
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.375rem 0.75rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.range-preset:hover {
  color: var(--text);
}

.range-preset--active {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.drawdown-group {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr));
  gap: 0.5rem;
  width: 100%;
}

.drawdown-btn {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  width: 100%;
  min-width: 0;
  font-family: var(--font);
  text-align: left;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.drawdown-btn:hover {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.06);
}

.drawdown-btn--active {
  border-color: rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.drawdown-btn__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
}

.drawdown-btn__years {
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

.drawdown-btn__name {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.drawdown-btn__drop {
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 600;
  color: #f87171;
  white-space: nowrap;
  flex-shrink: 0;
}

.summary__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.summary__card--overall {
  grid-column: span 1;
  border-color: rgba(59, 130, 246, 0.35);
  background: linear-gradient(135deg, var(--surface) 0%, rgba(59, 130, 246, 0.08) 100%);
}

.summary__label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.summary__value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--mono);
}

.summary__card--bull .summary__value { color: var(--bull); }
.summary__card--bear .summary__value { color: var(--bear); }
.summary__card--neutral .summary__value { color: var(--neutral); }

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 4rem;
  color: var(--muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.error {
  background: var(--bear-bg);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.hidden {
  display: none !important;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr));
  gap: 1rem;
  width: 100%;
  min-width: 0;
}

.card__footer {
  display: flex;
  justify-content: center;
  padding-top: 0.25rem;
  margin-top: auto;
}

.category-badge {
  font-size: 0.5625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.125rem 0.4375rem;
  border-radius: 999px;
  white-space: nowrap;
}

.category-badge--financial_conditions {
  background: rgba(56, 189, 248, 0.12);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.category-badge--business_activity {
  background: rgba(251, 191, 36, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.3);
}

.category-badge--consumers {
  background: rgba(167, 139, 250, 0.12);
  color: #a78bfa;
  border: 1px solid rgba(167, 139, 250, 0.3);
}

.external-link-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 180px;
  padding: 1.25rem;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 10px;
  text-align: center;
}

.external-link__note {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.45;
  max-width: 260px;
}

.external-link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border: 1px solid rgba(59, 130, 246, 0.35);
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.08);
  transition: background 0.15s, border-color 0.15s;
}

.external-link:hover {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent);
  text-decoration: none;
}

.card {
  background: var(--surface);
  border: 4px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
  overflow: hidden;
}

.card--insufficient {
  gap: 0;
}

.card--insufficient .card__measure,
.card--insufficient .card__series,
.card--insufficient .info-btn,
.card--insufficient .card__content {
  display: none;
}

.card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.info-btn {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.info-btn:hover,
.info-btn:focus-visible {
  color: var(--accent);
  border-color: rgba(59, 130, 246, 0.45);
  background: rgba(59, 130, 246, 0.08);
  outline: none;
}

.info-btn__icon {
  width: 1rem;
  height: 1rem;
}

.info-tooltip {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  width: min(280px, 70vw);
  padding: 0.75rem 0.875rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  text-align: left;
  transition: opacity 0.15s, visibility 0.15s;
}

.info-tooltip strong {
  display: block;
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.info-tooltip strong:not(:first-child) {
  margin-top: 0.625rem;
}

.info-tooltip p {
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--text);
  margin: 0;
}

.info-btn:hover .info-tooltip,
.info-btn:focus-visible .info-tooltip,
.info-btn.is-open .info-tooltip {
  visibility: visible;
  opacity: 1;
}

.card__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.card__title > div {
  min-width: 0;
}

.card__name {
  font-size: 0.9375rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.card__measure {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
  margin-top: 0.125rem;
  margin-bottom: 0.125rem;
  overflow-wrap: anywhere;
}

.card__emoji {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.card__series {
  display: inline-block;
  font-size: 0.6875rem;
  font-family: var(--mono);
  color: var(--muted);
  margin-top: 0.125rem;
  text-decoration: none;
  transition: color 0.15s;
}

.card__series:hover {
  color: var(--accent);
  text-decoration: underline;
}

.badge {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  white-space: nowrap;
}

.badge--bullish {
  background: var(--bull-bg);
  color: var(--bull);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge--bearish {
  background: var(--bear-bg);
  color: var(--bear);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge--neutral {
  background: var(--neutral-bg);
  color: var(--neutral);
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.pick-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.pick-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.pick-group {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.pick-btn {
  font-family: var(--font);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 0.3125rem 0.625rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.pick-btn:hover {
  color: var(--text);
}

.pick-btn--active.pick-btn--bullish {
  background: var(--bull-bg);
  color: var(--bull);
}

.pick-btn--active.pick-btn--bearish {
  background: var(--bear-bg);
  color: var(--bear);
}

.pick-btn--active.pick-btn--neutral {
  background: var(--neutral-bg);
  color: var(--neutral);
}

.card--bullish {
  border-color: rgba(34, 197, 94, 0.45);
}

.card--bearish {
  border-color: rgba(239, 68, 68, 0.45);
}

.chart-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chart-container {
  position: relative;
  height: 180px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  cursor: crosshair;
}

.chart-container canvas {
  max-width: 100%;
}

.footer {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.8125rem;
  color: var(--muted);
}

@media (max-width: 640px) {
  .page {
    padding: 1.25rem 0.75rem 2rem;
  }

  .header__top {
    flex-direction: column;
    align-items: stretch;
  }

  .header__actions {
    flex-wrap: wrap;
  }

  .controls-panel {
    padding: 0.875rem 1rem;
  }

  .intro {
    padding: 0.875rem 1rem;
  }

  .intro p {
    font-size: 0.8125rem;
  }

  .control-section__row {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .filter-btn,
  .range-preset {
    width: 100%;
    text-align: center;
    justify-content: center;
  }

  .year-range {
    width: 100%;
  }

  .year-select {
    flex: 1;
    min-width: 0;
  }

  .drawdown-group {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 1rem;
  }

  .pick-wrap {
    flex-direction: column;
    align-items: stretch;
  }

  .pick-group {
    width: 100%;
    justify-content: stretch;
  }

  .pick-btn {
    flex: 1;
    text-align: center;
  }

  .summary__card--overall {
    grid-column: span 1;
  }
}

@media (max-width: 380px) {
  .drawdown-group {
    grid-template-columns: 1fr;
  }
}
