/* ============================================================
   Quote Builder — Owner Dashboard v5
   Alp Web Studio brand system: parchment + abyss navy + alpine
   teal, with summit terracotta / glacier peach for money.
   Space Grotesk (display) + DM Sans (UI). Built for readability —
   40+ trades business owners.
   Light is the default; dark is the "abyss" navy world from the
   alpwebstudio.com dashboard mockup.
   ============================================================ */

:root {
  /* ── Parchment & surfaces ── */
  --bg:           #f6f2ec;   /* parchment */
  --bg-elev:      #fbf9f4;
  --surface:      #ffffff;
  --surface-2:    #ede7df;   /* parchment-dark */
  --hover:        #e7ded1;

  /* ── Hairlines ── */
  --border:       #e1d8c9;
  --border-light: #ebe4d8;

  /* ── Ink (abyss navy) ── */
  --text:         #1a2436;   /* abyss */
  --text-muted:   #525c70;
  --text-light:   #8a94a6;   /* ridge-light */

  /* ── Accent: alpine teal (brand) ── */
  --accent:       #1f5e7a;   /* alpine-700 */
  --accent-rgb:   31, 94, 122;
  --accent-soft:  rgba(31, 94, 122, .10);
  --accent-glow:  rgba(31, 94, 122, .22);
  --accent-hover: #154b63;   /* alpine-800 */
  --on-accent:    #f6f2ec;   /* parchment on teal */

  /* ── Money: summit terracotta ── */
  --gold:         #8a4e3b;   /* summit-dark */
  --gold-soft:    rgba(138, 78, 59, .10);

  /* ── Semantic ── */
  --info:         #1f5e7a;   /* alpine teal */
  --info-soft:    rgba(31, 94, 122, .10);
  --teal:         #3a8ca8;   /* alpine-500 */
  --teal-soft:    rgba(58, 140, 168, .11);
  --success:      #3f7a52;   /* muted forest — "won" */
  --success-soft: rgba(63, 122, 82, .11);
  --warning:      #9a6209;
  --warning-soft: rgba(154, 98, 9, .12);
  --danger:       #b5443b;   /* warm brick */
  --danger-soft:  rgba(181, 68, 59, .09);
  --purple:       #6a4ab0;
  --purple-soft:  rgba(106, 74, 176, .10);
  --slate:        #566076;   /* ridge */
  --slate-soft:   rgba(86, 96, 118, .12);

  /* ── Chrome ── */
  --topbar-bg:    rgba(246, 242, 236, .86);
  --scrim:        rgba(26, 36, 54, .45);   /* abyss-tinted */

  /* ── Layout ── */
  --radius:       8px;
  --radius-lg:    12px;
  --radius-pill:  99px;
  --sidebar-w:    228px;
  --topbar-h:     64px;
  --content-max:  1380px;

  /* ── Typography ── */
  --font-head:    "Space Grotesk", system-ui, -apple-system, sans-serif;
  --font-body:    "DM Sans", system-ui, -apple-system, sans-serif;

  /* ── Shadows (abyss-tinted, single light source from above) ── */
  --shadow-sm:    0 1px 2px rgba(26, 36, 54, .06);
  --shadow-md:    0 6px 20px -6px rgba(26, 36, 54, .14);
  --shadow-lg:    0 18px 44px -12px rgba(26, 36, 54, .22);
}

