:root{
  --bg:#f4f6f9; --card:#ffffff; --line:#e3e8ef;
  --ink:#16202e; --gray:#5f6b78; --muted:#8a96a3;
  --blue:#143c8c; --orange:#f15a22; --violet:#7b2ff7;
  --shadow:0 10px 30px rgba(16,32,46,.08);
  --font:'Montserrat',-apple-system,Segoe UI,Roboto,Arial,sans-serif;
}
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%}
body{font-family:var(--font);color:var(--ink);background:var(--bg);overflow:hidden}

/* layout: header + 3 columns */
.app{display:grid;grid-template-rows:56px 1fr;height:100vh}
.topbar{
  display:flex;align-items:center;gap:14px;padding:0 18px;background:var(--card);
  border-bottom:1px solid var(--line);box-shadow:var(--shadow);z-index:10}
.brand{display:flex;align-items:center;gap:10px;font-weight:800;letter-spacing:.02em}
.brand .logo{width:30px;height:30px;border-radius:8px;background:linear-gradient(135deg,var(--blue),var(--violet));
  display:grid;place-items:center;color:#fff;font-size:14px;font-weight:900}
.brand small{display:block;font-weight:600;color:var(--muted);font-size:11px;letter-spacing:.04em}
.topbar .spacer{flex:1}
.topbar .badge{font-size:11px;color:var(--gray);background:#eef2f8;border:1px solid var(--line);
  padding:5px 10px;border-radius:20px}

.workspace{display:grid;grid-template-columns:300px 1fr 380px;min-height:0}

/* sidebar */
.sidebar{background:var(--card);border-right:1px solid var(--line);padding:18px;overflow:auto}
.side-label{font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--muted);margin:0 0 8px}
.select{width:100%;padding:11px 12px;border:1px solid var(--line);border-radius:10px;background:#fff;
  font-family:inherit;font-size:14px;font-weight:600;color:var(--ink);margin-bottom:22px;cursor:pointer}
