:root {
  --bg: #f6f7f9; --surface: #fff; --surface-2: #f0f2f5; --line: #e3e6ea;
  --text: #1c2024; --muted: #6b7280; --accent: #3b82f6; --danger: #dc2626;
  --over: rgba(59,130,246,.12); --shadow: 0 1px 2px rgba(0,0,0,.06), 0 1px 1px rgba(0,0,0,.04);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --surface: #1a1d22; --surface-2: #22262c; --line: #2e333a;
    --text: #e8eaed; --muted: #9aa1ab; --over: rgba(59,130,246,.22);
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Header */
.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; }
.tabs { display: flex; background: var(--surface-2); border-radius: 8px; padding: 3px; }
.tabs button { border: 0; background: none; padding: 6px 14px; border-radius: 6px; color: var(--muted); font-weight: 500; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.me { color: var(--muted); font-size: 12px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: #fef3c7; color: #92400e; }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 8px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.icon { border: 0; background: none; padding: 4px 8px; border-radius: 6px; color: var(--muted); font-size: 16px; }
.icon:hover { background: var(--surface-2); color: var(--text); }

/* List filter chips */
.filters { display: flex; gap: 6px; padding: 10px 16px 0; flex-wrap: wrap; align-items: center; }
.fchip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 4px 10px; border-radius: 99px; font-size: 13px; }
.fchip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.fchip.off { opacity: .45; }
.fchip.off .dot { background: transparent; border: 1.5px solid var(--c); }
.filters .label { color: var(--muted); font-size: 12px; margin-right: 2px; }

.layout { display: flex; align-items: flex-start; }
main { flex: 1; min-width: 0; padding: 12px 16px 40px; }

/* Board */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { flex: 0 0 290px; background: var(--surface-2); border-radius: var(--radius); padding: 10px; border-top: 3px solid var(--c); min-height: 120px; }
.col header { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.col h2 { font-size: 14px; margin: 0; cursor: pointer; flex: 1; }
.col .count { color: var(--muted); font-size: 12px; }
.add-col { flex: 0 0 200px; border: 2px dashed var(--line); background: none; border-radius: var(--radius); padding: 20px; color: var(--muted); border-top-width: 2px; }
.quick { display: flex; gap: 6px; margin-bottom: 8px; }
.quick input[name="t"] { flex: 1; min-width: 0; }
.quick input, .quick select { border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 6px 8px; }
.quick input[type="date"] { width: 38px; padding: 6px 4px; color: transparent; }
.quick input[type="date"]:valid, .quick input[type="date"]:focus { width: 130px; color: inherit; }
.cards { display: flex; flex-direction: column; gap: 6px; min-height: 24px; }
.done-label { font-size: 12px; color: var(--muted); margin: 10px 2px 2px; }

/* Card */
.card { display: flex; gap: 8px; align-items: flex-start; background: var(--surface); border-radius: 8px; padding: 8px; box-shadow: var(--shadow); border-left: 3px solid var(--c); cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.card .t { font-weight: 500; word-break: break-word; }
.card .body { flex: 1; min-width: 0; cursor: pointer; }
.card .meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.card .due.overdue { color: var(--danger); font-weight: 600; }
.card .due.today { color: var(--accent); font-weight: 600; }
.card.done .t { text-decoration: line-through; color: var(--muted); }
.card.done { opacity: .7; }
.tag { display: inline-flex; align-items: center; gap: 4px; }
.tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.chk { flex: 0 0 18px; width: 18px; height: 18px; margin-top: 1px; border-radius: 50%; border: 1.5px solid var(--muted); background: none; padding: 0; color: transparent; font-size: 11px; line-height: 1; }
.card.done .chk { background: var(--c); border-color: var(--c); color: #fff; }

/* Drag */
.dragging { opacity: .35; }
.ghost { position: fixed; z-index: 1000; pointer-events: none; transform: rotate(2deg); box-shadow: 0 10px 30px rgba(0,0,0,.25); opacity: .95; }
.over { background-color: var(--over) !important; outline: 2px dashed var(--accent); outline-offset: -2px; }
.drop-line { height: 3px; background: var(--accent); border-radius: 2px; margin: -1.5px 0; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }

/* Calendar toolbar */
.cal-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.cal-bar h2 { margin: 0 8px; font-size: 18px; min-width: 170px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 10px; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.cal-wrap { display: flex; gap: 12px; align-items: flex-start; }
.cal-main { flex: 1; min-width: 0; }

/* Unscheduled tray */
.tray { flex: 0 0 230px; background: var(--surface-2); border-radius: var(--radius); padding: 10px; position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
.tray h3 { font-size: 13px; margin: 0 0 4px; }
.tray .hint { font-size: 11.5px; color: var(--muted); margin: 0 0 8px; }

/* Month */
.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.dow { background: var(--surface-2); padding: 6px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; text-align: center; }
.day { background: var(--surface); min-height: 112px; padding: 4px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.day.other { background: var(--surface-2); }
.day.other .dnum { opacity: .5; }
.dnum { font-size: 12px; font-weight: 600; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; }
.day.today .dnum { background: var(--accent); color: #fff; }
.day.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.chip { font-size: 11.5px; padding: 2px 5px; border-radius: 4px; background: color-mix(in srgb, var(--c) 16%, transparent); border-left: 3px solid var(--c); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.chip.done { text-decoration: line-through; opacity: .55; }
.chip .tm { font-weight: 600; margin-right: 3px; }
.more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.grp-name { font-size: 10px; font-weight: 700; color: var(--c); text-transform: uppercase; letter-spacing: .03em; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Year */
.year { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.ym { background: var(--surface); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow); }
.ym h3 { margin: 0 0 6px; font-size: 14px; cursor: pointer; }
.ym h3:hover { color: var(--accent); }
.ygrid { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 2px; }
.ygrid .yw { font-size: 10px; color: var(--muted); text-align: center; }
.yd { aspect-ratio: 1; display: flex; justify-content: center; padding-top: 3px; font-size: 11px; border-radius: 5px; cursor: pointer; position: relative; }
.yd:hover { outline: 1px solid var(--accent); }
.yd.l1 { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.yd.l2 { background: color-mix(in srgb, var(--accent) 38%, transparent); }
.yd.l3 { background: color-mix(in srgb, var(--accent) 65%, transparent); color: #fff; }
.yd.today { box-shadow: inset 0 0 0 2px var(--accent); font-weight: 700; }
.yd.sel { outline: 2px solid var(--text); }

/* Day panel */
#panel { flex: 0 0 360px; background: var(--surface); border-left: 1px solid var(--line); position: sticky; top: 53px; height: calc(100vh - 53px); overflow: auto; padding: 14px; }
.panel-head { display: flex; align-items: center; gap: 4px; margin-bottom: 10px; }
.panel-head h2 { flex: 1; font-size: 16px; margin: 0; text-align: center; }
.panel-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.psec { background: var(--surface-2); border-radius: 8px; padding: 8px; margin-bottom: 10px; border-top: 3px solid var(--c, var(--line)); }
.psec h3 { margin: 0 0 6px; font-size: 13px; display: flex; justify-content: space-between; }
.psec h3 span { color: var(--muted); font-weight: 400; }
.empty { color: var(--muted); font-size: 12.5px; padding: 6px 2px; }

/* Dialogs */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog form { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
dialog h2 { margin: 0 0 4px; font-size: 17px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); flex: 1; }
dialog input:not([type="checkbox"]), dialog select, dialog textarea { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 8px 10px; color: var(--text); font-size: 14px; }
dialog .row { display: flex; gap: 10px; }
dialog label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.info { font-size: 12px; color: var(--muted); margin: 0; }
.actions { display: flex; gap: 8px; margin-top: 6px; }
.spacer { flex: 1; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; background: var(--c); }
.swatches button[aria-pressed="true"] { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px); background: #111; color: #fff; padding: 10px 16px; border-radius: 8px; transition: transform .2s; z-index: 2000; font-size: 13px; }
#toast.show { transform: translateX(-50%) translateY(0); }


/* Multi-day bars (month) */
.bar, .bar-gap { height: 19px; flex: none; }
.bar { font-size: 11.5px; line-height: 19px; padding: 0 5px; background: color-mix(in srgb, var(--c) 30%, var(--surface)); color: var(--text); margin: 0 -4px 0 -5px; cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; white-space: nowrap; overflow: visible; position: relative; }
.bar.bs { margin-left: 0; border-radius: 4px 0 0 4px; border-left: 3px solid var(--c); }
.day:nth-child(7n) .bar { margin-right: 0; }
.bar.be { margin-right: 0; border-top-right-radius: 4px; border-bottom-right-radius: 4px; }
.bar.done { opacity: .5; }
.bar.done .bl { text-decoration: line-through; }
.bar .bl { position: absolute; left: 5px; top: 0; z-index: 2; overflow: hidden; text-overflow: ellipsis; font-weight: 500; pointer-events: none; }
.bar.bs .bl { left: 3px; }

/* Year stripes for date ranges */
.yd .ys { position: absolute; left: 0; right: 0; height: 3px; bottom: calc(2px + var(--l) * 4px); background: var(--c); pointer-events: none; }
.yd .ys.s { left: 2px; border-radius: 2px 0 0 2px; }
.yd .ys.e { right: 2px; border-radius: 0 2px 2px 0; }
.yd .ys.s.e { border-radius: 2px; }
.yd .ys.done { opacity: .35; }
.cal-bar .hint { color: var(--muted); font-size: 12px; margin-left: 8px; }

/* Board extras */
.add-wrap { display: flex; flex-direction: column; gap: 8px; flex: 0 0 200px; }
.add-wrap .add-col { flex: none; }
.add-col.small { padding: 10px; font-size: 13px; }
.blk { color: #b45309; font-weight: 600; }
.lnk { color: var(--accent); }
@media (prefers-color-scheme: dark) { .blk { color: #fbbf24; } }

/* Dialog extras */
dialog .narrow { flex: 0 0 120px; }
dialog .row > label { min-width: 0; }
dialog .row input, dialog .row select { width: 100%; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
.flabel { font-size: 12.5px; color: var(--muted); }
.dchips { display: flex; flex-wrap: wrap; gap: 6px; }
.dchip { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; padding: 3px 4px 3px 8px; border-radius: 6px; background: color-mix(in srgb, var(--c) 16%, transparent); border-left: 3px solid var(--c); }
.dchip.done { text-decoration: line-through; opacity: .65; }
.dchip button { border: 0; background: none; color: var(--muted); padding: 0 4px; font-size: 11px; }
#importForm textarea { font-family: inherit; resize: vertical; }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }

/* Dependency map */
.map-hint { margin: -2px 0 10px; color: var(--muted); font-size: 13px; }
.map { position: relative; display: flex; gap: 96px; overflow-x: auto; padding: 4px 4px 24px; align-items: flex-start; }
.map svg.links { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; z-index: 1; }
.mcol { flex: 0 0 240px; display: flex; flex-direction: column; gap: 10px; position: relative; }
.mcol h3 { margin: 0 0 2px; font-size: 13px; padding-bottom: 6px; border-bottom: 3px solid var(--c); }
.node { position: relative; z-index: 2; background: var(--surface); border-radius: 8px; padding: 8px 10px; box-shadow: var(--shadow); border-left: 3px solid var(--c); cursor: pointer; transition: opacity .15s; }
.node:hover { box-shadow: 0 0 0 2px var(--c); }
.node .t { font-weight: 500; font-size: 13px; }
.node .meta { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.node.done .t { text-decoration: line-through; color: var(--muted); }
.node.sel { box-shadow: 0 0 0 3px var(--accent); }
.map.linking .node { cursor: crosshair; }
.st { font-weight: 600; }
.st.wait { color: #b45309; } .st.ready { color: #059669; } .st.done { color: var(--muted); }
.due.overdue { color: var(--danger); font-weight: 600; } .due.today { color: var(--accent); font-weight: 600; }
path.link { fill: none; stroke-width: 2; transition: opacity .15s; }
path.link.wait { stroke: #94a3b8; } path.link.ok { stroke: #10b981; } path.link.bad { stroke: var(--danger); stroke-dasharray: 5 4; }
path.hit { fill: none; stroke: transparent; stroke-width: 12; pointer-events: stroke; cursor: pointer; }
g.edge:hover path.link { stroke-width: 3.5; }
.mk-wait { fill: #94a3b8; } .mk-ok { fill: #10b981; } .mk-bad { fill: var(--danger); }
.map.focus .node:not(.hl) { opacity: .25; }
.map.focus g.edge:not(.hl) { opacity: .08; }
.map.focus g.edge.hl path.link { stroke-width: 3; }
.legend { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 18px; height: 0; border-top: 2px solid; margin-left: 6px; }
.lg.wait { border-color: #94a3b8; } .lg.ok { border-color: #10b981; } .lg.bad { border-color: var(--danger); border-top-style: dashed; }

/* Responsive */
@media (max-width: 900px) {
  .layout { display: block; }
  #panel { position: fixed; inset: auto 0 0 0; top: auto; height: 70vh; border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.2); z-index: 30; }
  .cal-wrap { flex-direction: column-reverse; align-items: stretch; }
  .tray { position: static; flex: none; width: 100%; max-height: 180px; }
  .day { min-height: 70px; }
  .chip .tx { display: none; }
  .chip { height: 6px; padding: 0; border-left-width: 0; background: var(--c); }
  .grp-name, .more { display: none; }
  .bar, .bar-gap { height: 6px; } .bar .bl { display: none; } .bar { line-height: 6px; font-size: 0; background: var(--c); border-left: 0 !important; }
  .bar.done { opacity: .35; }
  .map { gap: 48px; } .mcol { flex-basis: 200px; }
  .legend { display: none; }
}
@media (max-width: 600px) {
  .top { gap: 8px; }
  .me { display: none; }
  .col { flex-basis: 85vw; }
}
