/*
 * Data Dense style for the leads dashboard.
 * Efficiency first: compact 4px spacing rhythm, small type, hairline borders,
 * small radii, zebra rows, monospace for numbers and IDs, colour-coded status
 * pills, and every frequent action exposed on the toolbar or the row.
 * Flat at rest; at most a faint shadow on hover. Light is the default; dark
 * applies only via data-theme="dark".
 */

:root {
  --bg: #ffffff;
  --bg-2: #f6f8fb;
  --bg-3: #edf1f7;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #1e293b;
  --text-2: #475569;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-bg: #eef3ff;
  --on-accent: #ffffff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --ok: #15803d;
  --hover-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  --pop-shadow: 0 4px 14px rgba(15, 23, 42, 0.1);
  --edge-shade: rgba(15, 23, 42, 0.16);
  --row-alt: #f9fbfd;
  --divider: #edf1f6;
  --toast-bg: #1e293b;
  --toast-text: #f1f5f9;

  --st-pending: #5a92e5;
  --st-contacted: #41b5c2;
  --st-inspected: #722169;
  --st-quoted: #db7a0e;
  --st-accepted: #faca2e;
  --st-installed: #5e8034;
  --st-closed: #eb6d98;
  --st-dead: #64748b;

  /* Layers: a tinted canvas behind white cards, under a dark top bar */
  --canvas: #f2f4f8;
  --card-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  --topbar-bg: #1d2740;
  --topbar-text: #e8edf6;
  --topbar-muted: #9fb0cc;
  --topbar-link: #b9cff7;
  --topbar-line: rgba(255, 255, 255, 0.16);
  /* Column groups (validated with the dataviz palette checker, light and dark) */
  --grp-customer: #5a92e5;
  --grp-product: #5e8034;
  --grp-followup: #eb6d98;
  --xls: #5e8034;
  --pdf: #d4042d;
  /* Palette orange darkened enough to pass text contrast on white */
  --overdue: #b35f06;
  /* The Status filter's label on products that highlight it (palette 蕉红; 5.6:1 on white) */
  --status-label: #d4042d;
  --product: var(--accent);

  --font: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  --mono: "SF Mono", Menlo, Consolas, monospace;
  --radius: 4px;
  color-scheme: light;
}

