/* ============================================================
   GDS Lead Intelligence Cockpit — GDS brand (navy / blue / gray)
   ============================================================ */
:root {
  --navy-900: #0a1830;
  --navy-800: #0e2147;
  --navy-700: #143063;
  --navy-600: #1b3f80;
  --blue-500: #2f6fd0;
  --blue-400: #4a89e0;
  --blue-300: #8ab4ee;
  --blue-50: #eef4fd;

  --gray-50: #f5f7fa;
  --gray-100: #eef1f6;
  --gray-200: #e1e6ee;
  --gray-300: #cdd5e1;
  --gray-400: #9aa6b8;
  --gray-500: #6b7787;
  --gray-600: #4b5666;
  --ink: #16202f;

  --high: #d6483b;
  --high-bg: #fbeae8;
  --med: #e08a12;
  --med-bg: #fdf2e0;
  --low: #2a9d57;
  --low-bg: #e7f5ed;

  --white: #fff;
  --radius: 11px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 3px rgba(10, 24, 48, 0.08);
  --shadow: 0 8px 26px rgba(10, 24, 48, 0.14);
  --shadow-lg: 0 24px 60px rgba(10, 24, 48, 0.28);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --t: 0.18s ease;
  --header-h: 60px;
  --kpi-h: 78px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font); color: var(--ink); background: var(--gray-100);
  font-size: 14px; line-height: 1.45; overflow: hidden;
}
button, input, select { font: inherit; }
a { color: var(--blue-500); text-decoration: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

.app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- Header ---------- */
.hdr {
  height: var(--header-h); background: var(--navy-800); color: #fff; display: flex; align-items: center;
  gap: 1.2rem; padding: 0 1.1rem; flex: none; box-shadow: var(--shadow-sm); z-index: 40;
}
.logo { display: flex; align-items: center; gap: 0.55rem; }
.logo svg { height: 30px; width: auto; }
.logo .wm { font-weight: 800; font-size: 1.5rem; letter-spacing: -0.02em; color: #fff; }
.logo .sub { font-size: 0.62rem; letter-spacing: 0.18em; color: var(--blue-300); text-transform: uppercase; font-weight: 600; border-left: 1px solid rgba(255,255,255,0.25); padding-left: 0.55rem; margin-left: 0.15rem; }
.hdr__search { flex: 1; max-width: 460px; position: relative; }
.hdr__search input {
  width: 100%; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.16); color: #fff;
  padding: 0.5rem 0.8rem 0.5rem 2.1rem; border-radius: 8px; transition: var(--t);
}
.hdr__search input::placeholder { color: rgba(255,255,255,0.55); }
.hdr__search input:focus { outline: none; background: rgba(255,255,255,0.16); border-color: var(--blue-400); }
.hdr__search svg { position: absolute; left: 0.65rem; top: 50%; transform: translateY(-50%); color: rgba(255,255,255,0.6); }
.hdr__right { display: flex; align-items: center; gap: 0.9rem; margin-left: auto; }
.hdr__btn { background: var(--blue-500); color: #fff; border: 0; padding: 0.5rem 0.95rem; border-radius: 8px; font-weight: 600; cursor: pointer; transition: var(--t); display: inline-flex; align-items: center; gap: 0.4rem; }
.hdr__btn:hover { background: var(--blue-400); }
.hdr__btn--ghost { background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.18); }
.hdr__btn--ghost:hover { background: rgba(255,255,255,0.16); }
.srctoggle { display: flex; border: 1px solid rgba(255,255,255,0.2); border-radius: 8px; overflow: hidden; }
.srctoggle button { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.8); border: 0; padding: 0.45rem 0.8rem; font-weight: 600; font-size: 0.85rem; cursor: pointer; transition: var(--t); white-space: nowrap; }
.srctoggle button.active { background: var(--blue-500); color: #fff; }
.srctoggle button:hover:not(.active) { background: rgba(255,255,255,0.12); }
.srcmeta { font-size: 0.78rem; color: var(--gray-500); display: inline-flex; align-items: center; gap: 0.35rem; }
.srcmeta .live { color: var(--blue-500); font-weight: 700; }
.hdr__user { width: 34px; height: 34px; border-radius: 50%; background: var(--blue-500); display: grid; place-items: center; font-weight: 700; font-size: 0.8rem; color: #fff; }

/* ---------- KPI bar ---------- */
.kpis { height: var(--kpi-h); background: #fff; border-bottom: 1px solid var(--gray-200); display: flex; align-items: stretch; flex: none; overflow-x: auto; }
.kpi { padding: 0.8rem 1.3rem; display: flex; flex-direction: column; justify-content: center; border-right: 1px solid var(--gray-100); min-width: 150px; }
.kpi .label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gray-500); font-weight: 600; }
.kpi .val { font-size: 1.55rem; font-weight: 800; color: var(--navy-800); line-height: 1.1; margin-top: 0.15rem; }
.kpi .val.high { color: var(--high); }
.kpi .delta { font-size: 0.72rem; color: var(--gray-500); }
.kpi .delta b { color: var(--low); }
.kpi--spark { flex: 1; min-width: 220px; }

/* ---------- Body layout ---------- */
.body { flex: 1; display: grid; grid-template-columns: 290px 1fr; min-height: 0; }

/* ---------- Sidebar / filters ---------- */
.side { background: #fff; border-right: 1px solid var(--gray-200); overflow-y: auto; display: flex; flex-direction: column; }
.seg { display: flex; padding: 0.7rem; gap: 0.4rem; border-bottom: 1px solid var(--gray-100); position: sticky; top: 0; background: #fff; z-index: 5; }
.seg button { flex: 1; padding: 0.55rem; border: 1px solid var(--gray-200); background: var(--gray-50); border-radius: 8px; font-weight: 600; font-size: 0.8rem; color: var(--gray-600); cursor: pointer; transition: var(--t); display: flex; flex-direction: column; align-items: center; gap: 0.2rem; }
.seg button .c { font-size: 0.68rem; color: var(--gray-400); font-weight: 600; }
.seg button.active { background: var(--navy-800); color: #fff; border-color: var(--navy-800); }
.seg button.active .c { color: var(--blue-300); }

.filters { padding: 0.4rem 0.95rem 1.4rem; }
.fgroup { padding: 0.85rem 0; border-bottom: 1px solid var(--gray-100); }
.fgroup > label, .fgroup > .flabel { display: block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--gray-500); font-weight: 700; margin-bottom: 0.5rem; }
.fselect, .frange { width: 100%; }
select.fselect { padding: 0.5rem 0.6rem; border: 1px solid var(--gray-300); border-radius: 7px; background: #fff; color: var(--ink); }
select.fselect:focus { outline: none; border-color: var(--blue-500); }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip { padding: 0.32rem 0.6rem; border-radius: 999px; border: 1px solid var(--gray-300); background: #fff; font-size: 0.74rem; font-weight: 600; color: var(--gray-600); cursor: pointer; transition: var(--t); }
.chip:hover { border-color: var(--gray-400); }
.chip.active { color: #fff; border-color: transparent; }
.chip.active[data-v="all"] { background: var(--navy-700); }
.chip.active[data-v="high"] { background: var(--high); }
.chip.active[data-v="medium"] { background: var(--med); }
.chip.active[data-v="low"] { background: var(--low); }
.range__val { font-size: 0.74rem; color: var(--navy-700); font-weight: 700; float: right; }
input[type=range] { -webkit-appearance: none; appearance: none; height: 5px; background: var(--gray-200); border-radius: 4px; margin: 0.6rem 0 0.2rem; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 17px; height: 17px; border-radius: 50%; background: var(--blue-500); cursor: pointer; border: 2px solid #fff; box-shadow: var(--shadow-sm); }
input[type=range]::-moz-range-thumb { width: 15px; height: 15px; border-radius: 50%; background: var(--blue-500); cursor: pointer; border: 2px solid #fff; }
.fbtn { width: 100%; margin-top: 1rem; padding: 0.55rem; background: var(--gray-100); border: 1px solid var(--gray-200); border-radius: 8px; color: var(--gray-600); font-weight: 600; cursor: pointer; transition: var(--t); }
.fbtn:hover { background: var(--gray-200); }

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--gray-100); }
.toolbar { display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 1rem; background: #fff; border-bottom: 1px solid var(--gray-200); flex: none; }
.toolbar .count { font-weight: 700; color: var(--navy-800); }
.toolbar .count small { font-weight: 500; color: var(--gray-500); }
.viewtoggle { display: flex; border: 1px solid var(--gray-300); border-radius: 8px; overflow: hidden; margin-left: auto; }
.viewtoggle button { padding: 0.42rem 0.85rem; border: 0; background: #fff; color: var(--gray-600); font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 0.35rem; transition: var(--t); }
.viewtoggle button.active { background: var(--navy-800); color: #fff; }
.sortsel { padding: 0.42rem 0.6rem; border: 1px solid var(--gray-300); border-radius: 8px; background: #fff; }

/* isolate: traps Leaflet's internal high z-indexes (panes/controls up to ~1000)
   so they can't paint over the detail drawer / selection bar / toasts. */
.stage { flex: 1; position: relative; min-height: 0; isolation: isolate; }
#map { position: absolute; inset: 0; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }
#view-table { overflow: auto; background: var(--gray-100); }

/* map legend */
.legend { position: absolute; bottom: 16px; left: 16px; z-index: 500; background: #fff; border-radius: 10px; box-shadow: var(--shadow); padding: 0.7rem 0.9rem; font-size: 0.78rem; }
.legend b { display: block; font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--gray-500); margin-bottom: 0.45rem; }
.legend .row { display: flex; align-items: center; gap: 0.5rem; padding: 0.12rem 0; color: var(--gray-600); }
.legend .dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.15); }
.dot.high { background: var(--high); } .dot.medium { background: var(--med); } .dot.low { background: var(--low); }

/* leaflet marker pin label */
.pin { font-weight: 800; color: #fff; font-size: 11px; }

/* ---------- Table ---------- */
table.leads { width: 100%; border-collapse: collapse; background: #fff; }
table.leads thead th { position: sticky; top: 0; background: var(--gray-50); border-bottom: 2px solid var(--gray-200); padding: 0.6rem 0.7rem; text-align: left; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--gray-500); font-weight: 700; cursor: pointer; white-space: nowrap; z-index: 2; }
table.leads thead th.sorted::after { content: " ▾"; color: var(--blue-500); }
table.leads tbody tr { border-bottom: 1px solid var(--gray-100); cursor: pointer; transition: background var(--t); }
table.leads tbody tr:hover { background: var(--blue-50); }
table.leads tbody tr.sel { background: #fff7e6; }
table.leads td { padding: 0.55rem 0.7rem; vertical-align: middle; }
table.leads td.name b { color: var(--navy-800); }
table.leads td.name span { display: block; font-size: 0.76rem; color: var(--gray-500); }
.scorebadge { display: inline-flex; align-items: center; justify-content: center; min-width: 38px; padding: 0.2rem 0.4rem; border-radius: 7px; font-weight: 800; font-size: 0.86rem; }
.scorebadge.high { background: var(--high-bg); color: var(--high); }
.scorebadge.medium { background: var(--med-bg); color: var(--med); }
.scorebadge.low { background: var(--low-bg); color: var(--low); }
.tag { display: inline-block; padding: 0.12rem 0.5rem; border-radius: 999px; font-size: 0.7rem; font-weight: 600; background: var(--gray-100); color: var(--gray-600); }
.tag.com { background: #e7eefb; color: var(--navy-700); }
.tag.res { background: #f0ebfb; color: #6b48b8; }
.prov { display: inline-block; font-size: 0.6rem; font-weight: 800; letter-spacing: 0.05em; padding: 0.05rem 0.32rem; border-radius: 4px; vertical-align: 1px; }
.prov.real { background: var(--low-bg); color: var(--low); }
.prov.demo { background: var(--gray-100); color: var(--gray-400); }
.cbx { width: 16px; height: 16px; accent-color: var(--blue-500); cursor: pointer; }
.muted { color: var(--gray-500); }

/* ---------- Detail drawer ---------- */
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 420px; max-width: 92vw; background: #fff; box-shadow: var(--shadow-lg); transform: translateX(100%); transition: transform 0.26s cubic-bezier(0.22,0.61,0.36,1); z-index: 60; display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.drawer__head { padding: 1.1rem 1.2rem; color: #fff; position: relative; }
.drawer__head.high { background: linear-gradient(135deg, #b53024, var(--high)); }
.drawer__head.medium { background: linear-gradient(135deg, #b06a08, var(--med)); }
.drawer__head.low { background: linear-gradient(135deg, #1d7c43, var(--low)); }
.drawer__close { position: absolute; top: 0.9rem; right: 0.9rem; background: rgba(255,255,255,0.2); border: 0; width: 30px; height: 30px; border-radius: 7px; color: #fff; cursor: pointer; font-size: 1.1rem; }
.drawer__close:hover { background: rgba(255,255,255,0.35); }
.drawer__score { display: flex; align-items: center; gap: 0.8rem; }
.drawer__score .big { font-size: 2.7rem; font-weight: 800; line-height: 1; }
.drawer__score .meta .pr { font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.78rem; }
.drawer__score .meta .id { opacity: 0.85; font-size: 0.78rem; }
.drawer__name { margin-top: 0.8rem; font-size: 1.2rem; font-weight: 800; }
.drawer__addr { opacity: 0.92; font-size: 0.85rem; }
.drawer__body { overflow-y: auto; padding: 1.1rem 1.2rem; flex: 1; }
.dsec { margin-bottom: 1.3rem; }
.dsec h4 { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gray-500); font-weight: 700; margin-bottom: 0.55rem; display: flex; align-items: center; gap: 0.4rem; }
.dgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 1rem; }
.dgrid .it { padding: 0.4rem 0; border-bottom: 1px dashed var(--gray-200); }
.dgrid .it .k { font-size: 0.7rem; color: var(--gray-500); }
.dgrid .it .v { font-weight: 700; color: var(--navy-800); }
/* scoring breakdown bars */
.bd { margin-bottom: 0.6rem; }
.bd__top { display: flex; justify-content: space-between; font-size: 0.78rem; margin-bottom: 0.2rem; }
.bd__top .pts { font-weight: 700; color: var(--navy-800); }
.bd__bar { height: 9px; background: var(--gray-150, var(--gray-100)); border-radius: 5px; overflow: hidden; }
.bd__fill { height: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--blue-400), var(--blue-500)); transition: width 0.5s ease; }
.bd__total { display: flex; justify-content: space-between; margin-top: 0.5rem; padding-top: 0.5rem; border-top: 2px solid var(--gray-200); font-weight: 800; color: var(--navy-800); }
.bd__total.ded { color: var(--high); font-weight: 700; }
.triggers li { display: flex; gap: 0.5rem; padding: 0.4rem 0; font-size: 0.84rem; color: var(--gray-600); border-bottom: 1px solid var(--gray-100); }
.triggers li svg { flex: none; color: var(--med); margin-top: 2px; }
.permits .p { display: flex; justify-content: space-between; font-size: 0.8rem; padding: 0.35rem 0; border-bottom: 1px solid var(--gray-100); }
.rawtoggle { float: right; background: var(--gray-100); border: 1px solid var(--gray-300); color: var(--blue-500); font-size: 0.7rem; font-weight: 700; padding: 0.12rem 0.55rem; border-radius: 6px; cursor: pointer; text-transform: none; letter-spacing: 0; }
.rawtoggle:hover { background: var(--blue-50); border-color: var(--blue-400); }
.provenance { font-size: 0.76rem; color: var(--gray-500); line-height: 1.5; margin-bottom: 0.6rem; }
.scoredef { font-size: 0.76rem; color: var(--gray-500); line-height: 1.5; margin-bottom: 0.85rem; padding: 0.5rem 0.65rem; background: var(--gray-50); border-left: 3px solid var(--blue-400); border-radius: 0 6px 6px 0; }
.rawjson { background: var(--navy-900); color: #cfe0f5; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.74rem; line-height: 1.45; padding: 0.9rem; border-radius: 9px; overflow-x: auto; white-space: pre; max-height: 340px; overflow-y: auto; }
.rawactions { margin-top: 0.5rem; }
.drawer__actions { padding: 0.9rem 1.2rem; border-top: 1px solid var(--gray-200); display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; flex: none; }
.daction { padding: 0.6rem; border-radius: 8px; border: 1px solid var(--gray-300); background: #fff; font-weight: 600; cursor: pointer; transition: var(--t); display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; color: var(--navy-800); }
.daction:hover { border-color: var(--blue-500); color: var(--blue-500); }
.daction--primary { grid-column: 1 / -1; background: var(--blue-500); color: #fff; border-color: var(--blue-500); }
.daction--primary:hover { background: var(--blue-400); color: #fff; }
.daction--primary.synced { background: var(--low); border-color: var(--low); pointer-events: none; }

/* ---------- Selection action bar ---------- */
.selbar { position: fixed; bottom: 0; left: 290px; right: 0; background: var(--navy-800); color: #fff; padding: 0.7rem 1.1rem; display: none; align-items: center; gap: 0.9rem; z-index: 50; box-shadow: 0 -6px 20px rgba(0,0,0,0.2); }
.selbar.show { display: flex; }
.selbar .n { font-weight: 800; }
.selbar .n b { color: var(--blue-300); }
.selbar .sbtn { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); color: #fff; padding: 0.5rem 0.9rem; border-radius: 8px; font-weight: 600; cursor: pointer; transition: var(--t); display: inline-flex; align-items: center; gap: 0.4rem; }
.selbar .sbtn:hover { background: rgba(255,255,255,0.2); }
.selbar .sbtn--go { background: var(--blue-500); border-color: var(--blue-500); }
.selbar .sbtn--go:hover { background: var(--blue-400); }
.selbar .clear { margin-left: auto; background: none; border: 0; color: rgba(255,255,255,0.7); cursor: pointer; text-decoration: underline; }

/* ---------- Toast ---------- */
.toasts { position: fixed; top: calc(var(--header-h) + 12px); right: 16px; z-index: 90; display: flex; flex-direction: column; gap: 0.5rem; }
.toast { background: var(--navy-800); color: #fff; padding: 0.7rem 1rem; border-radius: 9px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 0.6rem; font-weight: 600; animation: slideIn 0.25s ease; max-width: 340px; }
.toast.ok { background: var(--low); }
.toast svg { flex: none; }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ---------- mini charts ---------- */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 38px; }
.spark .b { width: 14px; background: var(--blue-400); border-radius: 3px 3px 0 0; position: relative; }
.spark .b .lab { position: absolute; bottom: -15px; left: 50%; transform: translateX(-50%); font-size: 0.58rem; color: var(--gray-500); white-space: nowrap; }
.donut { display: flex; align-items: center; gap: 0.7rem; }
.donut .legend2 { font-size: 0.72rem; }
.donut .legend2 .r { display: flex; align-items: center; gap: 0.35rem; color: var(--gray-600); }
.donut .legend2 .r i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

/* ---------- empty state ---------- */
.empty { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; color: var(--gray-500); text-align: center; padding: 2rem; }
.empty.show { display: flex; }
.empty svg { color: var(--gray-300); margin-bottom: 0.8rem; }

/* ---------- print labels ---------- */
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { position: absolute; inset: 0; display: block !important; }
}
#print-area { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .body { grid-template-columns: 1fr; }
  .side { position: fixed; inset: calc(var(--header-h) + var(--kpi-h)) auto 0 0; width: 280px; z-index: 30; transform: translateX(-100%); transition: transform var(--t); }
  .side.open { transform: none; }
  .selbar { left: 0; }
  .hdr__search { display: none; }
}
.side-toggle { display: none; }
@media (max-width: 980px) { .side-toggle { display: inline-flex; } }
