/* =====================================================================
   X Dimension CRM — design system
   Sidebar layout · light UI · Inter · purple accent
   ===================================================================== */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #eceef3;
  --border-strong: #dfe2e9;
  --text: #111827;
  --text-2: #374151;
  --muted: #6b7280;
  --faint: #9ca3af;

  --primary: #c3337b;
  --primary-dark: #a3255f;
  --primary-soft: #fcedf4;
  --primary-ring: rgba(195, 51, 123, 0.18);
  --ink: #141b34;

  --success: #16a34a;
  --success-soft: #e9f8ef;
  --warning: #d97706;
  --warning-soft: #fff5e6;
  --danger: #dc2626;
  --danger-soft: #fdeeee;
  --info: #2563eb;
  --info-soft: #ebf2ff;
  --teal: #0d9488;
  --teal-soft: #e6f7f5;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.03);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);

  --sidebar-w: 248px;
  --topbar-h: 60px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;

  /* Theme helper tokens (light) — every hard-coded tint in the views points here */
  --chip: #f1f2f5;
  --switch-off: #d6d9e0;
  --tint-blue: #eef0ff; --tint-sky: #e0f2fe; --tint-teal: #e6f7f5; --tint-orange: #fff1e6; --tint-yellow: #fffbeb;
  --tint-pink: #fff8fb; --tint-pink-strong: #f9dcea; --tint-violet: #f3eefe; --tint-red: #fbdcdc;
  --line-red: #f8caca; --line-pink: #f6c9dd; --line-green: #c6ecd4; --line-blue: #d6e2ff; --line-yellow: #fde3b5;
  --c-red: #b91c1c; --c-green: #15803d; --c-amber: #b45309; --c-orange: #c2410c; --c-blue: #1d4ed8; --c-violet: #4338ca; --c-teal: #0f766e;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

h1, h2, h3, h4 { color: var(--text); letter-spacing: -0.01em; line-height: 1.25; }
h2 { font-size: 22px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 600; }
h4 { font-size: 14px; font-weight: 600; }

img, video { max-width: 100%; }

code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }

::selection { background: var(--primary-soft); }

/* ---------------------------------------------------------------------
   App shell
   --------------------------------------------------------------------- */
.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: transform 0.25s ease;
}

.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px;
  color: var(--text);
}
.sb-brand:hover { color: var(--text); }
.sb-logo {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #d9579a, #c3337b);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 800; font-size: 16px;
  box-shadow: 0 4px 10px rgba(195, 51, 123, 0.3);
  flex: 0 0 auto;
}
.sb-brand-name { font-weight: 700; font-size: 15px; line-height: 1.2; }
.sb-brand-sub { font-size: 11.5px; color: var(--muted); line-height: 1.2; }

.sb-close {
  display: none;
  margin-left: auto;
  width: 32px; height: 32px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  cursor: pointer;
}
.sb-close:hover { background: var(--surface-2); }

/* workspace card (client switcher for staff) */
.sb-workspace {
  margin: 4px 14px 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  position: relative;
}
.sb-ws-badge {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
  flex: 0 0 auto;
}
.sb-ws-text { min-width: 0; flex: 1; }
.sb-ws-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-ws-sub { font-size: 11.5px; color: var(--muted); }
.sb-ws-chev { color: var(--faint); flex: 0 0 auto; }
.sb-ws-select {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
  font-size: 16px;
}
.sb-workspace.is-filtered { border-color: var(--line-yellow); background: var(--tint-yellow); }

.sb-nav { flex: 1; overflow-y: auto; padding: 6px 12px 12px; }
.sb-section {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 14px 10px 6px;
}
.sb-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  margin-bottom: 2px;
  border-radius: 8px;
  color: var(--text-2);
  font-weight: 500;
  font-size: 13.5px;
  transition: background 0.15s, color 0.15s;
}
.sb-link svg { width: 18px; height: 18px; color: var(--muted); flex: 0 0 auto; }
.sb-link:hover { background: var(--surface-2); color: var(--text); }
.sb-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sb-link.active svg { color: var(--primary); }
.sb-count {
  margin-left: auto;
  font-size: 11px; font-weight: 600;
  background: var(--primary-soft); color: var(--primary);
  border-radius: 999px; padding: 1px 8px;
}
.sb-count.danger { background: var(--danger-soft); color: var(--danger); }

.sb-user {
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}
.sb-user-text { min-width: 0; flex: 1; }
.sb-user-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-role { font-size: 11.5px; color: var(--muted); }

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #c08457, #8d5b3c);
  color: #fff;
  font-size: 12px; font-weight: 700;
  display: grid; place-items: center;
  flex: 0 0 auto;
  letter-spacing: 0.02em;
}
.avatar.sm { width: 30px; height: 30px; font-size: 11px; }
.avatar.lg { width: 44px; height: 44px; font-size: 15px; }

