:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --border: #e6e0d6;
  --text: #2f2a26;
  --muted: #7b726a;
  --accent: #6f8a76;
  --accent-strong: #56705d;
  --accent-soft: #e6eee8;
  --rose: #c58b8b;
  --danger: #b05a5a;
  --danger-soft: #f6e5e5;
  --shadow: 0 1px 2px rgba(47, 42, 38, 0.06), 0 6px 24px rgba(47, 42, 38, 0.06);
  --radius: 12px;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1b19;
    --surface: #262320;
    --surface-2: #2c2926;
    --border: #3b3632;
    --text: #efe9e2;
    --muted: #a99f95;
    --accent: #8fb099;
    --accent-strong: #a6c6af;
    --accent-soft: #2f3a32;
    --danger: #d98080;
    --danger-soft: #3a2626;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 24px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: 0.01em; }
h1 { font-size: 28px; }
h2 { font-size: 24px; }
h3 { font-size: 19px; }
a { color: var(--accent-strong); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.loading { padding: 80px; text-align: center; color: var(--muted); }
.hidden { display: none !important; }

/* Buttons & inputs */
button, .btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
button.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
button.danger { color: var(--danger); border-color: var(--danger-soft); }
button.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--surface-2); border-color: var(--border); }
button.icon { padding: 4px 8px; }
button:disabled { opacity: 0.45; cursor: default; }
a.btn { text-decoration: none; display: inline-block; }
.tag.pending { background: #fdf3dc; border-color: #e8c66a; color: #8a6a12; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
input[type='checkbox'] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; margin: 0; }
input[type='color'] { padding: 2px; height: 38px; width: 56px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 13px; }
label.field .req { color: var(--rose); }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.error { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: 8px 12px; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px;
}
.auth-card h1 { text-align: center; }

