:root {
  color-scheme: light;
  --navy: #15181c;
  --accent: #2f7dbf;
  --accent-dark: #1f5f93;
  --cream: #f4f2ed;
  --paper: #fffdf9;
  --ink: #0f172a;
  --muted: #64748b;
  --warm-muted: #8a7b68;
  --line: #e3dacd;
  --line-cool: #e2e8f0;
  --green: #15803d;
  --gold: #b45309;
  --red: #b91c1c;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.05), 0 10px 40px rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  min-height: 100vh;
  padding-top: 58px;
  background: var(--cream);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, Inter, "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0;
}

button, input { font: inherit; }
button { border: 0; cursor: pointer; }
svg { width: 18px; height: 18px; stroke-width: 2.25; }

.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
  padding: 0 18px;
  background: var(--navy);
  color: #fff;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.2);
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.topbar-brand strong {
  display: block;
  font-size: 19px;
  font-weight: 950;
  line-height: 1;
}

.topbar-brand small {
  display: block;
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.64);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.brand-dot {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 950;
  letter-spacing: 0;
  box-shadow: 0 5px 18px rgba(47, 125, 191, 0.34);
}

.topbar-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.11);
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  font-weight: 850;
}

.app-shell {
  display: grid;
  grid-template-columns: 372px minmax(0, 1fr);
  min-height: calc(100vh - 58px);
}

.sidebar {
  padding: 16px 14px 24px;
  overflow: auto;
  background: #f1f5f9;
  border-right: 1px solid var(--line-cool);
}

.brand { display: none; }

.panel, .score-panel, .metric-card, .report-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
  margin-bottom: 12px;
}

.section-title, .report-header, .button-row, .input-action {
  display: flex;
  align-items: center;
}

.section-title {
  gap: 8px;
  margin-bottom: 14px;
  color: var(--navy);
}

.section-title h2, .report-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0;
}

.stack { display: grid; gap: 12px; }

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1.5px solid #dde3ec;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  padding: 11px 13px;
  outline: none;
  font-weight: 700;
  letter-spacing: 0;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(47, 125, 191, 0.12);
}

input::placeholder { color: #a5b1c0; }

input[type="range"] {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--accent);
}

.input-action { gap: 8px; }

.icon-button, .primary, .secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: 10px;
  font-weight: 900;
  white-space: nowrap;
}

.icon-button {
  width: 46px;
  flex: 0 0 auto;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(47, 125, 191, 0.28);
}

.primary {
  padding: 0 15px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(47, 125, 191, 0.28);
}

.secondary {
  padding: 0 14px;
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--line-cool);
}

.button-row { gap: 9px; flex-wrap: wrap; }
.input-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.range-stack { display: grid; gap: 15px; }
.range-stack label { grid-template-columns: 1fr auto; align-items: center; }
.range-stack input { grid-column: 1 / -1; }

output {
  color: var(--accent-dark);
  font-variant-numeric: tabular-nums;
  font-weight: 950;
}

.workspace {
  min-width: 0;
  padding: 16px;
  overflow: auto;
}

.map-band {
  position: relative;
  height: min(38vh, 390px);
  min-height: 300px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: #cbd5e1;
}

#map { height: 100%; width: 100%; }

.map-status {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: grid;
  gap: 2px;
  max-width: min(560px, calc(100% - 32px));
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 253, 249, 0.95);
  border: 1px solid var(--line);
  box-shadow: 0 12px 35px rgba(20, 16, 13, 0.16);
}

.map-status strong { font-weight: 900; }
.map-status span { color: var(--warm-muted); font-size: 12px; font-weight: 700; }

.summary-grid {
  display: grid;
  grid-template-columns: minmax(300px, 1.45fr) repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin: 12px 0;
}

.score-panel {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 132px;
  padding: 18px;
}

.score-ring {
  --score-color: var(--muted);
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  flex: 0 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--paper) 55%, transparent 57%),
    conic-gradient(var(--score-color) calc(var(--score, 0) * 1%), #e9edf2 0);
}

.score-ring span {
  font-size: 30px;
  font-weight: 950;
  line-height: 1;
}

.score-ring small {
  margin-top: -25px;
  color: var(--warm-muted);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.score-panel h2 {
  margin: 4px 0 7px;
  font-size: 25px;
  font-weight: 950;
  letter-spacing: 0;
}

.score-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.42;
}

