:root {
    --bg: #F7F5F0;
    --surface: #FFFFFF;
    --surface2: #F0EDE6;
    --border: rgba(0,0,0,0.09);
    --border-strong: rgba(0,0,0,0.18);
    --text: #1A1814;
    --text2: #5A5650;
    --text3: #9A9590;
    --red: #C0392B; --red-l: #FDECEA;
    --amber: #B7500A; --amber-l: #FEF3E7;
    --green: #1A7A4A; --green-l: #E8F6EE;
    --blue: #1558A0; --blue-l: #E8F0FB;
    --teal: #0E6E5A; --teal-l: #E3F4EF;
    --radius: 12px; --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.10);
  }
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  html { scroll-behavior: smooth; }
  body { font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; }

  /* NAV */
  .topnav { position: sticky; top: 0; z-index: 100; background: rgba(247,245,240,0.92); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 2rem; height: 60px; gap: 2rem; }
  .brand { font-family: 'DM Serif Display', serif; font-size: 20px; color: var(--text); white-space: nowrap; }
  .brand span { color: var(--red); }
  .nav-links { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-link { padding: 6px 14px; border-radius: var(--radius-sm); font-size: 13px; color: var(--text2); cursor: pointer; white-space: nowrap; border: none; background: none; font-family: inherit; transition: all 0.15s; }
  .nav-link:hover { background: var(--surface2); color: var(--text); }
  .nav-link.active { background: var(--text); color: white; }
  .nav-badge { display: inline-block; background: var(--red); color: white; font-size: 9px; padding: 1px 5px; border-radius: 99px; margin-left: 4px; vertical-align: middle; }

  /* LAYOUT */
  .page { display: none; padding: 2rem; max-width: 1200px; margin: 0 auto; }
  .page.active { display: block; animation: fadeUp 0.3s ease; }
  @keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

  /* HERO */
  .hero { background: var(--text); color: white; border-radius: var(--radius); padding: 2.5rem 3rem; margin-bottom: 2rem; position: relative; overflow: hidden; }
  .hero::before { content: ''; position: absolute; right: -60px; top: -60px; width: 300px; height: 300px; background: radial-gradient(circle, rgba(192,57,43,0.3) 0%, transparent 70%); pointer-events: none; }
  .hero h1 { font-family: 'DM Serif Display', serif; font-size: 2.4rem; line-height: 1.2; margin-bottom: 0.5rem; }
  .hero p { color: rgba(255,255,255,0.65); font-size: 14px; max-width: 480px; }
  .hero-metrics { display: flex; gap: 2rem; margin-top: 1.5rem; flex-wrap: wrap; }
  .hero-metric { }
  .hero-metric .val { font-family: 'DM Serif Display', serif; font-size: 2rem; color: #E8756A; }
  .hero-metric .lbl { font-size: 11px; color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: 0.05em; }

  /* CARDS */
  .card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: 1.5rem; box-shadow: var(--shadow); }
  .card-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 2px; letter-spacing: 0.01em; }
  .card-sub { font-size: 11px; color: var(--text3); margin-bottom: 1rem; }
  .grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
  .grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
  .grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.75rem; }
  .span-2 { grid-column: span 2; }
  .span-3 { grid-column: span 3; }
  .span-full { grid-column: 1 / -1; }

  /* METRIC CARDS */
  .metric-card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: 1.25rem 1.5rem; }
  .mc-label { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
  .mc-value { font-family: 'DM Serif Display', serif; font-size: 2rem; line-height: 1; }
  .mc-sub { font-size: 11px; color: var(--text3); margin-top: 4px; }
  .mc-red .mc-value { color: var(--red); }
  .mc-amber .mc-value { color: var(--amber); }
  .mc-green .mc-value { color: var(--green); }
  .mc-blue .mc-value { color: var(--blue); }

  /* FILTER ROW */
  .filter-row { display: flex; gap: 8px; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
  .filter-label { font-size: 12px; color: var(--text2); font-weight: 500; }
  select, input[type=text] { font-family: inherit; font-size: 13px; padding: 6px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); cursor: pointer; }
  select:focus, input:focus { outline: 2px solid var(--blue); outline-offset: 1px; }

  /* RISK TIERS */
  .tier-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
  .tier-card { border-radius: var(--radius); padding: 1.25rem; }
  .tier-high { background: var(--red-l); border: 1px solid rgba(192,57,43,0.2); }
  .tier-med { background: var(--amber-l); border: 1px solid rgba(183,80,10,0.2); }
  .tier-low { background: var(--green-l); border: 1px solid rgba(26,122,74,0.2); }
  .tier-title { font-size: 12px; font-weight: 600; margin-bottom: 10px; }
  .tier-high .tier-title { color: var(--red); }
  .tier-med .tier-title { color: var(--amber); }
  .tier-low .tier-title { color: var(--green); }
  .state-chip { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 99px; margin: 2px; font-weight: 500; cursor: pointer; transition: transform 0.1s; }
  .state-chip:hover { transform: scale(1.08); }
  .tier-high .state-chip { background: rgba(192,57,43,0.12); color: #8B1A10; }
  .tier-med .state-chip { background: rgba(183,80,10,0.12); color: #7A3506; }
  .tier-low .state-chip { background: rgba(26,122,74,0.12); color: #0D5230; }

  /* RISK ASSESSMENT */
  .assess-progress { display: flex; gap: 4px; margin-bottom: 2rem; }
  .step-dot { flex: 1; height: 4px; border-radius: 99px; background: var(--border); transition: background 0.3s; }
  .step-dot.done { background: var(--green); }
  .step-dot.active { background: var(--blue); }
  .assess-section { display: none; }
  .assess-section.active { display: block; animation: fadeUp 0.25s ease; }
  .section-header { display: flex; align-items: center; gap: 12px; margin-bottom: 1.5rem; }
  .section-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
  .icon-blue { background: var(--blue-l); }
  .icon-amber { background: var(--amber-l); }
  .icon-green { background: var(--green-l); }
  .icon-red { background: var(--red-l); }
  .section-title { font-size: 16px; font-weight: 600; }
  .section-desc { font-size: 13px; color: var(--text2); }
  .input-group { margin-bottom: 1.25rem; }
  .input-label { font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 6px; display: block; text-transform: uppercase; letter-spacing: 0.04em; }
  .input-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  input[type=number], input[type=text], textarea { width: 100%; font-family: inherit; font-size: 14px; padding: 10px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }
  input[type=number]:focus, textarea:focus { outline: 2px solid var(--blue); }
  .checkbox-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .check-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); cursor: pointer; transition: all 0.15s; }
  .check-item:hover { border-color: var(--blue); background: var(--blue-l); }
  .check-item input[type=checkbox] { margin-top: 2px; flex-shrink: 0; accent-color: var(--blue); width: 16px; height: 16px; }
  .check-item.checked { border-color: var(--blue); background: var(--blue-l); }
  .check-label { font-size: 13px; color: var(--text); }
  .check-sub { font-size: 11px; color: var(--text3); }
  .radio-group { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
  .radio-item { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); cursor: pointer; transition: all 0.15s; font-size: 13px; }
  .radio-item:hover { border-color: var(--blue); background: var(--blue-l); }
  .radio-item.selected { border-color: var(--blue); background: var(--blue-l); font-weight: 500; }
  .radio-item input { accent-color: var(--blue); }
  .range-wrapper { margin-bottom: 1rem; }
  .range-row { display: flex; align-items: center; gap: 12px; }
  input[type=range] { flex: 1; accent-color: var(--blue); height: 4px; }
  .range-val { font-size: 14px; font-weight: 600; min-width: 48px; text-align: right; color: var(--blue); }
  .nav-btn-row { display: flex; gap: 10px; margin-top: 2rem; justify-content: space-between; align-items: center; }
  .btn { padding: 10px 24px; border-radius: var(--radius-sm); font-size: 14px; font-family: inherit; font-weight: 500; cursor: pointer; border: 1px solid transparent; transition: all 0.15s; }
  .btn-primary { background: var(--text); color: white; }
  .btn-primary:hover { background: #333; }
  .btn-secondary { background: transparent; color: var(--text2); border-color: var(--border-strong); }
  .btn-secondary:hover { background: var(--surface2); }
  .btn-red { background: var(--red); color: white; }
  .btn-red:hover { background: #a0302a; }
  .btn-green { background: var(--green); color: white; }
  .btn-green:hover { background: #145c38; }

  /* RESULT PANEL */
  .result-panel { display: none; animation: fadeUp 0.35s ease; }
  .result-panel.show { display: block; }
  .bmi-gauge { position: relative; width: 200px; height: 110px; margin: 0 auto 1rem; }
  .bmi-arc { }
  .bmi-num { text-align: center; font-family: 'DM Serif Display', serif; font-size: 3rem; }
  .bmi-category { text-align: center; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
  .score-bar { height: 8px; border-radius: 99px; background: var(--surface2); overflow: hidden; margin-bottom: 4px; }
  .score-fill { height: 100%; border-radius: 99px; transition: width 0.8s cubic-bezier(0.34,1.56,0.64,1); }
  .risk-badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 99px; font-size: 13px; font-weight: 600; }
  .risk-high { background: var(--red-l); color: var(--red); border: 1px solid rgba(192,57,43,0.25); }
  .risk-med { background: var(--amber-l); color: var(--amber); border: 1px solid rgba(183,80,10,0.25); }
  .risk-low { background: var(--green-l); color: var(--green); border: 1px solid rgba(26,122,74,0.25); }
  .factor-list { list-style: none; }
  .factor-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
  .factor-item:last-child { border-bottom: none; }
  .factor-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
  .dot-red { background: var(--red); }
  .dot-amber { background: var(--amber); }
  .dot-green { background: var(--green); }

  /* AI SECTION */
  .ai-prompt-area { border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 1.25rem; background: var(--surface); margin-bottom: 1rem; }
  .ai-prompt-area textarea { border: none; background: transparent; resize: none; font-size: 14px; min-height: 80px; padding: 0; }
  .ai-prompt-area textarea:focus { outline: none; }
  .ai-response { background: linear-gradient(135deg, #F0EDE6 0%, #EAF6F0 100%); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; margin-top: 1rem; font-size: 14px; line-height: 1.75; min-height: 80px; white-space: pre-wrap; position: relative; }
  .ai-response.loading::after { content: ''; display: inline-block; width: 8px; height: 16px; background: var(--teal); margin-left: 4px; animation: blink 0.8s infinite; border-radius: 2px; vertical-align: text-bottom; }
  @keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
  .ai-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 1rem; }
  .ai-chip { padding: 6px 14px; border-radius: 99px; border: 1px solid var(--border-strong); font-size: 12px; cursor: pointer; background: var(--surface); color: var(--text2); transition: all 0.15s; }
  .ai-chip:hover { background: var(--text); color: white; border-color: var(--text); }
  .api-key-notice { background: var(--amber-l); border: 1px solid rgba(183,80,10,0.2); border-radius: var(--radius-sm); padding: 12px 16px; font-size: 13px; color: var(--amber); margin-bottom: 1rem; }
  .api-key-input-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
  .api-key-input-row input { flex: 1; font-size: 13px; }

  /* INSIGHTS */
  .insight-card { display: flex; gap: 14px; padding: 1rem 0; border-bottom: 1px solid var(--border); }
  .insight-card:last-child { border-bottom: none; }
  .insight-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
  .insight-body strong { font-weight: 600; display: block; font-size: 14px; margin-bottom: 3px; }
  .insight-body p { font-size: 13px; color: var(--text2); }

  /* MAP */
  #map-svg-wrap { border-radius: var(--radius); overflow: hidden; background: var(--surface2); }
  .map-tooltip { position: fixed; background: var(--text); color: white; padding: 8px 13px; border-radius: var(--radius-sm); font-size: 12px; pointer-events: none; display: none; z-index: 999; }
  .map-legend { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text3); padding: 8px 0; flex-wrap: wrap; }
  .leg-swatch { width: 20px; height: 12px; border-radius: 3px; }

  /* TABS inside pages */
  .tab-bar { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
  .tab-btn { padding: 8px 16px; font-size: 13px; font-family: inherit; background: none; border: none; border-bottom: 2px solid transparent; color: var(--text2); cursor: pointer; transition: all 0.15s; margin-bottom: -1px; }
  .tab-btn.active { color: var(--text); border-bottom-color: var(--text); font-weight: 500; }
  .tab-panel { display: none; }
  .tab-panel.active { display: block; }

  /* SCROLLBAR */
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }

  @media (max-width: 700px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .tier-grid { grid-template-columns: 1fr; }
    .span-2, .span-3 { grid-column: span 1; }
    .page { padding: 1rem; }
    .hero { padding: 1.5rem; }
    .hero h1 { font-size: 1.8rem; }
    .checkbox-grid, .input-row, .radio-group { grid-template-columns: 1fr; }
    .topnav { padding: 0 1rem; gap: 1rem; }
  }
  .section-divider { height: 1px; background: var(--border); margin: 2rem 0; }
  .tag { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 11px; font-weight: 600; }
  .tag-red { background: var(--red-l); color: var(--red); }
  .tag-amber { background: var(--amber-l); color: var(--amber); }
  .tag-green { background: var(--green-l); color: var(--green); }
  .tag-blue { background: var(--blue-l); color: var(--blue); }
