/* Kanli — offline kanban board */

:root {
  --accent: #2150c0;
  --accent-dark: #17367d;
  --bg: #111112;
  --e1: #1b1b1d;
  --e2: #27272a;
  --e3: #333338;
  --text: #f4f4f5;
  --text-btn: #f1f5f9;
  --t1: #e4e4e7;
  --t2: #d4d4d8;
  --t3: #a1a1aa;
  --t4: #71717a;
  --danger: #f87171;
  --accent-ink: #7b9cf0;
  --focus: #5a83e6;
  --ok: #15803d;
  --warn: #f59e0b;
  --radius: 10px;
  --side-w: 60px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35), 0 2px 6px rgba(0, 0, 0, .2);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  line-height: 1.45;
  display: flex;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-ink); text-underline-offset: .18em; }
::selection { background: color-mix(in srgb, var(--accent) 40%, transparent); color: var(--text); }
input, textarea, [contenteditable] { caret-color: var(--accent-ink); }
::placeholder { color: var(--t3); opacity: 1; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
[hidden] { display: none !important; }

.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--t3); }
.small { font-size: 0.75rem; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--e3) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--e3); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.modal:focus { outline: none; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--side-w);
  flex: none;
  background: var(--e1);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 6px;
  border-right: 1px solid var(--e2);
  z-index: 20;
}
.logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--accent); color: var(--text-btn);
  display: grid; place-items: center; margin-bottom: 10px;
}
.logo .i { width: 22px; height: 22px; fill: currentColor; stroke: none; }
.side-nav { display: flex; flex-direction: column; gap: 6px; }
.nav-btn {
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center;
  color: var(--t3); background: none; border: 0;
  text-decoration: none; position: relative;
}
.nav-btn:hover { background: var(--e2); color: var(--text); }
.nav-btn.active { background: var(--e2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.side-pins {
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--e2);
  flex: 1; overflow: auto; width: 100%;
}
.side-pins:empty { border-top: 0; }
.pin-link {
  width: 40px; height: 40px; flex: none; border-radius: 10px; background: var(--e2);
  display: grid; place-items: center; font-weight: 700; font-size: 0.8125rem;
  color: var(--t2); text-decoration: none; position: relative;
}
.pin-link:hover { background: var(--e3); color: var(--text); }
.pin-link.active { background: var(--accent); color: var(--text-btn); }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  background: var(--e3); color: var(--text); padding: 5px 9px; border-radius: 6px;
  white-space: nowrap; font-size: 0.75rem; font-weight: 500; z-index: 60; pointer-events: none;
  box-shadow: var(--shadow);
}

#view { flex: 1; min-width: 0; height: 100%; overflow: auto; position: relative; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px;
  background: var(--e2); border: 1px solid var(--e3);
  font-weight: 500; white-space: nowrap; text-decoration: none; color: var(--text);
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--e3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--text-btn); }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn.danger:hover { background: #b91c1c; }
.btn.danger-outline { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); background: transparent; }
.btn.danger-outline:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn.sm { padding: 5px 10px; font-size: 0.8125rem; }
.btn.block { width: 100%; justify-content: flex-start; }
.btn .i { width: 16px; height: 16px; }

