:root {
  --bg: #080b14;
  --bg-2: #0b0f1a;
  --panel: #0e1320;
  --panel-2: #121828;
  --line: #1b2234;
  --line-2: #242d44;
  --text: #e8ebf3;
  --muted: #8b93a7;
  --dim: #5d6579;
  --accent: #7c6cff;
  --accent-2: #9b8cff;
  --blue: #3b82f6;
  --purple: #8b5cf6;
  --cyan: #06b6d4;
  --amber: #f59e0b;
  --green: #10b981;
  --red: #ef4444;
  --gray: #6b7280;
  --radius: 14px;
  --sidebar: 300px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Outfit', system-ui, sans-serif;
  background: var(--bg);
  background-image: radial-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--text);
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
[hidden] { display: none !important; }

/* ---- sidebar ---- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
  background: linear-gradient(180deg, #0c1120, #0a0e19);
  border-right: 1px solid var(--line);
  padding: 0 13px; display: flex; flex-direction: column; z-index: 10;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 0 0 0; height: 56px; margin-bottom: 52px; }
.brand-logo {
  width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6d8bff, #8b5cf6); font-weight: 800; font-size: 18px;
  box-shadow: 0 6px 20px rgba(124, 108, 255, 0.35);
}
.brand-name { display: block; font-weight: 800; font-size: 22px; line-height: 1.1; }
.brand-sub { display: block; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.nav-label { font-size: 12px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); margin: 18px 0 10px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 10px;
  color: var(--muted); font-size: 16px; font-weight: 500; transition: background .15s, color .15s;
}
.nav a svg { width: 22px; height: 22px; }
.nav a:hover { background: rgba(255, 255, 255, 0.03); color: var(--text); }
.nav a.active { background: linear-gradient(90deg, rgba(91, 107, 255, 0.22), rgba(91, 107, 255, 0.08)); color: #7b9bff; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); padding: 16px 0; font-size: 13px; color: var(--muted); }

/* ---- main ---- */
.main { margin-left: var(--sidebar); padding: 0 44px 48px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; height: 58px; margin-bottom: 28px; }
.page-head h1 { margin: 0; font-size: 31px; font-weight: 800; letter-spacing: -0.02em; }
.accent { background: linear-gradient(90deg, #5b7bff, #8b6cff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.search {
  display: flex; align-items: center; gap: 10px; width: 375px; max-width: 100%;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px; padding: 11px 18px; color: var(--muted);
}
.search svg { width: 18px; height: 18px; flex: none; }
.search input { all: unset; flex: 1; font-size: 15px; color: var(--text); }
.search input::placeholder { color: var(--muted); }

.banner {
  margin: 14px 0 -10px; padding: 12px 16px; border-radius: 10px; font-size: 14px;
  background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.35); color: #fca5a5;
}