/* ── Dark: the "abyss" navy world (matches the alpwebstudio.com dashboard art) ── */
html[data-theme="dark"] {
  --bg:           #0e1520;   /* abyss-deep */
  --bg-elev:      #1a2436;   /* abyss */
  --surface:      #1f2a3d;
  --surface-2:    #26334a;
  --hover:        #2c3a52;

  --border:       #30405a;
  --border-light: #283449;

  --text:         #f6f2ec;   /* parchment */
  --text-muted:   #a8b2c4;
  --text-light:   #727e94;

  --accent:       #55aacb;   /* alpine-400 */
  --accent-rgb:   85, 170, 203;
  --accent-soft:  rgba(85, 170, 203, .13);
  --accent-glow:  rgba(85, 170, 203, .28);
  --accent-hover: #9ccfe2;   /* alpine-200 */
  --on-accent:    #0e1520;

  --gold:         #f2bba0;   /* glacier peach — money on navy */
  --gold-soft:    rgba(242, 187, 160, .14);

  --info:         #7fb8d6;
  --info-soft:    rgba(127, 184, 214, .14);
  --teal:         #6fc0dd;
  --teal-soft:    rgba(111, 192, 221, .14);
  --success:      #6fb58a;
  --success-soft: rgba(111, 181, 138, .14);
  --warning:      #d9a957;
  --warning-soft: rgba(217, 169, 87, .14);
  --danger:       #e08a85;
  --danger-soft:  rgba(224, 138, 133, .13);
  --purple:       #a88fe0;
  --purple-soft:  rgba(168, 143, 224, .14);
  --slate:        #97a1b5;
  --slate-soft:   rgba(151, 161, 181, .15);

  --topbar-bg:    rgba(14, 21, 32, .86);
  --scrim:        rgba(4, 8, 14, .6);

  --shadow-sm:    0 1px 2px rgba(0, 0, 0, .35);
  --shadow-md:    0 6px 20px -6px rgba(0, 0, 0, .5);
  --shadow-lg:    0 18px 44px -12px rgba(0, 0, 0, .65);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Enforce hidden attribute — class rules (display:flex/grid) beat UA stylesheet otherwise */
.login-screen[hidden],
.app[hidden],
.login-form[hidden],
.drawer-panel[hidden],
.messenger[hidden],
.nav-badge[hidden],
.modal-overlay[hidden],
.leads-view[hidden],
.analytics-view[hidden] { display: none !important; }

html { font-size: 16px; scroll-behavior: smooth; color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  font-family: var(--font-body);
  background-color: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  /* Faint paper grain — texture lives behind surfaces, in the gutters */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeComponentTransfer%3E%3CfeFuncA type='linear' slope='0.04'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

h1, h2, h3 { font-family: var(--font-head); font-weight: 600; letter-spacing: -.01em; }
/* Big numeric displays use the brand display face (Space Grotesk) for crisp numerals */
.stat-num, .metric-value, .price-range, .drawer-price-value, .review-score-num { font-family: var(--font-head); }
button { cursor: pointer; font-family: inherit; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; color: inherit; }
a { color: inherit; }
code { font-size: .8em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
::selection { background: var(--accent-glow); }

button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  html { scroll-behavior: auto; }
}


/* ══════════════════════════════════════════════════════════
   LOGIN
══════════════════════════════════════════════════════════ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  overflow: auto;
  background:
    radial-gradient(ellipse 70% 55% at 50% 22%, var(--accent-soft), transparent 70%),
    var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2.25rem 2.25rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo {
  width: 52px; height: 52px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-glow);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  margin: 0 auto 1.25rem;
}
.login-title {
  font-size: 1.65rem;
  font-weight: 600;
  margin-bottom: .3rem;
  color: var(--text);
}
.login-sub   { font-size: .9rem; color: var(--text-muted); margin-bottom: 1.75rem; }
.login-hint  { font-size: .85rem; color: var(--text-muted); margin-bottom: .75rem; text-align: left; line-height: 1.45; }

.login-form { text-align: left; display: flex; flex-direction: column; gap: 1.05rem; }
.login-field { display: flex; flex-direction: column; gap: .4rem; }
.login-field label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
}
.login-field input {
  padding: .8rem .9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
  background: var(--bg-elev);
  color: var(--text);
}
.login-field input::placeholder { color: var(--text-light); }
.login-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.login-error {
  font-size: .85rem;
  color: var(--danger);
  min-height: 1.1em;
}
.magic-message {
  font-size: .85rem;
  min-height: 1.1em;
  font-weight: 600;
  color: var(--accent);
}
.login-btn {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  font-size: 1rem;
  padding: .875rem;
  border-radius: var(--radius);
  position: relative;
  transition: background .15s, transform .05s;
  letter-spacing: .01em;
}
.login-btn:hover { background: var(--accent-hover); }
.login-btn:active { transform: translateY(1px); }
.login-btn.loading .login-btn-label { opacity: 0; }
.login-btn-spinner {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
}
.login-btn.loading .login-btn-spinner { display: flex; }
.login-btn-spinner::before {
  content: '';
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: var(--on-accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.login-toggle-wrap { margin-top: 1.4rem; }
.login-toggle { font-size: .85rem; color: var(--accent); font-weight: 500; text-decoration: none; }
.login-toggle:hover { text-decoration: underline; }


/* ══════════════════════════════════════════════════════════
   APP LAYOUT
══════════════════════════════════════════════════════════ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ── SIDEBAR ── */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  color: var(--text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: 1.35rem 1.25rem 1.1rem;
  font-family: var(--font-head);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}
.sidebar-logo svg { color: var(--accent); }
.sidebar-client {
  margin: 0 1rem .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem .7rem;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  word-break: break-all;
  min-height: 2rem;
}
.sidebar-nav {
  flex: 1;
  list-style: none;
  padding: .4rem .7rem;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  width: 100%;
  padding: .7rem .8rem;
  font-size: .94rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius);
  transition: background .12s, color .12s;
  text-align: left;
  position: relative;
  margin-bottom: .125rem;
}
.nav-link:hover { background: var(--hover); color: var(--text); }
.nav-link.active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
  font-weight: 600;
}
.nav-link.active svg { color: var(--accent); }
.nav-label { flex: 1; }
.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: var(--on-accent);
  font-size: .72rem;
  font-weight: 700;
  padding: .1rem .42rem;
  border-radius: var(--radius-pill);
  min-width: 19px;
  text-align: center;
}
.nav-badge[hidden] { display: none; }
.nav-badge--alert { background: var(--danger); color: var(--bg); }
.sidebar-logout {
  display: flex;
  align-items: center;
  gap: .55rem;
  margin: .15rem .7rem;
  padding: .65rem .8rem;
  font-size: .86rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius);
  transition: background .12s, color .12s;
}
.sidebar-logout:last-of-type { margin-bottom: .75rem; }
.sidebar-logout:hover { background: var(--hover); color: var(--text); }

/* ── MAIN CONTENT ── */
.main-content {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── TOP BAR ── */
.top-bar {
  height: var(--topbar-h);
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
}
.top-bar-right { display: flex; align-items: center; gap: .5rem; }
.page-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text);
}

/* Date range inputs */
.date-range-wrap {
  display: flex;
  align-items: center;
  gap: .375rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .3125rem .625rem;
  transition: border-color .15s;
}
.date-range-wrap:focus-within { border-color: var(--accent); }
.date-input {
  border: none;
  background: transparent;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text);
  outline: none;
  width: 122px;
}
.date-sep { font-size: .78rem; color: var(--text-muted); }

