/* ---------- tokens ---------- */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #ebecf0;
  --text: #1b2233;
  --muted: #6b7385;
  --border: #dfe1e6;
  --accent: #4f7cff;
  --accent-text: #ffffff;
  --danger: #d64545;
  --shadow: 0 1px 2px rgba(9, 30, 66, .12), 0 0 1px rgba(9, 30, 66, .16);
  --shadow-lg: 0 12px 32px rgba(9, 30, 66, .22);
  --radius: 10px;
  --col-width: 300px;
  --topbar-h: 56px;
}

/* JS resolves auto/light/dark and sets .dark on <html>. */
:root { color-scheme: light; }

:root.dark {
  color-scheme: dark;
  --bg: #14161c;
  --surface: #1d2129;
  --surface-2: #23272f;
  --text: #e7eaf0;
  --muted: #9aa3b2;
  --border: #2f343d;
  --accent: #6b93ff;
  --accent-text: #0d1017;
  --danger: #e06767;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- topbar ---------- */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 16px; font-weight: 650; margin: 0; letter-spacing: .2px; }
.spacer { flex: 1; }
.actions { display: flex; gap: 6px; }

.search { position: relative; display: flex; align-items: center; }
.search svg {
  position: absolute; left: 9px; width: 15px; height: 15px;
  fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round;
  pointer-events: none;
}
.search input {
  width: 230px;
  padding: 7px 10px 7px 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 7px 11px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { filter: brightness(.97); }
:root.dark .btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.icon { width: 32px; padding: 6px 0; text-align: center; font-size: 16px; line-height: 1; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-weight: 600; }

/* ---------- board ---------- */
.board {
  flex: 1 1 auto;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  overflow-x: auto;
  overflow-y: hidden;
}
.column {
  flex: 0 0 var(--col-width);
  width: var(--col-width);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.column.dragging { opacity: .45; }
.column.drop-target { outline: 2px dashed var(--accent); outline-offset: 2px; }

.col-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px 6px;
}
.grip {
  cursor: grab;
  color: var(--muted);
  padding: 2px 3px;
  border-radius: 5px;
  user-select: none;
  line-height: 1;
}
.grip:hover { background: var(--border); }
.col-title {
  flex: 1;
  min-width: 0;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  padding: 3px 6px;
  font-weight: 650;
}
.col-title:hover { border-color: var(--border); }
.col-title:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.count {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
  padding: 1px 6px;
  background: var(--bg);
  border-radius: 999px;
}

.cards {
  list-style: none;
  margin: 0;
  padding: 2px 8px 8px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 34px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.col-foot { padding: 0 8px 8px; }
.col-foot .btn { width: 100%; text-align: left; }

/* ---------- card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--prio, transparent);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 9px 10px;
  cursor: pointer;
}
.card:hover { border-color: var(--accent); }
.card.dragging { opacity: .4; }
.card.dimmed { opacity: .25; }
.card-title { word-wrap: break-word; }
.card-notes {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.card-meta:empty { display: none; }
.tag {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: hsl(var(--h) 62% 92%);
  color: hsl(var(--h) 55% 28%);
  border: 1px solid hsl(var(--h) 50% 82%);
}
:root.dark .tag {
  background: hsl(var(--h) 40% 22%);
  color: hsl(var(--h) 70% 82%);
  border-color: hsl(var(--h) 35% 32%);
}
.due {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.due.soon { color: #9a6b00; border-color: #e8c268; background: rgba(240, 190, 70, .16); }
.due.over { color: var(--danger); border-color: var(--danger); background: rgba(214, 69, 69, .12); }

.placeholder {
  border: 2px dashed var(--accent);
  border-radius: 8px;
  height: 38px;
  opacity: .6;
}
/* Drawn with CSS, not a node: an element removed under the cursor cancels the drag. */
.cards:empty::after {
  content: "Nothing here yet";
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 10px 4px;
}

/* ---------- dialog ---------- */
.dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: rgba(9, 30, 66, .45); }
.dialog form { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.dialog-head { display: flex; align-items: center; }
.dialog-head h2 { font-size: 15px; margin: 0; flex: 1; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.field > span em { font-weight: 400; font-style: normal; opacity: .75; }
.field input, .field select, .field textarea {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 9px;
  width: 100%;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface);
}
.row { display: flex; gap: 10px; }
.dialog-foot { display: flex; align-items: center; gap: 8px; margin-top: 2px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  border-radius: 10px;
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 10;
}
.toast[hidden] { display: none; }

@media (max-width: 640px) {
  .search input { width: 130px; }
  .brand { display: none; }
  .row { flex-wrap: wrap; }
}

/* ---------- save status ---------- */
.status {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);          /* grey until the live stream is up */
}
.status.live::before { background: #34c78a; }
.status.busy::before { background: #e0a83a; }
.status.error::before { background: var(--danger); }
.status.error { color: var(--danger); }

/* ---------- history ---------- */
#history-dialog { padding: 16px; }
#history-dialog .dialog-head { margin-bottom: 6px; }
.hint { color: var(--muted); font-size: 12px; margin: 0 0 10px; }
.hint code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.history {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 55vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.history li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 8px;
}
.history li:hover { background: var(--surface-2); }
.history .sha {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
}
.history .subject { flex: 1; min-width: 0; }
.history .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.history .btn { padding: 3px 8px; font-size: 12px; }

@media (max-width: 640px) {
  .status { display: none; }
}

/* ---------- no server ---------- */
.fatal {
  margin: 40px auto;
  max-width: 460px;
  text-align: center;
  color: var(--muted);
}
.fatal h2 { color: var(--text); font-size: 16px; margin: 0 0 8px; }
.fatal p { margin: 6px 0; }
.fatal pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  color: var(--text);
  display: inline-block;
}

/* ---------- board picker ---------- */
.boards { display: flex; align-items: center; gap: 2px; }
#board-picker {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  padding: 6px 6px 6px 8px;
  font-weight: 650;
  max-width: 190px;
}
#board-picker:hover { border-color: var(--border); background: var(--surface-2); }
#board-picker:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#board-dialog .hint { margin: 0; }
#board-dialog code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }

/* ---------- dragging ---------- */
.card, .grip { touch-action: manipulation; }
.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  margin: 0;
  pointer-events: none;
  opacity: .95;
  box-shadow: var(--shadow-lg);
  rotate: 1.5deg;
}
.column.drag-ghost { opacity: .9; }
body.dragging-active {
  user-select: none;
  -webkit-user-select: none;
  cursor: grabbing;
}

/* ---------- small screens ---------- */
#btn-menu { display: none; }

@media (max-width: 700px) {
  :root { --topbar-h: 52px; }

  body { height: 100dvh; }
  .topbar {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    gap: 6px;
  }
  .board {
    padding: 10px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    scroll-snap-type: x proximity;
    gap: 10px;
  }

  /* one column fills the screen, the next one peeks out to say it is there */
  .column {
    flex: 0 0 86vw;
    width: 86vw;
    scroll-snap-align: center;
  }

  #board-picker { max-width: 42vw; font-size: 15px; }

  /* the search shrinks to its icon and opens up when you tap it */
  .search input { width: 34px; padding-left: 28px; transition: width .15s ease; }
  .search:focus-within input { width: min(62vw, 320px); }

  #btn-menu { display: inline-block; }
  .actions {
    display: none;
    position: absolute;
    top: calc(var(--topbar-h) - 4px);
    right: 8px;
    z-index: 20;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
  }
  .actions.open { display: flex; }
  .actions .btn { text-align: left; padding: 10px 14px; }

  /* room for a finger */
  .card { padding: 11px 12px; }
  .btn.icon { width: 38px; padding: 9px 0; }
  .col-foot .btn, .cards { padding-bottom: 10px; }

  /* iOS zooms in on a field smaller than 16px */
  .field input, .field select, .field textarea, .search input { font-size: 16px; }
  .dialog { width: calc(100vw - 20px); max-height: 88dvh; overflow-y: auto; }
  .row { flex-wrap: wrap; }
  .row .field { flex: 1 1 45%; }
}

/* ---------- login ---------- */
.login {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login[hidden] { display: none; }
.login-card {
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.login-card h2 { margin: 0; font-size: 16px; }
.login-note {
  margin: 0;
  font-size: 13px;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--surface-2);
}
.login-note.bad { color: var(--danger); background: rgba(214, 69, 69, .12); }
.login-note[hidden] { display: none; }

/* logged out there is nothing to steer */
body.logged-out .boards,
body.logged-out .search,
body.logged-out .actions,
body.logged-out #btn-menu,
body.logged-out #status { display: none; }
body.logged-out .board { display: none; }
.fatal .btn { margin-top: 10px; }
.fatal .btn + .btn { margin-left: 8px; }

/* ---------- installeren ---------- */
.install {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 30;
  width: min(460px, calc(100vw - 24px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
}
.install[hidden] { display: none; }
.install-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.install-text strong { font-size: 14px; }
.install-text span { font-size: 12px; color: var(--muted); }

/* ---------- keuzevakje in een venster ---------- */
.check { display: flex; align-items: flex-start; gap: 9px; cursor: pointer; }
.check input { margin-top: 2px; width: 17px; height: 17px; accent-color: var(--accent); }
.check span { display: flex; flex-direction: column; font-size: 13px; }
.check em { font-style: normal; font-size: 12px; color: var(--muted); }
