/* Karnataka Customer Atlas — styles */
:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --ink: #12142b;
  --ink-2: #4a4f6a;
  --muted: #7b8099;
  --line: #e6e8f2;
  --line-2: #eef0f8;
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --brand-soft: #eef0ff;
  --good: #12a06a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(18, 20, 43, .04), 0 8px 28px -12px rgba(41, 37, 120, .18);
  --shadow-lg: 0 18px 50px -12px rgba(30, 27, 90, .35);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 14px; line-height: 1.45;
  background-image: radial-gradient(900px 380px at 12% -80px, rgba(124, 58, 237, .10), transparent 70%),
                    radial-gradient(800px 340px at 92% -60px, rgba(79, 70, 229, .12), transparent 70%);
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); font-size: 12.5px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 28px; background: rgba(255, 255, 255, .82); backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; color: #fff; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 8px 18px -6px rgba(79, 70, 229, .65);
}
.brand h1 { font-size: 17px; font-weight: 800; letter-spacing: -.02em; }
.brand p { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 4px; padding: 4px; background: #eceefa; border-radius: 12px; }
.tab {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 16px; border: 0; background: transparent; border-radius: 9px;
  color: var(--ink-2); font-weight: 600; font-size: 13.5px; transition: .15s;
}
.tab:hover { color: var(--ink); }
.tab.is-active { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(20, 20, 70, .12); }
.tab-count { background: var(--brand-soft); color: var(--brand); border-radius: 99px; padding: 1px 8px; font-size: 11.5px; font-weight: 700; }

main { padding: 22px 28px 60px; max-width: 1760px; margin: 0 auto; }
.view { display: none; }
.view.is-active { display: block; animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px 10px; }
.card-head h2 { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }

/* ---------- Filter bar ---------- */
.filterbar {
  display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 18px; padding: 10px 14px;
  background: linear-gradient(90deg, #eef0ff, #f6f0ff); border: 1px solid #dcdffc; border-radius: 12px; color: var(--brand);
}
.filterbar-main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
#filterSummary { font-weight: 600; color: var(--ink); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 6px 3px 10px; background: #fff; border: 1px solid #d5d9fb;
  border-radius: 99px; font-size: 12px; color: var(--ink-2); max-width: 340px;
}
.chip b { color: var(--ink); font-weight: 600; }
.chip span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { border: 0; background: #eceefc; color: var(--brand); width: 18px; height: 18px; border-radius: 50%; line-height: 1; font-size: 13px; padding: 0; flex: none; }
.chip button:hover { background: var(--brand); color: #fff; }
.link { border: 0; background: none; color: var(--brand); font-weight: 600; padding: 4px 6px; white-space: nowrap; }
.link:hover { text-decoration: underline; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.kpi { position: relative; overflow: hidden; padding: 18px 20px; display: flex; gap: 14px; align-items: center; }
.kpi .ico { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; flex: none; color: #fff; }
.kpi:nth-child(1) .ico { background: linear-gradient(135deg, #4f46e5, #7c3aed); }
.kpi:nth-child(2) .ico { background: linear-gradient(135deg, #0ea5e9, #2563eb); }
.kpi:nth-child(3) .ico { background: linear-gradient(135deg, #10b981, #0d9488); }
.kpi:nth-child(4) .ico { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.kpi .v { font-size: 26px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .s { color: var(--ink-2); font-size: 12px; margin-top: 2px; }
.kpi .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--line-2); }
.kpi .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: 0 3px 3px 0; }

/* ---------- Overview grid ---------- */
.overview-grid { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 16px; align-items: start; }
.map-wrap { position: relative; margin: 0 14px 14px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.map { height: min(74vh, 760px); min-height: 460px; background: #eef1fb; }
.map-legend {
  position: absolute; left: 14px; bottom: 14px; display: flex; gap: 8px; align-items: center; padding: 7px 12px; z-index: 5;
  background: rgba(255, 255, 255, .92); border-radius: 10px; font-size: 11.5px; color: var(--ink-2); box-shadow: 0 4px 14px -4px rgba(0, 0, 0, .25);
}
.map-legend i { width: 130px; height: 9px; border-radius: 6px; background: linear-gradient(90deg, #2b4cff, #00d5ff, #37e04a, #ffe51f, #e8202a); }
.map-badge { position: absolute; left: 14px; top: 14px; z-index: 5; background: rgba(255, 255, 255, .94); padding: 6px 11px; border-radius: 9px; font-size: 11.5px; color: var(--ink-2); box-shadow: 0 4px 14px -4px rgba(0, 0, 0, .25); }
.map-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 30px; color: var(--ink-2); background: rgba(244, 245, 251, .8); z-index: 4; font-weight: 500; }
.toggles { display: flex; gap: 14px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch span { width: 34px; height: 20px; border-radius: 99px; background: #cfd3e6; position: relative; transition: .2s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: .2s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(14px); }

.side-card { padding-bottom: 14px; position: sticky; top: 76px; max-height: calc(100vh - 92px); display: flex; flex-direction: column; }
.side-card > * { flex: none; }
.side-card .places { flex: 1 1 auto; min-height: 120px; }
#pie { padding: 0 16px; }
.subhead { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; padding: 14px 20px 6px; }
.places { list-style: none; margin: 0; padding: 0 10px 0 12px; overflow: auto; }
.places li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 6px 9px; border-radius: 9px; cursor: pointer; position: relative; }
.places li:hover { background: #f3f4fc; }
.places li.sel { background: var(--brand-soft); }
.places li .n { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.places li .c { font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.places li .b { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: var(--line-2); overflow: hidden; }
.places li .b i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: 4px; }
.selected { margin: 10px 16px 0; padding: 12px 14px; border-radius: 12px; background: linear-gradient(135deg, #1e1b4b, #312e81); color: #fff; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.selected b { font-size: 15px; display: block; }
.selected small { color: #c7c9f5; font-size: 12px; }
.selected .btn { background: #fff; color: var(--brand); border-color: transparent; }

/* ---------- Pie ---------- */
.pc-svg { width: 100%; height: auto; display: block; overflow: visible; }
.pc-slice { cursor: pointer; transition: transform .18s ease, opacity .18s ease; }
.pc-readout { text-align: center; font-size: 13px; color: var(--ink-2); margin: 2px 0 8px; min-height: 20px; }
.pc-readout b { color: var(--ink); }
.pc-legend, .pc-sub { list-style: none; margin: 0; padding: 0; }
.pc-sub { padding-left: 16px; max-height: 150px; overflow: auto; }
.pc-row { display: flex; align-items: center; gap: 9px; width: 100%; background: none; border: 0; padding: 5px 8px; border-radius: 8px; text-align: left; font-size: 13px; }
.pc-row:hover, .pc-row.is-on { background: #f1f2fb; }
.pc-swatch { width: 11px; height: 11px; border-radius: 4px; flex: none; }
.pc-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.pc-num { font-variant-numeric: tabular-nums; }
.pc-num small { color: var(--muted); margin-left: 5px; }

/* ---------- Table card ---------- */
.table-card { overflow: hidden; }
.toolbar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.search { position: relative; flex: 1 1 320px; max-width: 460px; color: var(--muted); }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); }
.search input {
  width: 100%; padding: 10px 14px 10px 38px; border: 1px solid var(--line); background: #f8f9fe; border-radius: 11px; outline: none; transition: .15s;
}
.search input:focus { background: #fff; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(79, 70, 229, .13); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  padding: 6px 12px; border: 1px solid var(--line); background: #fff; border-radius: 99px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); transition: .15s;
}
.pill:hover { border-color: #c7cbf3; color: var(--brand); }
.pill.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.toolbar-right { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.select-wrap { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.select-wrap select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border: 1px solid var(--line); background: #fff; border-radius: 10px;
  font-weight: 600; font-size: 13px; color: var(--ink); transition: .15s;
}
.btn:hover { border-color: #c7cbf3; color: var(--brand); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); padding: 6px 10px; }
.btn.ghost:hover:not(:disabled) { background: #f1f2fb; color: var(--brand); }
.btn:disabled { opacity: .35; cursor: default; }

.table-scroll { overflow: auto; max-height: calc(100vh - 262px); min-height: 320px; position: relative; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
thead th {
  position: sticky; top: 0; z-index: 3; background: #f8f9fe; text-align: left; font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-2); padding: 0; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.th { display: flex; align-items: center; gap: 4px; padding: 10px 8px 10px 14px; }
.th .lab { cursor: pointer; display: inline-flex; align-items: center; gap: 5px; user-select: none; }
.th .lab:hover { color: var(--brand); }
.th .arr { color: var(--brand); font-size: 11px; }
.fbtn { margin-left: auto; width: 26px; height: 26px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 7px; color: #a2a7c0; }
.fbtn:hover { background: #e9ebfa; color: var(--brand); }
.fbtn.on { background: var(--brand); color: #fff; }
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--line-2); vertical-align: top; max-width: 320px; }
tbody tr:hover td { background: #fafaff; }
td.num { font-variant-numeric: tabular-nums; color: var(--muted); }
td .ell { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }
.nil { color: #c2c6da; }
.name { font-weight: 600; }
.phone { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 500; letter-spacing: .01em; color: var(--ink); text-decoration: none; }
.phone:hover { color: var(--brand); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--brand-soft); color: var(--brand); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.badge.src { background: #f1f2f8; color: var(--ink-2); font-weight: 500; }
.badge.brand { background: #fff4e5; color: #b45309; }
.badge.st { background: #e7f8f1; color: #0b7d52; }
.empty { display: grid; place-items: center; gap: 10px; padding: 60px 20px; color: var(--muted); text-align: center; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.pager-btns { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-2); }
#pageLabel { padding: 0 10px; font-weight: 600; }

/* ---------- Filter popover ---------- */
.popover {
  position: fixed; z-index: 60; width: 300px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg);
  padding: 14px; text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 13px; animation: pop .14s ease both; color: var(--ink);
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
.pop-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.pop-title b { font-size: 14px; }
.pop-sort { display: flex; gap: 6px; margin-bottom: 12px; }
.pop-sort button { flex: 1; padding: 6px; border: 1px solid var(--line); background: #fff; border-radius: 8px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.pop-sort button.on, .pop-sort button:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.pop-label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; margin: 12px 0 6px; }
.ops { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.op { padding: 7px 8px; border: 1px solid var(--line); background: #fff; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); text-align: center; }
.op:hover { border-color: #c7cbf3; }
.op.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.op.blank.on { border-color: var(--warn); background: #fff7e8; color: #b45309; }
.pop-input { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; outline: none; background: #f8f9fe; }
.pop-input:focus { border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px rgba(79, 70, 229, .13); }
.pop-input:disabled { opacity: .45; }
.vals-head { display: flex; justify-content: space-between; align-items: center; margin: 12px 0 6px; }
.vals-head .pop-label { margin: 0; }
.vals { max-height: 230px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.val { display: flex; align-items: center; gap: 9px; padding: 5px 8px; border-radius: 7px; cursor: pointer; }
.val:hover { background: #f3f4fc; }
.val input { accent-color: var(--brand); width: 15px; height: 15px; flex: none; }
.val .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.val .k { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.val.blank { background: #fff9ec; font-weight: 600; }
.val.blank .t { color: #b45309; }
.pop-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 80; background: #1e1b4b; color: #fff; padding: 10px 18px; border-radius: 11px;
  box-shadow: var(--shadow-lg); font-weight: 600; font-size: 13px; animation: rise .25s ease both;
}

/* Google Maps tweaks */
.gm-style-cc, .gmnoprint a, .gm-style a[href*="maps.google"] { opacity: .8; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .overview-grid { grid-template-columns: 1fr; }
  .side-card { position: static; max-height: none; }
  .places { max-height: 320px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .topbar { padding: 10px 14px; flex-wrap: wrap; }
  main { padding: 14px; }
  .kpis { grid-template-columns: 1fr; }
  .toolbar-right { margin-left: 0; width: 100%; justify-content: space-between; }
  .map { min-height: 360px; }
  .tabs { width: 100%; } .tab { flex: 1; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