.icon-btn {
  width: 34px; height: 34px; flex: none;
  display: inline-grid; place-items: center;
  border-radius: 8px; border: 0; background: transparent; color: var(--t3);
  text-decoration: none;
}
.icon-btn:hover { background: var(--e2); color: var(--text); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm .i { width: 16px; height: 16px; }
.icon-btn.xs { width: 22px; height: 22px; border-radius: 6px; }
.icon-btn.xs .i { width: 14px; height: 14px; }

.link { background: none; border: 0; padding: 0; color: var(--accent-ink); font-size: 0.75rem; font-weight: 500; text-underline-offset: .18em; }
.link:hover { text-decoration: underline; }

.input, .select, input[type="text"], input[type="search"], input[type="datetime-local"], textarea.input {
  background: var(--e2); border: 1px solid var(--e3); border-radius: 8px;
  padding: 8px 10px; outline: none; width: 100%;
}
.input:focus, .select:focus, input[type="text"]:focus, textarea:focus { border-color: var(--focus); }
.input.sm, .select.sm { padding: 6px 8px; font-size: 0.8125rem; }
.select { width: auto; padding-right: 28px; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--t3) 50%), linear-gradient(135deg, var(--t3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
input[type="datetime-local"] { color-scheme: inherit; }
.save-status { white-space: nowrap; }
.save-status::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #22c55e; margin-right: 6px; vertical-align: 1px; }
.save-status[data-state="saving"]::before { background: var(--t3); }
.save-status[data-state="error"], .save-status[data-state="paused"] { color: var(--danger); }
.save-status[data-state="error"]::before, .save-status[data-state="paused"]::before { background: var(--danger); }
.filter-count { font-size: 0.75rem; color: var(--t3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.filter-count:empty { display: none; }

.search {
  display: flex; align-items: center; gap: 6px;
  background: var(--e2); border: 1px solid var(--e3); border-radius: 8px;
  padding: 0 6px 0 10px; height: 36px; color: var(--t3);
}
.search:focus-within { border-color: var(--focus); }
.search input { background: none; border: 0; outline: none; padding: 0; width: 170px; color: var(--text); }
.search .i { width: 16px; height: 16px; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.8125rem; color: var(--t2); }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.7188rem;
  background: var(--e2); border: 1px solid var(--e3); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px; color: var(--t2); white-space: nowrap;
}

/* ---------- Pages ---------- */
.page { max-width: 1240px; margin: 0 auto; padding: 32px 32px 80px; }
.page.narrow { max-width: 820px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { font-size: 1.625rem; font-weight: 700; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.tile {
  position: relative; background: var(--e1); border: 1px solid var(--e2);
  border-radius: 12px; overflow: hidden; cursor: pointer; text-align: left;
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.tile:hover { transform: translateY(-2px); border-color: var(--e3); box-shadow: var(--shadow); }
.tile-preview {
  height: 118px; background: var(--e2);
  display: flex; gap: 6px; padding: 12px; align-items: flex-start; position: relative;
}
.mini-col {
  flex: 1; max-width: 54px; background: color-mix(in srgb, var(--e1) 82%, transparent);
  border-radius: 6px; padding: 4px; display: flex; flex-direction: column; gap: 3px; min-height: 20px;
}
.mini-col i { display: block; height: 9px; border-radius: 3px; background: var(--e3); }
.tile-body { padding: 12px 14px 14px; }
.tile-title { font-weight: 600; font-size: 0.9375rem; display: flex; gap: 6px; align-items: center; min-width: 0; padding-right: 28px; }
.tile-link { color: inherit; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-link:focus-visible { outline: none; }
.tile:has(.tile-link:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.pin-mark { display: inline-grid; color: var(--accent-ink); }
.pin-mark .i { width: 14px; height: 14px; fill: currentColor; }
.tile-meta { color: var(--t3); font-size: 0.7812rem; margin-top: 3px; }
.tile-menu { position: absolute; bottom: 10px; right: 8px; background: var(--e1); opacity: 0; transition: opacity .12s; }
.tile:hover .tile-menu, .tile:focus-within .tile-menu { opacity: 1; }
.tile-new {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 190px; border: 2px dashed var(--e3); background: transparent; color: var(--t3); font-weight: 500;
}
.tile-new:hover { color: var(--text); border-color: var(--accent); }
.tile-new .i { width: 26px; height: 26px; }
.empty-state { text-align: center; padding: 80px 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-state p { margin: 0 0 8px; }

.notice {
  display: flex; align-items: center; gap: 14px; margin: -6px 0 22px; padding: 12px 12px 12px 16px;
  background: color-mix(in srgb, var(--accent) 12%, var(--e1)); border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--e2));
  border-radius: 12px;
}
.notice > .i { color: var(--accent-ink); }
.notice > div { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.notice span { color: var(--t2); font-size: 0.8125rem; }

.panel { background: var(--e1); border: 1px solid var(--e2); border-radius: 12px; padding: 20px 22px; margin-bottom: 16px; }
.panel > h2 { font-size: 1rem; margin-bottom: 4px; }
.panel > p { margin: 0 0 14px; color: var(--t3); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--e2); }
.setting-row:first-of-type { border-top: 0; }
.setting-row .label { font-weight: 500; }
.setting-row .desc { color: var(--t3); font-size: 0.7812rem; }

.toggle { position: relative; width: 40px; height: 22px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle span { position: absolute; inset: 0; background: var(--e3); border-radius: 22px; transition: background .15s; cursor: pointer; }
.toggle span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .15s; }
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(18px); }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.theme-opt { background: var(--e2); border: 2px solid transparent; border-radius: 10px; padding: 8px; text-align: left; font-weight: 500; display: flex; flex-direction: column; gap: 8px; }
.theme-opt:hover { border-color: var(--e3); }
.theme-opt.active { border-color: var(--accent); }
.theme-swatch { height: 52px; border-radius: 6px; display: flex; gap: 4px; padding: 6px; border: 1px solid rgba(128,128,128,.25); }
.theme-swatch i { flex: 1; border-radius: 4px; }
.theme-swatch.auto { background: linear-gradient(135deg, #ffffff 50%, #111112 50%); }
.theme-editor { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; margin-top: 16px; }
.color-field { display: flex; align-items: center; gap: 10px; background: var(--e2); padding: 6px 10px; border-radius: 8px; font-size: 0.8125rem; }
.color-field input { width: 28px; height: 28px; border: 0; padding: 0; background: none; cursor: pointer; border-radius: 6px; }

.storage-bar { height: 8px; background: var(--e2); border-radius: 8px; overflow: hidden; margin: 10px 0 6px; }
.storage-bar i { display: block; height: 100%; background: var(--accent); }
.import-list { margin: 8px 0 16px; padding-left: 20px; max-height: 220px; overflow: auto; }
.import-list li { margin: 3px 0; }

/* ---------- Board ---------- */
.board-view { position: relative; height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.board-bg { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.board-head {
  position: relative; z-index: 2; display: flex; align-items: center; gap: 8px;
  padding: 12px 20px; min-height: 62px; flex-wrap: nowrap;
}
.has-bg .board-head { background: color-mix(in srgb, var(--bg) 88%, transparent); border-bottom: 1px solid color-mix(in srgb, var(--e2) 60%, transparent); }
.board-title { min-width: 6rem; max-width: 40vw; display: flex; flex: 0 1 auto; }
.title-btn {
  font-size: 1.25rem; font-weight: 700; padding: 4px 8px; border-radius: 8px; cursor: text; border: 0; background: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: -.01em; text-align: left; min-width: 0;
}
.title-btn:hover { background: color-mix(in srgb, var(--e2) 80%, transparent); }
.title-input { font-size: 1.25rem !important; font-weight: 700; width: 360px !important; max-width: 50vw; padding: 3px 8px !important; }
.board-stats { font-size: 0.7812rem; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; }
.board-head > :not(.board-title):not(.board-stats):not(.spacer) { flex-shrink: 0; }
@media (max-width: 1100px) { .board-stats { display: none; } }
.spacer { flex: 1; }
.zoom { display: flex; align-items: center; background: var(--e2); border-radius: 8px; border: 1px solid var(--e3); }
.zoom .icon-btn { width: 30px; height: 32px; }
.zoom-val { background: none; border: 0; font-size: 0.7812rem; min-width: 46px; padding: 0 4px; white-space: nowrap; color: var(--t2); font-variant-numeric: tabular-nums; }
.has-bg .search, .has-bg .zoom { background: color-mix(in srgb, var(--e2) 85%, transparent); }

.columns-wrap { flex: 1; min-height: 0; position: relative; z-index: 1; }
.columns {
  zoom: var(--z, 1);
  height: calc(100% / var(--z, 1));
  width: calc(100% / var(--z, 1));
  display: flex; align-items: flex-start; gap: 12px;
  padding: 6px 20px 20px; overflow-x: auto; overflow-y: hidden;
}
.column {
  width: var(--col-w, 280px); flex: none; max-height: 100%;
  background: var(--e1); border-radius: 12px;
  display: flex; flex-direction: column;
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.has-bg .column { box-shadow: 0 6px 18px rgba(0,0,0,.18), 0 1px 2px rgba(0,0,0,.2); }
.column.dragging { opacity: .45; outline: 2px dashed var(--accent); outline-offset: -2px; }
.col-head { display: flex; align-items: center; gap: 4px; padding: 10px 8px 6px 12px; cursor: grab; }
.col-head:active { cursor: grabbing; }
.col-title { font-size: 0.875rem; font-weight: 600; flex: 1; min-width: 0; display: flex; }
.col-title-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 3px 4px; margin-left: -4px; border-radius: 6px; cursor: grab; }
.col-title-input { flex: 1; min-width: 0; padding: 4px 6px !important; font-weight: 600; }
.count { font-size: 0.75rem; color: var(--t3); background: var(--e2); padding: 1px 8px; border-radius: 10px; font-variant-numeric: tabular-nums; }
.col-head .icon-btn { opacity: .7; }
.col-head .icon-btn:hover { opacity: 1; }
.cards { display: flex; flex-direction: column; gap: 8px; padding: 4px 8px 6px; overflow-y: auto; min-height: 14px; flex: 0 1 auto; }
.cards-empty { border: 2px dashed var(--e3); border-radius: 8px; color: var(--t3); font-size: 0.7812rem; text-align: center; padding: 14px 8px; }
.col-foot { padding: 4px 8px 8px; }
.add-card-btn, .add-col-btn {
  width: 100%; display: flex; align-items: center; gap: 6px;
  background: none; border: 0; color: var(--t3); padding: 8px 8px; border-radius: 8px; text-align: left; font-weight: 500;
}
.add-card-btn:hover { background: var(--e2); color: var(--text); }
.add-card-btn .i, .add-col-btn .i { width: 16px; height: 16px; }
.composer textarea { resize: none; min-height: 64px; display: block; margin-bottom: 6px; line-height: 1.4; }
.composer .row { gap: 4px; }
.add-column { width: var(--col-w, 280px); flex: none; }
.add-col-btn { background: color-mix(in srgb, var(--e1) 70%, transparent); padding: 12px 14px; border-radius: 12px; }
.add-col-btn:hover { background: var(--e1); color: var(--text); }
.has-bg .add-col-btn { background: var(--e1); }
.has-bg .add-col-btn:hover { background: var(--e2); }
.col-composer { background: var(--e1); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }

.card {
  background: var(--e2); color: var(--text); border-radius: 9px; padding: 9px 11px;
  cursor: pointer; border: 1px solid transparent; box-shadow: 0 1px 1px rgba(0,0,0,.18);
  user-select: none; display: flex; flex-direction: column; gap: 6px; flex: none;
  transition: border-color .1s, box-shadow .1s;
}
.card:hover { border-color: var(--e3); box-shadow: 0 3px 10px rgba(0,0,0,.2); }
.card:focus-visible { outline-offset: 0; }
.card.colored { background: var(--card-bg); color: var(--card-fg); }
.card.colored:hover { border-color: color-mix(in srgb, var(--card-fg) 30%, transparent); }
.card.hidden { display: none; }
.card.dragging { opacity: .4; outline: 2px dashed var(--focus); outline-offset: -1px; box-shadow: none; }
.card { -webkit-touch-callout: none; }
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 500; pointer-events: none; margin: 0; overflow: hidden;
  opacity: .95; box-shadow: 0 18px 40px rgba(0,0,0,.35), 0 4px 10px rgba(0,0,0,.25); will-change: transform;
}
.drag-ghost.column { max-height: 320px; }
body.is-dragging { user-select: none; -webkit-user-select: none; }
body.is-dragging .columns { scroll-snap-type: none !important; }
.card-name { font-weight: 500; white-space: pre-wrap; overflow-wrap: anywhere; }
.card-desc {
  font-size: 0.7812rem; color: var(--t3); overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere;
}
.card.colored .card-desc { color: inherit; }
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 0.75rem; font-weight: 500;
  padding: 1px 7px 1px 5px; border-radius: 6px; background: color-mix(in srgb, var(--e3) 70%, transparent); color: var(--t2);
  font-variant-numeric: tabular-nums;
}
.card.colored .badge { background: rgba(0,0,0,.16); color: inherit; }
.badge .i { width: 13px; height: 13px; }
.badge.ok { background: var(--ok) !important; color: #fff !important; }
.badge.late { background: #dc2626 !important; color: #fff !important; }
.badge.soon { background: var(--warn) !important; color: #1f1300 !important; }

.tag {
  display: inline-flex; align-items: center; gap: 3px; font-size: 0.7188rem; font-weight: 600;
  padding: 1px 8px; border-radius: 999px; background: var(--tag, var(--e3)); line-height: 1.6;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 1px solid transparent;
}
.tag .i { width: 12px; height: 12px; stroke-width: 3; }
.tag.more { background: var(--e3); color: var(--t1); }

/* ---------- Menus ---------- */
.ctx-menu {
  position: fixed; z-index: 300; min-width: 200px; max-width: 280px; max-height: 70vh; overflow: auto;
  background: var(--e1); border: 1px solid var(--e3); border-radius: 10px; padding: 4px;
  box-shadow: var(--shadow); animation: pop .1s ease-out;
}
.ctx-menu button {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  background: none; border: 0; padding: 7px 10px; border-radius: 6px; color: var(--t1);
}
.ctx-menu button:hover:not(:disabled), .ctx-menu button:focus-visible { background: var(--e2); outline: none; }
.ctx-menu button:disabled { opacity: .4; cursor: default; }
.ctx-menu button.danger { color: var(--danger); }
.ctx-menu button span:nth-child(2) { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-menu .i { width: 16px; height: 16px; color: var(--t3); }
.ctx-menu .danger .i { color: var(--danger); }
.ctx-menu hr { border: 0; border-top: 1px solid var(--e2); margin: 4px 2px; }
.ctx-menu .dot { width: 14px; height: 14px; border-radius: 4px; flex: none; border: 1px solid rgba(128,128,128,.4); }
.ctx-menu .menu-label { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: .05em; color: var(--t4); padding: 6px 10px 2px; }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 7vh 16px 16px; overflow: auto; animation: fade .12s ease-out;
}
.modal {
  background: var(--e1); border-radius: 14px; width: min(460px, 100%);
  box-shadow: var(--shadow); border: 1px solid var(--e2); animation: pop .14s ease-out;
}
.modal.wide { width: min(880px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 4px 20px; }
.modal-head h2 { font-size: 1.062rem; }
.modal-body { padding: 12px 20px 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.confirm-msg { margin: 0; color: var(--t2); }
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.8125rem; font-weight: 500; color: var(--t2); }
.seg { display: flex; flex-direction: column; gap: 6px; }
.seg label { display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: var(--e2); border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.seg label:has(input:checked) { border-color: var(--accent); }
.seg input { accent-color: var(--accent); }
@keyframes pop { from { transform: translateY(4px) scale(.98); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* Card modal */
.card-modal { border-top: 4px solid var(--card-accent, transparent); }
.card-modal .modal-body { padding: 16px 20px 22px; }
.cm-head { display: flex; align-items: flex-start; gap: 8px; }
.cm-title {
  flex: 1; font-size: 1.25rem; font-weight: 700; background: transparent; border: 1px solid transparent;
  border-radius: 8px; padding: 4px 8px; margin-left: -8px; resize: none; overflow: hidden; outline: none; line-height: 1.3;
}
.cm-title:hover { background: var(--e2); }
.cm-title:focus { background: var(--e2); border-color: var(--accent); }
.cm-sub { font-size: 0.7812rem; margin: 2px 0 18px; overflow-wrap: anywhere; }
.cm-grid { display: grid; grid-template-columns: minmax(0, 1fr) 230px; gap: 28px; }
.cm-main { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.cm-main h2 { font-size: 0.875rem; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cm-main h2 .i { width: 16px; height: 16px; color: var(--t3); }
.cm-side { display: flex; flex-direction: column; gap: 18px; }
.cm-side h3 { font-size: 0.7188rem; text-transform: uppercase; letter-spacing: .06em; color: var(--t3); margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.cm-side .select { width: 100%; }
.side-block { display: flex; flex-direction: column; gap: 6px; }
.side-block.actions { gap: 6px; padding-top: 6px; border-top: 1px solid var(--e2); }
@media (max-width: 760px) { .cm-grid { grid-template-columns: 1fr; } }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 26px; height: 26px; border-radius: 7px; border: 1px solid rgba(128,128,128,.35); padding: 0; position: relative; display: grid; place-items: center; cursor: pointer; }
.swatch.sel { outline: 2px solid var(--text); outline-offset: 2px; }
.swatch.none { background: linear-gradient(135deg, transparent 45%, var(--danger) 45%, var(--danger) 55%, transparent 55%), var(--e2); }
.swatch.custom { background: conic-gradient(#ef4444, #eab308, #22c55e, #0ea5e9, #8b5cf6, #ef4444); }
.swatch.custom .i { width: 14px; height: 14px; color: #fff; filter: drop-shadow(0 0 2px rgba(0,0,0,.6)); }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }

.tag-picker { display: flex; flex-wrap: wrap; gap: 5px; }
.tag-picker .tag, .card-tags .tag { flex: 0 0 auto; max-width: 100%; }
.card.colored .tag { box-shadow: 0 0 0 1px rgba(0,0,0,.18); }
.tag.pick { cursor: pointer; font-size: 0.75rem; padding: 2px 9px; }
.tag.pick:not(.on) { background: transparent; border-color: var(--tag, var(--e3)); color: var(--t2); }
.tag.pick:not(.on)::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--tag, var(--t4)); margin-right: 2px; }
.tag.pick:hover { filter: brightness(1.1); }

.rte-toolbar {
  display: flex; flex-wrap: wrap; gap: 2px; padding: 4px;
  background: var(--e2); border: 1px solid var(--e3); border-bottom: 0; border-radius: 8px 8px 0 0;
}
.rte-toolbar button {
  min-width: 30px; height: 28px; border: 0; background: none; border-radius: 6px; color: var(--t2);
  font-size: 0.8125rem; font-weight: 600; padding: 0 6px; display: grid; place-items: center;
}
.rte-toolbar button:hover { background: var(--e3); color: var(--text); }
.rte-toolbar button.on { background: var(--e3); color: var(--accent-ink); }
.rte-toolbar button:disabled { opacity: .35; cursor: default; background: none; }
.rte-toolbar .sep { width: 1px; background: var(--e3); margin: 4px 4px; }
.rte-toolbar .i { width: 15px; height: 15px; }
.rte {
  position: relative; min-height: 130px; max-height: 50vh; overflow: auto;
  background: var(--bg); border: 1px solid var(--e3); border-radius: 0 0 8px 8px;
  padding: 10px 12px; outline: none; line-height: 1.55; overflow-wrap: anywhere;
}
.rte:focus { border-color: var(--accent); }
.rte.is-empty::before { content: attr(data-placeholder); color: var(--t4); position: absolute; pointer-events: none; }
.rte p, .rte div { margin: 0 0 .4em; }
.rte h1, .rte h2, .rte h3 { font-size: 1.2em; margin: .6em 0 .3em; }
.rte ul, .rte ol { margin: .3em 0; padding-left: 1.4em; }
.rte blockquote { margin: .4em 0; padding: 4px 12px; background: var(--e2); border-radius: 6px; color: var(--t2); font-style: italic; }
.rte pre, .rte code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.7812rem; background: var(--e2); border-radius: 6px; }
.rte pre { padding: 8px 10px; white-space: pre-wrap; margin: .4em 0; }
.rte code { padding: 1px 4px; }
.rte a { color: var(--accent-ink); }
.hint { font-size: 0.75rem; color: var(--t3); margin-top: 6px; }

.progress { height: 6px; background: var(--e2); border-radius: 6px; overflow: hidden; margin-bottom: 8px; }
.progress i { display: block; height: 100%; width: 0; background: #22c55e; transition: width .2s; }
.task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.task { display: flex; align-items: center; gap: 8px; padding: 2px 4px; border-radius: 7px; }
.task:hover { background: var(--e2); }
.task.dragging { opacity: .4; }
.task-check { width: 28px; height: 28px; flex: none; display: grid; place-items: center; border-radius: 6px; cursor: pointer; }
.task-check:hover { background: var(--e3); }
.task input[type="checkbox"] { accent-color: #22c55e; width: 18px; height: 18px; margin: 0; cursor: pointer; }
.task-name { flex: 1; min-width: 0; background: transparent !important; border: 1px solid transparent !important; padding: 5px 6px !important; border-radius: 6px; }
.task-name:focus { border-color: var(--accent) !important; background: var(--bg) !important; }
.task.done .task-name { text-decoration: line-through; color: var(--t4); }
.grip { color: var(--t3); cursor: grab; display: grid; place-items: center; opacity: 0; touch-action: none; }
.grip .i { width: 14px; height: 14px; }
.task:hover .grip { opacity: 1; }
.task .icon-btn { opacity: 0; }
.task:hover .icon-btn, .task:focus-within .icon-btn { opacity: 1; }
.task-add { display: flex; align-items: center; gap: 8px; padding: 2px 4px 2px 32px; color: var(--t3); }
.task-add .i { width: 16px; height: 16px; }
.task-add input { background: transparent; border: 1px solid transparent; padding: 6px; border-radius: 6px; width: 100%; outline: none; }
.task-add input:focus { border-color: var(--accent); background: var(--bg); }

/* Tag manager */
.tag-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; max-height: 50vh; overflow: auto; }
.tag-row { display: flex; align-items: center; gap: 8px; }
.tag-row input[type="color"] { width: 32px; height: 32px; border: 0; padding: 0; background: none; cursor: pointer; flex: none; }
.tag-row .uses { font-size: 0.75rem; color: var(--t4); white-space: nowrap; width: 64px; text-align: right; }

/* Background modal */
.bg-preview { height: 120px; border-radius: 10px; background: var(--e2); margin-bottom: 16px; display: grid; place-items: center; color: var(--t4); border: 1px solid var(--e3); }
.bg-label { font-size: 0.7188rem; text-transform: uppercase; letter-spacing: .06em; color: var(--t3); margin: 14px 0 8px; }
.bg-presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 8px; }
.bg-swatch { aspect-ratio: 1.4; border-radius: 8px; border: 1px solid rgba(128,128,128,.35); padding: 0; cursor: pointer; }
.bg-swatch:hover { transform: scale(1.06); }
.bg-swatch.sel { outline: 2px solid var(--text); outline-offset: 2px; }
.bg-swatch.none { background: linear-gradient(135deg, transparent 46%, var(--danger) 46%, var(--danger) 54%, transparent 54%), var(--e2); }
.seg-tabs { display: inline-flex; background: var(--e2); border-radius: 8px; padding: 3px; gap: 2px; margin-bottom: 10px; }
.seg-tabs button { background: none; border: 0; padding: 5px 12px; border-radius: 6px; color: var(--t3); font-weight: 500; font-size: 0.8125rem; }
.seg-tabs button.on { background: var(--e1); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.bg-custom { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.bg-custom .range-field { flex: 1; min-width: 220px; margin: 0; grid-template-columns: 50px 1fr 44px; }
.range-field { display: grid; grid-template-columns: 90px 1fr 48px; align-items: center; gap: 10px; font-size: 0.8125rem; }
.range-field input { accent-color: var(--accent); width: 100%; }
.range-field output { text-align: right; color: var(--t3); font-variant-numeric: tabular-nums; }

/* Help */
.shortcuts { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; }
.shortcuts h3 { grid-column: 1 / -1; font-size: 0.75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--t3); margin: 12px 0 4px; }
.sc { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--e2); font-size: 0.8125rem; }
@media (max-width: 600px) { .shortcuts { grid-template-columns: 1fr; } }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 400; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px;
  background: var(--e3); color: var(--text); padding: 9px 10px 9px 16px; border-radius: 10px;
  box-shadow: var(--shadow); animation: pop .15s ease-out; max-width: 90vw; transition: opacity .2s, transform .2s;
}
.toast:not(:has(button)) { padding-right: 16px; }
.toast.error { background: #b91c1c; color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---------- Touch & small screens ---------- */
@media (hover: none) {
  .tile-menu, .task .icon-btn, .grip { opacity: 1; }
  [data-tip]:hover::after { display: none; }
}
@media (pointer: coarse) {
  .icon-btn.sm { width: 36px; height: 36px; }
  .icon-btn.xs { width: 30px; height: 30px; }
  .zoom-val { height: 36px; }
  .task { padding: 4px; }
  .swatch { width: 32px; height: 32px; }
  .tag.pick { padding: 5px 11px; }
}
@media (max-width: 700px) {
  body { flex-direction: column; }
  #view { order: 1; flex: 1; min-height: 0; height: auto; }
  #sidebar {
    order: 2; width: 100%; height: auto; flex-direction: row; justify-content: space-around;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--e2);
  }
  .logo { display: none; }
  .side-nav { flex-direction: row; gap: 4px; }
  .nav-btn { width: 48px; height: 44px; }
  .nav-btn.active { box-shadow: inset 0 -3px 0 var(--accent); }
  .side-pins { flex-direction: row; flex: 0 1 auto; margin: 0; padding: 0 0 0 8px; border-top: 0; border-left: 1px solid var(--e2); width: auto; max-width: 40vw; overflow-x: auto; }
  .side-pins:empty { display: none; }
  .pin-link { width: 40px; height: 40px; }

  .page { padding: 20px 16px 40px; }
  .page-head h1 { font-size: 1.375rem; }
  .head-actions { width: 100%; }
  .head-actions .search { flex: 1 1 100%; }
  .head-actions .select { flex: 1; }
  .head-actions .search input { width: 100%; }
  .notice { flex-wrap: wrap; }

  .columns { padding: 10px 12px 16px; gap: 10px; scroll-snap-type: x mandatory; scroll-padding: 0 12px; }
  .column, .add-column { width: min(var(--col-w, 280px), calc(100vw - 48px)); scroll-snap-align: start; }
  .modal-overlay { padding: 12px 8px; }
  .modal-body { padding: 10px 16px 18px; }
  .card-modal .modal-body { padding: 14px 16px 20px; }
  .toast { max-width: calc(100vw - 24px); }
  #toasts { bottom: calc(72px + env(safe-area-inset-bottom)); }
}

/* Compact board header: narrow screens and short landscape phones share it. */
@media (max-width: 700px), (max-height: 500px) and (pointer: coarse) {
  .board-head { padding: 8px 10px; gap: 4px; flex-wrap: nowrap; min-height: 52px; }
  .board-title { max-width: none; flex: 1; }
  .title-btn { font-size: 1.0625rem; }
  .board-stats, .hide-sm, .board-head .spacer { display: none; }
  .board-head .search { width: 40px; padding: 0 11px; flex: none; cursor: pointer; transition: width .18s ease-out; }
  .board-head .search input { width: 0; }
  .board-head .search:focus-within, .board-head .search.active { width: auto; flex: 1; }
  .board-head .search:focus-within input, .board-head .search.active input { width: 100%; }
  .board-head:has(.search:focus-within) .board-title, .board-head:has(.search.active) .board-title { display: none; }
}
@media (max-height: 500px) and (pointer: coarse) {
  .columns { padding-top: 8px; padding-bottom: 10px; }
  .col-head { padding-top: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  /* Keep state feedback (fades, colour changes); drop movement and scaling. */
  @keyframes pop { from { opacity: 0; } }
  .tile:hover, .bg-swatch:hover { transform: none; }
  .toast.out { transform: none; }
  .progress i, .board-head .search, .toggle span::after { transition: none; }
}

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

h1[tabindex="-1"]:focus { outline: none; }