/* Layout */
header.top {
  position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 24px; padding: 10px 24px; flex-wrap: wrap;
}
header.top h1 { font-size: 24px; }
nav.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
nav.tabs button { border-color: transparent; background: transparent; color: var(--muted); }
nav.tabs button.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.user-menu { display: flex; align-items: center; gap: 8px; }
.role-badge { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
main { padding: 24px; max-width: 1400px; margin: 0 auto; }
main.wide { max-width: none; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.toolbar input[type='search'] { max-width: 280px; }
.toolbar select { width: auto; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* Table */
.table-wrap { overflow-x: auto; }

/* Chunky, easy-to-grab horizontal scroll bars for the table and board */
/* Chrome ignores the ::-webkit-scrollbar styles below if scrollbar-color is set, so only Firefox gets it */
@supports not selector(::-webkit-scrollbar) {
  .table-wrap, .board { scrollbar-width: auto; scrollbar-color: var(--accent) var(--surface-2); }
}
.table-wrap::-webkit-scrollbar, .board::-webkit-scrollbar { height: 18px; }
.table-wrap::-webkit-scrollbar-track, .board::-webkit-scrollbar-track { background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.table-wrap::-webkit-scrollbar-thumb, .board::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 99px; border: 4px solid var(--surface-2); }
.table-wrap::-webkit-scrollbar-thumb:hover, .board::-webkit-scrollbar-thumb:hover { background: var(--accent-strong); }

/* Keep the stage and name columns pinned while scrolling sideways */
.table-wrap th:nth-child(-n+2), .table-wrap td:nth-child(-n+2) { position: sticky; z-index: 1; background: var(--surface); }
.table-wrap th:nth-child(-n+2) { background: var(--surface-2); }
.table-wrap th:nth-child(1), .table-wrap td:nth-child(1) { left: 0; width: 150px; min-width: 150px; max-width: 150px; }
.table-wrap th:nth-child(2), .table-wrap td:nth-child(2) { left: 150px; box-shadow: 6px 0 8px -6px rgba(0, 0, 0, 0.18); }
tbody tr:hover td { background: var(--surface-2); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; background: var(--surface-2); min-width: 90px; vertical-align: bottom; cursor: pointer; user-select: none; }
th.nosort { cursor: default; }
tbody tr { cursor: pointer; }
tbody tr:last-child td { border-bottom: none; }
td.center, th.center { text-align: center; }
.empty { padding: 48px; text-align: center; color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px;
  font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; }
select.stage-select { width: auto; padding: 4px 8px; font-size: 12px; font-weight: 600; border-radius: 99px; }

/* Board */
.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.column { flex: 0 0 260px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 200px); }
.column.drag-over { outline: 2px dashed var(--accent); }
.column-head { padding: 12px 14px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); font-weight: 600; }
.column-head .count { margin-left: auto; color: var(--muted); font-weight: 500; }
.column-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 60px; }
.board-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.board-card:hover { border-color: var(--accent); }
.board-card .title { font-weight: 600; margin-bottom: 4px; }
.board-card .meta { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.board-card .ticks { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.tick-chip { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.tick-chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
button.tick-chip { font-size: 12px; padding: 2px 9px; cursor: pointer; }
button.tick-chip:hover { border-color: var(--accent); }
td .ticks { display: flex; flex-wrap: wrap; gap: 4px; min-width: 220px; }
td { white-space: nowrap; }

/* Summary */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { padding: 18px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value { font-family: var(--serif); font-variant-numeric: lining-nums tabular-nums; font-size: 36px; font-weight: 600; line-height: 1.2; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.summary-grid .card { padding: 18px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 40px; gap: 10px; align-items: center; margin-top: 10px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.bar-row .n { text-align: right; font-variant-numeric: tabular-nums; }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(30, 26, 22, 0.45); z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 860px; box-shadow: 0 20px 60px rgba(0,0,0,0.25); }
.modal.narrow { max-width: 480px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 24px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 24px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 16px 16px; flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }
.form-section h3 { margin-bottom: 10px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.computed { padding: 8px 10px; background: var(--surface-2); border: 1px dashed var(--border); border-radius: 8px; color: var(--muted); font-weight: 400; }
.check-box { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-weight: 400; min-height: 38px; }

.activity { display: flex; flex-direction: column; gap: 10px; max-height: 320px; overflow-y: auto; }
.activity-item { border-left: 3px solid var(--border); padding: 2px 0 2px 12px; }
.activity-item.note { border-left-color: var(--rose); }
.activity-item .msg { white-space: pre-wrap; }
.note-form { display: flex; gap: 8px; }
.note-form textarea { min-height: 42px; }

/* Admin */
.admin-layout { display: grid; grid-template-columns: 200px 1fr; gap: 20px; }
.admin-nav { display: flex; flex-direction: column; gap: 4px; }
.admin-nav button { text-align: left; border-color: transparent; background: transparent; }
.admin-nav button.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.admin-panel { padding: 20px; }
.admin-panel > .head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.admin-panel > .head h2 { flex: 1; }
.admin-panel > p { margin-top: 0; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; min-width: 160px; }
.list-row.archived { opacity: 0.55; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.swatch { width: 16px; height: 16px; border-radius: 50%; flex: 0 0 auto; }
.options-editor { display: flex; flex-direction: column; gap: 6px; }
.options-editor .opt { display: flex; gap: 6px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px; z-index: 100;
  transition: opacity 0.2s, transform 0.2s; pointer-events: none; font-weight: 500;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 760px) {
  header.top { padding: 10px 16px; gap: 10px; }
  main { padding: 16px; }
  .admin-layout { grid-template-columns: 1fr; }
  .admin-nav { flex-direction: row; flex-wrap: wrap; }
  .overlay { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; }
  .modal-foot { border-radius: 0; }
  .bar-row { grid-template-columns: 100px 1fr 32px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .value { font-size: 28px; }
  header.top h1 { width: 100%; }
}

/* Import column mapping: no pinned columns, and dim the columns being skipped */
.import-map th, .import-map td { position: static !important; box-shadow: none !important; width: auto !important; min-width: 0 !important; max-width: none !important; white-space: normal; }
.import-map tbody tr { cursor: default; }
.import-map tr.skipped td:first-child { color: var(--muted); text-decoration: line-through; }
.import-map select { min-width: 200px; }

/* Live refresh / save status in the header */
.sync-status { font-size: 12px; color: var(--muted); padding: 4px 10px; border-radius: 99px; }
.sync-status:empty { display: none; }
.sync-status.busy { color: var(--accent-strong); }
.save-state { align-self: center; }

/* "Save this enquiry?" box shown on top of a form */
.choice-overlay { position: fixed; inset: 0; background: rgba(30, 26, 22, 0.35); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.draft-banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: space-between; background: var(--accent-soft); color: var(--accent-strong); padding: 8px 12px; border-radius: 8px; }

/* Board tick chips are buttons now */
.board-card .tick-chip { cursor: pointer; }

/* Conversion & drop-off */
.funnel { padding: 18px; margin-bottom: 14px; }
.funnel .table-wrap th, .funnel .table-wrap td { position: static; box-shadow: none; width: auto; min-width: 0; max-width: none; }
.funnel tbody tr { cursor: default; }
.funnel tbody tr:hover td { background: transparent; }
.funnel-bar { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.funnel-bar .bar { flex: 1; }
.funnel td.lost { color: var(--danger); font-weight: 600; }

