:root{
  --bg:#F1F2F4;--surface:#FFFFFF;--surface2:#F7F8FA;
  --text:#15161C;--muted:#6A6C78;--faint:#9A9CA8;
  --border:rgba(20,22,30,.10);--border2:rgba(20,22,30,.16);
  --accent:#4F46E5;--accent-soft:rgba(79,70,229,.10);
  --shadow:0 1px 2px rgba(16,16,29,.05),0 10px 30px -14px rgba(16,16,29,.18);
  --shadow-sm:0 1px 2px rgba(16,16,29,.05),0 6px 16px -10px rgba(16,16,29,.14);
}
.dark{
  --bg:#0A0B10;--surface:#15161E;--surface2:#10121A;
  --text:#EEF0F4;--muted:#9DA0AE;--faint:#6B6E7C;
  --border:rgba(255,255,255,.10);--border2:rgba(255,255,255,.18);
  --accent:#8B83FF;--accent-soft:rgba(139,131,255,.16);
  --shadow:0 1px 2px rgba(0,0,0,.4),0 14px 34px -16px rgba(0,0,0,.7);
  --shadow-sm:0 1px 2px rgba(0,0,0,.4),0 6px 16px -10px rgba(0,0,0,.6);
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent;}
html,body{height:100%;margin:0;}
body{font-family:'Manrope',-apple-system,sans-serif;background:var(--bg);color:var(--text);transition:background .3s,color .3s;}
.num{font-variant-numeric:tabular-nums;letter-spacing:-.02em;}
button{font-family:inherit;cursor:pointer;border:none;background:none;color:inherit;}
input,select,textarea{font-family:inherit;}
::-webkit-scrollbar{width:10px;height:10px;}
::-webkit-scrollbar-thumb{background:var(--border2);border-radius:8px;border:3px solid transparent;background-clip:padding-box;}

/* ---- ORIGINAL map theme: clean Carto Positron (light) / dark matter (dark) ---- */
.leaflet-tile{filter:none;}
.dark .leaflet-tile{filter:brightness(1.16) contrast(1.02);}