:root[data-theme="dark"] .tag { color: color-mix(in srgb, var(--c) 55%, #fff); }

:root[data-theme="dark"] {
  --bg: #0f1520;
  --bg-2: #151c29;
  --bg-3: #1d2635;
  --border: #253043;
  --border-strong: #34425a;
  --text: #e2e8f0;
  --text-2: #c2ccda;
  --muted: #8a99b0;
  --accent: #5b9bff;
  --accent-hover: #7fb0ff;
  --accent-bg: #16233d;
  --on-accent: #0b1220;
  --danger: #f87171;
  --danger-bg: #2c1519;
  --ok: #4ade80;
  --hover-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --pop-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  --edge-shade: rgba(0, 0, 0, 0.6);
  --row-alt: #121926;
  --divider: #1e2838;
  --toast-bg: #e2e8f0;
  --toast-text: #0f1520;
  --st-inspected: #b566a9;
  --st-dead: #8a99b0;
  --canvas: #0a0e16;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  --topbar-bg: #060910;
  --topbar-text: #e2e8f0;
  --topbar-muted: #8a99b0;
  --topbar-link: #8fb6ff;
  --topbar-line: rgba(255, 255, 255, 0.14);
  --grp-followup: #dd6590;
  --overdue: #f0a04b;
  --status-label: #ff6b81;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  background: var(--canvas);
  color: var(--text);
  font: 13px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 15px; }
h2 { font-size: 13px; }
h3 { font-size: 13px; }
p { margin: 0; }

.mono { font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.micro { font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ─── Buttons ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 10px;
  font: 500 12px/1 var(--font);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-2); box-shadow: var(--hover-shadow); }
.btn:disabled { opacity: 0.5; cursor: default; box-shadow: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-xs { height: 22px; padding: 0 8px; font-size: 11.5px; }
.btn-text {
  height: auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
}
.btn-text:hover { background: none; box-shadow: none; text-decoration: underline; }
.btn-danger { color: var(--danger); }

/* ─── Form controls ────────────────────────────────────────────────────── */

input, select, textarea {
  font: 12.5px var(--font);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  width: 100%;
}
input, select { height: 28px; padding: 0 8px; }
textarea { padding: 6px 8px; min-height: 56px; resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
input[type="checkbox"] { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.field .req { color: var(--danger); font-weight: 700; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

.alert {
  padding: 6px 8px;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: var(--radius);
  background: var(--danger-bg);
  color: var(--danger);
}
.alert .actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.note {
  padding: 6px 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius);
  background: var(--accent-bg);
  color: var(--text-2);
}

/* ─── Status pills and dots ────────────────────────────────────────────── */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  color: color-mix(in srgb, var(--c) 55%, #000);
  background: color-mix(in srgb, var(--c) 18%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
}
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }

/* ─── Shell ────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 48px;
  padding: 0 28px;
  background: var(--topbar-bg);
  color: var(--topbar-text);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand .org { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--topbar-muted); }
.topbar h1 { color: var(--topbar-text); }
.topbar nav { display: flex; align-items: center; gap: 14px; }
.topbar nav a { color: var(--topbar-link); }
.topbar .btn { background: transparent; color: var(--topbar-text); border-color: var(--topbar-line); }
.topbar .btn:hover { background: rgba(255, 255, 255, 0.08); box-shadow: none; }
#menu-toggle { display: none; }

/* ─── Avatar and the "My account" menu ─────────────────────────────────── */

.avatar { display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; overflow: hidden; background: var(--accent); color: #fff; }
.avatar-md { width: 40px; height: 40px; }
/* A picture still loading shows a quiet grey disc, not the accent colour */
.avatar:has(> img) { background: var(--bg-3); }
.avatar-lg { width: 64px; height: 64px; }
.avatar img, .avatar-art, .avatar-art svg { display: block; width: 100%; height: 100%; object-fit: cover; }
.avatar-initials { font-size: 11px; font-weight: 700; letter-spacing: 0.02em; }
.avatar-md .avatar-initials { font-size: 14px; }
.avatar-lg .avatar-initials { font-size: 22px; }
/* First name + avatar: a pill one size up from the top bar's buttons, with the same border colour */
.avatar-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px 0 4px;
  border: 1px solid var(--topbar-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.avatar-btn:hover, .account-menu[open] .avatar-btn { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.32); }
.avatar-btn .avatar { order: -1; width: 26px; height: 26px; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.22); }
.avatar-btn .avatar-initials { font-size: 10.5px; }
.avatar-btn .icon { color: var(--topbar-muted); transition: transform 0.15s; }
.avatar-btn .icon svg { width: 12px; height: 12px; }
.account-menu[open] .avatar-btn .icon { transform: rotate(180deg); }
.account-first { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--topbar-text); font-size: 13px; font-weight: 600; letter-spacing: 0.01em; }
/* Inside the top bar's nav, so its light link colours and the generic dropdown width are overridden here */
.dropdown.account-menu .menu { min-width: 240px; padding: 6px; color: var(--text); white-space: nowrap; }
.topbar .account-menu .menu-item { color: var(--text); }
.account-head { display: flex; align-items: center; gap: 10px; padding: 6px 6px 10px; border-bottom: 1px solid var(--border); }
.account-name { font-weight: 600; }
.account-title { padding: 8px 6px 4px; color: var(--muted); }
.menu-item { display: block; width: 100%; padding: 6px 8px; border: 0; border-radius: var(--radius); background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.menu-item:hover { background: var(--bg-2); text-decoration: none; }
.menu-divider { height: 1px; margin: 4px 2px; background: var(--border); }
.topbar .account-menu .menu-danger { color: var(--danger); }
.profile-picture { display: flex; align-items: center; gap: 14px; }
.profile-picture-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.profile-picture-actions p { flex-basis: 100%; margin: 0; }
.preset-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.preset-tab { padding: 6px 12px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; color: var(--text-2); font: inherit; cursor: pointer; }
.preset-tab:hover { color: var(--text); }
.preset-tab[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }
/* Five across: each picture tab's ten fill two even rows */
.preset-grid { display: grid; grid-template-columns: repeat(5, 62px); gap: 12px; padding-top: 4px; }
.preset .avatar-md { width: 56px; height: 56px; }
.preset { display: grid; padding: 1px; border: 2px solid transparent; border-radius: 50%; background: none; cursor: pointer; }
.preset:hover { border-color: var(--border-strong); }
.preset[aria-pressed="true"] { border-color: var(--accent); }

.shell { display: grid; grid-template-columns: 184px minmax(0, 1fr); min-height: calc(100vh - 48px); }

.sidebar { background: var(--bg-2); border-right: 1px solid var(--border); padding: 12px 8px; }
.sidebar .micro { padding: 0 8px; }
.sidebar ol { list-style: none; margin: 4px 0 0; padding: 0; }
.sidebar a {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 8px;
  border-radius: var(--radius);
  color: var(--text-2);
}
.sidebar a:hover { background: var(--bg-3); text-decoration: none; }
.sidebar a.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.sidebar .count { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--muted); }

main { padding: 20px 28px 28px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }

/* Dashboard: the product sidebar and content fill the height under the top bar; the table takes the remaining height and scrolls internally */
body.dash { height: 100vh; display: flex; flex-direction: column; }
.dash .shell { flex: 1; min-height: 0; }
.dash main { min-height: 0; overflow: auto; padding-bottom: 20px; }
/* The sidebar marks the product on screen with its identity colour */
.dash .sidebar a { height: 32px; font-size: 13px; }
.dash .sidebar a.active { background: color-mix(in srgb, var(--product) 12%, var(--bg)); color: var(--text); box-shadow: inset 3px 0 0 var(--product); }
.product-title { font-size: 15px; font-weight: 700; }
.leads-card { flex: 1 0 280px; display: flex; flex-direction: column; min-height: 280px; }
.leads-card .table-wrap { flex: 1; min-height: 0; max-height: none; transition: opacity 0.15s; }
.table-scroll { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Loading: a thin moving bar under the card head, and the old rows dimmed until new ones arrive */
.progress { position: relative; height: 2px; overflow: hidden; }
.loading .progress::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: -30%; width: 30%;
  background: var(--accent); animation: progress 0.9s ease-in-out infinite;
}
@keyframes progress { to { left: 100%; } }
.loading .table-wrap { opacity: 0.55; }

/* ─── Dropdowns (column chooser, multi-select filters) ─ */

.dropdown { position: relative; }
.dropdown > summary { list-style: none; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown .caret { color: var(--muted); font-size: 10px; }
.dropdown .menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-height: 320px;
  overflow: auto;
  padding: 4px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--hover-shadow);
}
.dropdown .menu.align-right { left: auto; right: 0; }
.dropdown .menu label { display: flex; align-items: center; gap: 6px; height: 24px; padding: 0 4px; border-radius: var(--radius); white-space: nowrap; cursor: pointer; }
.dropdown .menu label:hover { background: var(--bg-2); }
.dropdown .menu label:has(input:disabled) { color: var(--muted); cursor: default; }
.dropdown .quick { padding: 2px 4px 4px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown .n { font-size: 11px; color: var(--muted); }

.product-swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--swatch); flex: none; }

/* ─── Page header ──────────────────────────────────────────────────────── */

.page-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.page-head .actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.btn-export { gap: 6px; }
.file-badge { padding: 3px 4px; border-radius: 3px; font: 700 9px/1 var(--mono); letter-spacing: 0.02em; color: #fff; background: var(--xls); }
.file-badge.pdf { background: var(--pdf); }
.page-head .actions #total-line { margin-right: 4px; }

.card { border: 1px solid var(--border); border-radius: 10px; background: var(--bg); box-shadow: var(--card-shadow); }
.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 12px 6px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  border-radius: 10px 10px 0 0;
}
.card-body { padding: 12px 16px 14px; }

/* Colour-coded column groups: the line along the top of each header cell */
[data-group="customer"] { --grp: var(--grp-customer); }
[data-group="product"] { --grp: var(--grp-product); }
[data-group="followup"] { --grp: var(--grp-followup); }

/* All filter fields sit in one row and share the width equally, with the search box taking two shares; the date field keeps a minimum width so dd/mm/yyyy doesn't get clipped */
.filters { display: flex; gap: 8px; align-items: end; }
.filters > .field { flex: 1 1 0; }
.filters > .wide { flex-grow: 1.5; }
/* Labels stay on one line so every control lines up; a label that doesn't fit is cut with an
   ellipsis and shown in full as a tooltip (set in filters.js) */
.filters .field > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: 0.03em; }
.filters > .date { min-width: 118px; }
/* Status options: each status gets its own colour pill, with that status's lead count on the right */
.status-filter .menu label { height: 28px; }
.status-filter .menu .n { margin-left: auto; padding-left: 12px; }
.status-filter summary { gap: 4px; }
.status-filter summary .tag { padding: 0 6px; }
/* The rightmost dropdown opens leftward, so long option lists don't overflow the screen */
.filters > .field:last-child .menu { left: auto; right: 0; }

.multi summary {
  display: flex;
  align-items: center;
  height: 28px;
  padding: 0 24px 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.multi summary::after { content: "▾"; position: absolute; right: 8px; color: var(--muted); font-size: 10px; }

/* ─── Data table ───────────────────────────────────────────────────────── */

.table-wrap { overflow: auto; max-height: calc(100vh - 270px); min-height: 200px; }
table.data { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 12.5px; }
.data th, .data td { text-align: left; vertical-align: middle; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--bg); }
/* Each header wears its group's colour: a 3px band on top and a faint tint */
.data th[data-group] { background: color-mix(in srgb, var(--grp) 7%, var(--bg)); box-shadow: inset 0 3px 0 var(--grp); }
.data td.pin-3 { font-weight: 600; color: var(--text); }
.data td.soft { color: var(--text-2); }
.overdue { color: var(--overdue); font-weight: 600; }
.data th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 30px;
  vertical-align: middle;
  background: var(--bg-2);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
/* A vertical rule between every two columns */
.data th + th, .data td + td { border-left: 1px solid var(--divider); }
.data th button { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.data th button:hover { color: var(--text); }
.data th button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Sort indicator: two small triangles stacked vertically, both light grey when unsorted; the matching direction turns the accent colour once sorted */
.sort { display: inline-flex; flex-direction: column; gap: 2px; }
.sort i { width: 0; height: 0; border-left: 3.5px solid transparent; border-right: 3.5px solid transparent; opacity: 0.4; }
.sort .up { border-bottom: 4px solid currentColor; }
.sort .down { border-top: 4px solid currentColor; }
.data th button:hover .sort i { opacity: 0.8; }
.data th[aria-sort="ascending"] .sort .up,
.data th[aria-sort="descending"] .sort .down { opacity: 1; color: var(--accent); border-bottom-color: var(--accent); border-top-color: var(--accent); }
.data th[aria-sort] button { color: var(--text); }
/* Cells never wrap, so every column is exactly as wide as its content; free text is capped and cut off with an
   ellipsis (table.js puts the full value in a hover tooltip). The cap sits on an inner block because browsers
   don't reliably honour max-width on table cells */
table.leads td { white-space: nowrap; }
.cell-text { display: block; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.data tbody tr:nth-child(even) td { background: var(--row-alt); }
.data tbody tr:hover td { background: var(--bg-3); }
.data tbody tr.selected td { background: var(--accent-bg); }
/* The open lead also gets an accent bar on its left edge, so it stays findable while scrolling */
.data tbody tr.selected td.pin-0 { box-shadow: inset 3px 0 0 var(--accent); }
.data td.pin-0 { padding: 4px 6px; vertical-align: middle; }
.data td.pin-2 { padding-top: 4px; padding-bottom: 4px; }

/* Row edit button: quiet by default, clear on the hovered row */
.row-edit, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0;
  border: 1px solid transparent; border-radius: var(--radius);
  background: none; color: var(--muted); cursor: pointer;
}
.data tbody tr:hover .row-edit, .row-edit:focus-visible { color: var(--accent); border-color: var(--border-strong); background: var(--bg); }
.icon-btn:hover:not(:disabled) { color: var(--text); background: var(--bg-3); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.row-edit:focus-visible, .icon-btn:focus-visible, .status-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon { display: inline-flex; }

/* Status pill in the table is a button that opens the pipeline menu */
.status-pill {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 2px; margin: 0; border: 0; border-radius: 999px;
  background: none; color: var(--muted); font: inherit; cursor: pointer;
}
.status-pill .icon { opacity: 0; transition: opacity 0.12s; }
.status-pill .icon svg { width: 14px; height: 14px; }
.data tbody tr:hover .status-pill .icon, .status-pill:focus-visible .icon, .status-pill[aria-expanded="true"] .icon { opacity: 1; }
.status-pill:hover .tag, .status-pill[aria-expanded="true"] .tag { border-color: var(--c); }
.data.clickable tbody tr { cursor: pointer; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.nowrap { white-space: nowrap; }
.id { font-family: var(--mono); font-size: 11.5px; color: var(--accent); }

/* The action column + Date, Status and Name columns are pinned to the left. `left` is measured from the actual
   column widths by table.js and written into the variable — hardcoding pixels would make the pinned columns
   overlap each other whenever column widths change */
.pin-0, .pin-1, .pin-2, .pin-3 { position: sticky; z-index: 1; }
th.pin-0, th.pin-1, th.pin-2, th.pin-3 { z-index: 3; }
.pin-0 { left: 0; }
.pin-1 { left: var(--pin-1, 0); }
.pin-2 { left: var(--pin-2, 0); min-width: 132px; }
.pin-3 { left: var(--pin-3, 0); min-width: 150px; border-right: 1px solid var(--border); }
/* The line at the right edge of the pinned area is attached to the Name column itself, so it doesn't scroll away during horizontal scrolling */
.data .pin-3 + th, .data .pin-3 + td { border-left: 0; }

/* ─── Horizontal scrolling cues ────────────────────────────────────────── */

/* A scrollbar that is always shown: macOS otherwise hides it until you scroll, so nobody knows the table is wider */
.table-wrap::-webkit-scrollbar { width: 12px; height: 12px; }
.table-wrap::-webkit-scrollbar-track, .table-wrap::-webkit-scrollbar-corner { background: var(--bg-2); }
.table-wrap::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted) 55%, var(--bg)); border: 2px solid var(--bg-2); border-radius: 999px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--muted); }
@supports not selector(::-webkit-scrollbar) {
  .table-wrap { scrollbar-width: auto; scrollbar-color: color-mix(in srgb, var(--muted) 55%, var(--bg)) var(--bg-2); }
}