.btn-icon {
  min-width: 38px; height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: background .12s, color .12s, border-color .12s;
}
.btn-icon:hover { background: var(--hover); color: var(--text); border-color: var(--text-light); }
.btn-icon:active { transform: translateY(1px); }
.btn-icon.btn-primary {
  width: auto;
  padding: 0 1rem;
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
  font-size: .875rem;
  font-weight: 600;
}
.btn-icon.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn-icon.spinning svg { animation: spin .6s linear infinite; }


/* ══════════════════════════════════════════════════════════
   STATS — one joined ledger strip, hairline-divided
══════════════════════════════════════════════════════════ */
.stats-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  margin: 1.25rem auto 1rem;
  padding: 0;
  max-width: min(100% - 3rem, calc(var(--content-max) - 3rem));
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.stat-card {
  background: transparent;
  border: none;
  padding: 1.05rem 1.25rem 1.15rem;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  position: relative;
}
.stat-card + .stat-card { border-left: 1px solid var(--border-light); }
.stat-card:hover { background: var(--surface-2); }
.stat-card:active { background: var(--hover); }
.stat-card.active {
  background: var(--accent-soft);
  box-shadow: inset 0 -3px 0 var(--accent);
}
.stat-card--highlight .stat-num { color: var(--gold); }

.stat-body { display: flex; flex-direction: column; gap: .45rem; }
.stat-label {
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-muted);
  order: -1;
}
.stat-num {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  letter-spacing: -.01em;
}
.stat-num--green { color: var(--success); }


/* ══════════════════════════════════════════════════════════
   FILTER BAR
══════════════════════════════════════════════════════════ */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 auto;
  padding: 0 1.5rem 1rem;
  max-width: var(--content-max);
  width: 100%;
  flex-wrap: wrap;
}
.filter-tabs {
  display: flex;
  gap: .25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .25rem;
}
.filter-tab {
  padding: .42rem .9rem;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.filter-tab:hover { color: var(--text); background: var(--hover); }
.filter-tab.active {
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
}

.search-wrap { position: relative; }
.search-icon {
  position: absolute;
  left: .8rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  padding: .55rem .9rem .55rem 2.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  width: 230px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.search-input::placeholder { color: var(--text-light); }
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }


/* ══════════════════════════════════════════════════════════
   LEADS TABLE
══════════════════════════════════════════════════════════ */
.table-wrap {
  margin: 0 auto;
  max-width: min(100% - 3rem, calc(var(--content-max) - 3rem));
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}
.leads-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
  min-width: 720px;
}
.leads-table th {
  background: var(--surface-2);
  padding: .7rem 1rem;
  text-align: left;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.leads-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.leads-table tr:last-child td { border-bottom: none; }
.leads-table tbody tr {
  cursor: pointer;
  transition: background .1s;
}
.leads-table tbody tr:hover { background: var(--surface-2); }

/* Emergency row highlight */
.leads-table tbody tr.row-emergency td:first-child {
  border-left: 3px solid var(--danger);
}
.leads-table tbody tr.row-emergency:hover { background: var(--danger-soft); }

/* Date cell */
.lead-date { font-size: .85rem; color: var(--text-muted); white-space: nowrap; }

/* Name + phone cell */
.lead-name  { font-weight: 600; color: var(--text); }
.lead-phone-sub { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }

/* Service chip — squared, quiet */
.service-pill {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .78rem;
  font-weight: 600;
  padding: .25rem .6rem;
  border-radius: 6px;
  white-space: nowrap;
}
html[data-theme="dark"] .service-pill { color: var(--accent); }

/* Urgency chip — squared */
.urgency-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .25rem .6rem;
  border-radius: 6px;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}
.urgency-emergency { background: var(--danger-soft);  color: var(--danger); }
.urgency-soon      { background: var(--warning-soft); color: var(--warning); }
.urgency-this_week { background: var(--warning-soft); color: var(--warning); }
.urgency-flexible  { background: var(--success-soft); color: var(--success); }
.urgency-unknown   { background: var(--slate-soft);   color: var(--slate); }

/* Phone */
.lead-phone-link {
  color: var(--accent);
  font-size: .85rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.lead-phone-link:hover { text-decoration: underline; }

/* Price — amber ledger ink */
.price-range {
  font-weight: 700;
  white-space: nowrap;
  color: var(--gold);
}
.price-na { color: var(--text-light); font-style: italic; font-size: .85rem; }

/* Status — dot + plain text, no pill (cleaner read) */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: 0;
  border-radius: 0;
  font-size: .85rem;
  font-weight: 600;
  white-space: nowrap;
}
.status-badge::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-new       { color: var(--info); }
.badge-contacted { color: var(--warning); }
.badge-quoted    { color: var(--purple); }
.badge-won       { color: var(--success); }
.badge-lost      { color: var(--slate); }

/* View button */
.row-action {
  padding: .4rem .8rem;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  transition: all .15s;
  white-space: nowrap;
}
.row-action:hover {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}

/* Source badge — squared chip */
.source-badge {
  display: inline-block; padding: .2rem .5rem; border-radius: 6px;
  font-size: .74rem; font-weight: 600; white-space: nowrap;
  background: var(--slate-soft); color: var(--slate);
}
.src-google_ads { background: var(--info-soft);    color: var(--info); }
.src-google     { background: var(--teal-soft);    color: var(--teal); }
.src-facebook   { background: var(--purple-soft);  color: var(--purple); }
.src-instagram  { background: var(--purple-soft);  color: var(--purple); }
.src-referral   { background: var(--success-soft); color: var(--success); }
.src-direct, .src-other { background: var(--slate-soft); color: var(--slate); }
.src-detail { font-size: .76rem; color: var(--text-light); }

