:root {
  color-scheme: light;
  --navy: #17233c;
  --blue: #2357d8;
  --line: #dfe4ec;
  --muted: #687386;
  --surface: #ffffff;
  --background: #f4f6f9;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--background); color: var(--navy); overflow: hidden; }
button, input, select, textarea { font: inherit; }

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  height: 58px;
  justify-content: space-between;
  padding: 0 20px;
}

.brand { align-items: center; display: flex; gap: 10px; }
.brand-mark {
  align-items: center;
  background: var(--navy);
  border-radius: 6px;
  color: white;
  display: flex;
  font-weight: 700;
  height: 32px;
  justify-content: center;
  width: 32px;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; line-height: 17px; }
.brand small { color: var(--muted); font-size: 11px; }
.status { color: var(--muted); font-size: 12px; }
.status.error { color: #a61b1b; }

.toolbar {
  align-items: end;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 150px 1fr 180px;
  min-height: 68px;
  padding: 9px 20px 11px;
}

.toolbar label { color: var(--muted); display: grid; font-size: 11px; gap: 4px; }
.toolbar input, .toolbar select {
  background: white;
  border: 1px solid #cdd4df;
  border-radius: 5px;
  color: var(--navy);
  height: 34px;
  min-width: 0;
  padding: 0 10px;
}
.toolbar input:focus, .toolbar select:focus, textarea:focus {
  border-color: var(--blue);
  outline: 2px solid rgb(35 87 216 / 12%);
}

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 390px; height: calc(100% - 126px); }
.map-panel { min-width: 0; position: relative; }
#map { height: 100%; width: 100%; }

.legend, .layers {
  background: rgb(255 255 255 / 96%);
  border: 1px solid var(--line);
  border-radius: 5px;
  box-shadow: 0 2px 8px rgb(23 35 60 / 9%);
  position: absolute;
  z-index: 2;
}
.legend { align-items: center; bottom: 18px; display: flex; font-size: 10px; gap: 7px; left: 12px; padding: 7px 9px; }
.scale { background: linear-gradient(90deg, #e9b949, #e46c38, #a61b1b); border-radius: 5px; height: 7px; width: 90px; }
.layers { display: grid; font-size: 11px; gap: 7px; left: 12px; padding: 10px 11px; top: 12px; }
.layers label { align-items: center; display: flex; gap: 6px; }
.layers input { accent-color: var(--blue); margin: 0; }

.insight-panel {
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 18px;
}
.panel-heading { align-items: start; display: flex; justify-content: space-between; }
.panel-heading small, .selected-card small { color: var(--muted); font-size: 11px; text-transform: uppercase; }
h1 { font-size: 18px; margin: 4px 0 0; }
h2 { font-size: 14px; margin: 4px 0 8px; }
.radius-badge { background: #edf2ff; border-radius: 4px; color: var(--blue); font-size: 11px; font-weight: 600; padding: 5px 7px; }

.metrics { display: grid; gap: 8px; grid-template-columns: repeat(3, 1fr); margin: 16px 0; }
.metrics article { border: 1px solid var(--line); border-radius: 6px; padding: 10px; }
.metrics span { color: var(--muted); display: block; font-size: 10px; min-height: 25px; }
.metrics strong { display: block; font-size: 20px; margin-top: 4px; }

.selected-card { background: #f7f9fc; border: 1px solid var(--line); border-radius: 6px; padding: 13px; }
.selected-card p { color: #465268; font-size: 12px; line-height: 1.55; margin: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.tags span { background: white; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); font-size: 10px; padding: 3px 5px; }

.ranking, .ask-panel { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 14px; }
.section-title { align-items: center; display: flex; justify-content: space-between; }
.section-title span { color: var(--muted); font-size: 10px; }
.ranking ol { list-style: none; margin: 0; padding: 0; }
.ranking li { border-bottom: 1px solid #edf0f4; }
.ranking button { align-items: center; background: none; border: 0; color: inherit; cursor: pointer; display: grid; gap: 8px; grid-template-columns: 20px 1fr auto; padding: 9px 2px; text-align: left; width: 100%; }
.ranking button:hover { color: var(--blue); }
.ranking .rank { color: var(--muted); font-size: 11px; text-align: center; }
.ranking .name { font-size: 12px; font-weight: 600; }
.ranking .sample { color: var(--muted); display: block; font-size: 10px; font-weight: 400; margin-top: 2px; }
.ranking .score { font-size: 13px; font-weight: 700; }
.ranking .empty { color: var(--muted); font-size: 12px; padding: 12px 0; }

.ask-panel form { display: grid; gap: 7px; grid-template-columns: 1fr auto; }
.ask-panel textarea { border: 1px solid #cdd4df; border-radius: 5px; min-height: 56px; padding: 8px; resize: vertical; }
.ask-panel button { align-self: stretch; background: var(--blue); border: 0; border-radius: 5px; color: white; cursor: pointer; font-size: 12px; font-weight: 600; padding: 0 12px; }
.ask-panel button:disabled { cursor: wait; opacity: .6; }
.answer { background: #edf2ff; border-radius: 5px; color: #263d75; font-size: 12px; line-height: 1.5; margin-top: 8px; padding: 10px; }

.sources { border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; margin-top: 16px; padding-top: 12px; }
.sources summary { cursor: pointer; }
.source-row { border-bottom: 1px solid #edf0f4; padding: 8px 0; }
.source-row strong { color: var(--navy); display: block; }
.source-row a { color: var(--blue); }
.maplibregl-popup-content { border-radius: 5px; color: var(--navy); font: 12px/1.5 Inter, sans-serif; padding: 10px 12px; }

@media (max-width: 900px) {
  body { overflow: auto; }
  .status { display: none; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .workspace { display: block; height: auto; }
  .map-panel { height: 56vh; min-height: 380px; }
  .insight-panel { border-left: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 520px) {
  .topbar { padding: 0 14px; }
  .toolbar { gap: 8px; grid-template-columns: 1fr; padding: 10px 14px; }
  .workspace { height: auto; }
  .map-panel { height: 52vh; min-height: 330px; }
  .insight-panel { padding: 14px; }
}
