/* ============================================================
   Hayden Homes - Market Intelligence Dashboard
   Design tokens from Claude Design slide deck
   ============================================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,300;0,8..60,400;0,8..60,600;0,8..60,700;1,8..60,400&family=Manrope:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* --- Design Tokens --- */
:root {
  --bg-cream: #F4EFE3;
  --bg-paper: #FAF6EC;
  --card: #FFFFFF;
  --border: #E2D9C4;
  --border-soft: #EDE5D2;

  --hh-green: #1F5D3A;
  --hh-green-mid: #2C7A4B;
  --hh-green-soft: #D8E5DC;
  --hh-green-tint: #EEF2EA;

  --navy: #1E3A56;
  --navy-soft: #D9E0E6;

  --rust: #B5532A;
  --rust-soft: #F0D9C8;

  --gold: #C8964D;
  --gold-soft: #EFE0C2;

  --ink: #1A2530;
  --ink-2: #2E3A45;
  --muted: #6B6259;
  --muted-2: #948A7E;

  /* Functional aliases */
  --positive: var(--hh-green);
  --negative: var(--rust);
  --neutral: var(--gold);
  --competitor: var(--navy);

  /* Typography */
  --font-heading: 'Source Serif 4', 'Georgia', serif;
  --font-body: 'Manrope', 'Segoe UI', sans-serif;
  --font-data: 'JetBrains Mono', 'Consolas', monospace;

  /* Layout */
  --sidebar-collapsed: 56px;
  --sidebar-expanded: 240px;
  --header-height: 0px;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 3px rgba(26,37,48,.06);
  --shadow-md: 0 2px 8px rgba(26,37,48,.08);
  --shadow-lg: 0 4px 16px rgba(26,37,48,.10);
  --transition: 220ms cubic-bezier(.4,0,.2,1);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-cream);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
}

/* --- Sidebar Navigation --- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-collapsed);
  height: 100vh;
  background: var(--hh-green);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: width var(--transition);
  overflow: hidden;
  box-shadow: 2px 0 12px rgba(31,93,58,.15);
}

.sidebar:hover {
  width: var(--sidebar-expanded);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px;
  min-height: 64px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}

.sidebar-brand .brand-mark {
  width: 28px;
  height: 28px;
  background: rgba(255,255,255,.15);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand .brand-text {
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--transition);
  line-height: 1.3;
}

.sidebar:hover .brand-text { opacity: 1; }

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: 6px;
  color: rgba(255,255,255,.7);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all var(--transition);
}

.nav-link:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
}

.nav-link.active {
  background: rgba(255,255,255,.18);
  color: #fff;
  font-weight: 600;
}

.nav-link .nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-link .nav-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-label {
  opacity: 0;
  transition: opacity var(--transition);
}

.sidebar:hover .nav-label { opacity: 1; }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,.12);
  font-size: 10px;
  color: rgba(255,255,255,.4);
  white-space: nowrap;
  line-height: 1.4;
}

.sidebar-footer span {
  opacity: 0;
  transition: opacity var(--transition);
}

.sidebar:hover .sidebar-footer span { opacity: 1; }

/* --- Main Content --- */
.main-content {
  margin-left: var(--sidebar-collapsed);
  flex: 1;
  padding: 28px 40px 40px;
  width: calc(100% - var(--sidebar-collapsed));
}

/* --- Page Header --- */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-family: var(--font-heading);
  font-size: 28px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

.page-header .subtitle {
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
}

/* --- Slicer / Filter Row --- */
.slicer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.slicer {
  display: flex;
  align-items: center;
  gap: 6px;
}

.slicer label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.slicer select,
.slicer input[type="range"] {
  font-family: var(--font-body);
  font-size: 13px;
  padding: 6px 28px 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  appearance: none;
  cursor: pointer;
  transition: border-color var(--transition);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' fill='none' stroke='%236B6259' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.slicer select:hover { border-color: var(--hh-green-mid); }
.slicer select:focus {
  outline: none;
  border-color: var(--hh-green);
  box-shadow: 0 0 0 2px var(--hh-green-soft);
}

/* --- Cards --- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

/* --- KPI Cards --- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  transition: box-shadow var(--transition);
}

.kpi-card:hover { box-shadow: var(--shadow-md); }

.kpi-card.green-accent { border-left: 3px solid var(--hh-green); }

.kpi-label {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  line-height: 1;
}

.kpi-value {
  font-family: var(--font-heading);
  font-size: 32px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.kpi-value.data {
  font-family: var(--font-data);
  font-variant-numeric: tabular-nums;
}

.kpi-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.kpi-change {
  font-family: var(--font-data);
  font-size: 12px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
}

.kpi-change.positive {
  color: var(--hh-green);
  background: var(--hh-green-tint);
}

.kpi-change.negative {
  color: var(--rust);
  background: var(--rust-soft);
}

.kpi-change.neutral {
  color: var(--gold);
  background: var(--gold-soft);
}

.kpi-sparkline {
  width: 80px;
  height: 28px;
  flex-shrink: 0;
}

.kpi-sparkline svg {
  width: 100%;
  height: 100%;
}

/* --- Layout Grids --- */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.grid-2-1 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.grid-1-2 {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 20px;
  margin-bottom: 24px;
}

.grid-3-2 {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 20px;
  margin-bottom: 24px;
}

.full-width {
  margin-bottom: 24px;
}

/* --- Chart Container --- */
.chart-container {
  width: 100%;
  min-height: 340px;
}

.chart-container.tall {
  min-height: 440px;
}

.chart-container.short {
  min-height: 260px;
}

/* --- Panel / Card Titles --- */
.card-title {
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 16px;
  letter-spacing: -0.01em;
}

.card-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 16px;
}