/* Edge shadows (flags set by tableScroll.js): on the right while columns remain off-screen,
   and beside the pinned Name column once columns have scrolled under it */
.table-scroll::after {
  content: ""; position: absolute; z-index: 4; top: 0; right: var(--sb-v, 0); bottom: var(--sb-h, 0); width: 32px;
  background: linear-gradient(to right, transparent, var(--edge-shade));
  pointer-events: none; opacity: 0; transition: opacity 0.15s;
}
.table-scroll.more-right::after { opacity: 1; }
.table-scroll { --edge-shadow: 6px 0 8px -4px var(--edge-shade); }
.table-scroll.more-left td.pin-3 { box-shadow: var(--edge-shadow); }
.table-scroll.more-left th.pin-3[data-group] { box-shadow: inset 0 3px 0 var(--grp), var(--edge-shadow); }

/* Round arrow buttons floating on the table's edges, shown only in a direction with more columns to see */
.scroll-btn {
  position: absolute; z-index: 5; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; padding: 0; border: 2px solid var(--bg); border-radius: 50%;
  background: var(--accent); color: var(--on-accent); cursor: pointer;
  box-shadow: 0 2px 10px var(--edge-shade);
}
.scroll-btn:hover { background: var(--accent-hover); }
.scroll-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.scroll-btn .icon svg { width: 22px; height: 22px; }
.scroll-btn.right { right: calc(var(--sb-v, 0px) + 12px); }
.scroll-btn.left { left: calc(var(--pin-w, 0px) + 12px); }

