/* ============================================
   Mortgage Affordability Dashboard
   "The Analyst's Desk" — Premium Financial UI
   ============================================ */

/* --- Design Tokens --- */
:root {
  /* Surface palette — warm light mode */
  --bg-body: #f5f0eb;
  --bg-container: #ffffff;
  --bg-card: #faf8f5;
  --bg-card-est: #fffbeb;
  --bg-header: linear-gradient(135deg, #1e293b 0%, #0f172a 50%, #1a1a2e 100%);
  --bg-chart: #fdfcfa;

  /* Text */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-on-dark: #f1f5f9;

  /* Accents */
  --accent-amber: #d97706;
  --accent-amber-glow: rgba(217, 119, 6, 0.15);
  --accent-blue: #3b82f6;
  --accent-blue-hover: #2563eb;
  --accent-purple: #8b5cf6;
  --accent-emerald: #059669;
  --accent-rose: #e11d48;
  --accent-slate: #64748b;
  --accent-warning: #f59e0b;

  /* Borders & Shadows */
  --border-color: #e2e0dc;
  --border-est: #fcd34d;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.08);
  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.04), 0 0 0 1px rgba(15, 23, 42, 0.02);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 100px;

  /* Typography */
  --font-display: 'Source Serif 4', Georgia, serif;
  --font-body: 'Outfit', -apple-system, sans-serif;
  --font-mono: 'DM Mono', 'SF Mono', monospace;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* --- Dark Mode --- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-body: #0c0f17;
    --bg-container: #141821;
    --bg-card: #1c2030;
    --bg-card-est: rgba(217, 119, 6, 0.08);
    --bg-header: linear-gradient(135deg, #0f172a 0%, #0a0e1a 50%, #111827 100%);
    --bg-chart: #181c28;

    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent-amber: #f59e0b;
    --accent-amber-glow: rgba(245, 158, 11, 0.1);
    --accent-blue: #60a5fa;
    --accent-purple: #a78bfa;
    --accent-emerald: #34d399;
    --accent-rose: #fb7185;
    --accent-slate: #94a3b8;

    --border-color: #2a2f3e;
    --border-est: #92400e;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.4);
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.03);
  }
}

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Container --- */
.container {
  max-width: 1360px;
  margin: 0 auto;
  background: var(--bg-container);
  min-height: 100vh;
  box-shadow: var(--shadow-lg);
}

@media (min-width: 1400px) {
  body {
    padding: 24px;
  }
  .container {
    min-height: auto;
    border-radius: var(--radius-lg);
    overflow: hidden;
  }
}

/* --- Header --- */
header {
  background: var(--bg-header);
  padding: 56px 48px 48px;
  position: relative;
  overflow: hidden;
}

.header-inner {
  position: relative;
  z-index: 1;
}

.header-decoration {
  position: absolute;
  top: -20px;
  right: -20px;
  width: 240px;
  height: 240px;
  color: var(--accent-amber);
  opacity: 0.6;
  pointer-events: none;
}

.header-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent-amber);
  margin-bottom: 16px;
  opacity: 0.9;
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 700;
  line-height: 1.15;
  color: #f1f5f9;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}

h1 .header-accent {
  color: var(--accent-amber);
}

.subtitle {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 400;
  color: #94a3b8;
  letter-spacing: 0.01em;
}

.update-info {
  margin-top: 16px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: #64748b;
  letter-spacing: 0.02em;
}

/* --- Main Content --- */
.content {
  padding: 40px 48px 32px;
}

/* --- Loading & Errors --- */
.loading,
.error-message {
  text-align: center;
  padding: 60px 40px;
  font-size: 1rem;
  color: var(--text-muted);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 2.5px solid var(--border-color);
  border-top-color: var(--accent-amber);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.8s linear infinite;
}

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

.error-message {
  color: var(--accent-rose);
  font-weight: 500;
}

/* --- Estimation Warning --- */
.legend-info {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--accent-amber-glow);
  border: 1px solid rgba(217, 119, 6, 0.2);
  padding: 14px 18px;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.legend-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  margin-top: 1px;
}

/* --- Dataset Indicator --- */
.dataset-indicator {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent-amber);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 20px;
}

/* --- Info Cards --- */
.info-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 32px;
}

.info-card {
  background: var(--bg-card);
  padding: 18px 18px 18px 22px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  position: relative;
  transition: transform 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out);
  border-left: 3px solid var(--accent-slate);
  overflow: hidden;
}

.info-card[data-accent="amber"]  { border-left-color: var(--accent-amber); }
.info-card[data-accent="blue"]   { border-left-color: var(--accent-blue); }
.info-card[data-accent="emerald"]{ border-left-color: var(--accent-emerald); }
.info-card[data-accent="rose"]   { border-left-color: var(--accent-rose); }
.info-card[data-accent="slate"]  { border-left-color: var(--accent-slate); }

.info-card.estimated {
  background: var(--bg-card-est);
  border-left-style: dashed;
}

.info-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.info-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

