:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #25231f;
  --muted: #6b675f;
  --border: #d9d5ca;
  --accent: #7a2e3b;
  --accent-text: #ffffff;
  --focus: #1f6feb;
  --danger: #b3261e;
  --ok: #1e7a3c;

  --s-uncontacted: #e7e5df;
  --s-first: #dbe7f7;
  --s-possible: #fbeec4;
  --s-top: #cfeed8;
  --s-dq: #f3d6d3;

  --radius: 8px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161a;
    --surface: #211f25;
    --surface-2: #2a2830;
    --text: #ece9f0;
    --muted: #a39fad;
    --border: #3a3742;
    --accent: #d9788a;
    --accent-text: #1a1215;
    --focus: #6ea8ff;
    --danger: #ff8a80;
    --ok: #6fd18c;
    --s-uncontacted: #34323a;
    --s-first: #25364f;
    --s-possible: #4b4220;
    --s-top: #224a31;
    --s-dq: #4f2a28;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0.2rem 0; text-decoration: underline; }
.btn.small { padding: 0.2rem 0.55rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.6; cursor: default; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card {
  width: min(26rem, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.75rem;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.login-card p.sub { margin: 0 0 1.25rem; color: var(--muted); }
.field { display: block; margin-bottom: 1rem; }
.field > span { display: block; font-weight: 600; margin-bottom: 0.25rem; }
.field input, .field select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.login-card .btn.primary { width: 100%; padding: 0.65rem; margin-top: 0.5rem; }
.gap-top { margin-top: 1rem; }
.form-error { color: var(--danger); min-height: 1.3em; margin: 0.5rem 0 0; }

/* ---------- app header ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.65rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header h1 { margin: 0; font-size: 1.1rem; }
.app-header nav { display: flex; gap: 0.25rem; flex: 1; }
.app-header nav a {
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text);
}
.app-header nav a[aria-current='page'] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.app-header .who { color: var(--muted); }

/* ---------- list page ---------- */
main { padding: 1rem; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.75rem;
}
.toolbar input[type='search'] {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  min-width: 14rem;
}
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  background: var(--surface);
  cursor: pointer;
  font-size: 0.88rem;
}
.chip[aria-pressed='true'] { border-color: var(--text); font-weight: 600; }
.chip[aria-pressed='false'] { opacity: 0.55; }
.spacer { flex: 1; }
.count { color: var(--muted); font-size: 0.9rem; }

.colpicker { position: relative; }
.colpicker > summary { list-style: none; }
.colpicker > summary::-webkit-details-marker { display: none; }
.colpicker .panel {
  position: absolute;
  right: 0;
  z-index: 30;
  margin-top: 0.3rem;
  width: min(22rem, 90vw);
  max-height: 70vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem;
}
.colpicker h3 { margin: 0.5rem 0 0.2rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.colpicker h3:first-child { margin-top: 0; }
.colpicker label { display: flex; gap: 0.5rem; align-items: center; padding: 0.15rem 0; }
.colpicker .panel-foot { margin-top: 0.75rem; display: flex; justify-content: space-between; align-items: center; }
.colpicker .saved-note { color: var(--muted); font-size: 0.82rem; }

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 11rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table.data { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
table.data th, table.data td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0;
  vertical-align: top;
  background: var(--surface);
}
table.data th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface-2);
  text-align: left;
  padding: 0.5rem 0.6rem;
  font-size: 0.85rem;
  white-space: nowrap;
  user-select: none;
}
table.data th button { all: unset; cursor: pointer; display: inline-flex; gap: 0.3rem; align-items: center; }
table.data th button:focus-visible { outline: 2px solid var(--focus); }
table.data th .arrow { color: var(--muted); font-size: 0.75rem; }
table.data .sticky { position: sticky; left: 0; z-index: 2; }
table.data th.sticky { z-index: 4; }
table.data tr.dim td { background: color-mix(in srgb, var(--s-dq) 35%, var(--surface)); }
table.data tr.dim td.sticky { background: color-mix(in srgb, var(--s-dq) 35%, var(--surface)); }

.cell-input {
  display: block;
  width: 100%;
  min-width: 7rem;
  border: 0;
  background: transparent;
  padding: 0.5rem 0.6rem;
  border-radius: 0;
}
.cell-input:hover { background: var(--surface-2); }
.cell-input:focus { background: var(--bg); outline: 2px solid var(--focus); outline-offset: -2px; }
textarea.cell-input { resize: none; height: 2.4rem; overflow: hidden; min-width: 12rem; }
textarea.cell-input:focus { height: 7rem; overflow: auto; position: relative; z-index: 5; }
input[type='number'].cell-input { min-width: 6rem; }
input.cell-input.w-name { min-width: 15rem; font-weight: 600; }
.cell-input.saving { opacity: 0.6; }
.cell-input.saved { box-shadow: inset 0 0 0 2px var(--ok); }

.cell-with-action { display: flex; align-items: center; }
.cell-with-action .btn { margin: 0 0.4rem; white-space: nowrap; }
.cell-link { padding: 0 0.5rem; text-decoration: none; align-self: center; }

select.cell-input[data-status='Uncontacted'], select.status[data-status='Uncontacted'] { background: var(--s-uncontacted); }
select.cell-input[data-status='First Contacted'], select.status[data-status='First Contacted'] { background: var(--s-first); }
select.cell-input[data-status='Possible'], select.status[data-status='Possible'] { background: var(--s-possible); }
select.cell-input[data-status='Top Contender'], select.status[data-status='Top Contender'] { background: var(--s-top); font-weight: 600; }
select.cell-input[data-status='Disqualified'], select.status[data-status='Disqualified'] { background: var(--s-dq); }

.empty { padding: 2rem; text-align: center; color: var(--muted); }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
  max-width: min(46rem, 96vw);
  width: 100%;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dlg-head { display: flex; align-items: center; gap: 0.75rem; padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--border); }
.dlg-head h2 { margin: 0; font-size: 1.15rem; flex: 1; }
.dlg-body { padding: 1rem 1.1rem; max-height: 70vh; overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0.8rem 1.1rem; border-top: 1px solid var(--border); }
.dlg-body .field input, .dlg-body .field textarea, .dlg-body .field select { width: 100%; }

.group { margin-bottom: 1.25rem; }
.group h3 { margin: 0 0 0.5rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 0.75rem; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid label > span { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.2rem; }
.form-grid .cell-input, .dlg-body textarea.cell-input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  height: auto;
  min-width: 0;
}
.form-grid textarea.cell-input { height: 5rem; overflow: auto; }
.form-grid textarea.cell-input:focus { height: 5rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0 0 1rem; }

.history { list-style: none; padding: 0; margin: 0; font-size: 0.88rem; }
.history li { padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.history time { color: var(--muted); margin-right: 0.4rem; }
.history .val { font-style: italic; }

/* ---------- toast ---------- */
#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 0.4rem; }
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 90vw;
}
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 640px) {
  main { padding: 0.5rem; }
  .toolbar input[type='search'] { min-width: 0; flex: 1; }
  input.cell-input.w-name { min-width: 11rem; }
}
