:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --col: #ebedf1;
  --col-over: #dfe6f5;
  --border: #dcdfe5;
  --border-strong: #c3c8d2;
  --text: #1a2233;
  --muted: #5b6475;
  --faint: #8a92a3;
  --accent: #2f6fed;
  --accent-hover: #2559c7;
  --accent-ink: #ffffff;
  --accent-soft: #e7eefd;
  --danger: #c9372c;
  --danger-soft: #fdecea;
  --ok: #1f845a;
  --side-bg: #171d2a;
  --side-text: #c2c9d6;
  --side-muted: #7d879a;
  --side-hover: #222a3b;
  --side-active: #2a3449;
  --shadow-card: 0 1px 1px rgba(16, 24, 40, .12), 0 0 1px rgba(16, 24, 40, .22);
  --shadow-lift: 0 10px 24px rgba(16, 24, 40, .18), 0 0 1px rgba(16, 24, 40, .3);
  --shadow-modal: 0 24px 64px rgba(16, 24, 40, .28);
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151c; --surface: #1d222c; --surface-2: #232935; --col: #181c25; --col-over: #1f2839;
    --border: #2d3442; --border-strong: #3c4456; --text: #e3e7ee; --muted: #a2abbb; --faint: #727c8f;
    --accent: #5b8ff9; --accent-hover: #79a3fa; --accent-ink: #0b1220; --accent-soft: #1d2a45;
    --danger: #f2705f; --danger-soft: #3a1f1c; --ok: #4cc38a;
    --side-bg: #0d1016; --side-text: #c2c9d6; --side-muted: #6d7689; --side-hover: #171c26; --side-active: #1f2633;
    --shadow-card: 0 1px 1px rgba(0,0,0,.4), 0 0 0 1px rgba(255,255,255,.04);
    --shadow-lift: 0 12px 28px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.06);
    --shadow-modal: 0 24px 64px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151c; --surface: #1d222c; --surface-2: #232935; --col: #181c25; --col-over: #1f2839;
  --border: #2d3442; --border-strong: #3c4456; --text: #e3e7ee; --muted: #a2abbb; --faint: #727c8f;
  --accent: #5b8ff9; --accent-hover: #79a3fa; --accent-ink: #0b1220; --accent-soft: #1d2a45;
  --danger: #f2705f; --danger-soft: #3a1f1c; --ok: #4cc38a;
  --side-bg: #0d1016; --side-text: #c2c9d6; --side-muted: #6d7689; --side-hover: #171c26; --side-active: #1f2633;
  --shadow-card: 0 1px 1px rgba(0,0,0,.4), 0 0 0 1px rgba(255,255,255,.04);
  --shadow-lift: 0 12px 28px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.06);
  --shadow-modal: 0 24px 64px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code { font: 12px ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--border); padding: 0 4px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1; }

