:root {
  --bg: #f4f6f2;
  --panel: #ffffff;
  --ink: #17251d;
  --muted: #5d6b62;
  --line: #e2e7e0;
  --accent: #1f6f43;
  --accent-soft: #e5f2ea;
  --high: #c0392b;
  --high-soft: #fdecea;
  --med: #c77700;
  --med-soft: #fff4e0;
  --low: #2e7d4f;
  --low-soft: #e8f5ec;
  --blue: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .05);
  font-family: Inter, "Noto Sans Devanagari", "Noto Sans", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
h1, h2, h3 { margin: 0; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }

/* ---------- top bar ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1000; }
.brand { display: flex; gap: 10px; align-items: center; }
.brand h1 { font-size: 19px; letter-spacing: -.01em; }
.brand h1 .hi { font-weight: 500; color: var(--accent); margin-left: 4px; }
.brand p { margin: 0; color: var(--muted); font-size: 12.5px; }
.status { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; font-size: 12px; color: var(--muted); }
.status span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #bbb; display: inline-block; }
.dot.ok { background: #22a35a; box-shadow: 0 0 0 3px #22a35a22; }
.dot.bad { background: var(--high); }
.dot.warn { background: var(--med); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: minmax(320px, 400px) 1fr; gap: 16px; padding: 16px 20px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.left { padding: 14px; position: sticky; top: 76px; }
.right { padding: 0; min-height: 70vh; overflow: hidden; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .left { position: static; }
}

/* ---------- search + map ---------- */
.search { position: relative; margin-bottom: 10px; }
.search input { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fafbf9; }
.search-results { position: absolute; z-index: 1100; left: 0; right: 0; top: 40px; margin: 0; padding: 4px; list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 240px; overflow: auto; }
.search-results li { padding: 7px 9px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.search-results li:hover { background: var(--accent-soft); }
#map { height: 330px; border-radius: 10px; border: 1px solid var(--line); }
.hint { margin: 8px 0 4px; color: var(--muted); font-size: 12.5px; }
.examples { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.link { background: none; border: 0; color: var(--blue); padding: 0; font-size: 12px; }
.link:hover { text-decoration: underline; }

/* ---------- form ---------- */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.form label:first-child { grid-column: 1 / -1; }
.form select, .form input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font-weight: 400; }
.actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 14px; border-radius: 8px; font-weight: 600; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; flex: 1; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 12px; background: #fbfcfa; }
.tab { background: none; border: 0; padding: 13px 14px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabpane { display: none; padding: 16px; }
.tabpane.active { display: block; }

.empty { max-width: 560px; margin: 60px auto; text-align: center; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: 8px; }
.loading { display: flex; gap: 18px; align-items: flex-start; padding: 40px; }
.loading ul { list-style: none; margin: 0; padding: 0; color: var(--muted); }
.loading li::before { content: "◌ "; }
.loading li.done::before { content: "✓ "; color: var(--accent); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- report ---------- */
.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 4px; }
.report-head h2 { font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.chip { display: inline-block; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.warn { background: var(--med-soft); color: var(--med); }
.chip.bad { background: var(--high-soft); color: var(--high); }
.section { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 0 8px; }

.risks { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.risk { border: 1px solid var(--line); border-left: 4px solid var(--low); border-radius: 10px; padding: 10px 12px; background: #fff; }
.risk.high { border-left-color: var(--high); background: linear-gradient(90deg, var(--high-soft), #fff 60%); }
.risk.medium { border-left-color: var(--med); background: linear-gradient(90deg, var(--med-soft), #fff 60%); }
.risk h4 { margin: 0 0 4px; font-size: 14px; display: flex; justify-content: space-between; gap: 8px; }
.risk .sev { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.risk.high .sev { color: var(--high); } .risk.medium .sev { color: var(--med); } .risk.low .sev { color: var(--low); }
.risk p { margin: 4px 0; font-size: 13px; }
.risk .act { font-weight: 600; }
.risk .ev { font-size: 11.5px; color: var(--muted); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
@media (max-width: 1200px) { .grid3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fff; min-width: 0; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.card h3 { font-size: 14px; }
.chart { position: relative; height: 220px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 13px; margin-top: 6px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; text-align: right; }
.big { font-size: 17px; font-weight: 700; margin: 4px 0; }
.big.high { color: var(--high); } .big.medium { color: var(--med); } .big.low { color: var(--low); }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 6px; }
th, td { text-align: left; padding: 4px 4px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; }
.unavail { color: var(--muted); font-style: italic; }
.sources { margin-top: 12px; }
.sources summary { cursor: pointer; font-weight: 600; }
.sources ul { margin: 8px 0 0; padding-left: 18px; font-size: 12.5px; }
.mode { font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 4px; margin-left: 4px; text-transform: uppercase; }
.mode.live { background: var(--low-soft); color: var(--low); }
.mode.cache { background: #e8eefc; color: var(--blue); }
.mode.stale { background: var(--med-soft); color: var(--med); }
.mode.reference { background: #f0f0f0; color: #555; }

/* ---------- ask ---------- */
.ask-layout { display: grid; grid-template-columns: 1fr 360px; gap: 14px; }
@media (max-width: 1100px) { .ask-layout { grid-template-columns: 1fr; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip-btn { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 11px; font-size: 12.5px; }
.chip-btn:hover { border-color: var(--accent); color: var(--accent); }
.chat-log { min-height: 340px; max-height: 58vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fbfcfa; }
.msg { max-width: 92%; margin: 8px 0; padding: 10px 12px; border-radius: 12px; white-space: pre-wrap; }
.msg.user { margin-left: auto; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.err { background: var(--high-soft); color: var(--high); }
.msg .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; font-size: 11.5px; color: var(--muted); white-space: normal; }
.msg details { margin-top: 6px; font-size: 12px; white-space: normal; }
.tag { display: inline-block; padding: 0 6px; margin: 0 1px; border-radius: 4px; background: #e8eefc; color: var(--blue); font-size: 11px; font-weight: 600; vertical-align: 1px; }
.verified { color: var(--low); font-weight: 700; }
.unverified { color: var(--med); font-weight: 700; }
.ask-row { display: flex; gap: 8px; margin-top: 10px; }
.ask-row input { flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.ask-row .btn.primary { flex: 0 0 auto; }
.mic { width: 44px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--accent); display: grid; place-items: center; }
.mic.rec { background: var(--high); color: #fff; border-color: var(--high); animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 #c0392b66; } 100% { box-shadow: 0 0 0 12px #c0392b00; } }
.play { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 2px 10px; font-size: 12px; }

.trace { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #0f1a14; color: #d7e4dc; max-height: 72vh; overflow-y: auto; }
.trace h3 { color: #fff; font-size: 13px; margin-bottom: 8px; }
.trace ol { list-style: none; margin: 0; padding: 0; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.trace li { padding: 6px 0; border-bottom: 1px dashed #26362d; }
.trace .k { font-weight: 700; }
.trace .k.call { color: #7cc4ff; } .trace .k.ok { color: #6ee7a0; } .trace .k.fail { color: #ff8a80; }
.trace .k.think { color: #c4b5fd; } .trace .k.fix { color: #fbbf24; } .trace .k.ver { color: #6ee7a0; }
.trace .s { color: #8fa79a; display: block; word-break: break-word; }

/* ---------- monitor ---------- */
.monitor-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.monitor-head .btn { flex: 0 0 auto; }
.plot-list, .alert-list { display: grid; gap: 8px; }
.plot-item, .alert-item { display: flex; justify-content: space-between; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.alert-item { display: block; border-left: 4px solid var(--med); }
.alert-item.high { border-left-color: var(--high); }
.alert-item h4 { margin: 0 0 3px; font-size: 13.5px; }
.alert-item p { margin: 2px 0; font-size: 12.5px; }

.banner { background: var(--high); color: #fff; text-align: center; padding: 8px 16px; font-weight: 600; font-size: 13px; }
.banner.warn { background: var(--med); }
.lab-targets { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 8px 0 10px; font-size: 13px; }
.lab-targets label { display: flex; align-items: center; gap: 6px; }

.foot { padding: 10px 20px 24px; color: var(--muted); font-size: 11.5px; text-align: center; }
.leaflet-container { font: inherit; }
