:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1d232b;
  --ink-2: #4b5563;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --info: #1d4ed8;
  --demo: #7c3aed;
  --radius: 8px;
  --shadow: 0 2px 10px rgba(16, 24, 40, .08);
  --panel-w: 360px;
  --detail-w: 400px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
a { color: var(--info); }
small { color: var(--muted); }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); height: 56px;
}
.brand { font-size: 16px; font-weight: 700; margin: 0; white-space: nowrap; letter-spacing: .01em; }
.brand::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px;
  background: radial-gradient(circle, #fde68a 0, #f97316 55%, #9a3412 100%); vertical-align: -1px; }
.top-controls { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.ctl { display: flex; align-items: center; gap: 6px; }
.ctl-label { color: var(--muted); font-size: 12px; }
select, input[type=month], input[type=date], input[type=search], input[type=number], input:not([type]), input[type=text], input[type=password] {
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; min-width: 0;
}
select:focus, input:focus, button:focus-visible { outline: 2px solid #fdba74; outline-offset: 1px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--ink); color: #fff; }
.user { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-demo { background: var(--demo); color: #fff; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 4px 9px; cursor: pointer; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 7px 12px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.only-mobile { display: none; }

.layout { position: relative; display: grid; grid-template-columns: var(--panel-w) 1fr; height: calc(100% - 56px); }
.panel { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); overflow-x: auto; flex-shrink: 0; }
.tabs button { flex: 1 0 auto; border: 0; background: none; padding: 10px 7px; cursor: pointer; color: var(--ink-2);
  border-bottom: 2px solid transparent; font-size: 12.5px; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tab-body { overflow-y: auto; padding: 12px 14px 40px; flex: 1; min-height: 0; }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 0 0 6px; padding: 10px 0 4px; }
legend { font-weight: 600; padding: 0 6px 0 0; font-size: 13px; }
fieldset label { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; font-size: 13px; color: var(--ink-2); }
fieldset label.check { flex-direction: row; align-items: flex-start; gap: 6px; }
.radio-row { flex-direction: row !important; align-items: center; gap: 8px !important; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 6px; }
.checks label { flex-direction: row; align-items: center; gap: 4px; margin: 0; }
.field { margin-bottom: 10px; }
.field > label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--ink-2); }
.hint { color: var(--muted); font-size: 12px; margin: 2px 0 8px; }
.hint.warn { color: var(--warn); }
.metric-note { background: #fff7ed; border: 1px solid #fed7aa; color: #7c2d12; border-radius: var(--radius);
  padding: 8px 10px; font-size: 12px; margin-bottom: 8px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 6px; }
fieldset[disabled] { opacity: .55; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #eef2f7; border-radius: 999px; padding: 2px 4px 2px 9px; font-size: 12px; }
.chip button { border: 0; background: none; cursor: pointer; padding: 0 4px; font-size: 13px; color: var(--muted); }
.ac { position: relative; }
.ac input { width: 100%; }
.ac-list { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; margin: 2px 0 0; padding: 4px 0; list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); max-height: 280px; overflow: auto; }
.ac-list li { padding: 6px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.ac-list li[aria-selected=true], .ac-list li:hover { background: #f1f5f9; }
.ac-list .t { color: var(--muted); font-size: 11px; white-space: nowrap; }

.map-wrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }
.card { background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.layers { position: absolute; top: 10px; left: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; font-size: 13px; z-index: 5; }
.layers label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.legend { position: absolute; left: 10px; bottom: 28px; padding: 8px 10px; font-size: 12px; max-width: 320px; z-index: 5; }
.legend h4 { margin: 0 0 4px; font-size: 12px; }
.legend .bar { height: 10px; border-radius: 3px; margin: 3px 0; }
.legend .scale { display: flex; justify-content: space-between; color: var(--muted); }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -2px; border: 1px solid rgba(0,0,0,.15); }
.legend .row { margin: 2px 0; }
.legend .sec + .sec { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); }
.map-status { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 5px 12px; border-radius: 999px; font-size: 12px; z-index: 6; opacity: 0; transition: opacity .2s; pointer-events: none; }
.map-status.show { opacity: .92; }

.detail { position: absolute; right: 0; top: 0; bottom: 0; width: var(--detail-w); background: var(--panel);
  border-left: 1px solid var(--line); box-shadow: -4px 0 16px rgba(16,24,40,.08); overflow-y: auto; padding: 14px 16px 40px; z-index: 20; }
.detail .close { position: sticky; top: 0; float: right; }
.detail h2 { font-size: 17px; margin: 0 0 2px; padding-right: 36px; }
.detail h3 { font-size: 13px; margin: 16px 0 6px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kpi { font-size: 26px; font-weight: 700; }
.kpi-sub { color: var(--muted); font-size: 12px; }
.meta-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px; }
.meta-table th { text-align: left; font-weight: 500; color: var(--muted); padding: 3px 8px 3px 0; vertical-align: top; width: 38%; }
.meta-table td { padding: 3px 0; }
.note { font-size: 12px; color: var(--ink-2); background: #f8fafc; border-left: 3px solid #cbd5e1; padding: 6px 8px; margin: 8px 0; }
.note.warn { border-left-color: var(--warn); background: #fffbeb; }
.pos { color: var(--bad); }
.neg { color: var(--info); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 7px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 22px 1fr auto; gap: 6px; align-items: baseline; cursor: pointer; }
.list li:hover { background: #fafafa; }
.list .n { color: var(--muted); font-size: 12px; text-align: right; }
.list .v { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.list .s { color: var(--muted); font-size: 12px; }
.sec-title { font-weight: 600; margin: 14px 0 4px; display: flex; justify-content: space-between; align-items: baseline; }
.sec-title small { font-weight: 400; }

.dest-item { border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 10px; margin-bottom: 8px; cursor: pointer; }
.dest-item:hover { border-color: #cbd5e1; }
.dest-head { display: flex; justify-content: space-between; gap: 8px; }
.ev { font-size: 12px; margin-top: 4px; }
.ev .d { color: var(--muted); }
.pill { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: #dcfce7; color: #14532d; }
.pill.warn { background: #fef3c7; color: #78350f; }
.pill.bad { background: #fee2e2; color: #7f1d1d; }
.pill.unk { background: #e5e7eb; color: #374151; }
.pill.info { background: #dbeafe; color: #1e3a8a; }
.pill.demo { background: #ede9fe; color: #4c1d95; }
.src { border-bottom: 1px solid var(--line); padding: 8px 0; }
.src-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.src p { margin: 3px 0; font-size: 12px; color: var(--ink-2); }

.chart { width: 100%; height: 150px; }
.chart .axis { stroke: #cbd5e1; stroke-width: 1; }
.chart text { font-size: 10px; fill: var(--muted); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 9px 16px; border-radius: 8px; z-index: 100; max-width: 90vw; }
.maplibregl-popup-content { font-size: 12px; padding: 8px 10px; }

.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; padding: 22px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.err { color: var(--bad); min-height: 1.2em; }

.admin-wrap { max-width: 1200px; margin: 0 auto; padding: 16px; }
.admin-wrap table { width: 100%; border-collapse: collapse; background: #fff; font-size: 13px; }
.admin-wrap th, .admin-wrap td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.admin-wrap th { background: #f8fafc; font-weight: 600; position: sticky; top: 0; }
.admin-wrap section { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; }
.admin-wrap h2 { margin: 0 0 10px; font-size: 16px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

@media (max-width: 900px) {
  :root { --panel-w: 0px; }
  .only-mobile { display: inline-block; }
  .layout { grid-template-columns: 1fr; }
  .panel { position: absolute; z-index: 25; left: 0; right: 0; bottom: 0; height: 62%; border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 20px rgba(16,24,40,.15); transform: translateY(100%); transition: transform .25s; }
  .panel.open { transform: translateY(0); }
  .detail { width: 100%; top: auto; height: 70%; border-radius: 14px 14px 0 0; }
  .top-controls { overflow-x: auto; }
  .ctl-label { display: none; }
  .brand { font-size: 14px; }
  .layers { font-size: 12px; padding: 6px 8px; }
  .legend { bottom: 10px; max-width: 60%; }
  .user { display: none; }
}
@media (max-width: 560px) {
  .seg button { padding: 6px 7px; font-size: 12px; }
  .brand { display: none; }
}
