:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #0f1b2d;
  --ink-2: #4a5568;
  --ink-3: #8a94a6;
  --line: #e4e7ec;
  --brand: #0A66C2;
  --brand-2: #084E96;
  --brand-soft: #EEF5FC;
  --accent: #ea580c;
  --accent-soft: #fff1e8;
  --good: #15803d;
  --good-soft: #e8f6ec;
  --bad: #c2410c;
  --bad-soft: #fdeee6;
  --warn: #b45309;
  --side: #0c1a2b;
  --side-ink: #b9c4d4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; background: linear-gradient(to right, var(--side) 236px, var(--bg) 236px); }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 750; font-size: 18px; padding: 4px 8px 18px; }
.logo-mark { width: 32px; height: 32px; display: grid; place-items: center; }
.logo-mark svg { width: 32px; height: 32px; }
.side .label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6b7a90; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; color: var(--side-ink); padding: 8px 10px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(95, 168, 240, .16); color: #fff; }
.nav a .ico { width: 18px; text-align: center; opacity: .85; }
.nav .badge { margin-left: auto; background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }
.side-foot { margin-top: auto; padding: 10px; font-size: 12px; border-top: 1px solid rgba(255, 255, 255, .08); }
.side-foot .plan { color: #fff; font-weight: 600; }
.meter { height: 6px; background: rgba(255, 255, 255, .1); border-radius: 4px; overflow: hidden; margin: 6px 0; }
.meter > div { height: 100%; background: #5FA8F0; }
.main { padding: 22px 28px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .grow { flex: 1; }
.crumb { color: var(--ink-3); font-size: 13px; margin-bottom: 2px; }

/* ---------- elements ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px; font-weight: 550; cursor: pointer; font-size: 13px; font-family: inherit; }
.btn:hover { border-color: #cbd2dc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: default; }
input, select, textarea { font-family: inherit; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(10, 102, 194, .25); border-color: var(--brand); }
textarea { resize: vertical; width: 100%; }
label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 550; font-size: 13px; margin-bottom: 14px; }
label.field input, label.field select, label.field textarea { font-weight: 400; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.kpi .v { font-size: 26px; font-weight: 750; margin-top: 6px; letter-spacing: -.02em; }
.kpi .s { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef1f5; color: var(--ink-2); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.up { color: var(--good); font-weight: 600; }
.down { color: var(--bad); font-weight: 600; }
.tabs { display: flex; gap: 4px; background: #eceff3; padding: 3px; border-radius: 9px; }
.tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font-weight: 550; color: var(--ink-2); cursor: pointer; font-family: inherit; font-size: 13px; }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.notice { background: var(--accent-soft); color: #9a3412; border: 1px solid #fed7aa; padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.notice.info { background: var(--brand-soft); color: var(--brand-2); border-color: #C7DDF3; }
.empty { text-align: center; padding: 50px 20px; color: var(--ink-3); }
.empty h2 { color: var(--ink); margin-bottom: 8px; }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--ink-3); font-weight: 600; background: #fafbfc; position: sticky; top: 0; z-index: 1; cursor: pointer; user-select: none; }
tbody tr:hover { background: #f8fafb; }
tbody tr.click { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { font-weight: 700; font-variant-numeric: tabular-nums; }
.kw { font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.url { max-width: 240px; overflow: hidden; text-overflow: ellipsis; color: var(--ink-3); font-size: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.flag { font-size: 11px; font-weight: 700; color: var(--ink-3); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-right: 6px; }
.bar { height: 8px; background: #eef1f5; border-radius: 4px; overflow: hidden; min-width: 80px; }
.bar > div { height: 100%; background: var(--brand); }
.bar.you > div { background: var(--accent); }

/* ---------- map ---------- */
#map { height: 560px; border-radius: var(--radius); border: 1px solid var(--line); }
.legend { display: flex; gap: 12px; align-items: center; font-size: 12px; color: var(--ink-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.map-list { max-height: 560px; overflow: auto; }
.map-list .item { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.map-list .item:hover { background: #f8fafb; }
.leaflet-tooltip.rd-tip { border-radius: 8px; border: 1px solid var(--line); box-shadow: var(--shadow); padding: 8px 10px; font-family: inherit; }

/* ---------- modal & drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(12, 26, 43, .45); z-index: 1000; display: flex; align-items: flex-start; justify-content: center; padding: 50px 16px; overflow: auto; }
.modal { background: #fff; border-radius: 14px; width: min(760px, 100%); padding: 22px 24px; box-shadow: 0 20px 50px rgba(0, 0, 0, .2); }
.modal.wide { width: min(980px, 100%); }
.modal-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-f { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; align-items: center; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100%); background: #fff; z-index: 1001; box-shadow: -10px 0 40px rgba(0, 0, 0, .15); overflow: auto; padding: 22px 24px; }
.x { border: 0; background: transparent; font-size: 22px; cursor: pointer; color: var(--ink-3); line-height: 1; }
.loc-picker { display: grid; grid-template-columns: 1.2fr 1fr; gap: 14px; }
.loc-results { height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.loc-results label { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border-bottom: 1px solid #f0f2f5; cursor: pointer; font-size: 13px; }
.loc-results label:hover { background: #f8fafb; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--brand-soft); color: var(--brand-2); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 550; }
.chip button { border: 0; background: transparent; cursor: pointer; color: inherit; padding: 0; font-size: 14px; line-height: 1; }
.chip.group { background: #eef1f5; color: var(--ink-2); cursor: pointer; border: 1px solid transparent; }
.chip.group:hover { border-color: #cbd2dc; }
.selected-box { min-height: 260px; max-height: 260px; overflow: auto; border: 1px dashed var(--line); border-radius: 8px; padding: 10px; }
.est { background: #f8fafb; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; font-size: 13px; }
.serp li { padding: 6px 0; border-bottom: 1px solid #f0f2f5; }
.serp li.me { background: var(--accent-soft); font-weight: 600; }
.serp { padding-left: 22px; margin: 0; }
.answer { background: #f8fafb; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; white-space: pre-wrap; font-size: 13px; line-height: 1.5; max-height: 220px; overflow: auto; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 2000; font-size: 13px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero { background: radial-gradient(1200px 600px at 10% 10%, #0A3E73, var(--side)); color: #d7e3ef; padding: 60px; display: flex; flex-direction: column; justify-content: center; }
.auth-hero h1 { color: #fff; font-size: 34px; line-height: 1.15; margin: 20px 0 14px; }
.auth-hero ul { padding-left: 18px; line-height: 1.9; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 40px; }
.auth-form .card { width: min(400px, 100%); padding: 28px; }
.auth-form input { width: 100%; }

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; background: var(--bg); }
  .side { position: static; height: auto; }
  .g2, .loc-picker, .auth { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .span2 { grid-column: auto; }
}

.map-label { font: 700 10px Inter, sans-serif; color: #fff; text-align: center; line-height: 14px; pointer-events: none; text-shadow: 0 0 2px rgba(0,0,0,.35); }

/* Nightwatch-style rankings table */
.nw td { vertical-align: middle; padding-top: 9px; padding-bottom: 9px; }
.nw .kwc { min-width: 300px; max-width: 420px; }
.nw .kw1 { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--ink); }
.nw .kwt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nw .kw2 { font-size: 12px; color: var(--ink-3); margin-top: 3px; padding-left: 41px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 380px; }
.nw .lang { margin-left: auto; font-size: 11px; color: var(--ink-3); font-weight: 400; padding-left: 8px; }
.nw .fl { width: 18px; height: 13px; border-radius: 2px; object-fit: cover; box-shadow: 0 0 0 1px rgba(0,0,0,.08); }
.nw .gi { flex: none; }
.nw .loc { white-space: nowrap; }
.nw .rk { white-space: nowrap; }
.nw .pos.big { font-size: 17px; }
.nw .mv { font-size: 12px; font-weight: 600; white-space: nowrap; }
.nw .mv.up { color: #16a34a; } .nw .mv.down { color: #dc2626; }
.nw .dot { color: #9ca3af; }
.nw .c3 { white-space: nowrap; } .nw td.c3 { display: table-cell; } .nw td.c3 > * { display: inline-block; min-width: 42px; text-align: center; }
.nw .ai-ic { color: #7c3aed; font-size: 14px; }
.evo { display: flex; align-items: center; gap: 6px; }
.evo-l { display: flex; flex-direction: column; justify-content: space-between; height: 34px; font-size: 10px; color: var(--ink-3); text-align: right; min-width: 22px; font-variant-numeric: tabular-nums; }