/* ─── Refresh button and reload animation (refreshButton.js) ───────────── */

.btn-refresh { gap: 6px; height: 28px; padding: 0 12px; border-color: var(--accent); background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.btn-refresh:hover:not(:disabled) { background: var(--accent); color: var(--on-accent); }
.btn-refresh:disabled { opacity: 1; cursor: progress; }
.btn-refresh .icon svg { width: 15px; height: 15px; }
.refreshing .btn-refresh .icon { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* While refreshing, a veil with a spinner covers the table */
.refresh-overlay {
  position: absolute; inset: 0; z-index: 6;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: color-mix(in srgb, var(--bg) 72%, transparent); backdrop-filter: blur(1.5px);
  color: var(--text-2); font-size: 13px; font-weight: 600;
  opacity: 0; visibility: hidden; transition: opacity 0.15s, visibility 0.15s;
}
.refreshing .refresh-overlay { opacity: 1; visibility: visible; }
.spinner { width: 34px; height: 34px; border: 3px solid color-mix(in srgb, var(--accent) 22%, transparent); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
/* Then the fresh rows fade in from an accent tint */
.refreshed .data tbody td { animation: row-in 0.6s ease-out; }
@keyframes row-in { from { opacity: 0.25; background: var(--accent-bg); } }

/* ─── Adding / deleting leads (rowActions.js) ─────────────────────────── */

.row-actions { display: inline-flex; gap: 8px; margin-left: 6px; }
.row-actions[hidden] { display: none; }
.btn .icon svg { width: 15px; height: 15px; }
.btn-strong { height: 30px; padding: 0 14px; gap: 6px; font-weight: 600; font-size: 12.5px; }
.btn-danger-outline { height: 30px; padding: 0 12px; gap: 6px; font-weight: 600; font-size: 12.5px; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 60%, transparent); background: var(--danger-bg); }
.btn-danger-outline:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-outline:disabled { color: var(--muted); border-color: var(--border-strong); background: var(--bg); opacity: 0.7; }
.btn-assign { height: 30px; padding: 0 12px; gap: 6px; font-weight: 600; font-size: 12.5px; color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); background: var(--accent-bg); }
.btn-assign:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-assign:disabled { color: var(--muted); border-color: var(--border-strong); background: var(--bg); opacity: 0.7; }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn-danger-solid:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }
.count-badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: color-mix(in srgb, currentColor 16%, transparent); font: 600 11px/18px var(--mono); text-align: center; }
.row-check { width: 15px; height: 15px; margin: 0 6px 0 2px; vertical-align: middle; accent-color: var(--accent); cursor: pointer; }
.data td.pin-0 { white-space: nowrap; }
.data td.pin-0 .row-edit { vertical-align: middle; }

