/* ==========================================================================
   Long Equity: S&P 500 Macro Valuation Monitor
   Styled consistently with Long Equity Portfolio X-Ray (portfolio-builder.html)
   ========================================================================== */

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

:root {
  --bg: #FFFFFF;
  --surface: #FAF9F7;
  --surface2: #F2EFEB;
  --border: #E5E0D8;
  --border-subtle: #EAE6DF;
  --text: #1C1917;
  --text2: #57534E;
  --text3: #78716C;
  --accent: #0284C7;
  --accent-light: #E0F2FE;
  --green: #10B981;
  --green-bg: #ECFDF5;
  --amber: #F59E0B;
  --red: #EF4444;
  --radius: 16px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(28, 25, 23, 0.04);
  --shadow-md: 0 4px 16px rgba(28, 25, 23, 0.05);
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Top Header Bar (Matches Portfolio Builder) */
.top-header {
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px 20px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}

.hero-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 9999px;
  background-color: #ffffff;
  border: 1px solid #E5E7EB;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.hero-pill-dot {
  width: 10px;
  height: 10px;
  border-radius: 9999px;
  background-color: #10B981;
  box-shadow: 0 0 0 4px #D1FAE5;
  animation: pillPulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  flex-shrink: 0;
}

@keyframes pillPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.hero-pill-text {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: #262626;
  text-transform: uppercase;
  line-height: 1;
}

.page-title {
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  font-size: clamp(32px, 3.8vw, 54px);
  font-weight: 400;
  letter-spacing: -0.03em;
  color: #18181B;
  line-height: 1.14;
  margin: 0;
  text-align: center;
}

.page-title-bold {
  font-weight: 600;
  color: #171717;
}

.page-subtitle {
  margin: 0;
  max-width: 720px;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text2);
  text-align: center;
}

.portfolio-save-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text2);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 5px 14px;
  line-height: 1.4;
  text-align: center;
  max-width: 760px;
}

.portfolio-save-tip svg {
  color: var(--accent);
  flex-shrink: 0;
}

.portfolio-save-tip strong {
  color: var(--text);
  font-weight: 600;
}

/* Workspace Container */
.macro-workspace {
  max-width: 1620px;
  margin: 0 auto;
  padding: 12px 20px 28px;
}

/* 4-Card Summary KPI Strip (Matches Portfolio Builder) */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

@media (max-width: 960px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
}

@media (max-width: 540px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}

.kpi-card {
  background: #FAF9F7;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease;
}

.kpi-card:hover {
  border-color: #C7BFB2;
}

.kpi-label {
  font-size: 9.5px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text3);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 21px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.kpi-sub {
  font-size: 11px;
  color: var(--text2);
  margin-top: 4px;
  font-weight: 500;
}

/* Controls Row & Warm Stone Tabs (Matches Portfolio Builder) */
.macro-controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.macro-right-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.tabs-row {
  display: inline-flex;
  gap: 4px;
  background: #EDE9E3;
  border-radius: 10px;
  padding: 4px;
  border: 1px solid #DDD7CC;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs-row::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  padding: 7px 14px;
  border-radius: 7px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text2);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  touch-action: manipulation;
}

.tab-btn:hover:not(.active) {
  color: var(--text);
}

.tab-btn.active {
  background: #FAF9F7;
  color: var(--text);
  box-shadow: 0 1px 4px rgba(28, 25, 23, 0.08);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.15s;
  touch-action: manipulation;
}

.btn-secondary {
  background: #FAF9F7;
  color: var(--text);
  border: 1px solid #DDD7CC;
}

.btn-secondary:hover {
  background: #EDE9E3;
}

.btn-sm {
  height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

/* Charts Grid & Warm Stone Panel Cards */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 1279px) {
  .charts-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 859px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

.chart-panel {
  background: #FAF9F7;
  border: 1px solid #E5E0D8;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chart-panel.full-span {
  grid-column: 1 / -1;
}

@media (max-width: 859px) {
  .chart-panel.full-span {
    grid-column: auto;
  }
}

.panel-header {
  background: #F2EFEB;
  border-bottom: 1px solid #E2DDD4;
  padding: 11px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.panel-title {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #292524;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.kicker-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10B981;
  display: inline-block;
  flex-shrink: 0;
}

.csv-status {
  font-size: 10.5px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  color: var(--text2);
  background: #FFFFFF;
  border: 1px solid #DDD7CC;
  padding: 3px 9px;
  border-radius: 6px;
  white-space: nowrap;
}

.panel-body {
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.card-title-row h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
}

.card-headline {
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 12px;
  color: var(--text2);
  font-weight: 500;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 12px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}

.svg-wrap {
  position: relative;
  width: 100%;
  background: #FFFFFF;
  border: 1px solid #E2DDD4;
  border-radius: 10px;
  padding: 10px 8px 6px;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.chart-note {
  margin: 2px 0 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text2);
}

/* Loading Spinner */
.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 240px;
  gap: 12px;
  color: var(--text2);
  font-size: 13px;
}

.spinner {
  width: 32px;
  height: 32px;
  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); }
}

/* Tooltip */
.macro-tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 60;
  background: rgba(255, 255, 255, 0.98);
  color: var(--text);
  border: 1px solid #DDD7CC;
  border-top: 3px solid var(--accent);
  border-radius: 9px;
  padding: 10px 13px;
  font-size: 12px;
  min-width: 220px;
  box-shadow: 0 14px 30px rgba(28, 25, 23, 0.14);
  font-variant-numeric: tabular-nums;
}

.tooltip-title {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 5px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 3px;
  color: var(--text2);
}

.tooltip-row strong {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text);
}

/* Bottom Methodology Notice (Matches Fund Overlap & Portfolio Builder) */
.macro-notice-wrap {
  max-width: 1480px;
  margin: 0 auto 36px;
  padding: 0 20px;
}

.macro-notice-box {
  background: #FAF9F7;
  border: 1px solid #E5E0D8;
  border-radius: 14px;
  padding: 16px 20px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text2);
}

.macro-notice-box strong {
  color: var(--text);
}

.macro-notice-box code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  background: #F2EFEB;
  border: 1px solid #DDD7CC;
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text);
}

@media (max-width: 768px) {
  .top-header {
    padding: 18px 14px 10px;
    gap: 10px;
  }
  .macro-workspace,
  .macro-notice-wrap {
    padding-left: 14px;
    padding-right: 14px;
  }
  .portfolio-save-tip {
    font-size: 11px;
    padding: 6px 12px;
    border-radius: 8px;
    width: 100%;
  }
  .panel-header {
    padding: 10px 14px;
  }
  .panel-body {
    padding: 12px 14px 14px;
  }
  .macro-tooltip {
    min-width: 0;
    max-width: calc(100vw - 24px);
    padding: 8px 11px;
  }
}
