:root {
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --ink: #101C2C;
  --navy: #1E3552;
  --blue: #2788D8;
  --blue-soft: #EAF2FB;
  --muted: #5A6B84;
  --line: #E4EAF2;
  --green: #1F9D55;
  --green-soft: #E5F6EC;
  --red: #D64545;
  --red-soft: #FBECEC;
  --amber: #C77E1F;
  --amber-soft: #FDF3E3;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16,28,44,.07), 0 4px 14px rgba(16,28,44,.05);
  --sidebar-w: 232px;
  --font-head: 'Sora', sans-serif;
  --font-body: 'Inter', sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--blue); }

/* ===== SHELL ===== */
.shell { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--ink) 0%, var(--navy) 100%);
  color: #fff;
  display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0;
  z-index: 40;
  padding: 20px 14px;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; border-bottom: 1px solid rgba(255,255,255,.12); }
.side-logo { width: 38px; height: 38px; object-fit: contain; }
.side-brand-name { font-family: var(--font-head); font-weight: 700; font-size: 15px; }
.side-brand-sub { font-size: 11px; color: rgba(255,255,255,.6); letter-spacing: .4px; text-transform: uppercase; }
.side-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 18px; flex: 1; }
.nav-btn {
  display: flex; align-items: center; gap: 11px;
  background: none; border: none; color: rgba(255,255,255,.75);
  font-size: 14px; font-weight: 500;
  padding: 11px 12px; border-radius: 10px;
  text-align: left; transition: background .15s, color .15s;
}
.nav-btn svg { width: 19px; height: 19px; flex-shrink: 0; }
.nav-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-btn.active { background: var(--blue); color: #fff; }
.side-foot { font-size: 11px; color: rgba(255,255,255,.45); padding: 10px 8px 0; border-top: 1px solid rgba(255,255,255,.12); }
.side-backdrop { position: fixed; inset: 0; background: rgba(16,28,44,.5); z-index: 35; }

/* ===== CONTENT ===== */
.content { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 14px 26px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-family: var(--font-head); font-size: 20px; font-weight: 700; }
.topbar-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.synced-note { font-size: 12px; color: var(--muted); }
.icon-btn {
  background: none; border: 1px solid var(--line); border-radius: 10px;
  width: 40px; height: 40px; display: none;
  align-items: center; justify-content: center; color: var(--ink);
}
.icon-btn svg { width: 20px; height: 20px; }
.btn-outline {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  color: var(--ink); font-size: 13.5px; font-weight: 600;
  padding: 9px 14px; transition: border-color .15s, background .15s;
}
.btn-outline svg { width: 16px; height: 16px; }
.btn-outline:hover { border-color: var(--blue); background: var(--blue-soft); }

main { padding: 24px 26px 40px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== STAT CARDS ===== */
.stat-grid {
  display: grid; gap: 16px; margin-bottom: 20px;
  grid-template-columns: repeat(6, 1fr);
}
.stat-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stat-card-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-ico { width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center; }
.stat-ico svg { width: 17px; height: 17px; }
.stat-ico.navy { background: var(--blue-soft); color: var(--blue); }
.stat-ico.green { background: var(--green-soft); color: var(--green); }
.stat-ico.red { background: var(--red-soft); color: var(--red); }
.stat-ico.amber { background: var(--amber-soft); color: var(--amber); }
.stat-card-val { font-family: var(--font-head); font-size: 26px; font-weight: 800; }
.stat-card-val.green { color: var(--green); }
.stat-card-val.red { color: var(--red); }
.stat-card-val.amber { color: var(--amber); }
.stat-card-foot { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ===== CARDS ===== */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dash-grid.single { grid-template-columns: 1fr; max-width: 720px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-family: var(--font-head); font-size: 15px; font-weight: 700; }
.link-btn { background: none; border: none; color: var(--blue); font-size: 13px; font-weight: 600; }
.mini-stat-row { display: flex; gap: 28px; flex-wrap: wrap; margin-bottom: 14px; }
.stat-label { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-val { font-family: var(--font-head); font-size: 22px; font-weight: 800; margin-top: 2px; }
.stat-val.green { color: var(--green); }
.stat-val.red { color: var(--red); }
.stat-val.amber { color: var(--amber); }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--blue), var(--green)); border-radius: 99px; transition: width .5s ease; }
.progress-note { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

/* count badge + mini list */
.count-badge {
  border-radius: 99px; padding: 3px 11px;
  font-family: var(--font-head); font-size: 13px; font-weight: 700;
}
.count-badge.amber { background: var(--amber-soft); color: var(--amber); }
.count-badge.green { background: var(--green-soft); color: var(--green); }
.mini-list { display: flex; flex-direction: column; }
.mini-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.mini-item:last-child { border-bottom: none; }
.mini-item-main { flex: 1; min-width: 0; }
.mini-item-name { font-weight: 600; font-size: 13.5px; }
.mini-item-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.mini-item-phone { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty-note.small { padding: 14px 0 4px; text-align: left; font-size: 12.5px; }

/* ===== SETTINGS ===== */
.settings-note { font-size: 13.5px; color: var(--muted); line-height: 1.55; margin-bottom: 16px; }
.backend-link {
  display: flex; align-items: center; gap: 14px;
  border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; text-decoration: none; color: var(--ink);
  transition: border-color .15s, background .15s;
}
.backend-link:hover { border-color: var(--blue); background: var(--blue-soft); }
.backend-ico {
  width: 42px; height: 42px; border-radius: 11px; flex-shrink: 0;
  background: var(--green-soft); color: var(--green);
  display: flex; align-items: center; justify-content: center;
}
.backend-ico svg { width: 21px; height: 21px; }
.backend-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.backend-name { font-weight: 600; font-size: 14.5px; }
.backend-sub { font-size: 12.5px; color: var(--muted); }
.backend-arrow { color: var(--muted); flex-shrink: 0; }
.backend-arrow svg { width: 18px; height: 18px; }
.about-rows { display: flex; flex-direction: column; }
.about-row {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.about-row:last-child { border-bottom: none; }
.about-row span:first-child { color: var(--muted); font-weight: 500; }
.about-row span:last-child { text-align: right; }

/* ===== PANEL / LEADS ===== */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.search-box {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 0 12px; flex: 1; min-width: 200px; max-width: 320px;
  background: var(--bg);
}
.search-box svg { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }
.search-box input {
  border: none; background: none; outline: none;
  font-family: inherit; font-size: 13.5px; color: var(--ink);
  height: 38px; width: 100%;
}
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; flex: 2; }
.chip {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 99px; padding: 6px 13px;
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  transition: all .15s;
}
.chip:hover { border-color: var(--blue); color: var(--blue); }
.chip.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--blue); color: #fff; border: none; border-radius: 10px;
  font-size: 14px; font-weight: 600; padding: 11px 18px;
  transition: background .15s;
}
.btn-primary:hover { background: #1f74bd; }
.btn-primary.sm { padding: 9px 15px; font-size: 13px; margin-left: auto; }
.btn-primary:disabled { opacity: .6; cursor: default; }

.panel-toolbar-title { font-family: var(--font-head); font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.panel-toolbar-sub { font-size: 12.5px; color: var(--muted); width: 100%; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 11.5px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .5px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: #FAFBFD;
  position: sticky; top: 0;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #F8FAFD; }
.td-name { font-weight: 600; }
.td-sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.td-phone { font-variant-numeric: tabular-nums; white-space: nowrap; }
.td-notes { max-width: 220px; color: var(--muted); font-size: 12.5px; }
.actions-col { width: 190px; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.mini-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  font-size: 11.5px; font-weight: 600; padding: 5px 10px; color: var(--muted);
  transition: all .15s; white-space: nowrap;
}
.mini-btn:hover { border-color: var(--blue); color: var(--blue); }
.mini-btn.danger:hover { border-color: var(--red); color: var(--red); background: var(--red-soft); }
.status-sel {
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  font-family: inherit; font-size: 12px; font-weight: 600; color: var(--ink);
  padding: 5px 7px; max-width: 120px;
}
.empty-note { padding: 34px; text-align: center; color: var(--muted); font-size: 13.5px; }

/* status pills */
.pill { display: inline-block; border-radius: 99px; padding: 4px 11px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.pill.New { background: #EDF1F7; color: var(--navy); }
.pill.Picked { background: var(--blue-soft); color: var(--blue); }
.pill.NotPicked { background: var(--red-soft); color: var(--red); }
.pill.Converted { background: var(--green-soft); color: var(--green); }
.pill.Approved { background: var(--amber-soft); color: var(--amber); }
.pill.Paid { background: var(--green-soft); color: var(--green); }

/* ===== MOBILE CARD LIST ===== */
.card-list { display: none; }

/* ===== MODAL / SHEET ===== */
.overlay {
  position: fixed; inset: 0; background: rgba(16,28,44,.55);
  z-index: 60; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.sheet {
  background: var(--surface); border-radius: 18px;
  width: 100%; max-width: 460px; max-height: 88vh; overflow-y: auto;
  padding: 22px 24px 26px;
}
.sheet-handle { display: none; }
.sheet-title { font-family: var(--font-head); font-size: 17px; font-weight: 700; margin-bottom: 18px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  font-family: inherit; font-size: 14px; color: var(--ink);
  padding: 10px 12px; outline: none; background: var(--surface);
  transition: border-color .15s;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue); }
.form-error { color: var(--red); font-size: 12.5px; font-weight: 500; min-height: 16px; margin-bottom: 8px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; }
.btn-ghost {
  background: none; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; font-weight: 600; color: var(--muted); padding: 11px 18px;
}

/* ===== TOAST / LOADING ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; border-radius: 10px;
  font-size: 13.5px; font-weight: 500; padding: 12px 20px;
  z-index: 80; box-shadow: 0 8px 24px rgba(16,28,44,.3);
  max-width: 90vw;
}
.toast.error { background: var(--red); }
.loading {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(245,247,250,.75);
  display: flex; align-items: center; justify-content: center;
}
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3.5px solid var(--line); border-top-color: var(--blue);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== PIN GATE ===== */
.pin-gate {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(160deg, var(--ink) 0%, var(--navy) 100%);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.pin-card {
  background: var(--surface); border-radius: 20px;
  width: 100%; max-width: 360px; padding: 34px 30px;
  text-align: center; box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.pin-logo { width: 54px; height: 54px; object-fit: contain; background: var(--navy); border-radius: 14px; padding: 8px; margin-bottom: 14px; }
.pin-title { font-family: var(--font-head); font-size: 20px; font-weight: 800; }
.pin-sub { font-size: 13px; color: var(--muted); margin: 6px 0 20px; }
.pin-input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px;
  font-family: inherit; font-size: 16px; font-weight: 600; letter-spacing: 1px;
  text-align: center; padding: 13px; outline: none; margin-bottom: 6px;
}
.pin-input:focus { border-color: var(--blue); }
.pin-card .btn-primary { width: 100%; margin-top: 6px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 900px) {
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; box-shadow: none; }
  .shell.nav-open .sidebar { transform: translateX(0); box-shadow: 12px 0 40px rgba(0,0,0,.3); }
  .content { margin-left: 0; }
  .menu-btn { display: flex; }
  main { padding: 18px 16px 32px; }
  .topbar { padding: 12px 16px; }
  .topbar-title h1 { font-size: 17px; }
  .synced-note { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 11px; }
  .stat-card { padding: 13px 14px; }
  .stat-card-val { font-size: 22px; }
  .stat-ico { width: 28px; height: 28px; }
  .table-wrap { display: none; }
  .card-list { display: flex; flex-direction: column; }
  .lead-card { padding: 14px 16px; border-bottom: 1px solid var(--line); }
  .lead-card:last-child { border-bottom: none; }
  .lead-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
  .lead-card-name { font-weight: 600; font-size: 14.5px; }
  .lead-card-phone { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 1px; }
  .lead-card-meta { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
  .lead-card-notes { font-size: 12.5px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 7px 10px; margin-bottom: 10px; }
  .lead-card-actions { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
  .panel-toolbar { gap: 10px; flex-direction: column; align-items: stretch; }
  .search-box { max-width: none; min-width: 0; width: 100%; }
  .btn-primary.sm { margin-left: 0; width: 100%; }
  .chip-row { width: 100%; }
  .overlay { padding: 0; align-items: flex-end; }
  .sheet { max-width: none; border-radius: 20px 20px 0 0; padding: 14px 20px calc(20px + env(safe-area-inset-bottom)); }
  .sheet-handle { display: block; width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 0 auto 14px; }
}