.icon-btn {
  width: 36px; height: 36px;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  position: relative;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn .dot {
  position: absolute; top: 7px; right: 8px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--danger); border: 2px solid var(--surface);
  box-sizing: content-box;
}

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, 0.45);
  z-index: 55;
}

.app-main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky; top: 0;
  z-index: 40;
  height: var(--topbar-h);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
}
.tb-menu { display: none; }
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--faint); min-width: 0; }
.crumbs span:last-child { color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.tb-search { position: relative; }
.tb-search input {
  width: 220px;
  height: 36px;
  padding: 0 12px 0 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  font: inherit; font-size: 13px;
  color: var(--text);
  outline: none;
  transition: width 0.2s, border-color 0.15s, box-shadow 0.15s;
}
.tb-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); background: var(--surface); width: 260px; }
.tb-search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--faint); pointer-events: none; }

.menu-wrap { position: relative; }
.avatar-btn { border: 0; background: transparent; padding: 2px; border-radius: 50%; cursor: pointer; }
.avatar-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.dropdown {
  position: absolute;
  right: 0; top: calc(100% + 8px);
  min-width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
  z-index: 80;
}
.dropdown.open { display: block; }
.dropdown.up { top: auto; bottom: calc(100% + 8px); left: 0; right: 0; }
.dd-head { display: flex; gap: 10px; align-items: center; padding: 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dd-head .n { font-weight: 600; font-size: 13px; }
.dd-head .e { font-size: 12px; color: var(--muted); word-break: break-all; }
.dd-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0; background: transparent;
  border-radius: 8px;
  color: var(--text-2);
  font: inherit; font-size: 13px; font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.dd-item svg { width: 16px; height: 16px; color: var(--muted); }
.dd-item:hover { background: var(--surface-2); color: var(--text); }
.dd-item.danger { color: var(--danger); }
.dd-item.danger svg { color: var(--danger); }
.dd-form { margin: 0; }

.container {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 28px 32px;
  flex: 1;
}

.app-footer {
  padding: 16px 28px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface);
}
.app-footer a { color: var(--muted); }
.app-footer a:hover { color: var(--primary); }
.app-footer .brand-x { color: var(--primary); font-weight: 600; }
.app-footer .links { display: flex; gap: 14px; }

/* guest (login / register) */
.guest-shell { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.guest-top { padding: 22px 28px; }
.guest-shell .container { max-width: 1100px; display: flex; flex-direction: column; }
.guest-shell .app-footer { background: transparent; border-top: 0; justify-content: center; }

/* ---------------------------------------------------------------------
   Notices
   --------------------------------------------------------------------- */
.alert, .alert-box {
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--success-soft);
  border: 1px solid var(--line-green);
  color: var(--c-green);
  margin-bottom: 16px;
  font-size: 13.5px;
}
.alert-danger, .alert-error, .alert-box.alert-error { background: var(--danger-soft); border-color: var(--line-red); color: var(--c-red); }
.alert-success, .alert-box.alert-success { background: var(--success-soft); border-color: var(--line-green); color: var(--c-green); }
.alert-warning { background: var(--warning-soft); border-color: var(--line-yellow); color: var(--c-amber); }
.alert-info { background: var(--info-soft); border-color: var(--line-blue); color: var(--c-blue); }