/* --- Commentary Panel --- */
.commentary-panel {
  background: var(--bg-paper);
  border-radius: var(--radius);
  padding: 20px 24px;
  border: 1px solid var(--border-soft);
}

.commentary-panel h3 {
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 10px;
}

.commentary-panel p {
  font-size: 13px;
  line-height: 1.65;
  color: var(--ink-2);
  margin-bottom: 8px;
}

.commentary-panel p:last-child { margin-bottom: 0; }

/* --- Data Tables --- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead th {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 8px 12px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table thead th.right { text-align: right; }

.data-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

.data-table tbody td.right { text-align: right; }

.data-table tbody td.data-value {
  font-family: var(--font-data);
  font-variant-numeric: tabular-nums;
}

.data-table tbody tr:hover {
  background: var(--hh-green-tint);
}

.data-table tbody tr:last-child td { border-bottom: none; }

/* inline sparkline cell */
.data-table .sparkline-cell {
  width: 100px;
  padding: 4px 8px;
}

.data-table .sparkline-cell > div {
  width: 100%;
  height: 24px;
}

/* --- Region Mini Cards --- */
.region-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.region-card {
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid var(--border-soft);
}

.region-card .region-name {
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}

.region-card .region-metric {
  font-family: var(--font-data);
  font-size: 12px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.region-card.healthy { background: var(--hh-green-tint); }
.region-card.watch   { background: var(--gold-soft); }
.region-card.concern  { background: var(--rust-soft); }
.region-card.neutral  { background: var(--navy-soft); }

/* --- What-If Panel --- */
.whatif-panel {
  background: var(--bg-paper);
  border: 1px solid var(--gold-soft);
  border-radius: var(--radius);
  padding: 20px 24px;
}

.whatif-panel h3 {
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.whatif-panel h3::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
}

.slider-group {
  margin-bottom: 14px;
}

.slider-group:last-child { margin-bottom: 0; }

.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.slider-label span {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}

.slider-label .slider-value {
  font-family: var(--font-data);
  font-size: 13px;
  font-weight: 600;
  color: var(--hh-green);
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--hh-green);
  border: 2px solid var(--card);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--hh-green);
  border: 2px solid var(--card);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

/* --- Badges --- */
.badge {
  display: inline-block;
  font-family: var(--font-data);
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
}

.badge.green  { color: var(--hh-green); background: var(--hh-green-tint); }
.badge.rust   { color: var(--rust);     background: var(--rust-soft); }
.badge.gold   { color: var(--gold);     background: var(--gold-soft); }
.badge.navy   { color: var(--navy);     background: var(--navy-soft); }

/* --- Affordability result readout --- */
.affordability-readout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}

.readout-item .readout-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 2px;
}

.readout-item .readout-value {
  font-family: var(--font-data);
  font-size: 16px;
  font-weight: 600;
  color: var(--hh-green);
}

/* --- Widescreen (1600px+) --- */
@media (min-width: 1600px) {
  .main-content {
    padding: 24px 44px 20px;
  }
  .kpi-grid {
    gap: 18px;
    margin-bottom: 18px;
  }
  .grid-2, .grid-2-1, .grid-1-2, .grid-3-2 {
    gap: 20px;
    margin-bottom: 18px;
  }
  .full-width {
    margin-bottom: 18px;
  }
  .card {
    padding: 20px 24px;
  }
  .chart-container { min-height: 340px; }
  .chart-container.tall { min-height: 420px; }
  .page-header {
    margin-bottom: 16px;
  }
  .page-header h1 { font-size: 26px; }
  .slicer-row { margin-bottom: 18px; }
}

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

@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .main-content { padding: 16px; }
  .slicer-row { flex-direction: column; align-items: stretch; }
}

/* --- Page accent stripe --- */
.main-content::before {
  content: '';
  display: block;
  height: 3px;
  margin: -24px -44px 20px;
  background: linear-gradient(90deg, var(--hh-green) 0%, var(--hh-green-mid) 50%, var(--gold) 100%);
  border-radius: 0 0 2px 2px;
}

@media (max-width: 1599px) {
  .main-content::before {
    margin: -28px -40px 20px;
  }
}

/* --- Card accent variants --- */
.card.navy-accent   { border-top: 3px solid var(--navy); }
.card.green-accent   { border-top: 3px solid var(--hh-green); }
.card.gold-accent    { border-top: 3px solid var(--gold); }
.card.rust-accent    { border-top: 3px solid var(--rust); }

/* --- Data highlight callout --- */
.callout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-family: var(--font-data);
  font-size: 12px;
  font-weight: 600;
}

.callout.green { background: var(--hh-green-tint); color: var(--hh-green); }
.callout.rust  { background: var(--rust-soft);     color: var(--rust); }
.callout.gold  { background: var(--gold-soft);     color: var(--gold); }
.callout.navy  { background: var(--navy-soft);     color: var(--navy); }

/* --- Smooth chart fade-in --- */
.chart-container canvas {
  animation: chartFadeIn 0.4s ease-out;
}

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

/* --- Utility --- */
.text-green  { color: var(--hh-green); }
.text-rust   { color: var(--rust); }
.text-gold   { color: var(--gold); }
.text-navy   { color: var(--navy); }
.text-muted  { color: var(--muted); }
.text-data   { font-family: var(--font-data); font-variant-numeric: tabular-nums; }

.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

/* Chart tooltip overrides */
.echarts-tooltip {
  font-family: var(--font-body) !important;
}