/* ---------- buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 6px; border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--muted); padding: 0; }
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.tiny { width: 24px; height: 24px; }
.icon-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.link { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=number], input:not([type]), select, textarea {
  width: 100%; height: 34px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); outline: none;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }
.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; white-space: nowrap; }
.chk input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }

/* ---------- login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; box-shadow: var(--shadow-card); }
.login-card h1 { margin: 12px 0 4px; font-size: 20px; }
.login-card form { display: grid; gap: 14px; margin-top: 20px; }
.login-card .btn { justify-content: center; height: 38px; }
.login-err { color: var(--danger); font-size: 13px; min-height: 18px; margin: -4px 0 0; }

/* ---------- layout */
.app { display: flex; height: 100vh; }
.sidebar { width: 240px; flex: none; background: var(--side-bg); color: var(--side-text); display: flex; flex-direction: column; padding: 14px 10px; gap: 2px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; color: #fff; padding: 4px 8px 16px; }
.logo { width: 26px; height: 26px; flex: none; }
.side-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--side-muted); padding: 8px 8px 6px; }
.board-nav { display: flex; flex-direction: column; gap: 2px; }
.board-link { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px; color: var(--side-text); text-decoration: none; }
.board-link:hover { background: var(--side-hover); }
.board-link.active { background: var(--side-active); color: #fff; }
.bkey { width: 24px; height: 24px; flex: none; border-radius: 6px; display: grid; place-items: center; font-size: 10.5px; font-weight: 700; color: #fff; background: hsl(var(--h) 55% 45%); }
.bname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bcount { font-size: 11.5px; color: var(--side-muted); }
.side-btn { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 8px; border: 0; border-radius: 6px; background: none; color: var(--side-text); cursor: pointer; text-align: left; }
.side-btn:hover { background: var(--side-hover); color: #fff; }
.side-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.side-empty { color: var(--side-muted); font-size: 13px; padding: 4px 8px 8px; }
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--side-hover); display: flex; flex-direction: column; gap: 2px; }
.me { display: flex; align-items: center; gap: 10px; padding: 8px; color: var(--side-text); font-size: 13px; }
.me .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; padding: 16px 20px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
.tb-title { min-width: 0; flex: 1 1 220px; }
.tb-title h1 { margin: 0; font-size: 19px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.tb-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.search { position: relative; width: 200px; }
.search svg { position: absolute; left: 9px; top: 9px; width: 16px; height: 16px; stroke: var(--faint); fill: none; stroke-width: 2; }
.search input { padding-left: 32px; height: 32px; }
.tb-tools select { width: auto; max-width: 170px; height: 32px; }

.workspace { flex: 1; min-height: 0; display: flex; }
.board-scroll { flex: 1; min-width: 0; overflow: auto; padding: 0 20px 20px; }

/* ---------- board grid */
.grid { display: grid; column-gap: 10px; align-items: start; min-width: min-content; }
.col-head { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; gap: 8px; padding: 14px 10px 8px; background: var(--bg); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.col-count { font-weight: 500; color: var(--faint); }
.done-tag { color: var(--ok); font-size: 13px; }
.cell { background: var(--col); border-radius: var(--radius); padding: 6px; display: flex; flex-direction: column; gap: 6px; min-height: 72px; transition: background .12s; }
.cell.over { background: var(--col-over); }
.lane-cells { display: contents; }

.lane-head { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 16px 4px 8px; font-weight: 600; flex-wrap: wrap; }
.lane-head .lane-toggle { width: 22px; height: 22px; border: 0; background: none; cursor: pointer; color: var(--muted); border-radius: 4px; display: grid; place-items: center; padding: 0; }
.lane-head .lane-toggle:hover { background: var(--col); }
.lane-head .lane-toggle svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2.2; transition: transform .15s; transform: rotate(90deg); }
.lane-head.collapsed .lane-toggle svg { transform: rotate(0); }
.lane-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.lane-key { color: var(--faint); font-weight: 500; font-size: 12.5px; }
.lane-count { color: var(--muted); font-weight: 400; font-size: 12.5px; }
.lane-progress { width: 120px; }

/* ---------- cards */
.card { background: var(--surface); border-radius: 6px; padding: 10px 10px 8px; box-shadow: var(--shadow-card); cursor: grab; display: flex; flex-direction: column; gap: 8px; transition: box-shadow .12s, transform .12s; }
.card:hover { box-shadow: var(--shadow-lift); }
.card.dragging { opacity: .35; }
.card-title { font-size: 14px; line-height: 1.4; word-break: break-word; }
.card.is-done .card-title { color: var(--muted); }
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 11.5px; line-height: 18px; padding: 0 6px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag.epic { background: color-mix(in srgb, var(--c) 16%, transparent); border-color: color-mix(in srgb, var(--c) 35%, transparent); color: color-mix(in srgb, var(--c) 75%, var(--text)); font-weight: 600; }
.card-foot { display: flex; align-items: center; gap: 6px; min-height: 22px; }
.card-key { font-size: 12px; color: var(--muted); font-weight: 500; }
.card.is-done .card-key { text-decoration: line-through; }
.points { min-width: 20px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--col); color: var(--muted); font-size: 11.5px; font-weight: 600; display: grid; place-items: center; }
.placeholder { border: 2px dashed var(--border-strong); border-radius: 6px; background: transparent; flex: none; }
.add-card { border: 0; background: none; text-align: left; padding: 6px 8px; border-radius: 6px; color: var(--muted); cursor: pointer; opacity: 0; transition: opacity .12s; }
.cell:hover .add-card, .cell:empty .add-card, .add-card:focus-visible, .cell .add-card:only-child { opacity: 1; }
.add-card:hover { background: color-mix(in srgb, var(--text) 7%, transparent); color: var(--text); }
.quick textarea { box-shadow: var(--shadow-card); border-color: var(--accent); min-height: 60px; }
.quick-hint { font-size: 11.5px; color: var(--faint); padding: 4px 2px 0; }

/* icons */
.ticon { width: 16px; height: 16px; border-radius: 3px; display: inline-grid; place-items: center; flex: none; }
.ticon svg { width: 12px; height: 12px; }
.t-story { background: #36a26b; } .t-story path { fill: #fff; }
.t-task { background: #3b82f6; } .t-task path { fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.t-bug { background: #e5484d; } .t-bug circle { fill: #fff; }
.t-subtask { background: #6aa6f8; } .t-subtask path { fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pri { display: inline-grid; place-items: center; width: 16px; height: 16px; flex: none; }
.pri svg { width: 16px; height: 16px; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.pri-highest svg { stroke: #d93025; } .pri-high svg { stroke: #f06a30; } .pri-medium svg { stroke: #e2a400; }
.pri-low svg { stroke: #3b82f6; } .pri-lowest svg { stroke: #6aa6f8; }
.avatar { width: 22px; height: 22px; border-radius: 50%; flex: none; display: inline-grid; place-items: center; font-size: 10px; font-weight: 700; color: #fff; background: hsl(var(--h) 50% 46%); }
.avatar.unassigned { background: transparent; border: 1.5px dashed var(--border-strong); }
.avatar.lg { width: 28px; height: 28px; font-size: 11px; }

.progress { height: 6px; border-radius: 3px; background: var(--col); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ok); border-radius: 3px; }

/* ---------- epic panel */
.epic-panel { width: 290px; flex: none; border-left: 1px solid var(--border); background: var(--surface); overflow-y: auto; display: flex; flex-direction: column; }
.panel-close { display: none; }
.panel-head { display: flex; align-items: center; gap: 6px; padding: 14px 14px 10px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.panel-head h2 { font-size: 13px; margin: 0; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.epic-list { display: flex; flex-direction: column; gap: 4px; padding: 0 10px; }
.epic-item { border: 1px solid transparent; border-left: 4px solid var(--c, var(--border-strong)); border-radius: 6px; padding: 8px 10px; cursor: pointer; display: flex; flex-direction: column; gap: 5px; background: var(--surface-2); }
.epic-item:hover { border-color: var(--border); border-left-color: var(--c, var(--border-strong)); }
.epic-item.active { border-color: var(--accent); border-left-color: var(--c, var(--accent)); background: var(--accent-soft); }
.epic-item.done .epic-name { text-decoration: line-through; color: var(--muted); }
.epic-top { display: flex; align-items: center; gap: 6px; }
.epic-name { flex: 1; font-weight: 600; font-size: 13.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.epic-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.panel-foot { padding: 12px 14px 16px; }

/* ---------- empty state */
.empty { margin: auto; max-width: 440px; text-align: center; padding: 40px 20px; }
.empty h2 { margin: 16px 0 6px; font-size: 20px; }
.empty p { color: var(--muted); margin: 0 0 20px; }
.empty .actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.empty .logo { width: 48px; height: 48px; }

/* ---------- modal */
dialog { border: 0; padding: 0; border-radius: 12px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-modal); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog.wide { width: min(880px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 15, 25, .5); }
.m-wrap { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.m-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px 0; }
.m-head h2 { margin: 0; font-size: 17px; flex: 1; }
.m-body { padding: 16px 20px; overflow-y: auto; display: grid; gap: 14px; }
.m-foot { display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
label.f { display: grid; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.hint { font-weight: 400; color: var(--faint); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.key-badge { font-size: 13px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.story-grid { display: grid; grid-template-columns: 1fr 240px; gap: 20px; }
.title-input { font-size: 18px !important; font-weight: 600; height: 42px !important; }
.story-side { display: grid; gap: 12px; align-content: start; }
.story-meta { font-size: 12px; color: var(--faint); display: grid; gap: 2px; padding-top: 4px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches label { cursor: pointer; }
.swatches input { position: absolute; opacity: 0; pointer-events: none; }
.swatches span { display: block; width: 26px; height: 26px; border-radius: 6px; background: var(--c); border: 2px solid transparent; box-shadow: inset 0 0 0 2px var(--surface); }
.swatches input:checked + span { border-color: var(--text); }
.swatches input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.col-rows { display: grid; gap: 6px; }
.col-row { display: flex; gap: 4px; align-items: center; }
.col-row .num { width: 18px; color: var(--faint); font-size: 12px; text-align: right; flex: none; }
.danger-zone { border: 1px solid var(--danger-soft); background: color-mix(in srgb, var(--danger-soft) 50%, transparent); border-radius: 8px; padding: 12px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.danger-zone p { margin: 0; flex: 1; font-size: 13px; color: var(--muted); min-width: 200px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 20px; margin-top: 12px; }
.tab { border: 0; background: none; padding: 8px 10px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.steps { margin: 0; padding-left: 20px; color: var(--muted); display: grid; gap: 4px; }
.jb-list { border: 1px solid var(--border); border-radius: 8px; max-height: 320px; overflow-y: auto; }
.jb-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.jb-row:last-child { border-bottom: 0; }
.jb-row .jb-name { flex: 1; min-width: 0; }
.jb-row .jb-name b { font-weight: 600; }
.jb-row .jb-sub { font-size: 12px; color: var(--muted); }
.jb-status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.jb-status.ok { color: var(--ok); } .jb-status.err { color: var(--danger); white-space: normal; max-width: 260px; }
.pill { font-size: 11px; padding: 1px 6px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.user-table { width: 100%; border-collapse: collapse; }
.user-table td, .user-table th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 13px; }
.user-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); }
.user-table td:last-child { text-align: right; white-space: nowrap; }
.add-user { display: grid; grid-template-columns: 1fr 1fr 1fr auto auto; gap: 8px; align-items: end; }

/* ---------- toasts */
.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-modal); font-size: 13.5px; max-width: 420px; animation: tin .18s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transition: opacity .3s; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* ---------- responsive */
.menu-btn { display: none; }
@media (max-width: 900px) {
  .epic-panel { position: fixed; right: 0; top: 0; bottom: 0; z-index: 20; box-shadow: var(--shadow-modal); max-width: 88vw; }
  .panel-close { display: inline-grid; }
}
@media (max-width: 760px) {
  .app { flex-direction: column; height: auto; min-height: 100vh; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px 12px; gap: 4px; }
  .sidebar .brand { padding: 4px 8px 4px 0; }
  .sidebar .side-label, .sidebar .bcount { display: none; }
  .board-nav { flex-direction: row; overflow-x: auto; flex: 1 1 100%; order: 3; }
  .board-link { flex: none; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; flex-direction: row; }
  .side-foot .side-btn span, .me .who { display: none; }
  .side-btn { width: auto; }
  .main { min-height: 0; }
  .toolbar { padding: 12px 16px; }
  .board-scroll { padding: 0 16px 16px; }
  .search { width: 100%; }
  .tb-tools { width: 100%; }
  .story-grid { grid-template-columns: 1fr; }
  .row2, .add-user { grid-template-columns: 1fr; }
}
