:root {
  --bg: #f3f1ec;
  --panel: #fbfaf7;
  --ink: #1f1e1b;
  --dim: #7a766d;
  --line: #dcd8ce;
  --line-soft: #e9e6de;
  --hover: #ece9e1;
  --accent: #a8481c;
  --accent-ink: #fff;
  --field: #fff;
  --ok: #2f6b3a;
  --err: #a32b23;
  --st-new: #6b7480;
  --st-contacted: #2c63a8;
  --st-talking: #b07a12;
  --st-signed: #2f7d45;
  --st-dropped: #9a3b33;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312;
    --panel: #1a1a18;
    --ink: #e6e2d9;
    --dim: #8b867b;
    --line: #2e2d29;
    --line-soft: #242320;
    --hover: #22211e;
    --accent: #e0793f;
    --accent-ink: #1a1009;
    --field: #0f0f0e;
    --ok: #6fbf7e;
    --err: #ec6a5f;
    --st-new: #8f98a3;
    --st-contacted: #6a9fe0;
    --st-talking: #dcae4c;
    --st-signed: #6cc185;
    --st-dropped: #d7766c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 2px; }
a:hover { color: var(--accent); text-decoration-color: currentColor; }

h1 { font-size: 20px; font-weight: 600; margin: 0 0 2px; letter-spacing: -0.01em; }
h2 { font-size: 13px; font-weight: 600; margin: 0 0 10px; text-transform: uppercase; letter-spacing: 0.06em; }

.dim { color: var(--dim); }
.small { font-size: 12.5px; }
.r { text-align: right; }
.grow { flex: 1; }

/* top bar */

.top {
  display: flex;
  align-items: center;
  gap: 28px;
  height: 46px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  font: 600 13px var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: none;
}
.brand::before { content: ""; display: inline-block; width: 8px; height: 8px; background: var(--accent); margin-right: 9px; vertical-align: 1px; }

.top nav { display: flex; gap: 2px; }
.top nav a {
  text-decoration: none;
  padding: 5px 10px;
  color: var(--dim);
  border-radius: 3px;
}
.top nav a:hover { color: var(--ink); background: var(--hover); }
.top nav a.on { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }

.me { margin-left: auto; display: flex; gap: 14px; align-items: center; color: var(--dim); font-size: 13px; }

main { padding: 18px 20px 60px; max-width: 1500px; margin: 0 auto; }

/* controls */

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

input, select, textarea {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 6px 9px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}
textarea { resize: vertical; width: 100%; line-height: 1.5; }

button, .btn {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--accent);
  border-radius: 3px;
  padding: 6px 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:hover, .btn:hover { filter: brightness(1.08); color: var(--accent-ink); }

.btn { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn:hover { border-color: var(--ink); color: var(--ink); filter: none; }

button.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--dim);
  font-weight: 400;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 2px;
}
button.link:hover { color: var(--ink); filter: none; }
button.danger:hover { color: var(--err); }

.err, .ok {
  padding: 8px 12px;
  border-left: 3px solid var(--err);
  background: color-mix(in srgb, var(--err) 9%, transparent);
  margin: 0 0 14px;
}
.ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); transition: opacity .6s; }
.ok.gone { opacity: 0; }

/* list */

.bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
#q { flex: 0 1 380px; font-family: var(--mono); font-size: 13.5px; }
.narrow { width: 120px; }
.count { color: var(--dim); font-size: 13px; }
.count b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.tablewrap { overflow-x: auto; border: 1px solid var(--line); background: var(--panel); }

.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.grid th {
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--dim);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--panel);
}
.grid td { padding: 6px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr[data-href] { cursor: pointer; }
.grid tbody tr:hover td { background: var(--hover); }
.grid .id { width: 1%; color: var(--dim); font: 12.5px var(--mono); }
.grid .id a { text-decoration: none; }
.grid .name { font-weight: 500; min-width: 120px; }
.grid .num { font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12.5px; }
.grid tr.none td { padding: 28px 10px; color: var(--dim); text-align: center; cursor: default; }

.h {
  font-family: var(--mono);
  font-size: 12.5px;
  cursor: copy;
  border-radius: 2px;
  padding: 0 2px;
  margin: 0 -2px;
}
.h:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.h.copied { background: var(--ok); color: var(--bg); }
.other .h { margin-right: 10px; white-space: nowrap; display: inline-block; }
.other i { font-style: normal; color: var(--dim); font-size: 10.5px; margin-right: 4px; text-transform: uppercase; }

.tag {
  font: 11px var(--mono);
  color: var(--dim);
  border: 1px solid var(--line);
  padding: 0 5px;
  border-radius: 2px;
  font-weight: 400;
  white-space: nowrap;
}

.st { font-size: 12.5px; white-space: nowrap; }
.st::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--c, var(--dim)); vertical-align: 1px; }
.st-new { --c: var(--st-new); }
.st-contacted { --c: var(--st-contacted); }
.st-talking { --c: var(--st-talking); }
.st-signed { --c: var(--st-signed); }
.st-dropped { --c: var(--st-dropped); color: var(--dim); }