.app{display:none;flex-direction:column;height:100vh;}
.app.show{display:flex;}
header{display:flex;align-items:center;gap:13px;padding:11px 18px;background:var(--surface);border-bottom:1px solid var(--border);z-index:600;flex-wrap:wrap;}
.logo{display:flex;align-items:center;gap:10px;font-weight:800;font-size:16px;letter-spacing:-.02em;white-space:nowrap;}
.logo .mark{width:32px;height:32px;border-radius:9px;background:var(--accent);color:#fff;display:flex;align-items:center;justify-content:center;font-size:15px;}
nav.tabs{display:flex;gap:6px;}
.tab{padding:8px 16px;border-radius:10px;font-size:13.5px;font-weight:700;color:var(--muted);}
.tab:hover{background:var(--surface2);}
.tab.on{background:var(--accent);color:#fff;}
.search{flex:1;min-width:150px;max-width:300px;display:flex;align-items:center;gap:9px;background:var(--surface2);border:1px solid var(--border);border-radius:11px;padding:9px 12px;}
.search input{flex:1;border:none;background:transparent;color:var(--text);font-size:14px;font-weight:500;outline:none;}
.search input::placeholder{color:var(--faint);}
select.sel{padding:9px 11px;border-radius:11px;border:1px solid var(--border);background:var(--surface);color:var(--text);font-size:13px;font-weight:700;outline:none;}
.hbtn{width:40px;height:40px;border-radius:11px;border:1px solid var(--border);background:var(--surface);display:flex;align-items:center;justify-content:center;color:var(--text);}
.hbtn:hover{border-color:var(--border2);}
.btn-primary{display:inline-flex;align-items:center;gap:7px;padding:10px 15px;border-radius:11px;background:var(--accent);color:#fff;font-weight:700;font-size:14px;box-shadow:0 8px 20px -8px var(--accent);white-space:nowrap;}
.btn-primary:hover{filter:brightness(1.06);}
.btn-ghost{display:inline-flex;align-items:center;gap:7px;padding:9px 13px;border-radius:11px;border:1px solid var(--border);background:var(--surface);color:var(--text);font-weight:700;font-size:13px;white-space:nowrap;}
.btn-ghost:hover{border-color:var(--border2);}
.userchip{display:flex;align-items:center;gap:8px;font-size:12.5px;font-weight:700;color:var(--muted);}

.filterbar{display:flex;align-items:center;gap:8px;padding:9px 18px;background:var(--surface);border-bottom:1px solid var(--border);flex-wrap:wrap;}
.chips{display:flex;gap:6px;flex-wrap:wrap;}
.chip{padding:6px 12px;border-radius:9px;font-size:12.5px;font-weight:700;border:1px solid var(--border);background:var(--surface);color:var(--muted);white-space:nowrap;}
.chip:hover{border-color:var(--border2);}
.chip.on{background:var(--accent);color:#fff;border-color:transparent;}
.vdiv{width:1px;height:22px;background:var(--border);margin:0 2px;}

.main{flex:1;display:flex;min-height:0;position:relative;}
#map{flex:1;height:100%;background:var(--surface2);z-index:1;}
.panel{flex-shrink:0;height:100%;background:var(--surface);border-left:1px solid var(--border);overflow:hidden;}

.clients-layout{display:flex;height:100%;}
.clients-list{width:380px;flex-shrink:0;border-right:1px solid var(--border);overflow-y:auto;height:100%;}
.clients-detail{flex:1;overflow-y:auto;height:100%;}
.empty-detail{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;color:var(--faint);font-weight:700;}
.scrollpane{overflow-y:auto;height:100%;}

.stats{display:grid;grid-template-columns:repeat(3,1fr);gap:10px;padding:18px 18px 8px;}
.stat{background:var(--surface2);border:1px solid var(--border);border-radius:14px;padding:12px 13px;}
.stat .v{font-size:23px;font-weight:800;line-height:1;}
.stat .l{font-size:11.5px;color:var(--muted);font-weight:600;margin-top:5px;}
.panel-head{display:flex;align-items:center;justify-content:space-between;padding:16px 18px 8px;}
.panel-head h2{margin:0;font-size:16px;font-weight:800;letter-spacing:-.02em;}
.list{padding:8px 18px 28px;display:flex;flex-direction:column;gap:10px;}

.card{background:var(--surface);border:1px solid var(--border);border-radius:16px;padding:14px;box-shadow:var(--shadow-sm);transition:.15s;cursor:pointer;}
.card:hover{transform:translateY(-2px);border-color:var(--border2);}
.card.active{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-soft);}
.card-top{display:flex;align-items:flex-start;gap:11px;}
.lvl{width:30px;height:30px;border-radius:10px;display:flex;align-items:center;justify-content:center;font-weight:800;font-size:14px;flex-shrink:0;}
.repdot{width:9px;height:9px;border-radius:50%;display:inline-block;flex-shrink:0;}
.card .nm{font-weight:800;font-size:15.5px;letter-spacing:-.01em;}
.card .ind{font-size:12px;color:var(--muted);font-weight:600;margin-top:1px;display:flex;align-items:center;gap:6px;}
.meta{display:flex;flex-wrap:wrap;gap:4px 14px;margin:10px 0;font-size:12px;color:var(--muted);font-weight:600;}
.meta span{display:flex;align-items:center;gap:5px;}
.pill{display:inline-block;font-size:11px;font-weight:700;padding:4px 9px;border-radius:999px;}
.card-actions{display:flex;gap:7px;margin-top:11px;}
.mini{flex:1;display:flex;align-items:center;justify-content:center;gap:5px;padding:8px;border-radius:10px;border:1px solid var(--border);background:var(--surface2);font-size:12px;font-weight:700;color:var(--text);}
.mini:hover{border-color:var(--border2);}
.mini.go{background:var(--accent);color:#fff;border-color:transparent;}

.dview{padding:18px;}
.back{display:inline-flex;align-items:center;gap:6px;font-weight:700;font-size:13.5px;color:var(--muted);margin-bottom:14px;}
.hero{background:var(--surface2);border:1px solid var(--border);border-radius:18px;padding:16px;}
.hero h2{margin:2px 0 0;font-size:21px;font-weight:800;letter-spacing:-.03em;}
.sectitle{font-size:13.5px;font-weight:800;letter-spacing:-.01em;margin:22px 0 10px;}
.info-row{display:flex;justify-content:space-between;gap:14px;padding:11px 0;border-bottom:1px solid var(--border);font-size:13.5px;}
.info-row:last-child{border-bottom:none;}
.info-row .k{color:var(--muted);font-weight:600;}
.info-row .v{font-weight:700;text-align:right;word-break:break-word;}
.tl-item{display:flex;gap:13px;}
.tl-dot{display:flex;flex-direction:column;align-items:center;}
.tl-dot i{width:12px;height:12px;border-radius:50%;border:3px solid var(--surface);box-shadow:0 0 0 1px var(--border);margin-top:5px;display:block;}
.tl-line{width:2px;flex:1;background:var(--border);margin-top:2px;}
.tl-body{flex:1;background:var(--surface2);border:1px solid var(--border);border-radius:14px;padding:12px 13px;margin-bottom:10px;}
.tl-date{font-size:11.5px;font-weight:700;}
.tl-title{font-weight:800;font-size:14px;margin:3px 0;letter-spacing:-.01em;}
.tl-text{font-size:13px;color:var(--muted);font-weight:500;line-height:1.45;}

.field{margin-bottom:13px;}
.field label{display:block;font-size:12.5px;font-weight:700;color:var(--muted);margin-bottom:6px;}
.field input,.field select{width:100%;padding:11px 13px;border-radius:11px;border:1px solid var(--border);background:var(--surface);color:var(--text);font-size:14.5px;font-weight:600;outline:none;}
.field input:focus{border-color:var(--accent);box-shadow:0 0 0 4px var(--accent-soft);}
.opts{display:flex;gap:7px;flex-wrap:wrap;}
.opt{padding:9px 13px;border-radius:11px;font-size:13px;font-weight:700;border:1px solid var(--border);background:var(--surface);color:var(--muted);}
.opt.on{background:var(--accent);color:#fff;border-color:transparent;}
.lvlopt{flex:1;min-width:60px;text-align:center;padding:10px 0;border-radius:11px;border:1px solid var(--border);background:var(--surface);}
.loc-box{border:1px solid var(--border);border-radius:13px;padding:13px;background:var(--surface2);}
.loc-row{display:flex;gap:8px;margin-top:9px;}
.loc-row input{flex:1;}
.hint{font-size:11.5px;color:var(--faint);font-weight:600;line-height:1.55;margin-top:8px;}
.coord-show{display:flex;align-items:center;gap:8px;margin-top:10px;font-size:13px;font-weight:700;}
.coord-ok{color:#10B981;}
.save-bar{display:flex;gap:10px;margin-top:8px;}
.save-bar .btn-primary{flex:1;justify-content:center;padding:13px;}
.spin{width:15px;height:15px;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;display:inline-block;animation:sp .7s linear infinite;}
@keyframes sp{to{transform:rotate(360deg)}}

.matrix{width:100%;border-collapse:separate;border-spacing:0;font-size:13px;}
.matrix th,.matrix td{padding:11px 8px;border-bottom:1px solid var(--border);text-align:center;}
.matrix th:first-child,.matrix td:first-child{text-align:left;font-weight:700;}
.matrix thead th{font-size:12px;color:var(--muted);font-weight:800;}
.cbx{width:22px;height:22px;border-radius:7px;border:2px solid var(--border2);display:inline-flex;align-items:center;justify-content:center;color:#fff;cursor:pointer;}
.cbx.on{background:var(--accent);border-color:var(--accent);}
.cbx.lock{background:var(--muted);border-color:var(--muted);opacity:.6;cursor:not-allowed;}
.team-row{display:flex;align-items:center;gap:10px;padding:10px 0;border-bottom:1px solid var(--border);}

.pin-wrap{width:34px;height:44px;position:relative;}
.pin-body{width:30px;height:30px;border-radius:50% 50% 50% 0;transform:rotate(-45deg);border:2.5px solid #fff;box-shadow:0 3px 8px rgba(0,0,0,.4);position:absolute;left:2px;top:2px;display:flex;align-items:center;justify-content:center;}
.pin-body b{transform:rotate(45deg);font-size:13px;font-weight:800;}
.pin-seq{position:absolute;top:-2px;right:-2px;min-width:17px;height:17px;padding:0 3px;border-radius:9px;background:#fff;font-size:10px;font-weight:800;display:flex;align-items:center;justify-content:center;box-shadow:0 1px 3px rgba(0,0,0,.35);}
.pin-wrap.sel .pin-body{box-shadow:0 0 0 5px rgba(79,70,229,.4),0 3px 8px rgba(0,0,0,.4);}
.pin-temp .pin-body{background:var(--accent);border-color:#fff;animation:pulse 1.4s ease-in-out infinite;}
.pin-temp .pin-body b{color:#fff;}
@keyframes pulse{0%,100%{box-shadow:0 0 0 0 rgba(79,70,229,.5)}50%{box-shadow:0 0 0 9px rgba(79,70,229,0)}}
.cluster-pie{width:48px;height:48px;border-radius:50%;display:flex;align-items:center;justify-content:center;box-shadow:0 4px 12px rgba(0,0,0,.35);border:3px solid var(--surface);}
.cluster-core{width:30px;height:30px;border-radius:50%;background:var(--surface);color:var(--text);display:flex;align-items:center;justify-content:center;font-size:14px;font-weight:800;}
.leaflet-popup-content-wrapper{border-radius:14px;}
.pop{min-width:185px;font-family:'Manrope',sans-serif;}
.pop .pn{font-weight:800;font-size:14.5px;margin-bottom:2px;}
.pop .pm{font-size:12px;color:#666;margin-bottom:8px;}
.pop button{width:100%;padding:7px;border-radius:9px;background:#4F46E5;color:#fff;font-weight:700;font-size:12.5px;}

.map-tools{position:absolute;left:14px;top:14px;z-index:500;display:flex;flex-direction:column;gap:8px;}
.map-tool{background:var(--surface);border:1px solid var(--border);border-radius:11px;padding:9px 12px;font-size:13px;font-weight:700;color:var(--text);box-shadow:var(--shadow-sm);display:flex;align-items:center;gap:7px;}
.map-tool:hover{border-color:var(--border2);}
.legend{position:absolute;left:14px;bottom:18px;z-index:500;background:var(--surface);border:1px solid var(--border);border-radius:12px;padding:11px 13px;box-shadow:var(--shadow-sm);max-width:230px;}
.legend .lt{font-size:10px;font-weight:800;color:var(--muted);text-transform:uppercase;letter-spacing:.04em;margin:0 0 6px;}
.legend .lr{display:flex;align-items:center;gap:7px;font-size:12px;font-weight:700;margin:3px 0;}
.swatch{width:14px;height:14px;border-radius:4px;border:2px solid #fff;box-shadow:0 0 0 1px var(--border);flex-shrink:0;}
.picking-banner{position:absolute;top:14px;left:50%;transform:translateX(-50%);z-index:500;background:var(--accent);color:#fff;padding:10px 18px;border-radius:12px;font-weight:700;font-size:13.5px;box-shadow:var(--shadow);display:none;align-items:center;gap:8px;}
svg.ic{width:1em;height:1em;display:inline-block;vertical-align:-.12em;}

/* ---- LOGIN ---- */
#login{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:var(--bg);z-index:2000;padding:20px;}
.login-card{width:100%;max-width:380px;background:var(--surface);border:1px solid var(--border);border-radius:22px;padding:30px;box-shadow:var(--shadow);}
.login-card h1{margin:0 0 4px;font-size:23px;font-weight:800;letter-spacing:-.03em;display:flex;align-items:center;gap:10px;}
.login-card p{color:var(--muted);font-size:13.5px;margin:0 0 22px;}
.login-card .field{margin-bottom:14px;}
.login-err{color:#EF4444;font-size:13px;font-weight:700;margin-top:6px;min-height:18px;}
.login-hint{margin-top:18px;font-size:11.5px;color:var(--faint);line-height:1.6;}

@media(max-width:860px){
  .main{flex-direction:column;}
  #map{height:46vh;flex:none;}
  .panel{width:100%!important;border-left:none;border-top:1px solid var(--border);}
  .clients-layout{flex-direction:column;}
  .clients-list{width:100%;border-right:none;border-bottom:1px solid var(--border);max-height:42vh;}
}
