:root {
  --bg: #eef0f7;
  --bg-grad:
    radial-gradient(220vw 170vh at 0% 30%, rgba(46, 125, 255, 0.13), transparent 78%),
    radial-gradient(200vw 170vh at 100% 0%, rgba(255, 138, 30, 0.10), transparent 76%),
    radial-gradient(230vw 180vh at 50% 100%, rgba(47, 184, 114, 0.12), transparent 78%),
    linear-gradient(160deg, #f8f9fc 0%, #f1f2f8 55%, #eceef5 100%);
  /* fixed dark-navy brand header — same in light & dark mode, matches the logo ink */
  --topbar: #1a2140;
  --list-bg: #e9ebf2;
  --list-header: #1a2140;
  --card-bg: #ffffff;
  --card-shadow: 0 1px 2px rgba(20, 24, 50, 0.10), 0 1px 0 rgba(20, 24, 50, 0.05);
  --text: #1a2140;
  --muted: #5e6c84;
  --accent: #2e7dff;
  --accent-green: #2fb872;
  --accent-orange: #ff8a1e;
  --danger: #eb5a46;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Solid background options (Settings > Background) — referenced by var() name,
     not copied as a literal hex, so switching light/dark later re-resolves them. */
  --bg-solid-neutral: #f3f4f8;
  --bg-solid-blue: #eaf1ff;
  --bg-solid-orange: #fff3e8;
  --bg-solid-green: #eafbf3;
  /* Original brand gradient (pre-rebrand) — kept fixed across light/dark, not
     re-derived per theme like --bg-grad. */
  --bg-purple-grad: linear-gradient(150deg, #4e4291 0%, #6a4f8c 50%, #965585 100%);
}

body.dark {
  --bg: #0a0b12;
  --bg-solid-neutral: #0d0f16;
  --bg-solid-blue: #0d1524;
  --bg-solid-orange: #1a130a;
  --bg-solid-green: #0a1712;
  --bg-grad:
    radial-gradient(220vw 170vh at 0% 30%, rgba(46, 125, 255, 0.12), transparent 78%),
    radial-gradient(200vw 170vh at 100% 0%, rgba(255, 138, 30, 0.08), transparent 76%),
    radial-gradient(230vw 180vh at 50% 100%, rgba(47, 184, 114, 0.09), transparent 78%),
    linear-gradient(160deg, #12141f 0%, #0a0b12 55%, #07080d 100%);
  /* --topbar intentionally not overridden — stays the fixed brand navy from :root,
     which is clearly lighter than this near-black canvas so the header stays visible */
  --list-bg: #181b28;
  --list-header: #d8dbe8;
  --card-bg: #262a3d;
  --card-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
  --text: #e1e3ee;
  --muted: #9aa0ba;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
}

body {
  background: var(--user-bg, var(--bg-grad));
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}

/* ---------- Icons (Lucide) ---------- */
.lucide {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.125em;
  stroke-width: 2;
  flex: 0 0 auto;
}
/* Buttons that contain only an icon: center it */
.icon-btn, .list-menu, .list-collapse, .modal-close, .legend-x, .btn-x,
.tile-edit, .tile-del, .card-check, .list-swatch.none {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
/* Icon + text rows */
.badge, .archive-done, .add-card, .board-tile.create, .logo {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.add-card, .board-tile.create { display: flex; }
/* Idle "+ Add a list" label (not while the composer is open) */
.add-list:not(.composing) { display: flex; align-items: center; gap: 5px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  /* keep content below the iOS notch / status bar */
  padding-top: max(8px, env(safe-area-inset-top));
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
  background: var(--topbar);
  flex: 0 0 auto;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }

.logo {
  background: none;
  border: none;
  padding: 4px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.logo:hover { opacity: 0.82; }
.logo-wordmark { height: 28px; width: auto; display: block; border-radius: 6px; }
@media (max-width: 640px) { .logo-wordmark { height: 24px; } }

.crumbs { color: #fff; font-weight: 600; opacity: 0.95; font-size: 15px; display: flex; }
.board-title-input {
  border: none;
  background: transparent;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  font-family: var(--font);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  width: 220px;
  max-width: 40vw;
}
.board-title-input:hover { background: rgba(255, 255, 255, 0.16); }
.board-title-input:focus { background: rgba(255, 255, 255, 0.95); color: var(--text); cursor: text; outline: none; }

.search {
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 14px;
  width: 220px;
  background: rgba(255, 255, 255, 0.95);
  color: #1a2140; /* always dark — the field is light in both themes */
}
.search::placeholder { color: #5e6c84; opacity: 1; }
.search:focus { outline: 2px solid #fff; background: #fff; }

.icon-btn {
  background: rgba(255, 255, 255, 0.16);
  border: none;
  color: #fff;
  width: 34px; height: 34px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  position: relative;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.28); }
.icon-btn.linked { background: var(--accent-green); color: #fff; }
.icon-btn.linked:hover { background: #269a63; }
.icon-btn.attention { background: var(--accent-orange); color: #1a2140; animation: pulse 1.6s ease-in-out infinite; }
.icon-btn.active { background: var(--accent, #2e7dff); color: #fff; }
.filter-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 8px; background: #eb5a46; color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
  box-shadow: 0 0 0 2px var(--topbar, #1a2140);
}
.filter-badge.hidden { display: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

.reconnect-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: var(--accent-orange); color: #1a2140;
  font-size: 13px; font-weight: 600;
  flex: 0 0 auto;
}
.reconnect-bar.hidden { display: none; }
.reconnect-bar span { flex: 1; }

/* ---------- App / main ---------- */
#app { flex: 1 1 auto; overflow: hidden; display: flex; }

/* ---------- Boards home ---------- */
.boards-home {
  padding: 28px 32px;
  overflow-y: auto;
  width: 100%;
  color: var(--text);
}
.boards-home h1 { font-size: 20px; margin: 0 0 18px; }
.board-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  max-width: 1100px;
}
.board-tile {
  height: 110px;
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  position: relative;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.08s ease;
}
.board-tile:hover { transform: translateY(-2px); }
.board-tile .tile-meta { font-size: 12px; font-weight: 500; opacity: 0.9; }
.board-tile .tile-del, .board-tile .tile-edit, .board-tile .tile-priv {
  position: absolute; top: 8px;
  background: rgba(0,0,0,0.25); border: none; color: #fff;
  border-radius: 4px; width: 24px; height: 24px; cursor: pointer;
  opacity: 0; transition: opacity 0.1s;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; line-height: 1; padding: 0;
}
.board-tile .tile-del { right: 8px; }
.board-tile .tile-edit { right: 38px; }
.board-tile .tile-priv { right: 68px; }
.board-tile .tile-del:hover, .board-tile .tile-edit:hover, .board-tile .tile-priv:hover { background: rgba(0,0,0,0.45); }
.board-tile:hover .tile-del, .board-tile:hover .tile-edit, .board-tile:hover .tile-priv { opacity: 1; }
.board-tile .tile-priv.disabled { cursor: not-allowed; }
.board-tile .tile-priv.disabled:hover { background: rgba(0,0,0,0.25); }
.board-tile .tile-priv.disabled .lucide { opacity: 0.55; }
.board-tile .tile-meta { display: inline-flex; align-items: center; gap: 4px; }
.tile-edit-input {
  font-weight: 700; font-size: 16px; color: #fff;
  background: rgba(0,0,0,0.25); border: none; border-radius: 5px;
  padding: 4px 6px; width: calc(100% - 16px); font-family: var(--font);
  outline: 2px solid rgba(255,255,255,0.7);
}
.board-tile.create {
  background: rgba(127, 127, 127, 0.14);
  border: 1.5px dashed rgba(127, 127, 127, 0.4);
  color: var(--text);
  align-items: center; justify-content: center;
  font-size: 15px;
}
.board-tile.create:hover { background: rgba(127, 127, 127, 0.22); }

/* ---------- Board view ---------- */
.board {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  overflow-x: hidden;
  overflow-y: auto;
  width: 100%;
  height: 100%;
}
.board-row {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
  overflow-x: auto;
  overflow-y: visible;
  padding: 4px 0 14px;
}
.row-divider {
  flex: 0 0 auto;
  height: 0;
  border-top: 2px dashed rgba(127, 127, 127, 0.3);
  margin: 6px 0;
}
.row-dropzone {
  flex: 0 0 auto;
  min-height: 14px;
  margin-top: 4px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px; font-weight: 600;
  border: 2px dashed transparent;
  transition: min-height 0.12s, background 0.12s, border-color 0.12s;
}
.row-dropzone span { display: none; }
.dragging-list .row-dropzone {
  min-height: 48px;
  border-color: rgba(127, 127, 127, 0.45);
  background: rgba(127, 127, 127, 0.14);
}
.dragging-list .row-dropzone span { display: block; }
.row-dropzone.active {
  border-color: var(--accent);
  background: rgba(46, 125, 255, 0.18);
}
.add-row {
  align-self: flex-start;
  margin-top: 4px;
  background: rgba(127, 127, 127, 0.14);
  color: var(--text); font-weight: 600;
  border: none; border-radius: var(--radius);
  padding: 10px 16px; cursor: pointer;
  font-family: var(--font); font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px;
}
.add-row:hover { background: rgba(127, 127, 127, 0.22); }
.add-row.composing { display: block; width: 280px; }

.list {
  background: var(--list-bg);
  border-radius: var(--radius);
  width: 280px;
  flex: 0 0 280px;
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 2px 6px rgba(20, 24, 50, 0.12), 0 1px 2px rgba(20, 24, 50, 0.08);
}
.list.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.list.dragging { opacity: 0.5; }
/* Vertical drop-line indicator while reordering lists */
.list.list-drop-before { box-shadow: -6px 0 0 -2px var(--accent), 0 2px 6px rgba(20,24,50,0.12); }
.list.list-drop-after { box-shadow: 6px 0 0 -2px var(--accent), 0 2px 6px rgba(20,24,50,0.12); }

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 8px 8px 6px;
  cursor: default;
}
.list-grip {
  flex: 0 0 auto;
  display: inline-flex; align-items: center;
  color: var(--muted); cursor: grab;
  opacity: 0.45; transition: opacity 0.1s;
  padding: 2px;
}
.list-grip:hover { opacity: 1; }
.list-grip:active,
.list.dragging .list-grip { cursor: grabbing; }
.list.colored .list-grip { color: rgba(255, 255, 255, 0.85); }
.list-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--list-header);
  border: none;
  background: transparent;
  flex: 1 1 0;
  min-width: 0;
  width: 0;
  padding: 4px;
  border-radius: 4px;
  font-family: var(--font);
}
.list-count, .list-menu { flex: 0 0 auto; }
/* While editing, always use readable dark text on the light field */
.list-title:focus { outline: 2px solid var(--accent); background: var(--card-bg); color: var(--text); }
.list-count {
  font-size: 12px; color: var(--muted);
  background: rgba(0,0,0,0.06); border-radius: 10px;
  padding: 1px 8px; margin: 0 4px;
}
.list-menu, .list-collapse {
  background: transparent; border: none; cursor: pointer;
  color: var(--muted); font-size: 18px; line-height: 1;
  padding: 2px 6px; border-radius: 4px; flex: 0 0 auto;
}
.list-collapse { font-size: 14px; font-weight: 700; }
.list-menu:hover, .list-collapse:hover { background: rgba(0,0,0,0.08); }
.list.colored .list-collapse { color: var(--header-fg, #1a2140); }
.list.colored .list-collapse:hover { background: rgba(127,127,127,0.25); }

/* ---------- Collapsed list ---------- */
.list.collapsed {
  width: 44px;
  flex: 0 0 44px;
  align-self: flex-start; /* size to content, don't stretch the full board height */
  max-height: 100%;
  overflow: hidden;
}
.list-expand {
  width: 100%; height: auto;
  min-height: 120px; /* floor so short-titled lists still read as a bar */
  background: transparent; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 12px 0; color: var(--list-header); font-family: var(--font);
}
.list-expand:hover { background: rgba(0,0,0,0.05); }
.collapsed-count {
  font-size: 12px; font-weight: 700;
  background: rgba(0,0,0,0.08); color: var(--muted);
  border-radius: 10px; padding: 1px 8px; flex: 0 0 auto;
}
.collapsed-title {
  writing-mode: vertical-rl;
  font-weight: 700; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-height: 100%;
}
.list.collapsed.colored .list-expand { color: #fff; }
.list.collapsed.colored .collapsed-count {
  background: rgba(255,255,255,0.2); color: #fff;
}

.cards {
  list-style: none;
  margin: 0;
  padding: 8px 8px 0;
  overflow-y: auto;
  flex: 1;
  min-height: 8px;
}

.card {
  background: var(--card-bg);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
  box-shadow: var(--card-shadow);
  cursor: grab;
  font-size: 14px;
  color: var(--text);
  position: relative;
}
.card:hover { background: var(--card-bg); filter: brightness(0.98); }
.card:active { cursor: grabbing; }
.card.dragging { opacity: 0.4; cursor: grabbing; }
.card.card-drop-before { box-shadow: 0 -3px 0 var(--accent), var(--card-shadow); }
.card.card-drop-after { box-shadow: 0 3px 0 var(--accent), var(--card-shadow); }

.card-archive {
  position: absolute; top: 6px; right: 6px; z-index: 1;
  width: 22px; height: 22px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(127, 127, 127, 0.14); border: none; color: var(--muted);
  cursor: pointer; opacity: 0; transition: opacity 0.12s, background 0.12s;
  font-size: 12px; padding: 0;
}
.card:hover .card-archive { opacity: 1; }
.card-archive:hover { background: rgba(127, 127, 127, 0.28); color: var(--text); }

.card-labels { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.card-label { height: 8px; width: 38px; border-radius: 4px; }
.card-title { white-space: pre-wrap; word-break: break-word; flex: 1; }
.card-main { display: flex; align-items: flex-start; }
.card-check {
  flex: 0 0 auto;
  box-sizing: border-box;
  width: 0; height: 18px; margin-top: 1px; margin-right: 0;
  border: 0 solid var(--muted); border-radius: 50%;
  background: transparent; color: transparent;
  cursor: pointer; font-size: 11px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; overflow: hidden; padding: 0;
  transition: width 0.12s ease, margin-right 0.12s ease, opacity 0.12s ease;
}
/* Collapsed by default; expands on hover (pushing the title right) or when done */
.card:hover .card-check,
.card-check.on {
  width: 18px; border-width: 2px; margin-right: 7px; opacity: 1;
}
.card-check:hover { border-color: var(--accent-green); }
.card-check.on {
  background: var(--accent-green); border-color: var(--accent-green); color: #fff;
}
.card.done .card-title { text-decoration: line-through; color: var(--muted); }
.card.done { opacity: 0.85; }
.card-badges { display: flex; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--muted); align-items: center; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; gap: 3px; padding: 1px 5px; border-radius: 4px; }
.badge.due { background: rgba(0,0,0,0.05); }
.badge.due.overdue { background: var(--danger); color: #fff; }
.badge.due.soon { background: #f2d600; color: #1a2140; }

.add-card {
  margin: 4px 8px 8px;
  border: none; background: transparent;
  color: var(--muted); cursor: pointer;
  text-align: left; padding: 8px; border-radius: 6px;
  font-size: 14px; font-family: var(--font);
}
.add-card:hover { background: rgba(0,0,0,0.08); color: var(--text); }

.composer { margin: 0 8px 8px; }
.composer textarea {
  width: 100%; border: none; border-radius: 6px;
  padding: 8px 10px; font-size: 14px; resize: none;
  box-shadow: var(--card-shadow); font-family: var(--font);
  min-height: 56px;
}
.composer-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }

.add-list {
  width: 280px; flex: 0 0 280px;
  background: rgba(127, 127, 127, 0.14);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
  color: var(--text); font-weight: 600;
}
.add-list:hover { background: rgba(127, 127, 127, 0.22); }
.add-list textarea, .add-row textarea {
  width: 100%; border: none; border-radius: 8px;
  padding: 10px 12px; font-size: 14px; line-height: 1.4; resize: none;
  font-family: var(--font);
  background: var(--card-bg); color: var(--text);
  box-shadow: 0 1px 3px rgba(20, 24, 50, 0.15);
  min-height: 52px;
}
.add-list textarea::placeholder, .add-row textarea::placeholder { color: var(--muted); }
.add-list textarea:focus, .add-row textarea:focus { outline: 2px solid var(--accent); }
.add-list.composing, .add-row.composing { padding: 8px; }
.add-list.composing .composer-actions, .add-row.composing .composer-actions { margin-top: 8px; }

/* ---------- Buttons ---------- */
.btn {
  background: var(--accent); color: #fff; border: none;
  border-radius: 6px; padding: 8px 14px; cursor: pointer;
  font-size: 14px; font-weight: 600; font-family: var(--font);
}
.btn:hover { filter: brightness(1.08); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.ghost { background: transparent; color: inherit; }
.btn.ghost:hover { background: rgba(0,0,0,0.08); }
.btn.danger { background: var(--danger); }
.btn-x { background: transparent; border: none; cursor: pointer; font-size: 20px; color: var(--muted); padding: 4px; border-radius: 4px; }
.btn-x:hover { background: rgba(0, 0, 0, 0.08); color: var(--text); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.modal-card {
  position: relative; background: var(--card-bg); color: var(--text);
  width: 640px; max-width: calc(100vw - 32px);
  margin-top: 56px; margin-bottom: 40px;
  border-radius: 10px; padding: 22px 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
  max-height: calc(100vh - 96px); overflow-y: auto;
}
.modal-close {
  position: absolute; top: 12px; right: 12px;
  background: transparent; border: none; font-size: 18px;
  cursor: pointer; color: var(--muted);
}
.m-title {
  font-size: 20px; font-weight: 700; border: none;
  width: 100%; background: transparent; color: var(--text);
  font-family: var(--font); padding: 4px; border-radius: 4px;
}
.m-title:focus { outline: 2px solid var(--accent); }
.m-meta { color: var(--muted); font-size: 12px; margin: 2px 0 14px 4px; }
.m-done {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600; color: var(--text);
  margin: 0 0 18px 4px; cursor: pointer;
}
.m-done input { width: 16px; height: 16px; cursor: pointer; }
.m-title-static { font-size: 20px; font-weight: 700; margin: 0 0 4px; color: var(--text); }
.m-section { margin-bottom: 20px; }
.m-label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; margin-bottom: 8px; letter-spacing: 0.04em; }
.m-input, .m-textarea {
  width: 100%; border: 1px solid rgba(0,0,0,0.15); border-radius: 6px;
  padding: 8px 10px; font-size: 14px; font-family: var(--font);
  background: var(--card-bg); color: var(--text);
}
.m-textarea { min-height: 90px; resize: vertical; }
.m-input:focus, .m-textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.m-due-row { display: flex; gap: 8px; align-items: center; }
.m-due-row .m-input { flex: 1; min-width: 0; }
.m-due-row .btn { flex: 0 0 auto; }

.m-labels { display: flex; gap: 8px; flex-wrap: wrap; }
.m-priority { display: flex; gap: 8px; flex-wrap: wrap; }
.prio-btn {
  border: 2px solid transparent; border-radius: 6px;
  padding: 6px 10px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: var(--font); color: #fff;
}
.prio-btn.on { border-color: var(--text); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.6); }
.prio-btn.none { background: rgba(127, 127, 127, 0.2); color: var(--text); }
.badge.prio { font-weight: 700; padding: 1px 6px; border-radius: 4px; }

/* ---------- Assignee ---------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  color: #fff; font-size: 10px; font-weight: 700; letter-spacing: 0.02em;
  flex: 0 0 auto;
}
.avatar-group { display: inline-flex; margin-left: auto; }
.avatar-group .avatar { margin-left: -6px; border: 2px solid var(--card-bg); }
.avatar-group .avatar:first-child { margin-left: 0; }
.avatar.overflow { background: rgba(127, 127, 127, 0.5); color: var(--text); font-size: 9px; }
.m-assignee { display: flex; flex-direction: column; gap: 10px; }
.assignee-list { display: flex; gap: 8px; flex-wrap: wrap; }
.assignee-btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 2px solid transparent; border-radius: 6px;
  padding: 5px 10px 5px 6px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: var(--font);
  background: rgba(127, 127, 127, 0.14); color: var(--text);
}
.assignee-btn:hover { background: rgba(127, 127, 127, 0.24); }
.assignee-btn.on { border-color: var(--accent); }
.assignee-btn.none { padding: 5px 10px; }
.assignee-hint { margin: 0; font-size: 13px; color: var(--muted); }
.assignee-add { display: flex; gap: 8px; }
.assignee-add .m-input { flex: 1; min-width: 0; }
.label-swatch {
  min-width: 80px; height: 32px; border-radius: 5px; cursor: pointer;
  border: 2px solid transparent;
  display: flex; align-items: center; padding: 0 10px;
  color: #1a2140; font-size: 13px; font-weight: 600;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.label-swatch.on { border-color: var(--text); box-shadow: inset 0 0 0 2px rgba(255,255,255,0.6); }

.m-checklist { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.check-item { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check-item input[type=checkbox] { width: 16px; height: 16px; }
.check-text {
  flex: 1; min-width: 0;
  border: none; background: transparent;
  color: var(--text); font-size: 14px; font-family: var(--font);
  padding: 4px 6px; border-radius: 4px;
}
.check-text:focus { outline: none; background: var(--card-bg); box-shadow: 0 0 0 2px var(--accent); }
.check-item.done .check-text { text-decoration: line-through; color: var(--muted); }
.check-item button { background: transparent; border: none; color: var(--muted); cursor: pointer; }
.check-grip {
  flex: 0 0 auto; display: inline-flex; align-items: center;
  color: var(--muted); cursor: grab; opacity: 0.5; transition: opacity 0.1s;
}
.check-grip:hover { opacity: 1; }
.check-grip:active { cursor: grabbing; }
.check-item.dragging { opacity: 0.4; }
.check-item.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.check-item.drop-after { box-shadow: 0 3px 0 var(--accent); }
.m-add-check { display: flex; gap: 8px; }

.m-links { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.link-item {
  display: flex; align-items: center; gap: 8px; font-size: 14px;
  background: rgba(127, 127, 127, 0.1); border-radius: 6px; padding: 6px 8px;
}
.link-item .lucide { flex: 0 0 auto; color: var(--muted); }
.link-item .link-icon { flex: 0 0 auto; width: 16px; height: 16px; object-fit: contain; }
.link-item a {
  flex: 1; min-width: 0; color: var(--accent); text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.link-item a:hover { text-decoration: underline; }
.link-item button { background: transparent; border: none; color: var(--muted); cursor: pointer; flex: 0 0 auto; }
.m-add-link { display: flex; gap: 8px; }
.m-add-link input:first-child { flex: 3; min-width: 0; }
.m-add-link input:nth-child(2) { flex: 2; min-width: 0; }
.m-drive-btn { margin-top: 8px; display: inline-flex; align-items: center; gap: 6px; }

.m-footer { display: flex; justify-content: space-between; gap: 10px; border-top: 1px solid rgba(0,0,0,0.1); padding-top: 16px; }

/* ---------- Archive viewer ---------- */
.archive-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.archive-empty { color: var(--muted); font-size: 14px; }
.archive-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: rgba(127,127,127,0.1); border-radius: 8px; padding: 10px 12px;
}
.archive-info { min-width: 0; }
.archive-card-title { font-size: 14px; font-weight: 600; color: var(--text); word-break: break-word; }
.archive-done { color: var(--accent-green); font-size: 12px; font-weight: 700; }
.archive-from { font-size: 12px; color: var(--muted); margin-top: 2px; }
.archive-actions { display: flex; gap: 8px; flex: 0 0 auto; }

.list-popover {
  position: fixed;
  z-index: 60;
  background: var(--card-bg);
  color: var(--text);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  padding: 6px;
  min-width: 160px;
  display: flex;
  flex-direction: column;
}
.list-popover button {
  background: transparent;
  border: none;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
}
.list-popover button:hover { background: rgba(0, 0, 0, 0.08); }
.list-popover button.danger { color: var(--danger); }
.list-popover button.danger:hover { background: rgba(235, 90, 70, 0.12); }
.popover-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted);
  padding: 8px 10px 4px;
}
.list-swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  padding: 2px 10px 8px;
}
.list-swatch {
  height: 26px; border: 2px solid transparent; border-radius: 5px;
  cursor: pointer; padding: 0;
}
.list-swatch.on { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--card-bg); }
.list-swatch.none {
  background: transparent; border: 1px solid rgba(0,0,0,0.2);
  color: var(--muted); font-size: 12px;
}

/* Colored list header (Trello-style) — deep dark header shade with white text */
.list.colored .list-header { border-radius: var(--radius) var(--radius) 0 0; padding-top: 16px; padding-bottom: 12px; }
.list.colored .list-title { color: #fff; font-weight: 700; }
.list.colored .list-count { background: rgba(255,255,255,0.2); color: #fff; }
.list.colored .list-menu, .list.colored .list-collapse { color: #fff; }
.list.colored .list-menu:hover, .list.colored .list-collapse:hover { background: rgba(255,255,255,0.2); }
.list.colored .list-title:focus { color: var(--text); }

/* ---------- Label legend ---------- */
.legend {
  position: fixed;
  top: 52px;
  right: 0;
  bottom: 0;
  width: 280px;
  background: var(--card-bg);
  color: var(--text);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.25);
  z-index: 40;
  padding: 16px;
  overflow-y: auto;
  transform: translateX(0);
  transition: transform 0.18s ease;
}
.legend.hidden { transform: translateX(100%); pointer-events: none; }
.legend-head {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 16px; margin-bottom: 6px;
}
.legend-x {
  background: transparent; border: none; cursor: pointer;
  color: var(--muted); font-size: 16px; border-radius: 4px; padding: 2px 6px;
}
.legend-x:hover { background: rgba(0,0,0,0.08); }
.legend-section-label {
  display: block; font-size: 12px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em; margin: 18px 0 6px;
}
.legend-section-label:first-of-type,
.legend-section-label.first { margin-top: 0; }
.legend-hint { font-size: 12px; color: var(--muted); margin: 0 0 12px; line-height: 1.4; }
.assignee-btn.filter.active { border-color: var(--accent); background: rgba(46, 125, 255, 0.14); }
.legend-rows { display: flex; flex-direction: column; gap: 10px; }
.legend-row { display: flex; align-items: center; gap: 10px; }
.legend-swatch {
  width: 36px; height: 28px; border-radius: 5px; flex: 0 0 auto;
  display: inline-block;
}

.card.filtered-out { display: none; }

/* ---------- Quick filter popover ---------- */
.filter-popover {
  position: fixed;
  top: 52px;
  right: 130px;
  width: 260px;
  max-height: calc(100vh - 72px);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 10px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.3);
  z-index: 45;
  padding: 14px;
  overflow-y: auto;
}
.filter-popover.hidden { display: none; }
.filter-pop-head {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 14px; margin-bottom: 4px;
}
.filter-chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; border-radius: 14px;
  padding: 5px 10px 5px 6px; font-size: 12px; font-weight: 600;
  background: rgba(127, 127, 127, 0.14); color: var(--text);
  cursor: pointer; font-family: var(--font);
}
.filter-chip:hover { background: rgba(127, 127, 127, 0.24); }
.filter-chip.active { border-color: var(--accent); background: rgba(46, 125, 255, 0.14); }
.filter-chip-dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.filter-manage-link {
  width: 100%; justify-content: center; margin-top: 14px;
  border-top: 1px solid rgba(127, 127, 127, 0.2); padding-top: 12px;
  border-radius: 0;
}
.legend-name {
  flex: 1; min-width: 0;
  border: 1px solid rgba(0,0,0,0.15); border-radius: 6px;
  padding: 7px 9px; font-size: 14px; font-family: var(--font);
  background: var(--card-bg); color: var(--text);
}
.legend-name:focus { outline: 2px solid var(--accent); border-color: transparent; }
.legend-icon-btn {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 5px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(127, 127, 127, 0.14); color: var(--muted);
  border: none; cursor: pointer; position: relative; padding: 0;
}
.legend-icon-btn:hover { background: rgba(127, 127, 127, 0.26); color: var(--text); }
.legend-icon-btn.danger:hover { background: rgba(235, 90, 70, 0.16); color: var(--danger); }
.legend-color-input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; border: none; padding: 0;
}
#legendAddLabel { margin-top: 6px; align-self: flex-start; }

.search-hit { outline: 3px solid #f2d600 !important; }
.dim { opacity: 0.35; }

/* ---------- Settings ---------- */
.bg-swatches { display: flex; flex-wrap: wrap; gap: 14px; }
.bg-swatch-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  font-family: var(--font); color: var(--muted); font-size: 11px;
}
.bg-swatch-color {
  width: 64px; height: 44px; border-radius: 6px;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
  display: flex; align-items: center; justify-content: center;
}
.bg-swatch-btn.on .bg-swatch-color { border-color: var(--accent); }
.bg-swatch-btn.on { color: var(--text); font-weight: 600; }
.bg-swatch-color .lucide {
  display: none; color: #fff;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}
.bg-swatch-btn.on .bg-swatch-color .lucide { display: block; }
.bg-swatch-gradient { background: var(--bg-grad); }
.bg-swatch-purple { background: var(--bg-purple-grad); }

/* ---------- Auth overlay ---------- */
.auth-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg-grad);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.auth-overlay.hidden { display: none; }
.auth-card {
  background: var(--card-bg); color: var(--text);
  width: 340px; max-width: 100%;
  border-radius: 12px; padding: 28px 26px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  display: flex; flex-direction: column; gap: 12px;
}
.auth-brand {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 20px; font-weight: 800;
}
.auth-brand .logo-wordmark { height: 34px; }
.auth-title { margin: 2px 0 6px; font-size: 15px; font-weight: 600; color: var(--muted); text-align: center; }
.auth-submit { margin-top: 4px; }
.auth-error { color: var(--danger); font-size: 13px; min-height: 16px; text-align: center; }
.auth-note { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }
.auth-download {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 4px; padding: 8px; border-radius: 6px;
  background: rgba(127, 127, 127, 0.12); color: var(--text);
  font-size: 13px; font-weight: 600; text-decoration: none;
}
.auth-download:hover { background: rgba(127, 127, 127, 0.22); }

/* ---------- Calendar view ---------- */
.calendar {
  display: flex; flex-direction: column;
  width: 100%; height: 100%;
  padding: 16px; gap: 10px;
  color: var(--text); overflow: hidden;
}
.cal-header { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.cal-title { font-size: 18px; font-weight: 700; min-width: 170px; text-align: center; }
.cal-header .btn.ghost { color: var(--text); }
.cal-header .btn.ghost:hover { background: rgba(127, 127, 127, 0.16); }
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-weekday {
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  color: var(--muted); text-transform: uppercase; padding: 0 6px;
}
.cal-grid { flex: 1; min-height: 0; }
.cal-day {
  background: var(--card-bg); color: var(--text);
  border-radius: 8px; padding: 6px;
  display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto; min-height: 0;
}
.cal-day.other-month { opacity: 0.45; }
.cal-day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day-num { font-size: 12px; font-weight: 700; color: var(--muted); flex: 0 0 auto; }
.cal-day.today .cal-day-num { color: var(--accent); }
.cal-cards { display: flex; flex-direction: column; gap: 4px; }
.cal-card {
  text-align: left; border: none; border-radius: 4px;
  background: rgba(127,127,127,0.14); color: var(--text);
  padding: 4px 6px; font-size: 12px; font-family: var(--font);
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-card:hover { background: rgba(127,127,127,0.26); }
.cal-card.done { text-decoration: line-through; color: var(--muted); }

@media (max-width: 640px) {
  .calendar { padding: 10px; }
  .cal-title { min-width: 110px; font-size: 15px; }
  .cal-weekday { font-size: 9px; padding: 0 2px; }
  .cal-day { padding: 3px; }
  .cal-card { font-size: 10px; padding: 2px 3px; }
}

/* ---------- Responsive / mobile ---------- */
@media (max-width: 640px) {
  /* Topbar wraps to multiple rows */
  .topbar {
    flex-wrap: wrap; gap: 8px;
    padding: 8px 10px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  .topbar-left { flex: 1 1 100%; min-width: 0; gap: 8px; }
  .topbar-right { flex: 1 1 100%; flex-wrap: wrap; gap: 6px; }
  .crumbs { min-width: 0; flex: 1; }
  .board-title-input { width: 100%; max-width: none; }
  .search { flex: 1 1 140px; width: auto; min-width: 0; }
  .logo { font-size: 15px; padding: 5px 10px; }

  /* One list mostly fills the screen, with a peek of the next */
  .board { padding: 10px; gap: 10px; }
  .list, .add-list { flex: 0 0 85vw; width: 85vw; max-width: 320px; }
  .list.collapsed { flex: 0 0 44px; width: 44px; }

  /* Boards home: single column */
  .boards-home { padding: 18px 14px; }
  .board-grid { grid-template-columns: 1fr; }

  /* Legend becomes a full-screen sheet */
  .legend { top: 0; width: 100vw; max-width: 100vw; }
  .filter-popover { top: 0; right: 0; left: 0; width: auto; max-height: 100vh; border-radius: 0; }

  /* Card / archive modals: tighter, near full width */
  .modal-card { margin-top: 16px; padding: 18px 16px; }
  .label-swatch { min-width: 64px; }

  .reconnect-bar { flex-wrap: wrap; }

  /* Compact board tiles on phones */
  .board-tile { height: 88px; padding: 12px 14px; }
  .boards-home h1 { margin-bottom: 12px; }
}

/* ---------- Touch devices: hover-revealed controls must always show ---------- */
@media (hover: none), (pointer: coarse) {
  .board-tile .tile-del,
  .board-tile .tile-edit,
  .board-tile .tile-priv { opacity: 1; background: rgba(0, 0, 0, 0.35); }

  /* Done-check circle: no hover to reveal it, keep it expanded */
  .card-check {
    width: 18px;
    border-width: 2px;
    margin-right: 7px;
    opacity: 0.65;
  }
  .card-check.on { opacity: 1; }

  /* Archive button: no hover to reveal it, keep it visible */
  .card-archive { opacity: 0.65; }

  /* Grips readable without hover */
  .list-grip, .check-grip { opacity: 0.7; }
}

/* Bottom safe-area so content clears the iOS home indicator / Safari bar */
.board, .boards-home, .calendar {
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