.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 2px; font-size: 13px; }

/* record */

.head { margin-bottom: 16px; }
.head p { margin: 0; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 28px; align-items: start; }

.fields fieldset {
  border: 1px solid var(--line);
  background: var(--panel);
  margin: 0 0 14px;
  padding: 12px 14px 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px 14px;
}
.fields legend {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--dim);
  padding: 0 6px;
  margin-left: -6px;
}
.fields label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--dim); }
.fields label.wide { grid-column: 1 / -1; }
.fields input, .fields select { font-family: var(--mono); font-size: 13.5px; color: var(--ink); }
.fields textarea { color: var(--ink); }
.actions { display: flex; gap: 14px; align-items: center; }

.notes { position: sticky; top: 64px; }
.addnote { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; margin-bottom: 16px; }
.thread { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; }
.thread li { border-left: 2px solid var(--line); padding: 2px 0 2px 12px; margin-bottom: 14px; }
.thread .by { font-size: 12px; }
.thread p { margin: 3px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.remove { margin-top: 26px; padding-top: 12px; border-top: 1px solid var(--line-soft); font-size: 12.5px; }

/* activity */

.log td { white-space: nowrap; }
.log td:last-child { white-space: normal; }
.act { font: 12px var(--mono); }
.act-login { color: var(--dim); }
.act-deleted, .act-exported { color: var(--accent); }

/* sign in */

main.gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.signin {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.signin .brand { margin-bottom: 18px; font-size: 14px; }
.signin label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--dim); }
.signin input { padding: 8px 10px; color: var(--ink); }
.signin input[name=code] { font-family: var(--mono); letter-spacing: 0.3em; }
.signin button { margin-top: 6px; padding: 8px; }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .notes { position: static; }
  .thread { max-height: none; }
}

/* phones */

@media (max-width: 700px) {
  body { font-size: 15px; }
  main { padding: 12px 12px 40px; }

  .top { gap: 10px; padding: 0 12px; height: 50px; }
  .top nav a { padding: 8px 8px; }
  .me span { display: none; }
  .brand::before { margin-right: 7px; }

  /* 16px stops iOS zooming into fields */
  input, select, textarea,
  .fields input, .fields select, #q, .signin input { font-size: 16px; }
  input, select { padding: 9px 10px; }
  button, .btn { padding: 10px 14px; }

  .bar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  #q, .bar select[name=sort] { grid-column: 1 / -1; }
  .narrow { width: auto; }
  .bar .grow { display: none; }
  .bar .btn { justify-self: end; }

  /* client list as cards */
  .tablewrap { border: 0; background: none; overflow: visible; }
  .grid thead { display: none; }
  .grid, .grid tbody { display: block; }
  .grid tbody tr {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 6px 10px;
    align-items: baseline;
    background: var(--panel);
    border: 1px solid var(--line);
    padding: 12px;
    margin-bottom: 8px;
  }
  .grid tbody tr:hover td { background: none; }
  .grid tbody tr:active { background: var(--hover); }
  .grid td { display: block; padding: 0; border: 0; min-width: 0; }
  .grid td:empty { display: none; }
  .grid .id { width: auto; }
  .grid .name { min-width: 0; font-size: 15.5px; }
  .grid .stc { text-align: right; }
  .grid .hd, .grid .other, .grid .num { grid-column: 1 / -1; text-align: left; }
  .grid .hd::before, .grid .num::before {
    content: attr(data-label);
    display: inline-block;
    width: 74px;
    color: var(--dim);
    font: 12px var(--sans);
  }
  .grid .h { font-size: 14px; padding: 3px 4px; margin: -3px -4px; }
  .grid .other { display: flex; flex-wrap: wrap; gap: 6px 14px; }
  .grid .other .h { margin: -3px -4px; }
  .grid .num { font-family: var(--sans); font-size: 14px; }
  .grid .upd { display: none; }
  .grid tr.none { display: block; }
  .grid tr.none td { display: block; }

  /* activity as compact rows */
  .log tbody tr { grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; }
  .log td { white-space: normal; }
  .log .lx { grid-row: 1; grid-column: 1; }
  .log .lr { grid-row: 1; grid-column: 2; text-align: right; }
  .log .la, .log .lw { grid-column: 1 / -1; font-size: 13px; }
  .log .la { color: var(--dim); }
  .log .ld { grid-column: 1 / -1; font-size: 13px; }

  /* record page */
  h1 { font-size: 19px; overflow-wrap: anywhere; }
  .fields fieldset { grid-template-columns: 1fr; padding: 10px 12px 12px; }
  .actions {
    position: sticky;
    bottom: 0;
    background: var(--bg);
    padding: 10px 0 12px;
    margin: 0 -12px;
    padding-left: 12px;
    padding-right: 12px;
    border-top: 1px solid var(--line);
  }
  .actions button { flex: 1; }
  .kbd { display: none; }
  .addnote button { width: 100%; }
  .notes { margin-top: 10px; }

  .pager { padding: 14px 0; }
  .pager a { padding: 8px 4px; }
}