.toggle{display:flex;align-items:center;gap:10px;padding:9px 0;cursor:pointer;font-size:13px;color:var(--ink)}
.toggle input{accent-color:var(--blue);width:16px;height:16px;cursor:pointer}
.toggle .dot{width:12px;height:12px;border-radius:50%;border:2px solid #fff;box-shadow:0 0 0 1px var(--line)}
.legend-note{margin-top:22px;font-size:12px;color:var(--gray);line-height:1.5;
  background:#f7f9fc;border:1px solid var(--line);border-radius:10px;padding:12px}

/* map */
.map-wrap{position:relative;min-width:0}
#map{position:absolute;inset:0}
.map-error{position:absolute;inset:0;display:grid;place-items:center;text-align:center;padding:40px;
  color:var(--gray);font-size:14px;background:#eef2f8}

/* right panel */
.panel{background:var(--card);border-left:1px solid var(--line);padding:20px;overflow:auto}
.panel-head{margin-bottom:16px}
.panel-kicker{font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--muted);font-weight:700}
.panel h2{font-size:20px;line-height:1.2;margin-top:4px}
.cand-addr{font-size:12px;color:var(--gray);margin-top:4px}

.kpi{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:18px}
.kpi-card{background:#f7f9fc;border:1px solid var(--line);border-radius:12px;padding:14px}
.kpi-blue{background:linear-gradient(135deg,#eaf0ff,#f7f9ff);border-color:#d4e0ff}
.kpi-violet{background:linear-gradient(135deg,#f1eaff,#faf7ff);border-color:#e2d4ff}
.kpi-val{font-size:24px;font-weight:900;line-height:1}
.kpi-val span{font-size:13px;font-weight:700;color:var(--gray)}
.kpi-cap{font-size:11px;color:var(--gray);margin-top:6px}

.block-title{font-size:13px;text-transform:uppercase;letter-spacing:.05em;color:var(--ink);
  margin:18px 0 10px;padding-bottom:6px;border-bottom:1px solid var(--line)}

.cand-table{width:100%;border-collapse:collapse;font-size:13px}
.cand-table th{text-align:left;font-size:10px;text-transform:uppercase;letter-spacing:.05em;
  color:var(--muted);padding:6px 6px;border-bottom:1px solid var(--line)}
.cand-table td{padding:9px 6px;border-bottom:1px solid #eef2f7;vertical-align:top;cursor:pointer}
.cand-table tr:hover td{background:#f7f9fc}
.cand-table .rank{color:var(--muted);font-weight:800;width:22px}
.cand-table .num{text-align:right;white-space:nowrap}
.cand-name{font-weight:700}
.cand-table .empty{text-align:center;color:var(--muted);cursor:default;padding:18px}

.score-row{margin-bottom:12px}
.score-top{display:flex;justify-content:space-between;font-size:12px;margin-bottom:5px}
.score-top b{font-weight:800}
.score-bar{height:8px;background:#eef2f7;border-radius:6px;overflow:hidden}
.score-bar i{display:block;height:100%;border-radius:6px}

.info-row{display:flex;justify-content:space-between;gap:12px;font-size:13px;
  padding:9px 0;border-bottom:1px solid #eef2f7}
.info-row span{color:var(--gray)}
.info-row b{text-align:right}

.route-btn{display:block;text-align:center;margin-top:16px;padding:11px;border-radius:10px;
  background:var(--blue);color:#fff;font-weight:700;font-size:13px;text-decoration:none}
.route-btn:hover{background:#0f2f70}
.back{background:none;border:none;color:var(--blue);font-family:inherit;font-size:13px;
  font-weight:700;cursor:pointer;margin-bottom:12px;padding:0}
.hint{font-size:11px;color:var(--muted);line-height:1.5;margin-top:14px}

/* зоны: переключатель и легенда */
.toggle-zones{margin-top:6px}
.toggle-zones .dot{width:24px;border-radius:4px}
.zone-legend{margin:8px 0 18px;padding:10px 12px;background:#f7f9fc;border:1px solid var(--line);border-radius:10px}
.zone-legend .zl-title{font-size:10px;text-transform:uppercase;letter-spacing:.05em;color:var(--muted);margin-bottom:8px}
.zone-legend .zl{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--ink);margin:4px 0}
.zone-legend .zl i{width:16px;height:12px;border-radius:3px;display:inline-block;flex:none}

/* переключатель раскраски зон */
.zone-mode-row{margin:6px 0 4px;display:flex;flex-direction:column;gap:4px}
.zone-mode-row label{font-size:10px;text-transform:uppercase;letter-spacing:.05em;color:var(--muted)}
.zone-mode-row select{width:100%;padding:6px 8px;border:1px solid var(--line);border-radius:8px;background:#fff;color:var(--ink);font-size:13px}

/* AFS Index */
.afs-badge{display:inline-flex;align-items:baseline;gap:6px}
.afs-comp{padding:6px 10px;margin:5px 0;background:#f7f9fc;border-radius:8px}
.afs-comp .ac-top{display:flex;justify-content:space-between;font-size:12px}
.afs-comp .ac-bar{height:6px;border-radius:3px;background:#e6ebf5;margin-top:4px;overflow:hidden}
.afs-comp .ac-bar i{display:block;height:100%;background:#143c8c}

.factor-group{margin:6px 0 10px}
.factor-group .fg-title{font-size:11px;font-weight:700;color:var(--muted);margin:6px 0 4px}

.anchor-note{margin:8px 0;padding:8px 10px;background:#f3eefe;border-left:3px solid #7b2ff7;border-radius:0 8px 8px 0;font-size:12.5px;color:#3a2a66}
.wave-badge{display:inline-block;margin:6px 0;padding:5px 12px;border-radius:20px;font-size:12px;font-weight:700;color:#fff}
.wave-badge.wave-1{background:#5b1fb0}
.wave-badge.wave-2{background:#9a6ce0}
.wave-badge.wave-3{background:#c3aef0;color:#3a2a66}
.wave-tag{display:inline-block;margin-top:3px;padding:1px 7px;border-radius:10px;font-size:10px;font-weight:700;color:#fff}
.wave-tag.wave-1{background:#5b1fb0}
.wave-tag.wave-2{background:#9a6ce0}
.wave-tag.wave-3{background:#c3aef0;color:#3a2a66}

.place-btn{display:block;width:100%;margin:6px 0 12px;padding:11px 14px;border:0;border-radius:10px;background:#143c8c;color:#fff;font-size:13px;font-weight:700;cursor:pointer}
.place-btn:hover{background:#1a4aad}
.place-hint{position:absolute;top:14px;left:50%;transform:translateX(-50%);z-index:1000;display:none;padding:9px 16px;background:#143c8c;color:#fff;border-radius:20px;font-size:13px;font-weight:600;box-shadow:0 4px 14px rgba(0,0,0,.25)}
.manual-pin{display:flex;align-items:center;justify-content:center;width:26px;height:26px;border-radius:50%;background:#143c8c;color:#fff;font-size:15px;border:2px solid #fff;box-shadow:0 2px 6px rgba(0,0,0,.35)}
.verdict{margin:8px 0;padding:10px 12px;border-radius:10px;font-size:13.5px;font-weight:700}
.verdict-good{background:#e3f6ea;color:#0e7a3b;border-left:4px solid #1aa251}
.verdict-mid{background:#fff5e0;color:#9a6a0a;border-left:4px solid #e0982a}
.verdict-bad{background:#fdeaea;color:#b32626;border-left:4px solid #c0392b}
.route-btn-ghost{background:#eef1f7;color:#143c8c}
.route-btn-pin{background:#1aa251;color:#fff}
.route-btn-pin:hover{background:#159048}
.route-btn-unpin{background:#fdeaea;color:#b32626}
.route-btn-unpin:hover{background:#f8d7d7}
.pinned-pin{display:flex;align-items:center;justify-content:center;width:26px;height:26px;border-radius:50%;background:#1aa251;color:#fff;font-size:15px;border:2px solid #fff;box-shadow:0 2px 6px rgba(0,0,0,.35)}
.prospect-star{display:flex;align-items:center;justify-content:center;width:24px;height:24px;background:transparent;cursor:pointer}
.prospect-star::before{content:"⭐";position:absolute;font-size:22px;line-height:1;filter:drop-shadow(0 1px 2px rgba(0,0,0,.5))}
.prospect-star .ps-rank{position:relative;z-index:1;font-size:10px;font-weight:800;color:#5a3b00;margin-top:1px}
.gw-pin{display:flex;align-items:center;justify-content:center;width:28px;height:28px;border-radius:50%;background:#0aa6c2;color:#fff;font-size:15px;border:2px solid #fff;box-shadow:0 2px 6px rgba(0,0,0,.4);cursor:pointer}

/* ---------- экран входа ---------- */
#auth-gate{position:fixed;inset:0;z-index:9999;display:grid;place-items:center;
  background:linear-gradient(135deg,#0e1a33,#1a1040)}
#auth-gate .auth-card{background:#fff;border-radius:16px;padding:34px 30px;width:340px;max-width:92vw;
  box-shadow:0 20px 60px rgba(0,0,0,.4);text-align:center}
#auth-gate .auth-logo{width:52px;height:52px;border-radius:12px;margin:0 auto 14px;
  background:linear-gradient(135deg,#143c8c,#7b2ff7);display:grid;place-items:center;color:#fff;font-weight:900;font-size:20px}
#auth-gate h1{font-size:18px;margin:0 0 4px}
#auth-gate .auth-sub{color:#8a96a3;font-size:12px;margin-bottom:20px}
#auth-gate form{display:flex;flex-direction:column;gap:10px}
#auth-gate input{padding:12px 14px;border:1px solid #e3e8ef;border-radius:10px;font-family:inherit;font-size:14px}
#auth-gate input:focus{outline:none;border-color:#143c8c}
#auth-gate #auth-btn{margin-top:4px;padding:12px;border:none;border-radius:10px;cursor:pointer;
  background:#143c8c;color:#fff;font-weight:700;font-size:14px}
#auth-gate #auth-btn:disabled{opacity:.6;cursor:default}
#auth-gate .auth-msg{font-size:12px;color:#8a96a3;min-height:16px;margin-top:2px}
#auth-gate .auth-msg.err{color:#d73027}
#auth-gate .auth-msg.ok{color:#1a9850}
#auth-gate .auth-link{font-size:12px;color:#143c8c;text-decoration:none}
#auth-gate .auth-link:hover{text-decoration:underline}

/* ---------- бейдж пользователя в шапке ---------- */
.user-badge{display:flex;align-items:center;gap:8px;font-size:12px;color:#5f6b78}
.user-badge .ub-name{font-weight:700;color:#16202e}
.user-badge .ub-role{background:#eef2f8;border:1px solid #e3e8ef;border-radius:20px;padding:2px 8px;font-size:10px;text-transform:uppercase;letter-spacing:.03em}
.user-badge #logout-btn{border:1px solid #e3e8ef;background:#fff;border-radius:8px;padding:5px 10px;cursor:pointer;font-family:inherit;font-size:12px;color:#5f6b78}
.user-badge #logout-btn:hover{background:#f7f9fc;color:#d73027}
.pin-del{border:0;background:#fdeaea;color:#b32626;border-radius:6px;padding:2px 7px;cursor:pointer;font-weight:700}
.pin-del:hover{background:#f8d7d7}
.cl-tip{background:rgba(255,255,255,.9);border:0;box-shadow:none;font-size:10px;padding:0 3px;color:#3a3f55}
.reasons{margin:6px 0 10px;padding-left:0;list-style:none}
.reasons li{position:relative;padding:6px 8px 6px 22px;margin:4px 0;font-size:12.5px;line-height:1.4;background:#f7f9fc;border-radius:8px}
.reasons li:before{content:"✓";position:absolute;left:8px;top:6px;color:#1aa251;font-weight:700}

/* воронка L1..L4 */
.funnel-row{padding:8px 10px;margin:6px 0;border-left:3px solid var(--blue);background:#f7f9fc;border-radius:0 8px 8px 0}
.funnel-top{display:flex;justify-content:space-between;font-size:13px}
.funnel-top b{font-weight:800}
.funnel-note{font-size:11px;color:var(--muted);margin-top:3px}

/* иконки кластеров */
.cluster-icon{background:none;border:none}
.cl-pin{display:inline-block;font-size:10px;font-weight:800;color:#fff;padding:2px 5px;border-radius:9px;
  white-space:nowrap;box-shadow:0 1px 3px rgba(0,0,0,.3);border:1.5px solid #fff}
.cl-snt{background:#2e8b57}
.cl-vil{background:#8a5a2b}

/* склад */
.wh-icon{background:none;border:none}
.wh-pin{display:inline-block;font-size:10px;font-weight:800;color:#fff;background:#0a7d4d;padding:3px 7px;border-radius:5px;
  white-space:nowrap;box-shadow:0 1px 4px rgba(0,0,0,.35);border:1.5px solid #fff;letter-spacing:.03em}

/* методология / ссылки */
.m-link{border:none;background:#eef2fb;color:var(--blue);font-size:11px;font-weight:700;padding:3px 8px;border-radius:6px;cursor:pointer;margin-left:6px}
.m-link:hover{background:#e0e7f7}
.m-formula{background:#0f1830;color:#dbe4ff;font-size:12.5px;line-height:1.7;padding:12px 14px;border-radius:10px;margin:6px 0 10px;font-family:ui-monospace,Menlo,Consolas,monospace}

@media (max-width:1200px){
  .workspace{grid-template-columns:260px 1fr 340px}
}