.notice {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid;
  margin-bottom: 14px;
  font-size: 13.5px;
}
.notice.danger { background: var(--danger-soft); border-color: var(--line-red); color: var(--c-red); }
.notice.warn { background: var(--tint-yellow); border-color: var(--line-yellow); color: var(--c-amber); }
.notice.info { background: var(--primary-soft); border-color: var(--line-pink); color: #a3255f; }
.notice a { font-weight: 600; color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.notice form { margin: 0; }

/* ---------------------------------------------------------------------
   Page header
   --------------------------------------------------------------------- */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.page-eyebrow { font-size: 12px; font-weight: 600; color: var(--primary); margin-bottom: 4px; }
.page-title { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.25; color: var(--text); }
.page-subtitle { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.section-title { font-size: 16px; font-weight: 600; margin-bottom: 2px; }
.section-subtitle { color: var(--muted); font-size: 13px; margin-bottom: 14px; }

/* ---------------------------------------------------------------------
   Cards & grid
   --------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  max-width: 100%;
  min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 600; }
.card-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* ---------------------------------------------------------------------
   Stat cards
   --------------------------------------------------------------------- */
.stat-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  color: var(--text);
  position: relative;
}
a.stat-card:hover { color: var(--text); }
.stat-link, a.stat-card { transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s; }
.stat-link:hover, a.stat-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-link.active, a.stat-card.active { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }

.stat-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  flex: 0 0 auto;
}
.stat-icon svg { width: 19px; height: 19px; }
.stat-icon.danger { background: var(--danger-soft); color: var(--danger); }
.stat-icon.warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.success { background: var(--success-soft); color: var(--success); }
.stat-icon.primary { background: var(--primary-soft); color: var(--primary); }
.stat-icon.info { background: var(--info-soft); color: var(--info); }
.stat-icon.teal { background: var(--teal-soft); color: var(--teal); }

.stat-title { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; color: var(--text); }
.stat-value.danger, .stat-value.warning, .stat-value.success { color: var(--text); }
.stat-sub { color: var(--muted); font-size: 12px; }
.stat-primary { background: linear-gradient(135deg, #d9579a, #c3337b); color: #fff; border-color: transparent; }
.stat-primary .stat-title, .stat-primary .stat-sub { color: #e6e2ff; }
.stat-primary .stat-value { color: #fff; }
.kpi { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }

/* ---------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-ring); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-light { background: var(--surface); color: var(--text-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-dark:hover { background: #1f2937; border-color: #1f2937; color: #fff; }
.btn-danger { background: var(--danger-soft); border-color: var(--line-red); color: var(--c-red); }
.btn-danger:hover { background: var(--tint-red); color: var(--c-red); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; }
.btn-apply {
  height: 38px; padding: 0 18px;
  border: 1px solid var(--primary); border-radius: 8px;
  background: var(--primary); color: #fff;
  font: inherit; font-size: 13.5px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
.btn-apply:hover { background: var(--primary-dark); }
.link { color: var(--primary); font-weight: 600; }

/* ---------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------- */
label { font-size: 13px; font-weight: 500; color: var(--text-2); }

.input, .select, .textarea,
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="url"],
input[type="tel"], input[type="date"], input[type="datetime-local"], input[type="time"], input[type="month"], input[type="search"],
select, textarea {
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
}

.input, .select, .textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea { min-height: 90px; resize: vertical; }
.select, select.input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.input:focus, .select:focus, .textarea:focus,
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); outline: none; }
.search-input { background: var(--surface-2); }
.field-help { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }

input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 15px; height: 15px; vertical-align: middle; }

.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-row > * { min-width: 0; }
.followup-top-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }

.toolbar { display: flex; gap: 12px; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .actions { display: flex; gap: 10px; }
.filter-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------- */
.table-scroll, .table-wrapper, .table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-scroll::-webkit-scrollbar, .table-wrapper::-webkit-scrollbar, .table-responsive::-webkit-scrollbar { height: 6px; }
.table-scroll::-webkit-scrollbar-thumb, .table-wrapper::-webkit-scrollbar-thumb, .table-responsive::-webkit-scrollbar-thumb { background: var(--switch-off); border-radius: 10px; }

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  white-space: nowrap;
}
.table td { padding: 13px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-2); }
.table tbody tr { transition: background 0.12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }

/* ---------------------------------------------------------------------
   Badges / pills
   --------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--tint-blue);
  color: var(--c-violet);
  white-space: nowrap;
}
.badge.green, .badge.success { background: var(--success-soft); color: var(--c-green); }
.badge.red, .badge.danger { background: var(--danger-soft); color: var(--c-red); }
.badge.amber, .badge.warning { background: var(--warning-soft); color: var(--c-amber); }
.badge.blue, .badge.info { background: var(--info-soft); color: var(--c-blue); }
.badge.gray { background: var(--chip); color: var(--muted); }
.badge.teal { background: var(--teal-soft); color: var(--c-teal); }

.pill {
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
}

.score-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 22px; padding: 0 8px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--chip); color: var(--muted);
  border: 0;
}
.score-pill.green, .score-pill.score-high { background: var(--success-soft); color: var(--c-green); }
.score-pill.yellow, .score-pill.score-mid { background: var(--warning-soft); color: var(--c-amber); }
.score-pill.red, .score-pill.score-low { background: var(--danger-soft); color: var(--c-red); }

/* ---------------------------------------------------------------------
   Pagination
   --------------------------------------------------------------------- */