/* Unread lead indicators */
.unread-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: .4rem; vertical-align: middle; }
.leads-table tbody tr.row-unread .lead-name { font-weight: 700; }
.leads-table tbody tr.row-unread td:first-child { border-left: 3px solid var(--accent); }
.photo-pip { font-size: .8rem; }


/* ── Loading / empty states ── */
.loading-state, .empty-state {
  text-align: center;
  padding: 4rem 1.5rem;
  color: var(--text-muted);
}
.spinner {
  width: 32px; height: 32px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 1rem;
}
.empty-icon {
  width: 72px; height: 72px;
  margin: 0 auto .9rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border-radius: 50%;
  color: var(--text-light);
}
.empty-text {
  font-family: var(--font-head);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .3rem;
}
.empty-sub { font-size: .9rem; }

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
  max-width: var(--content-max);
  width: 100%;
}
.page-btn {
  padding: .55rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  transition: all .15s;
}
.page-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-info { font-size: .85rem; color: var(--text-muted); }


/* ══════════════════════════════════════════════════════════
   LEAD DRAWER
══════════════════════════════════════════════════════════ */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 100;
}
.lead-drawer {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: min(500px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 101;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.2,0,0,1);
}
.lead-drawer[hidden] { display: flex; visibility: hidden; }
.lead-drawer.open    { transform: translateX(0); visibility: visible; }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-title {
  font-family: var(--font-head);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
}
.drawer-close {
  width: 34px; height: 34px;
  border-radius: var(--radius);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
}
.drawer-close:hover { background: var(--hover); color: var(--text); }

.drawer-body { flex: 1; overflow-y: auto; padding: 1.25rem 1.5rem; }

/* Sections */
.drawer-section { margin-bottom: 1.6rem; }
.drawer-section-title {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .7rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--border-light);
}

/* Data rows */
.drawer-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border-light);
  font-size: .9rem;
  gap: .75rem;
}
.drawer-row:last-child { border-bottom: none; }
.drawer-key { color: var(--text-muted); flex-shrink: 0; }
.drawer-val { font-weight: 600; text-align: right; word-break: break-word; color: var(--text); }
.drawer-val a { color: var(--accent); }

/* Price block */
.drawer-price-block {
  background: var(--gold-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  text-align: center;
  margin-bottom: 1.25rem;
}
.drawer-price-label {
  font-size: .8rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: .35rem;
}
.drawer-price-value {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: -.01em;
}

/* CRM edit fields */
.drawer-field-group { margin-top: .9rem; }
.drawer-field-label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .4rem;
}
.drawer-field-input,
.drawer-field-textarea,
.drawer-status-select {
  width: 100%;
  padding: .7rem .875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  background: var(--bg-elev);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  resize: vertical;
}
.drawer-field-input::placeholder,
.drawer-field-textarea::placeholder { color: var(--text-light); }
.drawer-field-input:focus,
.drawer-field-textarea:focus,
.drawer-status-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.drawer-status-select { font-weight: 600; cursor: pointer; }

/* Revenue field hidden by default — shown via JS when status=won */
.revenue-group { display: none; }
.revenue-group.visible { display: block; }

/* Save button */
.drawer-save-btn {
  width: 100%;
  margin-top: 1rem;
  padding: .85rem;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  transition: background .15s, opacity .15s, transform .05s;
}
.drawer-save-btn:hover { background: var(--accent-hover); }
.drawer-save-btn:active { transform: translateY(1px); }
.drawer-save-btn:disabled { opacity: .5; cursor: not-allowed; }
.drawer-save-status {
  display: block;
  text-align: center;
  font-size: .85rem;
  font-weight: 600;
  color: var(--success);
  margin-top: .5rem;
  min-height: 1.2em;
}

/* Call button */
.drawer-call-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  width: 100%;
  padding: .85rem;
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid var(--success);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 1rem;
  text-decoration: none;
  margin-top: .75rem;
  transition: background .15s, color .15s;
}
.drawer-call-btn:hover { background: var(--success); color: var(--surface); }

/* Drawer tabs */
.drawer-tabs { display: flex; gap: .25rem; padding: 0 1.5rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.drawer-tab {
  padding: .8rem .25rem; margin-right: 1.1rem; font-size: .9rem; font-weight: 500;
  color: var(--text-muted); border-bottom: 2px solid transparent; transition: color .12s, border-color .12s;
}
.drawer-tab:hover { color: var(--text); }
.drawer-tab.active { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.drawer-tab-badge { background: var(--danger); color: var(--bg); font-size: .68rem; font-weight: 700; border-radius: var(--radius-pill); padding: 0 .38rem; }
.drawer-panel[hidden] { display: none; }
.drawer-panel[data-panel="messages"] { display: flex; flex-direction: column; height: 100%; }

.drawer-quick { display: flex; gap: .5rem; margin-bottom: 1.25rem; }
.quick-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .65rem; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg-elev); color: var(--text); font-weight: 600; font-size: .88rem;
  text-decoration: none; transition: border-color .12s, background .12s, color .12s;
}
.quick-btn:hover { border-color: var(--accent); color: var(--accent); }
.quick-btn--accent { background: var(--accent-soft); border-color: var(--accent-glow); color: var(--accent); }
html[data-theme="light"] .quick-btn--accent { color: var(--accent); }
.quick-btn--accent:hover { background: var(--accent); color: var(--on-accent); }

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { display: flex; gap: .75rem; padding: .35rem 0; position: relative; }
.tl-item:not(:last-child)::before { content: ''; position: absolute; left: 4px; top: 18px; bottom: -2px; width: 1px; background: var(--border); }
.tl-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; flex: none; z-index: 1; }
.dot-blue { background: var(--info); } .dot-green { background: var(--success); }
.dot-amber { background: var(--warning); } .dot-red { background: var(--danger); } .dot-slate { background: var(--slate); }
.tl-title { font-size: .88rem; font-weight: 600; color: var(--text); }
.tl-sub   { font-size: .79rem; color: var(--text-muted); }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--border); cursor: pointer; transition: opacity .12s; }
.photo-grid img:hover { opacity: .85; }