/* ─── Modal dialogs (modal.js) ─────────────────────────────────────────── */

.modal { width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--bg); color: var(--text); box-shadow: var(--pop-shadow); }
.modal-wide { width: min(720px, calc(100vw - 32px)); }
.modal-xwide { width: min(1100px, calc(100vw - 32px)); }
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgba(15, 23, 42, 0.45); }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { flex: 1; font-size: 14px; }
.modal-body { flex: 1; overflow: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 10px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 18px; border-top: 1px solid var(--border); background: var(--bg-2); border-radius: 0 0 10px 10px; }
.modal-form { display: grid; gap: 8px; }
.pick-quick { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pick-columns { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 14px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-2); }
.pick-columns .check { font-size: 12.5px; }
/* Excel import (importDialog.js) */
.btn-import { gap: 6px; font-weight: 600; color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.import-summary { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.chip-ok { background: color-mix(in srgb, var(--ok) 14%, var(--bg)); color: var(--ok); }
.chip-dupe { background: color-mix(in srgb, var(--overdue) 16%, var(--bg)); color: var(--overdue); }
.chip-bad { background: var(--danger-bg); color: var(--danger); }
.import-wrap { max-height: 52vh; border: 1px solid var(--border); border-radius: 6px; }
.import-notes { margin: 0; padding-left: 16px; font-size: 12px; }
/* Fit the dialog: long warnings wrap in the Notes column instead of widening the table */
.import-wrap table.data { width: 100%; }
.import-wrap td:last-child { min-width: 260px; }
.import-notes .bad { color: var(--danger); }
.import-notes .dupe { color: var(--overdue); }
.import-notes .warn { color: var(--text-2); }
.data tr.import-error td { background: color-mix(in srgb, var(--danger) 5%, var(--bg)); }
.confirm-list { margin: 0; padding-left: 18px; display: grid; gap: 4px; }

/* ─── Pager and column chooser (table top-right) ───────────────────────── */

.leads-card .card-head { flex-wrap: wrap; row-gap: 4px; }
.pager { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pager .pages { display: flex; align-items: center; gap: 2px; }
.pager .num { min-width: 26px; justify-content: center; padding: 0 6px; font-family: var(--mono); }
.pager .num.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); cursor: default; }
.pager .gap { width: 16px; text-align: center; color: var(--muted); }
.pager-field { display: inline-flex; align-items: center; gap: 4px; }
.pager-field > span:first-child { font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.pager-field select, .pager-field input { height: 22px; font-size: 11.5px; padding: 0 4px; }
.pager-field select { width: 56px; }
.pager-field input { width: 48px; font-family: var(--mono); }

.card-foot { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-top: 1px solid var(--border); }
.empty { padding: 48px 12px; color: var(--muted); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty-title { color: var(--text); font-weight: 600; font-size: 14px; }
.empty .btn { margin-top: 6px; }

/* ─── Edit panel ───────────────────────────────────────────────────────── */

.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  /* Wide enough for the customer, follow-up and job sections side by side, so nothing needs scrolling */
  width: min(1240px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--border-strong);
  transform: translateX(100%);
  transition: transform 0.15s ease-out;
  visibility: hidden;
}
.panel.open { transform: none; visibility: visible; }
.panel-head { display: flex; align-items: center; gap: 4px; min-height: 52px; padding: 6px 8px 6px 16px; border-bottom: 1px solid var(--border); background: var(--bg-2); }
.panel-title { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.panel-title h3 { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel.busy .panel-body { opacity: 0.6; transition: opacity 0.1s; }

/* Pipeline progress at the top of the panel */
.stage-bar { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-2); }
.stage-segments { display: flex; gap: 3px; }
.stage-segments span { flex: 1; height: 6px; border-radius: 3px; background: var(--bg-3); }
.stage-segments span.on { background: var(--c); }
.stage-label { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.panel-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.panel-foot { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--border); background: var(--bg-2); }
.panel-foot .msg { color: var(--muted); }
.kv { display: grid; grid-template-columns: 116px 1fr; gap: 4px 8px; margin: 0; }
.kv dt { color: var(--muted); font-size: 11.5px; }
.kv dd { margin: 0; word-break: break-word; }
/* An empty value reads as a dash, so a blank never looks like something failed to load */
.kv dd:empty::after { content: "—"; color: var(--muted); }
.panel form { display: grid; gap: 8px; }
/* The form's sections, side by side; each tinted with its column group's colour from the table header */
.panel-sections { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 10px; align-items: start; }
.panel-section { display: grid; gap: 8px; padding: 10px 12px 12px; border: 1px solid color-mix(in srgb, var(--tint) 30%, var(--border)); border-radius: 8px; background: color-mix(in srgb, var(--tint) 7%, var(--bg)); }
.panel-section .section-title { color: color-mix(in srgb, var(--tint) 60%, var(--text)); }
.panel-section .section-title::after { background: color-mix(in srgb, var(--tint) 30%, var(--border)); }
.sec-customer { --tint: var(--grp-customer); }
.sec-followup { --tint: var(--grp-followup); }
.sec-job { --tint: var(--grp-product); }
.panel-section textarea { min-height: 52px; }
/* Read-only facts (reference, origin, last update) in one line */
.kv-line { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 0; font-size: 12px; }
.kv-line > div { display: flex; gap: 6px; }
.kv-line dt { color: var(--muted); }
.kv-line dd { margin: 0; }
.history-box summary { cursor: pointer; padding: 4px 0; color: var(--muted); }
.history-box[open] summary { margin-bottom: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.section-title { display: flex; align-items: center; gap: 8px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.history li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.history .when { font-size: 11px; color: var(--muted); }
.history .change { white-space: pre-line; word-break: break-word; }

/* ─── Auth pages ───────────────────────────────────────────────────────── */

.auth-page { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 14vh 16px 0; background: var(--canvas); }
.auth-card { width: 100%; max-width: 340px; }
/* Cloudflare's widget is 300 px wide and 65 px tall; reserving the height keeps the button from jumping */
.turnstile { min-height: 65px; }
.auth-card form { display: grid; gap: 8px; }
.theme-corner { position: fixed; top: 8px; right: 12px; }

/* ─── Admin ────────────────────────────────────────────────────────────── */

.row-actions { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.inline-form { display: flex; gap: 4px; align-items: center; margin-top: 4px; }
.inline-form input { width: 180px; }
.new-user { display: grid; grid-template-columns: minmax(110px, 0.6fr) repeat(3, minmax(140px, 1fr)) auto; gap: 8px; align-items: end; }
.account-codes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.role-select { width: auto; height: 26px; font-size: 12px; }
.toolbar { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.toolbar .field { width: 180px; }
.admin-section { scroll-margin-top: 12px; }
.admin-section .table-wrap { min-height: 0; max-height: none; }
.admin-section .audit-wrap { max-height: 480px; }
.sidebar ol.back { margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--border); }

/* ─── Narrow screens ───────────────────────────────────────────────────── */

/* 900–1100px: when one row can't fit all filter fields, switch to an auto-wrapping grid */
@media (max-width: 1100px) and (min-width: 901px) {
  .filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .filters > .wide { grid-column: span 2; }
}

@media (max-width: 900px) {
  #menu-toggle { display: inline-flex; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar.open { display: block; }
  main { padding: 14px 14px 20px; gap: 12px; }
  .topbar { height: auto; min-height: 48px; padding: 8px 14px; flex-wrap: wrap; row-gap: 4px; }
  .topbar nav { flex-wrap: wrap; gap: 8px; }
  .account-first { display: none; }
  .filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters > .wide { grid-column: 1 / -1; }
  .filters > .date { min-width: 0; }
  .filters > .field:last-child .menu { left: 0; right: auto; }
  .table-wrap { max-height: none; }
  body.dash { height: auto; display: block; }
  .dash main { overflow: visible; }
  /* On phones the table grows to its full height and scrolls with the page, instead of a small inner box */
  .leads-card { flex: none; min-height: 0; }
  .leads-card .table-wrap { flex: none; overflow-y: visible; }
  .table-scroll { flex: none; }
  /* On phones the table runs the full page height, so keep the arrows up by the header instead of mid-table */
  .scroll-btn { top: 44px; transform: none; }
  .pager { gap: 8px; }
  .pin-0, .pin-1, .pin-2, .pin-3 { position: static; box-shadow: none; }
  .new-user { grid-template-columns: 1fr; }
}

/* ─── Active filters ───────────────────────────────────────────────────── */

.field.is-set > span { color: var(--accent); }
.field.is-set input, .field.is-set .multi summary { border-color: var(--accent); background: var(--accent-bg); }
.filter-count {
  display: inline-flex; align-items: center; height: 20px; padding: 0 8px;
  border-radius: 999px; background: var(--accent-bg); color: var(--accent);
  font-size: 11.5px; font-weight: 600;
}

/* ─── Status pipeline menu ─────────────────────────────────────────────── */

.pipeline-menu {
  position: fixed; z-index: 60; width: 208px; padding: 6px;
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: 6px;
  box-shadow: var(--pop-shadow);
}
.pipeline-title { padding: 2px 8px 6px; }
/* The track: a vertical rail behind the stage dots, because the stages really are a sequence */
.pipeline-track { position: relative; }
.pipeline-track::before { content: ""; position: absolute; left: 16px; top: 15px; bottom: 15px; width: 2px; background: var(--border); }
.stage {
  position: relative; display: flex; align-items: center; gap: 10px; width: 100%; height: 30px;
  padding: 0 10px 0 11px; border: 0; border-radius: var(--radius);
  background: none; color: var(--text-2); font: inherit; text-align: left; cursor: pointer;
}
.stage:hover, .stage:focus-visible { background: var(--bg-2); color: var(--text); outline: none; }
.stage:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.stage .dot { position: relative; z-index: 1; width: 12px; height: 12px; background: var(--bg); border: 2px solid var(--c); }
.stage.done .dot { background: var(--c); }
.stage.current .dot { background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 28%, transparent); }
.stage.current { color: var(--text); font-weight: 600; }
.stage.current::after { content: "Current"; margin-left: auto; font-size: 10.5px; font-weight: 500; color: var(--muted); }
.pipeline-divider { height: 1px; margin: 4px 6px; background: var(--border); }

/* ─── Toasts ───────────────────────────────────────────────────────────── */

.toasts { position: fixed; left: 50%; bottom: 20px; z-index: 70; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 12px; max-width: min(560px, calc(100vw - 32px));
  padding: 8px 8px 8px 14px; border-radius: 6px;
  background: var(--toast-bg); color: var(--toast-text); box-shadow: var(--pop-shadow);
  pointer-events: auto; animation: toast-in 0.16s ease-out;
}
.toast-error { background: var(--danger); color: #fff; }
.toast.leaving { opacity: 0; transition: opacity 0.16s; }
.toast-action { border: 0; background: none; color: inherit; font: 600 12.5px var(--font); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; padding: 4px 6px; }
.toast-close { display: inline-flex; border: 0; background: none; color: inherit; opacity: 0.7; cursor: pointer; padding: 4px; border-radius: var(--radius); }
.toast-close:hover { opacity: 1; }
.toast-action:focus-visible, .toast-close:focus-visible { outline: 2px solid currentColor; outline-offset: 1px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  .loading .progress::after { animation: none; left: 0; width: 100%; opacity: 0.5; }
  .toast, .panel { animation: none; transition: none; }
  .status-pill .icon, .leads-card .table-wrap { transition: none; }
  .refreshing .btn-refresh .icon, .spinner, .refreshed .data tbody td { animation: none; }
  .spinner { border-color: var(--accent); }
}

/* Products with "status_highlight": the Status filter's label stands out, and stays that colour when the filter is set */
.status-filter.highlight > span, .field.is-set.status-filter.highlight > span { color: var(--status-label); font-weight: 800; }
