:root {
  --bg: #eef0f3;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --column: #e3e6eb;
  --text: #1d2127;
  --muted: #697180;
  --border: #d5d9e0;
  --accent: #2f6fdb;
  --accent-text: #ffffff;
  --danger: #d14343;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.08), 0 1px 3px rgb(16 24 40 / 0.06);
  --shadow-lg: 0 20px 50px rgb(16 24 40 / 0.25);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --surface: #1f232a;
    --surface-2: #262b33;
    --column: #1a1d22;
    --text: #e5e8ec;
    --muted: #979fab;
    --border: #313741;
    --accent: #5b8ef0;
    --accent-text: #0d1117;
    --danger: #ef6b6b;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 20px 50px rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1f232a;
  --surface-2: #262b33;
  --column: #1a1d22;
  --text: #e5e8ec;
  --muted: #979fab;
  --border: #313741;
  --accent: #5b8ef0;
  --accent-text: #0d1117;
  --danger: #ef6b6b;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 20px 50px rgb(0 0 0 / 0.6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

[x-cloak] { display: none !important; }

html, body { margin: 0; }

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

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

h1, h2 { margin: 0; }

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

input, textarea, select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  min-width: 0;
}

input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, .card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

textarea { resize: vertical; width: 100%; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Buttons ---------- */

.btn {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 500;
  background: var(--surface-2);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:not(:disabled):hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: var(--surface); }
.btn-small { padding: 4px 10px; font-size: 13px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  text-decoration: none;
}
.brand svg { fill: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* ---------- Generic pages ---------- */

.page { width: 100%; max-width: 1000px; margin: 0 auto; padding: 28px 16px; }
.page.narrow { max-width: 480px; }

/* ---------- Auth ---------- */

.auth { flex: 1; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.auth-card label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; }
.auth-card p { margin: 0; }
.form-error {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border-radius: 6px;
  padding: 8px 10px;
}
.form-success {
  color: var(--text);
  background: color-mix(in srgb, #3fa55b 16%, transparent);
  border-radius: 6px;
  padding: 8px 10px;
}

/* ---------- Account ---------- */

.account-card { max-width: 420px; }
.account-fields { margin: 0; }
.account-field {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.account-field:last-child { border-bottom: 0; }
.account-field dt { color: var(--muted); }
.account-field dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.account-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.account-actions form { margin: 0; }
.account-password { padding-top: 14px; border-top: 1px solid var(--border); }
.account-password form { display: flex; flex-direction: column; gap: 12px; }
.account-password h2 { font-size: 16px; }
.account-password label .small { font-weight: 400; }

/* ---------- Board ---------- */

/* The board page fills the viewport exactly so each column scrolls on its own. */
body:has(.board) { height: 100vh; height: 100dvh; }

.board {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  min-height: 0;
}
.board-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.board-title { min-width: 0; flex: 1; }
.board-title h1 {
  /* Shrink to the text so the hover highlight doesn't span the whole header. */
  width: fit-content;
  max-width: 100%;
  font-size: 20px;
  cursor: text;
  padding: 3px 6px;
  margin-left: -6px;
  border-radius: 6px;
  overflow-wrap: anywhere;
}
.board-title h1:hover { background: var(--surface-2); }
.title-input { font-size: 20px; font-weight: 700; width: min(100%, 420px); padding: 2px 6px; margin-left: -6px; }
.board-actions { display: flex; align-items: center; gap: 8px; }

.board-menu { position: relative; }
.board-menu-btn { display: inline-flex; align-items: center; gap: 6px; }
.board-menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 5;
  min-width: 220px;
  max-width: 320px;
  max-height: 60vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
}
.board-menu-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.board-menu-item:hover { background: var(--surface-2); }
.board-menu-item.current { font-weight: 600; color: var(--accent); }
.board-menu-new { color: var(--accent); font-weight: 500; }
.board-menu-sep { height: 1px; background: var(--border); margin: 4px 2px; }
.modal-small { max-width: 400px; }
.modal-footer form { margin: 0; }
.settings-btn { display: inline-flex; align-items: center; gap: 6px; }

.color-settings { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.color-setting {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  border-radius: 6px;
  font-weight: 400;
}
.color-setting:hover { background: var(--surface-2); }
.color-setting.off .color-dot-input, .color-setting.off .color-name-input { opacity: 0.45; }
.color-setting-check { display: flex; }
.color-setting-check input { margin: 0; cursor: pointer; }
.color-setting-check.locked, .color-setting-check.locked input { cursor: not-allowed; }
.color-name-input { flex: 1; padding: 3px 8px; }

/* Render the native colour picker as a round dot, like the legend's. */
.color-dot-input {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid #000;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  flex: none;
  overflow: hidden;
}
.color-dot-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-dot-input::-webkit-color-swatch { border: 0; border-radius: 50%; }
.color-dot-input::-moz-color-swatch { border: 0; border-radius: 50%; }

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px;
  /* Full-width footer bar: cancel the board's side/bottom padding. */
  margin: 0 -16px -16px;
  padding: 4px 16px;
  font-size: 13px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  user-select: none;
  -webkit-user-select: none;
}
.legend-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 9px 1px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  cursor: pointer;
  transition: opacity 0.15s;
}
.legend-chip:hover { border-color: var(--muted); }
.legend-chip.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.legend-chip.dimmed { opacity: 0.45; }
.legend-count { color: var(--muted); font-size: 11.5px; min-width: 1ch; }
.legend .dot { width: 10px; height: 10px; }
.legend .btn-small { padding: 1px 8px; font-size: 12.5px; }

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
  border: 1px solid #000;
}

.columns {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.column {
  display: flex;
  flex-direction: column;
  max-height: 100%;
  min-height: 200px;
  background: var(--column);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.15s, background 0.15s;
}
.column.drag-over { border-color: var(--accent); }
.column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 6px;
  user-select: none;
  -webkit-user-select: none;
}
.column-header h2 { font-size: 14px; }
.column-actions { display: flex; align-items: center; gap: 6px; }
.add-btn {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.add-btn:hover { background: var(--accent); color: var(--accent-text); }
.column-count {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border-radius: 999px;
  padding: 1px 8px;
}

.cards {
  flex: 1;
  min-height: 60px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 2px 6px 8px;
}
.cards > * { flex: none; }
/* Wrapper per rendered item; display:contents keeps cards as direct flex children. */
.card-item { display: contents; }
.day-header {
  margin: 6px 2px 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
  -webkit-user-select: none;
}
.card-item:first-child .day-header { margin-top: 0; }

.card {
  --c: #e3e3e3;
  position: relative;
  /* Flat-coloured card with black text in both themes. */
  background: var(--c);
  color: #1d2127;
  border: 1px solid rgb(0 0 0 / 0.08);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 13px;
  line-height: 1.35;
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
}
.card:hover { filter: brightness(0.98); }
/* Dragging: the card moves live to where it would land, semi-transparent,
   while the original stays hidden in place. */
.card.drag-preview { opacity: 0.5; pointer-events: none; }
.card.drag-source { display: none; }
.card.drag-source.drag-source-idle { display: block; opacity: 0.5; }
.card-title { overflow-wrap: anywhere; }
.desc-toggle {
  display: flex;
  margin: 2px 0 0 -2px;
  padding: 1px 2px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: rgb(0 0 0 / 0.45);
  cursor: pointer;
}
.desc-toggle:hover, .desc-toggle.open { color: rgb(0 0 0 / 0.8); background: rgb(0 0 0 / 0.07); }
.card-desc {
  margin-top: 3px;
  color: rgb(0 0 0 / 0.7);
  font-size: 11.5px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  align-items: safe center;
  padding: 16px;
  overflow-y: auto;
  background: rgb(0 0 0 / 0.45);
}
.modal {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
}
.modal-heading { font-size: 17px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.field select { align-self: flex-start; }
.modal-footer { display: flex; gap: 8px; padding-top: 4px; }

/* ---------- Task window (KanbanFlow-style) ---------- */
/* Tinted with the task's colour; text stays black in both themes like the cards. */
/* Sit the task window near the top rather than dead centre. */
.modal-backdrop:has(.task-modal) { align-items: start; padding-top: 6vh; }
.task-modal {
  --ink: #1d2127;
  --ink-soft: rgb(0 0 0 / 0.58);
  --hover: rgb(0 0 0 / 0.06);
  position: relative;
  max-width: 660px;
  min-height: 380px;
  /* Grow with the content (the backdrop scrolls) so dropdowns aren't clipped. */
  max-height: none;
  overflow: visible;
  gap: 18px;
  padding: 30px 36px;
  background: var(--c, var(--surface));
  color: var(--ink);
  border: 0;
}
.task-modal input, .task-modal textarea {
  background: rgb(255 255 255 / 0.6);
  color: var(--ink);
  border-color: rgb(0 0 0 / 0.15);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  padding: 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: rgb(0 0 0 / 0.45);
  cursor: pointer;
}
.modal-close:hover { color: var(--ink); background: var(--hover); }

.task-title {
  width: fit-content;
  max-width: calc(100% - 28px);
  margin: 0 0 0 -6px;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 26px;
  line-height: 1.25;
  overflow-wrap: anywhere;
  cursor: text;
}
.task-title:hover { background: var(--hover); }
.task-title-input {
  width: calc(100% - 28px);
  margin-left: -6px;
  padding: 1px 6px;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.25;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: -10px;
  color: var(--ink-soft);
  font-size: 13px;
}
.meta-sep { margin: 0 4px; }
.task-created { cursor: default; }

.task-section { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.task-label { font-size: 13px; color: var(--ink-soft); }

.meta-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-left: -6px;
  padding: 2px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.meta-btn:hover { background: var(--hover); }
.colour-btn { gap: 7px; font-size: 13px; color: var(--ink); }
.colour-btn .dot { width: 12px; height: 12px; }

.task-desc {
  align-self: stretch;
  margin-left: -6px;
  padding: 4px 6px;
  min-height: 28px;
  border-radius: 6px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: text;
}
.task-desc:hover { background: var(--hover); }
.task-desc.empty {
  margin-left: 0;
  padding: 0;
  min-height: 0;
  font-size: 13px;
  color: rgb(0 0 0 / 0.45);
}
.task-desc.empty:hover { background: none; color: var(--ink); }
.task-desc-input { align-self: stretch; font-size: 13.5px; line-height: 1.5; }

.task-footer { margin-top: auto; }
.task-footer .modal-footer { width: 100%; }
.link-danger {
  padding: 0;
  border: 0;
  background: none;
  color: #b42318;
  font-size: 13px;
  cursor: pointer;
}
.link-danger:hover { text-decoration: underline; }

/* Small dropdown menus (column and colour pickers). */
.menu { position: relative; }
.menu-list {
  position: absolute;
  top: calc(100% + 4px);
  left: -6px;
  z-index: 5;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  padding: 4px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item.current { font-weight: 600; }
.spacer { flex: 1; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: var(--danger);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  max-width: calc(100vw - 32px);
}

@media (max-width: 800px) {
  body:has(.board) { height: auto; }
  .columns { grid-template-columns: 1fr; grid-template-rows: none; }
  .column { max-height: 70vh; }
}