.drawer-thread { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; padding: .5rem 0 1rem; min-height: 200px; }


/* ══════════════════════════════════════════════════════════
   ANALYTICS
══════════════════════════════════════════════════════════ */
.metric-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;
  margin: 0 auto; padding: 1.25rem 1.5rem 0;
  max-width: var(--content-max); width: 100%;
}
.metric-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.15rem 1.3rem; display: flex; flex-direction: column; gap: .3rem;
  box-shadow: var(--shadow-sm);
}
.metric-card--hero { background: var(--accent-soft); border-color: var(--accent-glow); }
.metric-label { font-size: .8rem; font-weight: 500; color: var(--text-muted); }
.metric-value { font-size: 2.1rem; font-weight: 700; line-height: 1.05; color: var(--text); letter-spacing: -.01em; }
.metric-card--hero .metric-value { color: var(--accent); }
.metric-sub { font-size: .79rem; color: var(--text-light); }

.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2.5rem;
  max-width: var(--content-max);
  width: 100%;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.chart-card--wide { grid-column: 1 / -1; }
.chart-header {
  padding: 1.1rem 1.25rem .8rem;
  border-bottom: 1px solid var(--border-light);
}
.chart-title { font-family: var(--font-head); font-size: 1.02rem; font-weight: 600; color: var(--text); }
.chart-sub   { font-size: .81rem; color: var(--text-muted); margin-top: .15rem; }
.chart-body  { padding: 1.25rem; }
.chart-loading { text-align: center; color: var(--text-muted); font-size: .9rem; padding: 1.5rem 0; }
.chart-empty   { text-align: center; color: var(--text-muted); font-size: .9rem; padding: 1.5rem 0; font-style: italic; }

/* SVG chart styles */
.line-chart { display: block; width: 100%; overflow: visible; }
.chart-label {
  font-family: var(--font-body);
  font-size: 11px;
  fill: var(--text-muted);
}
.chart-axis { stroke: var(--border); stroke-width: 1; }
.chart-grid { stroke: var(--border-light); stroke-width: 1; stroke-dasharray: 4,4; }

