:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #182235;
  --muted: #64748b;
  --line: #e1e7f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #047857;
  --warning: #a85d00;
  --danger: #c24141;
  --shadow: 0 14px 40px rgba(15, 23, 42, .08);
  --radius: 16px;
}* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100%; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; display: block; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 280px;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  padding: 20px 14px;
  background: linear-gradient(180deg, #0f172a 0%, #111c36 100%);
  color: #f8fafc;
  z-index: 30;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #3a4b6d transparent;
}
.sidebar::-webkit-scrollbar { width: 7px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #3a4b6d; border-radius: 999px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: #52678f; }

.brand { display: flex; align-items: center; gap: 12px; padding: 5px 9px 22px; }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-weight: 850; background: linear-gradient(135deg,#2563eb,#60a5fa); color: white; box-shadow: 0 8px 22px rgba(37,99,235,.28); }
.brand strong { display: block; color: #ffffff; font-size: 15px; }
.brand span { display: block; color: #a8b7d3; font-size: 12px; margin-top: 2px; }
.nav-label { color: #8fa2c5; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; padding: 18px 12px 8px; }
.nav-link { display: flex; align-items: center; gap: 11px; min-height: 44px; border-radius: 12px; padding: 0 12px; color: #d8e2f5; margin: 3px 0; font-size: 13px; font-weight: 560; transition: background .16s ease, color .16s ease, transform .16s ease; }
.nav-link:hover { background: rgba(59, 85, 139, .42); color: #ffffff; transform: translateX(2px); }
.nav-link.active { background: linear-gradient(135deg, #23427c, #1f3a6d); color: #ffffff; box-shadow: inset 3px 0 0 #60a5fa; }
.nav-link svg { width: 18px; height: 18px; opacity: .9; }
.nav-link > span:not(.nav-dot) { min-width: 0; }
.nav-count { margin-left: auto; min-width: 25px; height: 25px; padding: 0 8px; border-radius: 999px; display: inline-grid; place-items: center; background: #243454; color: #f1f5ff; border: 1px solid rgba(148,163,184,.18); font-size: 11px; font-weight: 850; }
.nav-link.active .nav-count { background: #dbeafe; color: #1e40af; border-color: #dbeafe; }
.nav-dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; background: #7f96bf; box-shadow: 0 0 0 3px rgba(127,150,191,.10); }
.success-dot { background: #42c48a; }
.sidebar-footer { margin-top: 24px; border-top: 1px solid rgba(148,163,184,.20); padding: 16px 8px 10px; font-size: 11px; line-height: 1.55; color: #9fb0cd; }
.main { min-width: 0; min-height: 100vh; margin-left: 280px; }
.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 28px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 20; }
.menu-button { display: none; border: 0; background: transparent; padding: 8px; }
.topbar-title h1 { margin: 0; font-size: 20px; }
.topbar-title p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: #e9efff; color: var(--primary); font-weight: 800; }
.user-chip strong { display: block; font-size: 13px; }
.user-chip span { display: block; font-size: 11px; color: var(--muted); }
.content { padding: 28px; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.page-head h2 { margin: 0; font-size: 25px; letter-spacing: -.02em; }
.page-head p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 15px; border-radius: 10px; border: 1px solid transparent; font-weight: 700; font-size: 13px; transition: .16s ease; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; border-color: var(--line); color: var(--text); }
.btn-success { background: #e7f7f0; color: var(--success); border-color: #c7eadc; }
.btn-danger { background: #fff0f0; color: var(--danger); border-color: #ffd1d1; }
.btn-warning { background: #fff7e8; color: var(--warning); border-color: #f4dfb6; }
.btn-sm { min-height: 34px; padding: 0 11px; font-size: 12px; }
.stats { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 16px; margin-bottom: 22px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: 0 8px 24px rgba(23,32,51,.04); }
.stat-top { display: flex; justify-content: space-between; align-items: center; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: #eef3ff; color: var(--primary); }
.stat-value { margin-top: 12px; font-size: 30px; line-height: 1; font-weight: 800; }
.stat-note { margin-top: 9px; color: var(--muted); font-size: 12px; }
.grid-2 { display: grid; grid-template-columns: 1.25fr .75fr; gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(23,32,51,.04); overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.card-head h3 { margin: 0; font-size: 16px; }
.card-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.card-body { padding: 20px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 12px 14px; color: var(--muted); background: var(--surface-2); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }
td { padding: 14px; border-top: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
tbody tr:hover { background: #fbfcff; }
.client-name { font-weight: 800; color: #1d2b48; }
.subtext { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 0 9px; border-radius: 999px; background: #eef2f7; color: #4b5b73; font-size: 11px; font-weight: 800; white-space: nowrap; }
.badge.primary { background: #eaf0ff; color: var(--primary); }
.badge.success { background: #e8f8f1; color: var(--success); }
.badge.warning { background: #fff5df; color: var(--warning); }
.badge.danger { background: #fff0f0; color: var(--danger); }
.badge.dark { background: #e9edf3; color: #364153; }
.row-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.search-bar { display: flex; gap: 10px; flex-wrap: wrap; }
.search-input { min-width: 260px; min-height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 0 13px; background: white; color: var(--text); outline: none; }
.search-input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: #7897ed; box-shadow: 0 0 0 3px rgba(36,87,230,.1); }
.form-card { max-width: 980px; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 17px; }
.field.full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; font-weight: 800; margin-bottom: 7px; color: #33405a; }
.field input, .field select, .field textarea { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; color: var(--text); background: #fff; }
.field textarea { min-height: 110px; resize: vertical; }
.help { margin-top: 5px; color: var(--muted); font-size: 11px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); margin-top: 20px; padding-top: 18px; }
.quick-dates { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; }
.quick-date { border: 1px solid var(--line); background: #fff; min-height: 32px; border-radius: 9px; padding: 0 10px; font-size: 11px; font-weight: 800; color: #465570; }
.quick-date:hover, .quick-date.active { border-color: #9bb2f4; background: #edf2ff; color: var(--primary); }
.alert { border-radius: 12px; padding: 13px 15px; margin-bottom: 18px; font-size: 13px; font-weight: 650; border: 1px solid; }
.alert.success { color: #126946; background: #ebfaf3; border-color: #c8eadb; }
.alert.error { color: #a12727; background: #fff1f1; border-color: #ffd0d0; }
.alert.info { color: #244896; background: #eef4ff; border-color: #cedcff; }
.empty { padding: 38px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: #33405a; margin-bottom: 7px; }
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ''; position: absolute; left: 7px; top: 8px; bottom: 8px; width: 2px; background: var(--line); }
.timeline-item { position: relative; padding: 0 0 22px 18px; }
.timeline-item::before { content: ''; position: absolute; left: -25px; top: 5px; width: 10px; height: 10px; background: var(--primary); border: 3px solid #dfe8ff; border-radius: 50%; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-date { color: var(--muted); font-size: 11px; margin-bottom: 5px; }
.timeline-title { font-weight: 800; font-size: 13px; }
.timeline-text { white-space: pre-wrap; margin-top: 5px; color: #4a5870; font-size: 13px; line-height: 1.55; }
.details { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.detail { border: 1px solid var(--line); border-radius: 12px; padding: 13px; background: #fbfcff; }
.detail label { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 5px; }
.detail div { font-size: 13px; font-weight: 750; word-break: break-word; }
.tabs { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 18px; }
.tab { min-height: 37px; display: inline-flex; align-items: center; padding: 0 13px; border: 1px solid var(--line); border-radius: 10px; font-size: 12px; font-weight: 800; color: #55627a; background: #fff; }
.tab.active { background: var(--primary); border-color: var(--primary); color: white; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 20%, #e4ecff 0, transparent 34%), linear-gradient(145deg,#f8faff,#eef3fa); }
.login-box { width: min(100%, 460px); background: #fff; border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); padding: 32px; }
.login-brand { text-align: center; margin-bottom: 25px; }
.login-brand .brand-mark { margin: 0 auto 12px; width: 52px; height: 52px; }
.login-brand h1 { margin: 0; font-size: 22px; }
.login-brand p { color: var(--muted); font-size: 13px; line-height: 1.5; }
.login-box .field { margin-bottom: 15px; }
.login-box .btn { width: 100%; min-height: 46px; }
.install-check { background: #f7f9fc; border: 1px solid var(--line); border-radius: 12px; padding: 13px; margin-bottom: 17px; font-size: 12px; }
.install-check.ok { color: var(--success); }
.install-check.bad { color: var(--danger); }
.sidebar-backdrop { display: none; }
.mobile-only { display: none; }
.pagination { display: flex; justify-content: flex-end; gap: 7px; padding-top: 16px; }
.pagination a, .pagination span { min-width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); background: #fff; border-radius: 9px; font-size: 12px; }
.pagination .active { background: var(--primary); color: white; border-color: var(--primary); }
@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .app-shell { display: block; }
  .main { margin-left: 0; }
  .sidebar { position: fixed; inset: 0 auto 0 -292px; width: 280px; height: 100vh; height: 100dvh; transition: left .2s ease; box-shadow: 18px 0 45px rgba(3,8,20,.26); }
  .sidebar.open { left: 0; }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 25; background: rgba(5,12,28,.48); }
  .sidebar-backdrop.show { display: block; }
  .menu-button { display: block; }
  .mobile-only { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .topbar-title p, .user-chip > div:not(.avatar) { display: none; }
  .content { padding: 20px 14px; }
  .page-head { align-items: stretch; flex-direction: column; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 15px; }
  .stat-value { font-size: 25px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .details { grid-template-columns: 1fr; }
  .search-input { min-width: 0; width: 100%; }
  .login-box { padding: 24px 20px; }
}
@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr; }
  .actions .btn { flex: 1; }
}
.result-scope-tabs { margin-top: -4px; }
.result-filter-form { align-items: flex-end; }
.result-filter-form .field { min-width: 180px; }
@media (max-width: 800px) {
  .result-filter-form { width: 100%; }
  .result-filter-form .field { min-width: 0; width: 100%; }
  .result-filter-form .btn { width: 100%; }
}

/* Sidebar layout protection: keeps every navigation item on the dark panel. */
.sidebar > * { position: relative; z-index: 1; }
@media (max-height: 760px) and (min-width: 801px) {
  .sidebar { padding-top: 12px; padding-bottom: 12px; }
  .brand { padding-bottom: 12px; }
  .nav-label { padding-top: 11px; padding-bottom: 5px; }
  .nav-link { min-height: 38px; margin: 1px 0; }
  .sidebar-footer { margin-top: 14px; padding-top: 12px; }
}


/* Version 6: permanent lead-history views */
.stat-link { display: block; transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease; }
.stat-link:hover { transform: translateY(-2px); border-color: #b9c8ef; box-shadow: 0 12px 28px rgba(23,32,51,.08); }
.record-count { color: var(--muted); font-size: 12px; white-space: nowrap; }
.date-range-panel { padding-top: 14px; padding-bottom: 14px; background: #fbfcff; border-bottom: 1px solid var(--line); }
.date-range-panel .field { min-width: 180px; margin: 0; }
.lead-filter-head { align-items: flex-start; }
@media (max-width: 800px) {
  .lead-filter-head { align-items: stretch; flex-direction: column; }
  .record-count { padding-left: 2px; }
  .date-range-panel .field { width: 100%; min-width: 0; }
}

/* Version 6: complete Google Maps sales CRM */
.stats-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.metric-list { display: grid; gap: 8px; }
.metric-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fbfcff; font-size: 13px; }
.metric-row:hover { border-color: #b8c8ee; background: #f5f8ff; }
.metric-row strong { min-width: 30px; text-align: center; color: var(--primary); font-size: 16px; }
.filter-grid { width: 100%; display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 10px; }
.filter-grid .search-input { min-width: 0; width: 100%; }
.bulk-bar { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); background: #fbfcff; }
.bulk-bar select { min-height: 40px; min-width: 240px; border: 1px solid var(--line); border-radius: 10px; background: white; padding: 0 12px; }
.field-group { border: 1px solid var(--line); border-radius: 12px; background: #fbfcff; padding: 15px; }
.lead-summary-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.lead-summary-strip > div { border: 1px solid var(--line); border-radius: 12px; background: white; padding: 14px; box-shadow: 0 5px 16px rgba(23,32,51,.035); }
.lead-summary-strip span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.lead-summary-strip strong { display: block; font-size: 15px; word-break: break-word; }
.stacked-actions { display: grid; gap: 9px; margin-top: 16px; }
.stacked-actions .btn { width: 100%; }
.code-list { padding: 14px; border-radius: 10px; background: #111827; color: #e5eefc; line-height: 1.8; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; word-break: break-word; }
.separator { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
.result-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.result-grid a { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 52px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fbfcff; font-size: 12px; }
.result-grid a:hover { border-color: #b8c8ee; background: #f4f7ff; }
.result-grid strong { font-size: 17px; color: var(--primary); }
.pagination { padding: 16px 18px; flex-wrap: wrap; }
@media (max-width: 1300px) {
  .stats-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filter-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
}
@media (max-width: 900px) {
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lead-summary-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .stats-6, .filter-grid, .lead-summary-strip, .result-grid { grid-template-columns: 1fr; }
  .bulk-bar { align-items: stretch; }
  .bulk-bar select, .bulk-bar .btn { width: 100%; min-width: 0; }
}