.eyebrow {
  margin: 0;
  color: var(--warm-muted);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.metric-card {
  display: grid;
  align-content: center;
  min-height: 132px;
  padding: 17px;
}

.metric-card span, .metric-card small {
  color: var(--muted);
  font-weight: 750;
}

.metric-card strong {
  margin: 5px 0;
  font-size: clamp(22px, 2.1vw, 30px);
  font-weight: 950;
  letter-spacing: 0;
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.report-panel {
  padding: 18px;
  min-width: 0;
}

.report-panel.wide { grid-column: 1 / -1; }

.report-header {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.radius-table {
  display: grid;
  grid-template-columns: 0.7fr repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.radius-table div {
  min-width: 0;
  padding: 11px 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
  font-weight: 750;
}

.radius-table div:nth-child(5n) { border-right: 0; }
.radius-table div:nth-last-child(-n + 5) { border-bottom: 0; }

.radius-table .head {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 950;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.signal-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.signal {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}

.signal strong {
  display: block;
  margin-bottom: 5px;
  font-weight: 900;
}

.signal span, .money-grid span, .memo li, .bar-list span { color: var(--muted); }

.money-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.money {
  padding: 13px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid #edf2f7;
}

.money strong {
  display: block;
  margin-top: 5px;
  font-size: 21px;
  font-weight: 950;
}

.bar-list {
  display: grid;
  gap: 12px;
  margin-top: 17px;
}

.bar-row {
  display: grid;
  grid-template-columns: 145px 1fr 44px;
  gap: 10px;
  align-items: center;
}

.bar-row strong { font-weight: 950; }

.bar-track {
  height: 10px;
  border-radius: 99px;
  background: #e2e8f0;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--accent);
}

.pill, .timestamp {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 11px;
  border-radius: 20px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 950;
}

.memo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.memo-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 15px;
  background: #fff;
}

.memo h3 {
  margin: 0 0 9px;
  font-size: 15px;
  font-weight: 900;
}

.memo ul { margin: 0; padding-left: 18px; }
.memo li { margin: 7px 0; line-height: 1.42; }
.leaflet-popup-content-wrapper { border-radius: 10px; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 330px minmax(0, 1fr); }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .score-panel { grid-column: 1 / -1; }
}

@media (max-width: 820px) {
  body { padding-top: 58px; background: #f1f5f9; }
  .topbar { padding: 0 12px; }
  .topbar-brand small, .topbar-actions { display: none; }
  .app-shell { display: block; }
  .sidebar { padding: 12px 10px; border-right: 0; }
  .workspace { padding: 10px; }
  .map-band { height: 320px; min-height: 300px; }
  .summary-grid, .content-grid, .memo, .signal-list { grid-template-columns: 1fr; }
  .report-panel.wide, .score-panel { grid-column: auto; }
  .money-grid { grid-template-columns: 1fr 1fr; }
  .radius-table { font-size: 12px; }
}

@media (max-width: 520px) {
  .topbar-brand strong { font-size: 17px; }
  .input-grid, .money-grid { grid-template-columns: 1fr; }
  .score-panel { align-items: flex-start; flex-direction: column; }
  .metric-card { min-height: 96px; }
  .bar-row { grid-template-columns: 1fr 44px; }
  .bar-row span:first-child { grid-column: 1 / -1; }
  .radius-table div { padding: 9px 7px; font-size: 11px; }
  .radius-table .head { font-size: 9px; }
}

@media print {
  body { padding-top: 0; background: #fff; }
  .topbar, .sidebar, .map-band, .report-header .button-row { display: none; }
  .app-shell, .content-grid, .summary-grid, .memo { display: block; }
  .workspace { padding: 0; }
  .report-panel, .metric-card, .score-panel {
    box-shadow: none;
    break-inside: avoid;
    margin-bottom: 12px;
  }
}


/* Tunnel sizing */
select {
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line-cool);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 750;
  text-transform: none;
  letter-spacing: 0;
}
.full-width { width: 100%; margin-top: 12px; }
#apply-tunnel { background: var(--accent); color: #fff; }
#apply-tunnel:hover { background: var(--accent-dark); }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.tunnel-reco { display: grid; gap: 6px; margin-bottom: 14px; }
.tunnel-reco p { margin: 0; line-height: 1.5; }
#tunnel-pill[data-fit="fits"] { background: #ecfdf3; color: var(--green); }
#tunnel-pill[data-fit="big"] { background: #fef2f2; color: var(--red); }
.tunnel-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 12px; }
.tunnel-table { display: grid; grid-template-columns: 0.7fr 1.4fr 0.8fr 0.8fr 0.9fr 0.9fr 0.9fr 1.2fr; min-width: 720px; }
.tunnel-table div { padding: 10px 9px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #fff; font-weight: 750; font-size: 13.5px; white-space: nowrap; }
.tunnel-table .head { background: #f8fafc; color: var(--muted); font-weight: 950; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.tunnel-table div.selected { background: #eff6ff; }
.fit-badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 900; }
.fit-fits { background: #ecfdf3; color: var(--green); }
.fit-stretch { background: #fffbeb; color: var(--gold); }
.fit-big, .fit-parcel { background: #fef2f2; color: var(--red); }
span.fit-fits, span.fit-stretch, span.fit-big, span.fit-parcel { padding: 1px 7px; border-radius: 12px; font-weight: 900; }
.ai-box { margin-top: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.ai-box p { margin: 0 0 8px; line-height: 1.5; }
.ai-box p:last-child { margin-bottom: 0; }
#ai-tunnel { margin-top: 12px; }