/* Horizontal bar rows (services / urgency / sources) */
.hbar-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .65rem;
  font-size: .9rem;
}
.hbar-row:last-child { margin-bottom: 0; }
.hbar-label {
  width: 120px;
  flex-shrink: 0;
  font-weight: 500;
  font-size: .85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.hbar-sub { font-weight: 500; color: var(--success); font-size: .75rem; }
.hbar-track {
  flex: 1;
  height: 12px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}
.hbar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width .5s cubic-bezier(.2,0,0,1);
}
.hbar-count {
  width: 30px;
  text-align: right;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Funnel rows */
.funnel-row {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  align-items: center;
  gap: .875rem;
  margin-bottom: .75rem;
  font-size: .9rem;
}
.funnel-row:last-child { margin-bottom: 0; }
.funnel-label { font-weight: 500; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.funnel-bars  { position: relative; height: 18px; }
.funnel-track {
  height: 100%;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  position: absolute;
  left: 0; top: 0;
  min-width: 4px;
  transition: width .5s cubic-bezier(.2,0,0,1);
}
.funnel-complete {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width .5s cubic-bezier(.2,0,0,1);
}
.funnel-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .1rem;
  white-space: nowrap;
}
.funnel-views { font-size: .76rem; color: var(--text-muted); }
.funnel-drop  { font-size: .76rem; font-weight: 600; color: var(--text-muted); }
.funnel-drop.high-drop { color: var(--danger); }


/* ══════════════════════════════════════════════════════════
   GENERIC VIEW BODY / PANELS
══════════════════════════════════════════════════════════ */
.view-body {
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2.5rem;
  max-width: var(--content-max);
  width: 100%;
}
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.35rem 1.5rem; margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.panel-title { font-family: var(--font-head); font-size: 1.1rem; font-weight: 600; color: var(--text); margin-bottom: .25rem; }
.panel-sub   { font-size: .85rem; color: var(--text-muted); margin-bottom: 1rem; }
.empty-panel { text-align: center; padding: 2.5rem 1.5rem; }
.section-head { font-size: .85rem; font-weight: 600; color: var(--text-muted); margin: 1.25rem 0 .75rem; padding-bottom: .35rem; border-bottom: 1px solid var(--border-light); }
.section-empty { color: var(--text-light); font-size: .9rem; margin-bottom: 1rem; }
.inline-note { font-size: .84rem; color: var(--text-muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: .65rem .8rem; margin-bottom: 1rem; }
.inline-note.warn { color: var(--warning); border-color: var(--warning); background: var(--warning-soft); }


/* ══════════════════════════════════════════════════════════
   MESSENGER (Messages view)
══════════════════════════════════════════════════════════ */
.messenger { display: grid; grid-template-columns: 330px 1fr; height: calc(100vh - var(--topbar-h)); }
.conversation-list { border-right: 1px solid var(--border); overflow-y: auto; background: var(--bg-elev); }
.convo-item {
  width: 100%; display: flex; align-items: center; gap: .75rem; padding: .9rem 1rem;
  border-bottom: 1px solid var(--border-light); text-align: left; position: relative; transition: background .1s;
}
.convo-item:hover { background: var(--hover); }
.convo-item.active { background: var(--surface); box-shadow: inset 3px 0 0 var(--accent); }
.convo-item.unread .convo-name { font-weight: 700; }
.convo-item.no-lead { opacity: .55; }
.convo-avatar {
  width: 40px; height: 40px; flex: none; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: .95rem;
}
.convo-main { flex: 1; min-width: 0; }
.convo-top { display: flex; justify-content: space-between; gap: .5rem; }
.convo-name { font-size: .9rem; color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-time { font-size: .74rem; color: var(--text-light); flex: none; }
.convo-preview { display: block; font-size: .83rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: .1rem; }
.convo-unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.convo-empty { padding: 2.5rem 1.25rem; text-align: center; }
.convo-skeleton { height: 64px; margin: .5rem; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface), var(--surface-2), var(--surface)); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.thread-pane { display: flex; flex-direction: column; min-width: 0; }
.thread-empty { margin: auto; text-align: center; color: var(--text-muted); }
.thread-active { display: flex; flex-direction: column; height: 100%; }
.thread-head { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); flex-shrink: 0; background: var(--surface); }
.thread-back { display: none; align-items: center; gap: .25rem; font-size: .84rem; font-weight: 600; color: var(--accent); margin-bottom: .4rem; }
.thread-head-name { font-family: var(--font-head); font-weight: 600; font-size: 1.05rem; color: var(--text); }
.thread-head-sub { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin: .3rem 0 .15rem; }
.thread-head-service { font-size: .82rem; color: var(--text-muted); font-weight: 500; }
.thread-head-phone { font-size: .85rem; color: var(--accent); text-decoration: none; }
.thread-scroll { flex: 1; overflow-y: auto; padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: .5rem; }
.thread-hint { margin: auto; max-width: 320px; text-align: center; color: var(--text-muted); font-size: .88rem; }

/* Chat bubbles */
.bubble-row { display: flex; }
.bubble-row.out { justify-content: flex-end; }
.bubble { max-width: 78%; padding: .65rem .85rem; border-radius: 12px; display: flex; flex-direction: column; gap: .3rem; }
.bubble-in  { background: var(--surface-2); color: var(--text); border-bottom-left-radius: 4px; }
.bubble-out { background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 4px; }
.bubble-failed { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); }
.bubble-text { font-size: .9rem; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.bubble-meta { font-size: .68rem; opacity: .75; }
.bubble-img { max-width: 180px; border-radius: var(--radius); display: block; }

/* Composer */
.composer { display: flex; gap: .5rem; align-items: flex-end; padding: 1rem 1.5rem; border-top: 1px solid var(--border); flex-shrink: 0; background: var(--surface); }
.composer--drawer { padding: .75rem 0 0; border-top: 1px solid var(--border); background: transparent; }
.composer-input {
  flex: 1; resize: none; padding: .7rem .9rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg-elev); color: var(--text);
  font-size: .92rem; outline: none; max-height: 120px; transition: border-color .15s, box-shadow .15s;
}
.composer-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer-send {
  width: 44px; height: 44px; flex: none; border-radius: var(--radius); background: var(--accent);
  color: var(--on-accent); display: flex; align-items: center; justify-content: center; transition: background .12s;
}
.composer-send:hover { background: var(--accent-hover); }
.composer-send:disabled { opacity: .5; }


/* ══════════════════════════════════════════════════════════
   BOOKINGS
══════════════════════════════════════════════════════════ */
.booking-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 1rem; }
.booking-card { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius-lg); padding: 1.05rem 1.2rem; box-shadow: var(--shadow-sm); }
.booking-card.status-completed { border-left-color: var(--success); opacity: .85; }
.booking-card.status-cancelled, .booking-card.status-no_show { border-left-color: var(--slate); opacity: .65; }
.booking-card.status-confirmed { border-left-color: var(--success); }
.booking-when { display: flex; align-items: center; gap: .4rem; font-size: .81rem; font-weight: 600; color: var(--accent); margin-bottom: .5rem; }
.booking-name { font-family: var(--font-head); font-size: 1.08rem; font-weight: 600; color: var(--text); margin-bottom: .4rem; }
.booking-meta { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .35rem; }
.booking-addr { font-size: .84rem; color: var(--text-muted); margin-bottom: .25rem; }
.booking-notes { font-size: .84rem; color: var(--text-muted); font-style: italic; margin-bottom: .5rem; }
.booking-status-select { width: 100%; margin-top: .5rem; padding: .55rem .65rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); color: var(--text); font-weight: 600; font-size: .85rem; cursor: pointer; }


