:root {
  --navy: #102847;
  --arctic: #0969DA;
  --glacier: #3B9AF2;
  --ice: #EAF4FF;
  --bg: #F6FAFE;
  --white: #FFFFFF;
  --text: #102847;
  --text-secondary: #64748B;
  --border: #DCE6F0;
  --positive: #15803D;
  --warning: #D97706;
  --error: #DC2626;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 40, 71, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 40, 71, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 40, 71, 0.14);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--arctic); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

.container { max-width: 1240px; margin: 0 auto; padding: 0 24px; }

/* ---------------------------------------------------------------- nav */
.topnav {
  position: sticky; top: 0; z-index: 50;
  background: var(--white); border-bottom: 1px solid var(--border);
}
.topnav-inner {
  max-width: 1240px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; color: var(--navy); cursor: pointer; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(145deg, var(--arctic), var(--glacier));
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-mark svg { width: 20px; height: 20px; }

.nav-links { display: flex; gap: 4px; flex: 1; justify-content: center; }
.nav-links a, .nav-links .navbtn {
  padding: 9px 14px; border-radius: 8px; font-weight: 600; font-size: 14px;
  color: var(--text-secondary); background: none; border: none;
}
.nav-links a.active, .nav-links .navbtn.active { color: var(--arctic); background: var(--ice); }
.nav-links a:hover, .nav-links .navbtn:hover { color: var(--navy); }

.nav-right { display: flex; align-items: center; gap: 10px; }
.btn {
  border: 1px solid var(--border); background: var(--white); color: var(--navy);
  padding: 9px 16px; border-radius: 8px; font-weight: 600; font-size: 14px;
}
.btn:hover { border-color: var(--arctic); }
.btn-primary {
  background: linear-gradient(135deg, var(--arctic), var(--glacier)); color: #fff; border: none;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-danger { color: var(--error); border-color: #F6C9C7; }
.user-pill {
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary);
  padding: 6px 10px; border-radius: 20px; background: var(--ice);
}

@media (max-width: 860px) {
  .nav-links { display: none; }
}

/* ---------------------------------------------------------------- hero */
.hero {
  position: relative; overflow: hidden; padding: 72px 24px 56px;
  background: linear-gradient(180deg, #E4F0FF 0%, var(--bg) 100%);
}
.hero::before, .hero::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(60px); opacity: .5;
}
.hero::before { width: 480px; height: 280px; background: #BFE0FF; top: -120px; left: -80px; }
.hero::after { width: 420px; height: 240px; background: #D7ECFF; top: -60px; right: -100px; }
.hero-content { position: relative; max-width: 760px; margin: 0 auto; text-align: center; }
.hero-eyebrow {
  display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .08em;
  color: var(--arctic); background: var(--white); border: 1px solid var(--border);
  padding: 6px 14px; border-radius: 20px; margin-bottom: 20px;
}
.hero h1 { font-size: 44px; font-weight: 800; margin: 0 0 12px; color: var(--navy); letter-spacing: -0.02em; }
.hero p.subtitle { font-size: 18px; color: var(--text-secondary); margin: 0 0 36px; }

.search-card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 20px; display: flex; gap: 10px; flex-wrap: wrap;
  text-align: left; position: relative;
}
.search-field { position: relative; }
.search-field.grow { flex: 1 1 260px; }
.search-field label {
  display: block; font-size: 11px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px;
}
.search-field input, .search-field select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; color: var(--text); background: var(--white);
}
.search-field input:focus, .search-field select:focus { outline: 2px solid var(--glacier); outline-offset: 1px; }
.autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; margin-top: 4px; box-shadow: var(--shadow-md); z-index: 10; max-height: 260px; overflow-y: auto;
}
.autocomplete-list div { padding: 10px 12px; font-size: 14px; cursor: pointer; }
.autocomplete-list div:hover { background: var(--ice); }
.search-submit { align-self: flex-end; padding: 11px 26px; font-size: 15px; white-space: nowrap; }

.shortcuts { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.shortcut-chip {
  font-size: 13px; font-weight: 600; color: var(--navy); background: var(--white);
  border: 1px solid var(--border); border-radius: 20px; padding: 7px 14px;
}
.shortcut-chip:hover { border-color: var(--glacier); color: var(--arctic); }

.feature-grid {
  max-width: 1040px; margin: 56px auto 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px;
}
.feature-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.feature-icon {
  width: 38px; height: 38px; border-radius: 10px; background: var(--ice); color: var(--arctic);
  display: flex; align-items: center; justify-content: center; margin-bottom: 12px;
}
.feature-card h3 { margin: 0 0 6px; font-size: 15px; font-weight: 700; }
.feature-card p { margin: 0; font-size: 13px; color: var(--text-secondary); line-height: 1.5; }

@media (max-width: 900px) {
  .hero h1 { font-size: 32px; }
  .feature-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .search-card { flex-direction: column; }
  .search-field.grow { flex: 1 1 auto; }
  .search-submit { width: 100%; }
  .feature-grid { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- generic page */
.page { max-width: 1240px; margin: 0 auto; padding: 28px 24px 64px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 24px; margin: 0; font-weight: 800; color: var(--navy); }
.page-header .actions { display: flex; gap: 10px; }
.card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.muted { color: var(--text-secondary); font-size: 13px; }

/* ---------------------------------------------------------------- results layout */
.results-top { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; }
.results-grid { display: grid; grid-template-columns: 360px 1fr; gap: 20px; align-items: start; }
@media (max-width: 980px) { .results-grid { grid-template-columns: 1fr; } }

.subject-card h2 { font-size: 16px; margin: 0 0 2px; }
.subject-card .sub { font-size: 13px; color: var(--text-secondary); margin-bottom: 16px; }
.stat-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.stat-row:last-child { border-bottom: none; }
.stat-row .label { color: var(--text-secondary); }
.stat-row .value { font-weight: 700; color: var(--navy); }
.stat-note { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.insufficient-note {
  background: #FFF7ED; border: 1px solid #FCD9A8; color: var(--warning);
  border-radius: 8px; padding: 10px 12px; font-size: 12.5px; margin-top: 10px;
}

.map-card { padding: 0; overflow: hidden; }
#map-canvas { width: 100%; height: 420px; background: var(--ice); }
.map-fallback {
  height: 420px; display: flex; align-items: center; justify-content: center; flex-direction: column;
  gap: 8px; color: var(--text-secondary); text-align: center; padding: 20px;
}

/* ---------------------------------------------------------------- filters */
.filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin: 20px 0; padding: 16px;
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.filter-field label { display: block; font-size: 10.5px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; margin-bottom: 4px; letter-spacing: .03em; }
.filter-field input, .filter-field select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; font-size: 13px; min-width: 110px;
}
.view-toggle { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-left: auto; }
.view-toggle button { border: none; background: var(--white); padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.view-toggle button.active { background: var(--navy); color: #fff; }

/* ---------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-lg); }
table.comps-table { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
table.comps-table th {
  text-align: left; padding: 11px 14px; font-size: 11px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--text-secondary); border-bottom: 1px solid var(--border); background: #FAFCFF; cursor: pointer;
  position: sticky; top: 0;
}
table.comps-table th:hover { color: var(--arctic); }
table.comps-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
table.comps-table tbody tr:hover { background: var(--ice); cursor: pointer; }
table.comps-table tbody tr.highlighted { background: #DCEEFF; }
.pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 12px; }
.pill-single { background: #E7F7EC; color: var(--positive); }
.pill-portfolio { background: #FFF3DC; color: var(--warning); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px; font-size: 13px; }

/* ---------------------------------------------------------------- KPI / dashboards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; }
.kpi-card .kpi-label { font-size: 11px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .03em; }
.kpi-card .kpi-value { font-size: 22px; font-weight: 800; color: var(--navy); margin-top: 6px; overflow-wrap: anywhere; line-height: 1.2; }
.kpi-card .kpi-sub { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .chart-grid { grid-template-columns: 1fr; } }
.chart-card h3 { font-size: 14px; margin: 0 0 14px; font-weight: 700; }
.chart-card canvas { max-height: 280px; }

/* ---------------------------------------------------------------- buyers */
.buyer-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 10px; padding: 14px; border-bottom: 1px solid var(--border); align-items: center; cursor: pointer; }
.buyer-row:hover { background: var(--ice); }
.buyer-row:last-child { border-bottom: none; }
.buyer-name { font-weight: 700; }
.buyer-types { font-size: 12px; color: var(--text-secondary); }

/* ---------------------------------------------------------------- admin */
.market-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.market-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; }
.market-card h3 { margin: 0 0 4px; font-size: 16px; }
.market-card .badge { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 10px; text-transform: uppercase; }
.badge-active { background: #E7F7EC; color: var(--positive); }
.badge-archived { background: #F1F5F9; color: var(--text-secondary); }
.market-stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; font-size: 12px; }
.market-stat-grid div b { display: block; font-size: 16px; color: var(--navy); }
.new-market-card {
  border: 2px dashed var(--border); border-radius: var(--radius-lg); display: flex; align-items: center;
  justify-content: center; min-height: 140px; color: var(--text-secondary); font-weight: 600; cursor: pointer;
}
.new-market-card:hover { border-color: var(--glacier); color: var(--arctic); }

/* ---------------------------------------------------------------- wizard */
.wizard-steps { display: flex; gap: 6px; margin-bottom: 24px; flex-wrap: wrap; }
.wizard-step {
  font-size: 11px; font-weight: 700; padding: 5px 11px; border-radius: 14px; color: var(--text-secondary);
  background: var(--ice);
}
.wizard-step.active { background: var(--navy); color: #fff; }
.wizard-step.done { background: var(--positive); color: #fff; }
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius-lg); padding: 48px 20px; text-align: center;
  color: var(--text-secondary); cursor: pointer; background: var(--white);
}
.dropzone.dragover { border-color: var(--glacier); background: var(--ice); }
.mapping-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mapping-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.mapping-row label { flex: 0 0 160px; font-size: 13px; font-weight: 600; }
.mapping-row select { flex: 1; padding: 7px 10px; border: 1px solid var(--border); border-radius: 7px; font-size: 13px; }
.issue-tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; background: #FFF3DC; color: var(--warning); margin-right: 4px; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin: 16px 0; }
.summary-box { background: var(--ice); border-radius: 10px; padding: 14px; text-align: center; }
.summary-box b { display: block; font-size: 22px; color: var(--navy); }
.summary-box span { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; }

/* ---------------------------------------------------------------- login */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(180deg, #E4F0FF 0%, var(--bg) 100%); padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 32px; text-align: center; }
.login-card .brand { justify-content: center; margin-bottom: 18px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { color: var(--text-secondary); font-size: 13px; margin: 0 0 22px; }
.login-field { text-align: left; margin-bottom: 14px; }
.login-field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.login-field input { width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.login-error { background: #FEF0EF; color: var(--error); border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-bottom: 14px; }
.login-card .btn-primary { width: 100%; padding: 12px; font-size: 14px; margin-top: 4px; }

/* ---------------------------------------------------------------- misc */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.form-field input, .form-field select { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(16,40,71,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-card { background: #fff; border-radius: var(--radius-lg); padding: 24px; max-width: 560px; width: 100%; max-height: 86vh; overflow-y: auto; }
.spinner { width: 20px; height: 20px; border: 3px solid var(--ice); border-top-color: var(--arctic); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-secondary); }
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--navy); color: #fff; padding: 12px 18px;
  border-radius: 8px; font-size: 13px; box-shadow: var(--shadow-lg); z-index: 200;
}
.toast.error { background: var(--error); }
table.simple-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.simple-table th { text-align: left; padding: 8px 10px; color: var(--text-secondary); font-size: 11px; text-transform: uppercase; border-bottom: 1px solid var(--border); }
table.simple-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