.info-value {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.dual-value {
  display: block;
  line-height: 1.4;
  font-size: 1.15rem;
}

.dual-value.single {
  color: var(--accent-blue);
}

.dual-value.household {
  color: var(--accent-purple);
}

.estimated-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--accent-warning);
  color: #fff;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: 0.55rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* --- Controls (Dataset Toggle) --- */
.controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

/* --- Buttons --- */
.btn {
  font-family: var(--font-body);
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-pill);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--accent-amber);
  outline-offset: 2px;
}

.btn-small {
  padding: 7px 14px;
  font-size: 0.8rem;
  font-weight: 500;
}

.btn-primary {
  background: var(--accent-amber);
  color: #fff;
  box-shadow: 0 1px 3px rgba(217, 119, 6, 0.25);
}

.btn-primary:hover {
  background: #b45309;
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.3);
}

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

.btn-secondary:hover {
  background: var(--bg-card);
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.btn.active {
  background: var(--accent-amber);
  color: #fff;
  border-color: var(--accent-amber);
  box-shadow: 0 1px 3px rgba(217, 119, 6, 0.25);
}

/* --- Chart Toolbar --- */
.chart-toolbar {
  margin-bottom: 16px;
}

.date-range-controls {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 12px 16px;
  border-radius: var(--radius-md);
}

.date-range-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.date-range-buttons,
.action-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.date-range-buttons .btn-small {
  min-width: 40px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

.action-buttons .btn-small {
  font-family: var(--font-body);
}

/* --- Chart Container --- */
.chart-container {
  height: 520px;
  background: var(--bg-chart);
  border: 1px solid var(--border-color);
  padding: 24px;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  transition: box-shadow 0.2s var(--ease-out);
}

.chart-container:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-amber), 0 0 0 4px var(--accent-amber-glow);
}

/* --- Zoom Tip --- */
.zoom-info {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  padding: 10px 0;
  letter-spacing: 0.03em;
  margin-bottom: 32px;
}

/* --- Methodology (Collapsible) --- */
.methodology {
  border-top: 1px solid var(--border-color);
  padding-top: 0;
}

.methodology summary {
  padding: 24px 0;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.methodology summary::-webkit-details-marker {
  display: none;
}

.methodology summary::after {
  content: '+';
  font-family: var(--font-mono);
  font-size: 1.1rem;
  color: var(--text-muted);
  margin-left: auto;
  transition: transform 0.2s var(--ease-out);
}

.methodology[open] summary::after {
  content: '−';
}

.methodology summary:hover {
  color: var(--accent-amber);
}

.methodology summary h2 {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0;
}

.methodology-content {
  padding-bottom: 28px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.7;
}

.methodology-content p {
  margin-bottom: 14px;
}

.data-sources {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  margin: 16px 0;
}

.data-sources h3 {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.data-sources ul {
  list-style: none;
  padding: 0;
}

.data-sources li {
  padding: 6px 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-color);
}

.data-sources li:last-child {
  border-bottom: none;
}

/* --- Footer --- */
footer {
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  padding: 28px 48px;
}

.footer-inner {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.7;
}

footer a {
  color: var(--accent-amber);
  text-decoration: none;
  transition: color 0.15s ease;
}

footer a:hover {
  color: var(--accent-blue);
  text-decoration: underline;
}

.footer-meta {
  margin-top: 4px;
  opacity: 0.7;
  font-size: 0.75rem;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
  .info-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  header {
    padding: 36px 24px 32px;
  }

  .header-decoration {
    width: 160px;
    height: 160px;
    top: -10px;
    right: -10px;
  }

  .content {
    padding: 24px 20px 20px;
  }

  h1 {
    font-size: 1.75rem;
  }

  .info-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .info-card {
    padding: 14px 14px 14px 18px;
  }

  .info-value {
    font-size: 1.15rem;
  }

  .chart-container {
    height: 360px;
    padding: 12px;
  }

  .date-range-header {
    flex-direction: column;
    align-items: flex-start;
  }

  footer {
    padding: 24px 20px;
  }

  .controls .btn {
    padding: 8px 16px;
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  header {
    padding: 28px 16px 24px;
  }

  .content {
    padding: 20px 16px 16px;
  }

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

  h1 {
    font-size: 1.5rem;
  }

  .chart-container {
    height: 300px;
    padding: 8px;
  }

  footer {
    padding: 20px 16px;
  }
}

/* --- Animations --- */
@media (prefers-reduced-motion: no-preference) {
  .info-card {
    animation: fadeUp 0.4s var(--ease-out) both;
  }
  .info-card:nth-child(1) { animation-delay: 0.05s; }
  .info-card:nth-child(2) { animation-delay: 0.1s; }
  .info-card:nth-child(3) { animation-delay: 0.15s; }
  .info-card:nth-child(4) { animation-delay: 0.2s; }
  .info-card:nth-child(5) { animation-delay: 0.25s; }

  .chart-container {
    animation: fadeUp 0.5s var(--ease-out) 0.3s both;
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- Selection Color --- */
::selection {
  background: var(--accent-amber);
  color: #fff;
}

/* --- Scrollbar (Webkit) --- */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-body);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