/* ══════════════════════════════════════════════════════════
   REVIEWS
══════════════════════════════════════════════════════════ */
.review-summary { display: flex; align-items: center; gap: 1.5rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.3rem 1.5rem; margin-bottom: 1.25rem; flex-wrap: wrap; box-shadow: var(--shadow-sm); }
.review-score { display: flex; align-items: center; gap: .6rem; }
.review-score-num { font-size: 2.3rem; font-weight: 700; color: var(--gold); line-height: 1; }
.review-score-count { font-size: .84rem; color: var(--text-muted); }
.review-summary-hint { flex: 1; min-width: 220px; font-size: .85rem; color: var(--text-muted); }
.stars { display: inline-flex; gap: 1px; color: var(--gold); }
.review-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; }
.review-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.15rem 1.25rem; display: flex; flex-direction: column; gap: .6rem; box-shadow: var(--shadow-sm); }
.review-card.featured { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold-soft), var(--shadow-sm); }
.review-card-top { display: flex; align-items: center; justify-content: space-between; }
.review-source { font-size: .74rem; color: var(--text-light); font-weight: 600; }
.review-body { font-size: .9rem; color: var(--text); line-height: 1.55; }
.review-body.muted { color: var(--text-light); font-style: italic; }
.review-foot { font-size: .81rem; color: var(--text-muted); }
.review-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.chip-toggle { padding: .42rem .75rem; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text-muted); font-size: .8rem; font-weight: 600; transition: all .12s; }
.chip-toggle:hover { color: var(--text); border-color: var(--accent); }
.chip-toggle.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-glow); }


/* ══════════════════════════════════════════════════════════
   SETTINGS
══════════════════════════════════════════════════════════ */
.settings-wrap { margin: 0 auto; padding: 1.25rem 1.5rem 6rem; max-width: 760px; width: 100%; }
.fld { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1.05rem; }
.fld > span { font-size: .85rem; font-weight: 600; color: var(--text); }
.fld input, .fld select, .fld textarea {
  padding: .7rem .85rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-elev); color: var(--text); font-size: .94rem; outline: none;
  transition: border-color .15s, box-shadow .15s; resize: vertical;
}
.fld input:focus, .fld select:focus, .fld textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.fld-hint { font-size: .79rem; color: var(--text-muted); font-weight: 400; }
.fld-check { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--text); margin: .25rem 0 .5rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }

/* Switch */
.switch-row { display: flex; gap: .8rem; align-items: flex-start; padding: .5rem 0 1rem; }
.switch { position: relative; flex: none; width: 46px; height: 26px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track { position: absolute; inset: 0; border-radius: var(--radius-pill); background: var(--surface-2); border: 1px solid var(--border); transition: background .15s, border-color .15s; }
.switch-track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--text-light); transition: transform .18s, background .15s; }
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(20px); background: var(--on-accent); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--accent-soft); }
.switch-text { display: flex; flex-direction: column; gap: .18rem; }
.switch-label { font-size: .94rem; font-weight: 600; color: var(--text); }
.switch-hint { font-size: .82rem; color: var(--text-muted); line-height: 1.45; }

/* Business hours grid */
.hours-grid { display: flex; flex-direction: column; }
.hours-row {
  display: grid;
  grid-template-columns: 100px 96px 1fr auto 1fr;
  align-items: center;
  gap: .6rem;
  padding: .45rem 0;
}
.hours-row + .hours-row { border-top: 1px solid var(--border-light); }
.hours-day { font-size: .9rem; font-weight: 600; color: var(--text); }
.hours-closed { font-size: .82rem; color: var(--text-muted); display: flex; align-items: center; gap: .35rem; cursor: pointer; }
.hours-closed input { accent-color: var(--accent); }
.hours-row input[type="time"] {
  padding: .5rem .55rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-elev); color: var(--text); font-size: .88rem; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.hours-row input[type="time"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hours-row input[type="time"]:disabled { opacity: .4; }
.hours-dash { color: var(--text-muted); text-align: center; }
@media (max-width: 600px) {
  .hours-row { grid-template-columns: 1fr 1fr 1fr; row-gap: .4rem; }
  .hours-day { grid-column: 1 / -1; padding-top: .2rem; }
  .hours-dash { display: none; }
}

.settings-save-bar { position: sticky; bottom: 0; display: flex; align-items: center; justify-content: flex-end; gap: 1rem; padding: 1rem 0; background: linear-gradient(transparent, var(--bg) 40%); }
.save-msg { font-size: .88rem; font-weight: 600; }
.btn-solid { background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: .94rem; padding: .75rem 1.5rem; border-radius: var(--radius); transition: background .12s, transform .05s; }
.btn-solid:hover { background: var(--accent-hover); }
.btn-solid:active { transform: translateY(1px); }
.btn-solid:disabled { opacity: .5; }
.btn-ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: .75rem 1.25rem; border-radius: var(--radius); font-weight: 500; transition: border-color .12s; }
.btn-ghost:hover { border-color: var(--accent); }


