:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1b1f27;
  --muted: #667085;
  --line: #e1e4ea;
  --line-strong: #c7ccd6;
  --weekend: rgba(16, 24, 40, 0.035);
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --today: #e5484d;
  --danger: #c4322f;
  --ok: #2f9e5b;
  --warn: #d48a0c;
  --c-blue: #3b6fe0;
  --c-green: #2f9e5b;
  --c-amber: #d48a0c;
  --c-red: #d6453d;
  --c-purple: #8152d6;
  --c-slate: #5b6576;
  --shadow: 0 8px 30px rgba(16, 24, 40, 0.18);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111318;
    --surface: #181b22;
    --surface-2: #222631;
    --text: #e7e9ee;
    --muted: #9198a6;
    --line: #262b36;
    --line-strong: #363c4a;
    --weekend: rgba(255, 255, 255, 0.025);
    --accent: #5b82f0;
    --today: #f2555a;
    --c-blue: #4d7ef0;
    --c-green: #36ad67;
    --c-amber: #dc9a22;
    --c-red: #e2554d;
    --c-purple: #9168e3;
    --c-slate: #6c7689;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111318;
  --surface: #181b22;
  --surface-2: #222631;
  --text: #e7e9ee;
  --muted: #9198a6;
  --line: #262b36;
  --line-strong: #363c4a;
  --weekend: rgba(255, 255, 255, 0.025);
  --accent: #5b82f0;
  --today: #f2555a;
  --c-blue: #4d7ef0;
  --c-green: #36ad67;
  --c-amber: #dc9a22;
  --c-red: #e2554d;
  --c-purple: #9168e3;
  --c-slate: #6c7689;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

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

button {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.topbar h1 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 7px 0 0 7px; margin-left: 0; }
.seg button:last-child { border-radius: 0 7px 7px 0; }
.seg button.on { background: var(--surface-2); font-weight: 600; }
.status { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.dot.ok { background: var(--ok); }
.dot.busy { background: var(--warn); }
.dot.err { background: var(--danger); }

#banner {
  padding: 8px 16px;
  background: var(--danger);
  color: #fff;
  font-size: 13px;
}

/* Board */
#scroller { flex: 1; overflow: auto; position: relative; }
#canvas { position: relative; min-height: 100%; }

.head {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
}
.corner {
  position: sticky;
  left: 0;
  z-index: 5;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line-strong);
  display: flex;
  align-items: flex-end;
  padding: 0 12px 6px;
  color: var(--muted);
  font-size: 12px;
}
.head-track { position: relative; height: 48px; flex-shrink: 0; }
.month, .tick {
  position: absolute;
  white-space: nowrap;
  overflow: hidden;
  font-size: 12px;
  padding-left: 6px;
}
.month { top: 0; height: 24px; line-height: 24px; font-weight: 600; border-left: 1px solid var(--line-strong); }
.tick { top: 24px; height: 24px; line-height: 24px; color: var(--muted); border-left: 1px solid var(--line); padding-left: 4px; }
.tick.weekend { color: var(--line-strong); }
.tick.today { color: var(--today); font-weight: 700; }

.body { position: relative; }
.grid { position: absolute; top: 0; bottom: 0; pointer-events: none; z-index: 0; }
.gl { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); }
.gl.gl-m { background: var(--line-strong); }
.we { position: absolute; top: 0; bottom: 0; background: var(--weekend); }
.today-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--today); z-index: 3; opacity: 0.85; }

.lane { display: flex; border-bottom: 1px solid var(--line); position: relative; }
.lane.drop { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.lane-label {
  position: sticky;
  left: 0;
  z-index: 2;
  flex-shrink: 0;
  background: var(--surface);
  border: 0;
  border-right: 1px solid var(--line-strong);
  border-radius: 0;
  padding: 8px 12px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 2px;
}
.lane-label:hover { background: var(--surface-2); }
.lane-label .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lane-label .count { color: var(--muted); font-size: 12px; }
.track { position: relative; flex-shrink: 0; }

.bar {
  position: absolute;
  z-index: 1;
  height: 28px;
  border-radius: 6px;
  background: var(--c, var(--c-blue));
  color: #fff;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 28px;
  padding: 0 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: grab;
  touch-action: none;
  user-select: none;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.2);
}
.bar:hover { filter: brightness(1.08); }
.bar.done { opacity: 0.5; text-decoration: line-through; }
.bar.dragging { cursor: grabbing; z-index: 6; box-shadow: var(--shadow); opacity: 0.92; }
.bar .h { position: absolute; top: 0; bottom: 0; width: 8px; cursor: ew-resize; }
.bar .h-l { left: 0; }
.bar .h-r { right: 0; }
[data-c="blue"] { --c: var(--c-blue); }
[data-c="green"] { --c: var(--c-green); }
[data-c="amber"] { --c: var(--c-amber); }
[data-c="red"] { --c: var(--c-red); }
[data-c="purple"] { --c: var(--c-purple); }
[data-c="slate"] { --c: var(--c-slate); }

.hint {
  position: absolute;
  z-index: 1;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
  top: 14px;
}

/* Dialogs */
dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(10, 12, 18, 0.45); }
dialog form { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
dialog h2 { margin: 0 0 4px; font-size: 16px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
dialog input:not([type="checkbox"]):not([type="radio"]), dialog select, dialog textarea {
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 7px 9px;
  color: var(--text);
  width: 100%;
}
dialog textarea { resize: vertical; }
dialog .row { display: flex; gap: 12px; }
dialog .row > * { flex: 1; }
dialog label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.swatches { border: 0; padding: 0; margin: 0; display: flex; gap: 8px; }
.swatches legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 4px; }
.swatches input { appearance: none; width: 24px; height: 24px; border-radius: 50%; margin: 0; cursor: pointer; background: var(--c); border: 2px solid transparent; }
.swatches input:checked { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface); }
.meta { margin: 0; font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 8px; margin-top: 4px; }
.spacer { flex: 1; }

@media (max-width: 600px) {
  .topbar { gap: 10px; }
  .status #who { display: none; }
}
