/* ============================================================
   LocalRadar v2 — Premium UI
   Brand: electric blue #1932EB · deep navy · Poppins
   All class names preserved from v1 (app.js untouched)
   ============================================================ */
:root {
  --blue: #1932EB;
  --blue-2: #4156F4;
  --blue-soft: #ECEFFF;
  --blue-dark: #1226b8;
  --navy: #0A1633;
  --navy-2: #101F4A;
  --ink: #16213D;
  --muted: #6B7693;
  --line: #E7EBF5;
  --bg: #F3F5FB;
  --white: #fff;
  --green: #12A150;
  --green-bg: #E4F7EC;
  --amber: #E8930C;
  --amber-bg: #FdF0DC;
  --red: #DC2626;
  --red-bg: #FDEAEA;
  --gray: #7C8499;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(10,22,51,.05), 0 2px 8px rgba(10,22,51,.05);
  --shadow: 0 1px 2px rgba(10,22,51,.05), 0 10px 30px rgba(10,22,51,.08);
  --shadow-lg: 0 24px 70px rgba(10,22,51,.22);
  --grad-blue: linear-gradient(135deg, #1932EB 0%, #4156F4 100%);
  --grad-navy: linear-gradient(170deg, #0A1633 0%, #101F4A 60%, #14246E 100%);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Poppins', system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 14px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
::selection { background: rgba(25,50,235,.16); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #C9D1E6; border-radius: 99px; border: 2.5px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #ADB8D6; }

/* ============ APP SHELL (sidebar layout) ============ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 236px; flex-shrink: 0;
  background: var(--grad-navy);
  display: flex; flex-direction: column;
  padding: 22px 16px 18px;
  position: sticky; top: 0; height: 100vh;
  z-index: 500;
}
.sidebar::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(420px 220px at 0% 0%, rgba(65,86,244,.22), transparent 60%);
}
.sidebar > * { position: relative; z-index: 1; }

.sidebar .logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 17.5px; color: #fff;
  padding: 4px 8px 22px; letter-spacing: -.01em;
}
.sidebar .logo .dot {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--grad-blue);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 16px;
  box-shadow: 0 6px 16px rgba(25,50,235,.45);
}
.sidebar .logo img { height: 32px; }

.sidebar .nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar .nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 11px;
  color: rgba(255,255,255,.62); font-weight: 500; font-size: 13.5px;
  transition: background .15s, color .15s;
}
.sidebar .nav a svg { width: 18px; height: 18px; opacity: .85; }
.sidebar .nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar .nav a.active {
  background: var(--grad-blue); color: #fff;
  box-shadow: 0 8px 20px rgba(25,50,235,.4);
}
.sidebar .nav a.active svg { opacity: 1; }

.side-spacer { flex: 1; }

.sidebar .usage { font-size: 11.5px; color: rgba(255,255,255,.55); padding: 12px 12px 10px; line-height: 1.5; }
.sidebar .usage .bar { height: 5px; background: rgba(255,255,255,.12); border-radius: 4px; margin-top: 6px; overflow: hidden; }
.sidebar .usage .bar i { display: block; height: 100%; background: var(--grad-blue); border-radius: 4px; }
.sidebar .usage .bar i.warn { background: var(--amber); }
.sidebar .usage .bar i.danger { background: var(--red); }

.btn.side-logout {
  background: rgba(255,255,255,.08); color: rgba(255,255,255,.85);
  width: 100%; justify-content: center; gap: 9px;
  border: 1px solid rgba(255,255,255,.1);
  margin-top: 6px;
}
.btn.side-logout:hover { background: rgba(255,255,255,.15); }
.btn.side-logout svg { width: 15px; height: 15px; }

.side-brand { text-align: center; font-size: 10.5px; color: rgba(255,255,255,.35); padding-top: 14px; letter-spacing: .04em; }

.main { flex: 1; min-width: 0; }

/* legacy topbar (report print rule safety) */
.topbar { display: none; }

/* ============ LAYOUT ============ */
.wrap { max-width: 1280px; margin: 0 auto; padding: 30px 30px 70px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; font-weight: 700; color: var(--navy); letter-spacing: -.015em; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.page-head .spacer { flex: 1; }

/* ============ CARDS ============ */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.card {
  background: var(--white); border: 1px solid rgba(231,235,245,.8);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm);
}
.card.click { cursor: pointer; transition: transform .16s ease, box-shadow .16s ease, border-color .16s; }
.card.click:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: rgba(25,50,235,.25);
}
.biz-name { font-weight: 600; font-size: 15.5px; color: var(--navy); margin-bottom: 2px; letter-spacing: -.01em; }
.biz-addr { color: var(--muted); font-size: 12.5px; margin-bottom: 14px; min-height: 34px; }
.biz-meta { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }

.pill { font-size: 11.5px; font-weight: 600; padding: 3.5px 11px; border-radius: 99px; background: var(--blue-soft); color: var(--blue); }
.pill.gray { background: #F0F3F9; color: var(--muted); font-weight: 500; }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.amber { background: var(--amber-bg); color: #B45309; }
.pill.red { background: var(--red-bg); color: var(--red); }

/* ============ BUTTONS / FORMS ============ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--grad-blue); color: #fff; border: 0; cursor: pointer;
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  padding: 10px 19px; border-radius: 11px;
  box-shadow: 0 6px 16px rgba(25,50,235,.26);
  transition: transform .14s ease, box-shadow .14s ease, background .14s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 9px 22px rgba(25,50,235,.34); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: default; transform: none; box-shadow: none; }
.btn.lg { padding: 12px 22px; font-size: 14.5px; border-radius: 12px; justify-content: center; }
.btn.ghost { background: #fff; color: var(--blue); border: 1.5px solid rgba(25,50,235,.35); box-shadow: none; }
.btn.ghost:hover { background: var(--blue-soft); border-color: var(--blue); box-shadow: none; }
.btn.subtle { background: #EEF1F8; color: var(--ink); box-shadow: none; }
.btn.subtle:hover { background: #E3E8F3; box-shadow: none; }
.btn.danger { background: #fff; color: var(--red); border: 1.5px solid #F3C7C7; box-shadow: none; }
.btn.danger:hover { background: var(--red-bg); border-color: var(--red); box-shadow: none; }
.btn.sm { padding: 7px 13px; font-size: 12.5px; border-radius: 9px; }

label.fld { display: block; font-size: 12.5px; font-weight: 600; color: var(--navy); margin: 15px 0 6px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; font-family: inherit; font-size: 13.5px; color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 11px; padding: 10px 13px; background: #FBFCFE;
  outline: none; transition: border-color .14s, box-shadow .14s, background .14s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue); background: #fff;
  box-shadow: 0 0 0 3.5px rgba(25,50,235,.12);
}
.hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ============ MODAL ============ */
.overlay {
  position: fixed; inset: 0; background: rgba(8, 15, 36, .55);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 64px 16px; z-index: 900; overflow-y: auto;
  animation: fade .16s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: #fff; border-radius: 20px; width: 100%; max-width: 530px; padding: 28px;
  box-shadow: var(--shadow-lg);
  animation: rise .2s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.985); } }
.modal h2 { font-size: 18px; color: var(--navy); margin-bottom: 4px; font-weight: 700; letter-spacing: -.01em; }
.modal .sub { color: var(--muted); font-size: 12.5px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.pick { border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 14px; margin-top: 9px; cursor: pointer; transition: border-color .12s, background .12s; }
.pick:hover, .pick.sel { border-color: var(--blue); background: var(--blue-soft); }
.pick b { display: block; font-size: 13.5px; color: var(--navy); }
.pick span { font-size: 12px; color: var(--muted); }

/* ============ BUSINESS PAGE ============ */
.kw-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; align-items: center; }
.kw-chip {
  padding: 8px 16px; border-radius: 99px; border: 1.5px solid var(--line);
  background: #fff; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--ink);
  font-family: inherit;
  transition: border-color .13s, background .13s, color .13s, box-shadow .13s, transform .13s;
}
.kw-chip:hover { border-color: rgba(25,50,235,.4); color: var(--blue); transform: translateY(-1px); }
.kw-chip.active {
  background: var(--grad-blue); border-color: transparent; color: #fff;
  box-shadow: 0 6px 16px rgba(25,50,235,.32);
}

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile {
  background: #fff; border: 1px solid rgba(231,235,245,.8); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
}
.tile::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3.5px;
  background: var(--grad-blue); opacity: .85; border-radius: 0 4px 4px 0;
}
.tile .v { font-size: 27px; font-weight: 800; color: var(--navy); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .v small { font-size: 14px; font-weight: 600; color: var(--muted); }
.tile .l { font-size: 10.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .07em; margin-bottom: 2px; }
.tile .d { font-size: 11.5px; font-weight: 600; margin-top: 3px; display: inline-block; padding: 1.5px 8px; border-radius: 99px; }
.d.up { color: var(--green); background: var(--green-bg); }
.d.down { color: var(--red); background: var(--red-bg); }
.d.flat { color: var(--muted); background: #F0F3F9; }

.split { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1080px) { .split { grid-template-columns: 1fr; } }
#map, .gridmap {
  height: 540px; border-radius: var(--radius); border: 1px solid var(--line);
  z-index: 1; box-shadow: var(--shadow-sm);
}
.side h3 { font-size: 13.5px; color: var(--navy); margin-bottom: 10px; font-weight: 700; }
.comp-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.comp-row:last-child { border-bottom: 0; }
.comp-row .n { flex: 1; }
.comp-row .me { color: var(--blue); font-weight: 600; }
.badge-cnt { background: var(--blue-soft); color: var(--blue); font-weight: 700; border-radius: 9px; padding: 2.5px 10px; font-size: 12px; font-variant-numeric: tabular-nums; }

.hist-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.hist-table th {
  text-align: left; color: var(--muted); font-weight: 600; padding: 8px 10px;
  border-bottom: 1.5px solid var(--line);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
}
.hist-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.hist-table tr { cursor: pointer; transition: background .1s; }
.hist-table tr:hover td { background: #F7F9FE; }
.hist-table tr.sel td { background: var(--blue-soft); }

/* ============ MAP PINS ============ */
.pin {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  color: #fff; font-weight: 700; font-size: 13px; font-family: 'Poppins', sans-serif;
  border: 2.5px solid #fff;
  box-shadow: 0 3px 10px rgba(10,22,51,.35), 0 0 0 1px rgba(10,22,51,.06);
}
.pin.g { background: linear-gradient(160deg, #16B25A, #0E8A43); }
.pin.a { background: linear-gradient(160deg, #F5A623, #DE860B); }
.pin.r { background: linear-gradient(160deg, #E54848, #C92020); }
.pin.x { background: linear-gradient(160deg, #8A93A8, #6E778E); font-size: 10.5px; background: #7C8499; }
.pin.home {
  background: var(--navy); width: 19px; height: 19px; border-width: 2.5px;
  box-shadow: 0 0 0 6px rgba(25,50,235,.18), 0 3px 10px rgba(10,22,51,.4);
}
.leaflet-popup-content-wrapper { border-radius: 12px; box-shadow: var(--shadow); }
.leaflet-popup-content { font-family: 'Poppins', sans-serif; font-size: 12.5px; margin: 13px 15px; }
.pop-rank { font-weight: 700; margin-bottom: 6px; color: var(--navy); }
.pop-li { padding: 2.5px 0; display: flex; gap: 7px; }
.pop-li .pos { color: var(--muted); width: 17px; font-weight: 600; }

/* ============ TOAST ============ */
#toasts { position: fixed; bottom: 24px; right: 24px; z-index: 1200; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: var(--navy); color: #fff; font-size: 13px; padding: 12px 18px 12px 16px;
  border-radius: 12px; box-shadow: var(--shadow-lg); max-width: 380px;
  border-left: 4px solid var(--blue-2);
  animation: tin .22s cubic-bezier(.2,.9,.3,1.2);
}
.toast.err { border-left-color: #FF6B6B; background: #3A0F14; }
@keyframes tin { from { opacity: 0; transform: translateY(10px) scale(.97); } }

/* ============ AUTH / LOGIN ============ */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: var(--grad-navy);
  position: relative; overflow: hidden;
}
.auth-glow { position: absolute; inset: 0; pointer-events: none; }
.auth-glow::before {
  content: ''; position: absolute; width: 720px; height: 720px; border-radius: 50%;
  background: radial-gradient(circle, rgba(65,86,244,.32), transparent 65%);
  top: -260px; right: -180px;
}
.auth-glow::after {
  content: ''; position: absolute; width: 560px; height: 560px; border-radius: 50%;
  background: radial-gradient(circle, rgba(25,50,235,.25), transparent 65%);
  bottom: -220px; left: -160px;
}
.auth-card {
  background: rgba(255,255,255,.985); border-radius: 22px; padding: 38px 36px;
  width: 100%; max-width: 426px;
  box-shadow: 0 32px 100px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.08);
  position: relative; z-index: 1;
}
.auth-card .logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 8px; font-size: 21px; font-weight: 700; color: var(--navy); letter-spacing: -.01em; }
.auth-card .logo .dot {
  width: 38px; height: 38px; border-radius: 11px; background: var(--grad-blue);
  display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 17px;
  box-shadow: 0 8px 20px rgba(25,50,235,.4);
}
.auth-card p.tag { text-align: center; color: var(--muted); font-size: 12.5px; margin-bottom: 16px; }
.auth-foot { text-align: center; color: #ADB8D6; font-size: 11px; margin-top: 22px; letter-spacing: .03em; }

/* ============ SCAN PROGRESS ============ */
.scanning {
  display: flex; align-items: center; gap: 13px; padding: 15px 18px;
  background: linear-gradient(135deg, #EEF1FF, #F5F7FF);
  border: 1px solid rgba(25,50,235,.18);
  border-radius: 13px; margin-bottom: 16px; font-weight: 500; color: var(--blue);
}
.spin { width: 18px; height: 18px; border: 3px solid #C5CDFA; border-top-color: var(--blue); border-radius: 50%; animation: sp .9s linear infinite; flex-shrink: 0; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ============ LEGEND ============ */
.legend {
  display: inline-flex; gap: 16px; align-items: center; font-size: 12px; color: var(--muted);
  margin: 12px 2px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 7px 16px;
  box-shadow: var(--shadow-sm);
}
.legend i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; margin-right: 5px; vertical-align: -1px; }

/* ============ CLIENT REPORT ============ */
.report-hero {
  background: var(--grad-navy); color: #fff; padding: 48px 26px 42px;
  position: relative; overflow: hidden;
}
.report-hero::before {
  content: ''; position: absolute; width: 600px; height: 600px; border-radius: 50%;
  background: radial-gradient(circle, rgba(65,86,244,.3), transparent 65%);
  top: -240px; right: -140px; pointer-events: none;
}
.report-hero .inner { max-width: 1100px; margin: 0 auto; position: relative; }
.report-hero h1 { font-size: 27px; font-weight: 700; letter-spacing: -.015em; }
.report-hero .meta { opacity: .8; font-size: 13px; margin-top: 6px; }
.report-brand { font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; opacity: .75; margin-bottom: 16px; }
.report-section { max-width: 1100px; margin: 30px auto; padding: 0 26px; }
.report-kw {
  background: #fff; border: 1px solid rgba(231,235,245,.8); border-radius: 18px;
  padding: 24px; margin-bottom: 26px; box-shadow: var(--shadow);
}
.report-kw h2 { font-size: 17.5px; color: var(--navy); margin-bottom: 14px; font-weight: 700; letter-spacing: -.01em; }
.report-foot { text-align: center; color: var(--muted); font-size: 12px; padding: 30px 0 56px; }
.trend-box { height: 230px; margin-top: 18px; }

@media print {
  .topbar, .sidebar, .no-print { display: none !important; }
  .report-kw { break-inside: avoid; box-shadow: none; }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0;
    flex-direction: row; align-items: center; gap: 6px;
    padding: 10px 14px;
  }
  .sidebar .logo { padding: 0 6px 0 0; font-size: 15.5px; }
  .sidebar .logo .dot { width: 28px; height: 28px; font-size: 13px; border-radius: 8px; }
  .sidebar .nav { flex-direction: row; gap: 2px; }
  .sidebar .nav a { padding: 8px 11px; font-size: 12.5px; }
  .sidebar .nav a svg { width: 15px; height: 15px; }
  .sidebar .usage, .side-brand { display: none; }
  .btn.side-logout { width: auto; margin: 0; padding: 7px 12px; font-size: 12px; }
  .wrap { padding: 20px 16px 60px; }
  .page-head h1 { font-size: 20px; }
  #map, .gridmap { height: 420px; }
  .row3 { grid-template-columns: 1fr; }
}