/* ══════════════════════════════════════════════════════════
   MODAL + TOAST
══════════════════════════════════════════════════════════ */
.modal-overlay { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: var(--scrim); opacity: 0; transition: opacity .2s; }
.modal-overlay.open { opacity: 1; }
.modal { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--accent); border-radius: var(--radius-lg); padding: 1.5rem; width: 100%; max-width: 460px; box-shadow: var(--shadow-lg); position: relative; transform: translateY(8px); transition: transform .2s; max-height: 90vh; overflow-y: auto; }
.modal-overlay.open .modal { transform: translateY(0); }
.modal-close { position: absolute; top: 1rem; right: 1rem; width: 32px; height: 32px; border-radius: var(--radius); color: var(--text-muted); display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: var(--hover); color: var(--text); }
.modal-title { font-family: var(--font-head); font-size: 1.2rem; font-weight: 600; margin-bottom: 1.25rem; color: var(--text); }
.modal-form .fld { margin-bottom: .9rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .75rem; margin-top: 1.25rem; }

.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(20px); z-index: 300; padding: .8rem 1.3rem; border-radius: var(--radius); font-size: .9rem; font-weight: 600; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--border); box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .25s, transform .25s; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--ok   { border-left-color: var(--success); color: var(--success); }
.toast--err  { border-left-color: var(--danger);  color: var(--danger); }
.toast--warn { border-left-color: var(--warning); color: var(--warning); }
@media (max-width: 860px) { .toast { bottom: 76px; } }


/* ══════════════════════════════════════════════════════════
   MOBILE TAB BAR
══════════════════════════════════════════════════════════ */
.mobile-tabs { display: none; }
@media (max-width: 860px) {
  .mobile-tabs {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
    background: var(--topbar-bg);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom));
  }
  .mtab {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: .45rem .25rem; color: var(--text-muted); font-size: .68rem; font-weight: 600;
    position: relative; transition: color .12s;
  }
  .mtab.active { color: var(--accent); }
  .mtab-dot { position: absolute; top: .3rem; right: 50%; transform: translateX(14px);
    width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
  .mtab-dot--alert { background: var(--danger); }
  .mtab-dot[hidden] { display: none; }
  .main-content { padding-bottom: 66px; }
}


/* ══════════════════════════════════════════════════════════
   ANIMATIONS
══════════════════════════════════════════════════════════ */
@keyframes spin { to { transform: rotate(360deg); } }

.leads-table tbody tr { animation: fadeIn .25s ease both; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}


/* ══════════════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
  .stats-row { grid-template-columns: repeat(3, 1fr); }
  .stat-card + .stat-card { border-left: none; }
  .stat-card:not(:nth-child(3n + 1)) { border-left: 1px solid var(--border-light); }
  .stat-card:nth-child(n + 4) { border-top: 1px solid var(--border-light); }
  .analytics-grid { grid-template-columns: 1fr; }
  .chart-card--wide { grid-column: auto; }
}

@media (max-width: 860px) {
  :root { --sidebar-w: 0px; }
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .top-bar { padding: 0 1rem; }
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
    margin: 1rem auto .75rem;
    max-width: min(100% - 2rem, calc(var(--content-max) - 2rem));
  }
  .stat-card { padding: .9rem 1rem 1rem; }
  .stat-card:not(:nth-child(3n + 1)) { border-left: none; }
  .stat-card:nth-child(2n) { border-left: 1px solid var(--border-light); }
  .stat-card:nth-child(n + 3) { border-top: 1px solid var(--border-light); }
  .stat-num { font-size: 1.55rem; }
  .filter-bar { padding: 0 1rem 1rem; }
  .table-wrap { max-width: min(100% - 2rem, calc(var(--content-max) - 2rem)); border-radius: var(--radius); }
  .pagination { padding: 1rem; }
  .metric-row { grid-template-columns: 1fr; padding: 1rem 1rem 0; }
  .analytics-grid { padding: 1rem; }
  .view-body { padding: 1rem 1rem 2.5rem; }
  .settings-wrap { padding: 1rem 1rem 6rem; }
  .search-input { width: 100%; }
  .search-wrap { flex: 1; min-width: 180px; }
  .messenger { grid-template-columns: 1fr; height: calc(100vh - var(--topbar-h) - 66px); }
  .conversation-list { display: block; border-right: none; }
  .thread-pane { display: none; }
  .messenger.show-thread .conversation-list { display: none; }
  .messenger.show-thread .thread-pane { display: flex; }
  .thread-back { display: inline-flex; }
}

@media (max-width: 520px) {
  html { font-size: 15px; }
  .top-bar { padding: 0 .875rem; height: 56px; }
  .page-title { font-size: 1.1rem; }
  .date-range-wrap { display: none; }
  .stats-row { margin: .75rem auto .6rem; max-width: min(100% - 1.5rem, 100%); }
  .stat-card { padding: .8rem .9rem .9rem; }
  .stat-num { font-size: 1.45rem; }
  .stat-label { font-size: .74rem; }
  .filter-bar { padding: 0 .75rem .75rem; gap: .625rem; }
  .filter-tabs {
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .filter-tabs::-webkit-scrollbar { display: none; }
  .table-wrap { max-width: min(100% - 1.5rem, 100%); }
  .pagination { padding: .875rem .75rem; gap: .625rem; }
  .lead-drawer { width: 100vw; }
  .drawer-header, .drawer-body { padding-left: 1rem; padding-right: 1rem; }
  .drawer-tabs { padding: 0 1rem; }
  .leads-table th, .leads-table td { padding: .7rem .75rem; }
}

/* Touch targets — at least 40px tall on coarse pointers */
@media (pointer: coarse) {
  .filter-tab { padding: .55rem 1rem; }
  .row-action { padding: .55rem .9rem; }
  .page-btn { padding: .65rem 1rem; }
  .nav-link { padding: .85rem .9rem; }
}