.pagination { margin-top: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.pagination .page {
  min-width: 32px; height: 32px;
  padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-weight: 500; font-size: 13px;
}
.pagination a.page:hover { background: var(--surface-2); }
.pagination .page.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .page.disabled { color: var(--faint); background: var(--surface-2); cursor: not-allowed; }

/* ---------------------------------------------------------------------
   Utilities
   --------------------------------------------------------------------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* follow-up history (lead page) */
.followup-history-scroll {
  max-height: 380px;
  overflow: auto;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}
.followup-history-table { min-width: 820px; }
.followup-history-table th { position: sticky; top: 0; z-index: 1; }
.followup-file-link { display: inline-block; font-weight: 600; }
.followup-file-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.followup-file-name { margin-top: 6px; font-size: 12px; color: var(--muted); word-break: break-word; }

/* ---------------------------------------------------------------------
   Bulk upload
   --------------------------------------------------------------------- */
.bulk-page { padding-top: 0; }
.bulk-grid { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 20px; align-items: start; }
.upload-card { padding: 20px; }
.upload-form { display: grid; gap: 14px; }
.dropzone {
  border: 1.5px dashed var(--line-pink);
  border-radius: 12px;
  padding: 24px;
  display: grid; gap: 6px;
  text-align: center;
  cursor: pointer;
  background: var(--tint-pink);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone input { display: none; }
.drop-icon { width: 42px; height: 42px; margin: 0 auto 4px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; }
.drop-title { font-weight: 600; }
.drop-sub { color: var(--muted); font-size: 12px; }
.upload-btn { width: 100%; }
.how-card { margin-top: 16px; background: var(--ink); color: #fff; border-color: var(--ink); }
.how-title { text-transform: uppercase; font-size: 11px; letter-spacing: 0.08em; font-weight: 600; margin-bottom: 10px; color: #f3a9cb; }
.how-list { margin: 0; padding-left: 18px; font-size: 13px; color: #e5e7eb; display: grid; gap: 8px; }
.template-card { margin-top: 16px; }
.preview-card { min-height: 360px; padding: 0; overflow: hidden; }
.preview-head { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.preview-body { min-height: 300px; display: grid; place-items: center; text-align: center; padding: 24px; }
.preview-icon { width: 54px; height: 54px; border-radius: 14px; background: var(--surface-2); display: grid; place-items: center; color: var(--faint); font-weight: 700; margin-bottom: 8px; }
.preview-table { width: 100%; overflow: auto; max-height: 340px; text-align: left; }
.preview-card .table { min-width: 760px; }
.preview-footer { margin-top: 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.map-source { display: flex; align-items: center; gap: 8px; }
.file-pill { display: flex; gap: 10px; align-items: center; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; border: 1px solid var(--border); }
.file-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 11px; }
.file-name { font-weight: 600; }

/* ---------------------------------------------------------------------
   Auth
   --------------------------------------------------------------------- */
.auth-wrap { flex: 1; min-height: 60vh; display: grid; place-items: center; padding: 20px 0 40px; }
.auth-card {
  width: min(420px, 100%);
  padding: 30px 28px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.05), 0 20px 40px -12px rgba(16, 24, 40, 0.1);
  border: 1px solid var(--border);
}
.auth-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.auth-sub { color: var(--muted); margin: 4px 0 20px; font-size: 13.5px; }
.auth-form { display: grid; gap: 14px; }
.auth-form label { display: block; margin-bottom: 6px; }
.auth-form .btn { height: 42px; width: 100%; }

/* ---------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  body.sb-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
  body.sb-open .sidebar-backdrop { display: block; }
  body.sb-open { overflow: hidden; }
  .sb-close { display: inline-grid; place-items: center; }
  .app-main { margin-left: 0; }
  .tb-menu { display: inline-grid; margin-left: -8px; }
  .topbar { padding: 0 18px; }
  .container { padding: 20px 18px 28px; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bulk-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .tb-search { display: none; }
  .crumbs .crumb-root, .crumbs .crumb-sep { display: none; }
  .page-title { font-size: 20px; }
  .page-head { align-items: stretch; margin-bottom: 18px; }
  .page-head .actions { width: 100%; }
  .page-head .actions > .btn, .page-head .actions > a.btn { flex: 1 1 0; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .form-row, .followup-top-row { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .app-footer { padding: 14px 18px; justify-content: center; text-align: center; }
  .filter-row > .input, .filter-row > .select, .filter-row > select, .filter-row > input { flex: 1 1 100%; min-width: 0; }
  .toolbar { align-items: stretch; }
}

@media (max-width: 520px) {
  .container { padding: 16px 14px 24px; }
  .topbar { padding: 0 12px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card { padding: 14px; gap: 10px; }
  .stat-value { font-size: 22px; }
  .auth-card { padding: 24px 18px; }
}

/* tables that cannot be wrapped (inline forms across rows) */
@media (max-width: 1024px) {
  .table-selfscroll { display: block; overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
}

/* =====================================================================
   Report kit — shared by Report, Cost Details, Pivot Cost, ROI, Ad Spend
   ===================================================================== */
.page-wrapper { width: 100%; }

.filter-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.filter-card .filter-row, .filter-card form > .filter-row { align-items: flex-end; gap: 12px; }
.fg { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.flabel { font-size: 12px; font-weight: 500; color: var(--muted); }
.finput {
  height: 38px;
  border-radius: 8px;
  font: inherit;
  font-size: 13.5px;
  border: 1px solid var(--border-strong);
  padding: 0 11px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  max-width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select.finput {
  appearance: none; -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
.finput:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }

.btn-export, .btn-clear, .btn-ghost {
  height: 38px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0 15px;
  border-radius: 8px;
  font: inherit; font-size: 13.5px; font-weight: 500;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-export { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.btn-export:hover { background: var(--surface-2); color: var(--text); }
.btn-clear, .btn-ghost { background: transparent; color: var(--muted); border: 1px solid transparent; }
.btn-clear:hover, .btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost { border-color: var(--border); background: var(--surface); color: var(--text-2); }
.button-group { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }

/* summary tiles */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.summary-card .s-label { font-size: 13px; color: var(--muted); font-weight: 500; margin-bottom: 8px; }
.summary-card .s-value { font-size: 24px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.summary-card .s-icon {
  position: absolute; right: 16px; top: 16px;
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  font-size: 17px;
  background: var(--primary-soft);
}
.summary-card.leads .s-icon { background: var(--info-soft); }
.summary-card.spend .s-icon { background: var(--warning-soft); }
.summary-card.cpl .s-icon { background: var(--success-soft); }

/* table card */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.table-card .table-responsive { max-height: 70vh; overflow: auto; position: relative; }

/* tree / pivot tables */
table.pivot, table.cost-tree { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.pivot thead, table.cost-tree thead { position: sticky; top: 0; z-index: 2; }
table.pivot th, table.cost-tree thead th {
  padding: 11px 12px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
table.pivot th:first-child, table.cost-tree thead th:first-child { text-align: left; }
table.pivot td, table.cost-tree td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
  color: var(--text-2);
  background: var(--surface);
}
table.pivot th:first-child, table.pivot td:first-child {
  position: sticky; left: 0;
  min-width: 320px; max-width: 320px;
  z-index: 5;
  white-space: normal;
}
table.pivot td:first-child { background: inherit; background-color: var(--surface); }
table.pivot thead th:first-child { background: var(--surface-2); z-index: 20; }
table.pivot tfoot td, table.cost-tree tfoot td {
  font-weight: 600;
  color: var(--text);
  border-top: 1px solid var(--border-strong);
  border-bottom: 0;
  background: var(--surface-2);
  position: sticky; bottom: 0;
}
table.pivot tfoot td:first-child { background: var(--surface-2); z-index: 20; }
tr.node-row:hover td, tr.node-row:hover td:first-child { background: var(--tint-pink) !important; }
tr.depth-0 td { background: var(--surface-2); }
tr.depth-0 td:first-child { background-color: var(--surface-2); }

.label-cell { text-align: left !important; }
.label-inner { display: flex; align-items: center; gap: 8px; }
.toggle-btn {
  width: 20px; height: 20px; min-width: 20px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  font-weight: 600; font-size: 13px; line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}
.toggle-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.toggle-spacer { display: inline-block; width: 20px; min-width: 20px; }
.node-label { font-weight: 500; color: var(--text); }
.lvl-0 { font-weight: 600; color: var(--text); }
.lvl-1 { font-weight: 500; color: var(--text-2); }
.lvl-2 { font-weight: 500; color: var(--muted); }
.lvl-3 { font-weight: 400; color: var(--muted); }

.pct-pill, .spend-pill, .cpl-pill, .na-pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
}
.spend-pill { background: var(--warning-soft); color: var(--c-amber); }
.cpl-pill { background: var(--success-soft); color: var(--c-green); }
.na-pill { background: var(--chip); color: var(--faint); font-weight: 500; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; font-size: 12px; color: var(--muted); }
.legend span.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.report-note { margin-top: 12px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.tree-tools { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }

@media (max-width: 760px) {
  .filter-card { padding: 14px; }
  .filter-card .filter-row > .fg { flex: 1 1 calc(50% - 6px); }
  .filter-card .finput { width: 100% !important; }
  .filter-card .button-group, .filter-card .filter-row > .fg:has(> .btn-apply),
  .filter-card .filter-row > .fg:has(> .btn-export), .filter-card .filter-row > .fg:has(> .btn-clear) { flex: 1 1 100%; }
  .button-group > * { flex: 1 1 0; }
  .fg > .btn-apply, .fg > .btn-export, .fg > .btn-clear { width: 100%; }
  table.pivot th:first-child, table.pivot td:first-child { min-width: 190px; max-width: 190px; }
  .summary-card .s-value { font-size: 20px; }
}
@media (max-width: 760px) { .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } .summary-card { padding: 14px; } .summary-card .s-icon { width: 30px; height: 30px; font-size: 14px; right: 12px; top: 12px; } .summary-card .s-label { padding-right: 34px; font-size: 12px; } }

/* every plain dropdown inside the app gets the same chevron */
.container select:not([multiple]):not([size]) {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-color: var(--surface);
}

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

/* =====================================================================
   Bell notifications
   ===================================================================== */
.notif-count {
  /* round red badge sitting on the bell's top-right corner */
  position: absolute; top: -3px; right: -4px;
  width: 19px; height: 19px; padding: 0;
  border-radius: 50%;
  background: #c0392b; color: #fff;
  font-size: 10.5px; font-weight: 800; line-height: 19px; text-align: center; letter-spacing: -.02em;
  border: 2px solid var(--surface); box-sizing: content-box;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  pointer-events: none;
}
.notif-count.wide { font-size: 9px; }
html[data-theme="dark"] .notif-count { background: #d64541; }
.notif-count[hidden] { display: none; }
.notif-panel { width: 360px; max-width: calc(100vw - 24px); padding: 0; overflow: hidden; right: -8px; }
.np-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.np-link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer; }
.np-link:hover { color: var(--primary-dark); text-decoration: underline; }
.np-alert { display: block; padding: 9px 14px; background: var(--danger-soft); color: var(--c-red); font-size: 12.5px; font-weight: 500; border-bottom: 1px solid var(--line-red); }
.np-alert:hover { color: var(--c-red); }
.np-alert[hidden] { display: none; }
.np-list { max-height: min(420px, 60vh); overflow-y: auto; }
.np-item { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text); position: relative; }
.np-item:last-child { border-bottom: 0; }
.np-item:hover { background: var(--surface-2); color: var(--text); }
.np-item.unread { background: var(--tint-pink); }
.np-item.unread::before { content: ""; position: absolute; left: 5px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--primary); }
.np-av { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 11px; font-weight: 700; display: grid; place-items: center; flex: 0 0 auto; }
.np-body { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.np-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-item.unread .np-name { color: var(--primary-dark); }
.np-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-time { font-size: 11.5px; color: var(--faint); white-space: nowrap; flex: 0 0 auto; }
.np-empty { padding: 28px 14px; text-align: center; color: var(--muted); font-size: 13px; }
.np-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--surface-2); }
.np-foot .np-link { margin-left: auto; }
.np-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); cursor: pointer; margin: 0; }
.np-toggle[hidden] { display: none; }
@media (max-width: 520px) {
  .notif-panel { position: fixed; top: calc(var(--topbar-h) + 4px); left: 12px; right: 12px; width: auto; max-width: none; }
}

/* =====================================================================
   Brand logo
   ===================================================================== */
.sb-brand { padding: 20px 18px 14px; gap: 8px; }
.sb-wordmark { display: block; height: 30px; width: auto; }
.guest-top .sb-wordmark { height: 34px; }
.sb-tag {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em;
  color: var(--primary); background: var(--primary-soft);
  border-radius: 6px; padding: 2px 6px; margin-top: 4px;
}
.sb-ws-badge { background: var(--ink); }

/* Brand button (register / password pages; restyled on the login scene by auth.css) */
.btn-brand {
  height: 46px; width: 100%;
  background: linear-gradient(135deg, #d0408a, #b02a6e);
  border: 0; color: #fff; font-weight: 600; font-size: 14.5px;
  box-shadow: 0 10px 22px -10px rgba(195, 51, 123, .7);
}
.btn-brand:hover { background: linear-gradient(135deg, #c33580, #9d2361); color: #fff; }

.sb-ws-badge img { width: 20px; height: 20px; display: block; }
.btn svg, .dd-item svg, .icon-btn svg { flex-shrink: 0; }


/* ---------------------------------------------------------------------
   Dark theme — <html data-theme="dark"> (picked in the account menu)
   --------------------------------------------------------------------- */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1120;
  --surface: #161a2c;
  --surface-2: #1b2034;
  --border: #272d45;
  --border-strong: #343b58;
  --text: #e9ebf3;
  --text-2: #c4c8d8;
  --muted: #959bb2;
  --faint: #6d7493;
  --primary: #e2579d;
  --primary-dark: #f283ba;
  --primary-soft: #36192b;
  --primary-ring: rgba(226, 87, 157, 0.32);
  --ink: #2b3250;
  --success-soft: #12301f;
  --warning-soft: #33260f;
  --danger-soft: #3a1a1e;
  --info-soft: #172443;
  --teal-soft: #11302d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 14px 34px rgba(0, 0, 0, 0.55);
  --chip: #252a42;
  --switch-off: #3b425f;
  --tint-blue: #1b2547; --tint-sky: #12293d; --tint-teal: #11302d; --tint-orange: #35220f; --tint-yellow: #312a10;
  --tint-pink: #2a1624; --tint-pink-strong: #4a2038; --tint-violet: #251c43; --tint-red: #3a1a1e;
  --line-red: #5b2a30; --line-pink: #5a2a46; --line-green: #23503a; --line-blue: #2d3f70; --line-yellow: #574516;
  --c-red: #f87171; --c-green: #4ade80; --c-amber: #fbbf24; --c-orange: #fb923c; --c-blue: #7aa7ff; --c-violet: #a99bff; --c-teal: #2dd4bf;
}
html[data-theme="dark"] .btn-dark:hover { background: #39416a; border-color: #39416a; }
html[data-theme="dark"] .sb-wordmark.for-light, html:not([data-theme="dark"]) .sb-wordmark.for-dark { display: none; }
html[data-theme="dark"] img.for-light { display: none; }
html:not([data-theme="dark"]) img.for-dark { display: none; }
html[data-theme="dark"] ::selection { background: #5a2a46; }
html[data-theme="dark"] input::placeholder, html[data-theme="dark"] textarea::placeholder { color: var(--faint); }
/* theme switcher in the account menu */
.theme-seg { display: flex; gap: 4px; padding: 6px 8px; }
.theme-seg button { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 5px; height: 30px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); border-radius: 8px; font: inherit; font-size: 12px; cursor: pointer; }
.theme-seg button.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.theme-label { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); padding: 8px 12px 0; }
.theme-toggle .tt-sun { display: none; }
html[data-theme="dark"] .theme-toggle .tt-sun { display: inline-flex; }
html[data-theme="dark"] .theme-toggle .tt-moon { display: none; }
.theme-toggle span { display: inline-flex; }
.theme-seg svg { width: 14px; height: 14px; }

/* dark: topbar */
html[data-theme="dark"] .topbar { background: rgba(22, 26, 44, 0.9); }

/* Cards / Table view switch (dashboard leads, clients) */
.view-toggle { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.view-toggle button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; height: 30px; padding: 0 10px; border-radius: 7px; font: inherit; font-size: 12.5px; font-weight: 500; color: var(--muted); cursor: pointer; }
.view-toggle button svg { width: 15px; height: 15px; }
.view-toggle button:hover { color: var(--text); }
.view-toggle button.on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
@media (max-width: 520px) { .view-toggle button span { display: none; } .view-toggle button { padding: 0 9px; } }

/* Searchable dropdown panel (js/xd-ui.js) */
select.xs-open { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.xs-panel { position: fixed; z-index: 1000; display: none; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 16px 40px -12px rgba(15, 23, 42, .28), 0 2px 6px rgba(15, 23, 42, .06); overflow: hidden; font-size: 13.5px; outline: none; }
.xs-panel.open { display: flex; }
.xs-search { position: relative; padding: 8px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.xs-search svg { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--faint); pointer-events: none; }
.xs-search input { width: 100%; height: 34px; padding: 0 10px 0 32px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-2); color: var(--text); font: inherit; font-size: 13px; outline: none; }
.xs-search input:focus { border-color: var(--primary); background: var(--surface); }
.xs-panel.no-search .xs-search { display: none; }
.xs-list { overflow-y: auto; padding: 4px; flex: 1 1 auto; min-height: 0; }
.xs-opt { padding: 7px 10px; border-radius: 6px; cursor: pointer; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xs-opt.in-grp { padding-left: 18px; }
.xs-opt.active { background: var(--chip); }
.xs-opt.sel { color: var(--primary); font-weight: 600; background: var(--primary-soft); }
.xs-opt.sel.active { background: var(--tint-pink-strong); }
.xs-opt.dis { color: var(--faint); cursor: default; }
.xs-opt[hidden], .xs-grp[hidden] { display: none; }
.xs-grp { padding: 8px 10px 3px; font-size: 11px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; }
.xs-empty { padding: 14px 12px; color: var(--muted); font-size: 13px; text-align: center; }

/* Table pages (js/xd-ui.js) */
.xp-off { display: none !important; }
.xp-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.xp-bar[hidden] { display: none; }
.xp-bar .page.dots { border-color: transparent; background: transparent; cursor: default; }

/* Scroll boxes around tables hold their own hidden labels (.sr-only is position:absolute) —
   without this a hidden "Actions" label escaped the box and made the whole phone page wide. */
.table-wrapper, .table-scroll, .followup-history-scroll { position: relative; }
/* long paths / URLs in notes wrap on phones instead of widening the page */
code { overflow-wrap: anywhere; }

/* ===== Table rows: alternate colour + hover colour (rows marked by js/xd-ui.js) ===== */
:root { --zebra: #f8f9fc; --zebra-card: #f2f4f9; --row-hover: #fdf1f7; --row-hover-line: #f6d3e4; }
html[data-theme="dark"] { --zebra-card: #1e233a; --zebra: rgba(255, 255, 255, .04); --row-hover: rgba(226, 87, 157, .10); --row-hover-line: rgba(226, 87, 157, .35); }
tbody > tr[data-z="1"] { background: var(--zebra); }
tbody > tr[data-z] { transition: background-color .12s; }
tbody > tr[data-z]:hover { background: var(--row-hover); }
tbody > tr[data-z]:hover > td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.table tbody tr[data-z]:hover { background: var(--row-hover); }
/* Dashboard Cards view: every other card tinted, hovered card pink with a pink edge */
.leads-card.view-cards .leads-table tbody > tr[data-z]:not(.reenq-today) { background: var(--surface); }
.leads-card.view-cards .leads-table tbody > tr[data-z="1"]:not(.reenq-today) { background: var(--zebra-card); }
.leads-card.view-cards .leads-table tbody > tr[data-z]:hover { background: var(--row-hover); border-color: var(--row-hover-line); box-shadow: inset 3px 0 0 var(--primary), var(--shadow); }
.leads-card.view-cards .leads-table tbody > tr[data-z]:hover > td:first-child { box-shadow: none; }
/* Clients page cards (data-z set by the page's own list script) */
body .cl-grid .cc[data-z="1"] { background: var(--zebra-card); }
body .cl-grid .cc:hover { background: var(--row-hover); border-color: var(--row-hover-line); box-shadow: inset 3px 0 0 var(--primary), var(--shadow); }
body .cl-grid.as-list .cc:hover { background: var(--row-hover); box-shadow: inset 3px 0 0 var(--primary); }
body .cl-grid .cc .cc-stats { background: rgba(127, 127, 127, .06); }
body .cl-grid.as-list .cc .cc-stats { background: transparent; }
@media (max-width: 1024px) {
  .leads-card:not(.view-table) .leads-table tbody > tr[data-z]:hover > td:first-child { box-shadow: none; }
}

/* ===== Manager tools (Attendance, Lead aging, Re-engage) ===== */
.tr-pick { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; }
.tr-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tr-tools .input, .tr-tools .select { height: 36px; width: auto; }
.tr-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.tr-kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; box-shadow: var(--shadow-sm); }
.tr-kpi span { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.tr-kpi b { display: block; font-size: 22px; font-weight: 700; margin-top: 2px; color: var(--text); }
.tr-kpi.red b { color: var(--c-red); } .tr-kpi.amber b { color: var(--c-amber); } .tr-kpi.green b { color: var(--c-green); }
.tr-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 16px; overflow: hidden; }
.tr-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tr-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.tr-head .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tr-scroll { overflow-x: auto; }
.tr-t { width: 100%; border-collapse: collapse; font-size: 13px; }
.tr-t th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; padding: 9px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.tr-t td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tr-t tbody tr:last-child td { border-bottom: 0; }
.tr-t .n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tr-t .c { text-align: center; white-space: nowrap; }
.tr-who b, .tr-who > a { display: block; font-weight: 600; }
.tr-who b { color: var(--text); }
.tr-who span { font-size: 12px; color: var(--muted); }
.tr-chip { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.tr-chip.ok { background: var(--success-soft); color: var(--c-green); }
.tr-chip.late { background: var(--warning-soft); color: var(--c-amber); }
.tr-chip.abs { background: var(--danger-soft); color: var(--c-red); }
.tr-chip.off { background: var(--chip); color: var(--muted); }
.tr-cell { display: block; min-width: 70px; padding: 6px 8px; border-radius: 8px; text-align: center; font-size: 12px; line-height: 1.3; color: var(--text-2); }
.tr-cell b { display: block; font-size: 13px; color: var(--text); }
.tr-cell.p { background: var(--success-soft); }
.tr-cell.l { background: var(--warning-soft); }
.tr-cell.a { background: var(--danger-soft); color: var(--c-red); }
.tr-cell.o { background: var(--chip); color: var(--faint); }
.tr-cell.today { outline: 2px solid var(--primary); outline-offset: -2px; }
a.age { display: block; text-align: center; padding: 6px 4px; border-radius: 8px; font-weight: 600; color: var(--text); }
a.age:hover { outline: 1px solid var(--primary); color: var(--text); }
a.age.z { color: var(--faint); font-weight: 400; }
a.age.h1 { background: var(--tint-yellow); } a.age.h2 { background: var(--warning-soft); color: var(--c-amber); } a.age.h3 { background: var(--danger-soft); color: var(--c-red); }
a.age.on { outline: 2px solid var(--primary); }
.tr-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); padding: 10px 18px; border-top: 1px solid var(--border); }
.tr-bulk { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 18px; background: var(--primary-soft); border-bottom: 1px solid var(--line-pink); font-size: 13px; }
.tr-bulk .input, .tr-bulk .select { height: 34px; width: auto; }
.tr-bulk[hidden] { display: none; }
.tr-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.tr-empty { padding: 34px 18px; text-align: center; color: var(--muted); }
@media (max-width: 760px) { .tr-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