/* ---- stat cards ---- */
.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 20px; margin-bottom: 36px; }
.stat {
  position: relative; display: block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px 24px 22px; transition: border-color .15s, transform .15s, background .15s;
}
.stat:hover { border-color: color-mix(in srgb, var(--c) 45%, var(--line)); background: var(--panel-2); transform: translateY(-2px); }
.stat::before { content: ''; position: absolute; inset: 0 0 auto; height: 3px; background: var(--c); border-radius: var(--radius) var(--radius) 0 0; }
/* Two lines tall, so the numbers line up even when a label wraps */
.stat-label {
  font-size: 12.5px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; min-height: 34px;
}
.stat-value { font-size: 36px; font-weight: 800; letter-spacing: -0.03em; margin-top: 10px; color: #dfe3ee; }
.stat-sub { margin-top: 6px; font-size: 13px; color: var(--muted); min-height: 18px; }

.head-actions { display: flex; align-items: center; gap: 12px; }
.updated { color: var(--dim); font-size: 13px; white-space: nowrap; }
.head-actions .icon-btn { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 10px; background: var(--panel); }
.head-actions .icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn:disabled { opacity: .6; cursor: default; }
.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

i[data-tip] {
  position: relative; font-style: normal; display: inline-grid; place-items: center; width: 17px; height: 17px;
  border-radius: 50%; border: 1px solid var(--line-2); font-size: 10px; color: var(--muted); cursor: help;
  letter-spacing: 0; text-transform: none; font-weight: 600;
}
i[data-tip]:hover::after {
  content: attr(data-tip); position: absolute; top: 24px; left: 50%; transform: translateX(-50%);
  width: max-content; max-width: 220px; padding: 8px 10px; border-radius: 8px; z-index: 20;
  background: #1a2133; border: 1px solid var(--line-2); color: var(--text); font-size: 12px; font-weight: 400; line-height: 1.4;
}

/* ---- cards & charts ---- */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 26px; margin-bottom: 50px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 30px; margin-bottom: 26px; }
.grid-3 .card { margin-bottom: 0; }
.card h3 { margin: 0 0 18px; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.chart { position: relative; height: 330px; }
.chart-wide { height: 360px; }

/* ---- toolbar ---- */
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 26px; }
.pills { display: flex; gap: 12px; }
.pills button, select {
  font: inherit; font-size: 15px; color: var(--muted); background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 999px; padding: 9px 20px; cursor: pointer; transition: all .15s;
}
.pills button:hover { color: var(--text); }
.pills button.active { color: #5b9bff; background: rgba(59, 130, 246, 0.14); border-color: rgba(59, 130, 246, 0.6); }
.divider { width: 1px; height: 30px; background: var(--line-2); margin: 0 8px; }
select {
  border-radius: 8px; color: var(--text); font-weight: 600; padding: 9px 40px 9px 20px; appearance: none; min-width: 152px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23e8ebf3' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
select option { background: var(--panel-2); }
.result-count { margin-left: auto; color: var(--muted); font-size: 14px; }

/* ---- table ---- */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table.leads { width: 100%; border-collapse: collapse; font-size: 15px; }
.leads th {
  text-align: left; font-size: 13px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
  padding: 16px 18px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel);
}
.leads th.sortable { cursor: pointer; user-select: none; }
.leads th.sortable:hover { color: var(--text); }
.leads th .sort-ind { opacity: .7; }
.leads td { padding: 16px 18px; border-bottom: 1px solid var(--line); white-space: nowrap; color: var(--muted); }
.leads tbody tr { cursor: pointer; transition: background .12s; }
.leads tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
.leads tbody tr:last-child td { border-bottom: 0; }
.leads td.phone { font-family: 'JetBrains Mono', monospace; color: var(--text); font-weight: 600; }
.leads td.strong { color: var(--text); font-weight: 600; }
.leads td.template { max-width: 230px; overflow: hidden; text-overflow: ellipsis; }
.leads td.empty { text-align: center; padding: 60px; cursor: default; }

.badge {
  display: inline-block; padding: 4px 13px; border-radius: 999px; font-size: 12.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--bc); background: color-mix(in srgb, var(--bc) 15%, transparent);
}
.conf { display: flex; align-items: center; gap: 12px; color: var(--text); font-family: 'JetBrains Mono', monospace; font-size: 14px; }
.conf-bar { width: 75px; height: 6px; background: #1c2333; border-radius: 99px; overflow: hidden; }
.conf-bar span { display: block; height: 100%; border-radius: 99px; background: var(--bc); }

.pager { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 18px; color: var(--muted); font-size: 14px; }
.pager button { font: inherit; font-size: 14px; color: var(--text); background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 14px; cursor: pointer; }
.pager button:disabled { opacity: .35; cursor: default; }

/* ---- drawer ---- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 520px; max-width: 100%; z-index: 31;
  background: var(--bg-2); border-left: 1px solid var(--line-2); transform: translateX(100%); transition: transform .22s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.drawer-title { font-size: 20px; font-weight: 600; }
.drawer-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.icon-btn { background: none; border: 1px solid var(--line-2); color: var(--muted); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 14px; }
.drawer-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 10px 14px; font-size: 14px; margin-bottom: 24px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.section-title { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
.bullets { margin: 0 0 24px; padding-left: 18px; font-size: 14px; line-height: 1.55; color: #c4c9d6; }
.bullets li { margin-bottom: 4px; }
.msgs { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.msg { max-width: 85%; padding: 9px 12px; border-radius: 12px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; background: var(--panel-2); border: 1px solid var(--line); }
.msg.out { align-self: flex-end; background: rgba(124, 108, 255, 0.14); border-color: rgba(124, 108, 255, 0.3); }
.msg small { display: block; color: var(--dim); font-size: 11px; margin-top: 4px; }
pre.raw { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; font-size: 12px; color: var(--muted); overflow-x: auto; max-height: 360px; }

/* ---- login ---- */
.login-body { display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 420px; max-width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 36px 34px 26px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.login-card .brand { margin-bottom: 30px; height: auto; }
.login-card h1 { margin: 0 0 8px; font-size: 26px; font-weight: 800; }
.login-sub { margin: 0 0 26px; color: var(--muted); font-size: 15px; line-height: 1.5; }
.google-btn { min-height: 44px; display: flex; justify-content: center; }
.login-error {
  margin: 18px 0 0; padding: 10px 14px; border-radius: 10px; font-size: 14px; line-height: 1.45;
  background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.35); color: #fca5a5;
}
.login-foot { margin: 28px 0 0; padding-top: 16px; border-top: 1px solid var(--line); color: var(--dim); font-size: 13px; }

/* ---- user box & admin ---- */
.user-box { display: flex; align-items: center; gap: 12px; padding: 16px 4px; border-top: 1px solid var(--line); margin-top: auto; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center; object-fit: cover;
  background: var(--blue); font-weight: 700; font-size: 16px;
}
.user-meta { min-width: 0; }
.user-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.signout {
  display: flex; align-items: center; gap: 10px; background: none; border: 0; color: var(--muted); font: inherit; font-size: 15px;
  padding: 6px 4px 14px; cursor: pointer;
}
.signout:hover { color: var(--text); }
.signout svg { width: 18px; height: 18px; }
.sidebar-foot { margin-top: 0; }

.admin-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 26px; align-items: start; }
.add-form { display: flex; gap: 10px; margin-bottom: 18px; }
.add-form input {
  flex: 1; min-width: 0; font: inherit; font-size: 15px; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 14px; outline: none;
}
.add-form input:focus { border-color: var(--accent); }
.btn {
  font: inherit; font-size: 15px; font-weight: 600; color: #fff; border: 0; border-radius: 10px; padding: 10px 18px; cursor: pointer;
  background: linear-gradient(90deg, #5b7bff, #8b6cff);
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-ghost {
  font: inherit; font-size: 13px; color: #fca5a5; background: none; border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 8px; padding: 5px 12px; cursor: pointer;
}
.btn-ghost:hover { background: rgba(239, 68, 68, 0.1); }
.add-form select { min-width: 120px; border-radius: 10px; }
.role-select {
  min-width: 0; padding: 4px 30px 4px 13px; border-radius: 999px; font-size: 12.5px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; background-position: right 10px center;
  color: #3b82f6; background-color: rgba(59, 130, 246, 0.15); border-color: transparent;
}
.role-select.admin { color: #8b5cf6; background-color: rgba(139, 92, 246, 0.15); }
.role-select:hover { border-color: currentColor; }
.form-msg { font-size: 14px; margin: -6px 0 14px; }
.form-msg.ok { color: #6ee7b7; }
.form-msg.err { color: #fca5a5; }
.card .table-wrap { border: 0; border-radius: 0; margin: 0 -30px -28px; }
.card table.leads td, .card table.leads th { padding: 12px 18px; }
.card table.leads tbody tr { cursor: default; }
.muted-note { color: var(--muted); font-size: 13px; margin: 14px 0 0; }
.leads td .sub { color: var(--dim); font-size: 12.5px; margin-top: 2px; }
.leads tr.row-warn td { background: rgba(239, 68, 68, 0.06); }
.leads tr.row-warn td:first-child { box-shadow: inset 3px 0 0 var(--red); }
.user-link { all: unset; cursor: pointer; display: block; }
.user-link:hover .strong { color: var(--accent-2); text-decoration: underline; }
.link-btn { all: unset; cursor: pointer; color: var(--accent-2); font-size: 14px; }
.link-btn:hover { text-decoration: underline; }

/* ---- audit summary ---- */
.mini-stats { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 22px; }
.mini-stat {
  display: flex; align-items: baseline; gap: 8px; padding: 10px 16px; border-radius: 10px;
  background: var(--bg-2); border: 1px solid var(--line);
}
.mini-stat b { font-size: 20px; font-weight: 800; }
.mini-stat span { color: var(--muted); font-size: 13px; }
.mini-stat.warn { border-color: rgba(239, 68, 68, 0.45); background: rgba(239, 68, 68, 0.08); }
.mini-stat.warn b { color: #fca5a5; }
.mini-note { color: var(--dim); font-size: 13px; }

/* ---- responsive ---- */
@media (max-width: 1500px) { .stats { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 1200px) { .grid-3, .admin-grid { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .sidebar { position: static; width: auto; height: auto; padding-bottom: 8px; }
  .brand { margin-bottom: 8px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { display: none; }
  .user-box { margin-top: 8px; }
  .main { margin-left: 0; padding: 0 16px 32px; }
  .page-head { flex-direction: column; align-items: stretch; height: auto; padding-top: 16px; }
  .head-actions { flex-wrap: wrap; }
  .head-actions .search { flex: 1; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .pills { flex-wrap: wrap; gap: 8px; }
  .divider { display: none; }
}
