:root {
  color-scheme: dark;
  --bg: #0a0c11;
  --bar: #0f131b;
  --line: #1b2131;
  --line2: #2a3350;
  --fg: #e8ebf3;
  --dim: #8b94ab;
  --accent: #4d8dff;
  --panel: #121722;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--fg);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: #6db3ff; }
::selection { background: #2d5bd6; }
* { scrollbar-width: thin; scrollbar-color: #2a3350 transparent; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; user-select: none; }

/* HUD + axis */
#hud { flex: none; height: 28px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px; background: var(--bar); border-bottom: 1px solid var(--line); color: var(--dim); }
#hud button { background: none; border: 0; padding: 2px 8px; border-radius: 5px; color: var(--dim); }
#hud button:hover, #hud button.on { color: var(--fg); background: #1b2233; }
#hud .proj { color: var(--fg); font-weight: 600; letter-spacing: .02em; }
#hud .proj::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); margin-right: 8px; box-shadow: 0 0 8px var(--accent); }
#hud .r { display: flex; align-items: center; gap: 2px; }
#hud .tz { padding: 0 8px; }
#axis { flex: none; height: 38px; position: relative; overflow: hidden; background: var(--bar);
  border-bottom: 1px solid var(--line2); }
#axis .dl, #axis .hl { position: absolute; white-space: nowrap; color: var(--dim); }
#axis .dl { top: 3px; font-weight: 600; color: #c4cbe0; }
#axis .hl { top: 21px; font-size: 11px; }
#axis .tk { position: absolute; bottom: 0; width: 1px; height: 8px; background: #2a3350; }
#axis .tk.dy { top: 0; height: auto; background: #3a4670; }
#axis .nowm { position: absolute; bottom: 0; width: 0; height: 0; margin-left: -5px;
  border: 5px solid transparent; border-bottom-color: #ff3b5c; border-top: 0; }

#stage { position: relative; flex: 1; overflow: hidden; }
#grid { position: absolute; inset: 0; pointer-events: none; }
#grid .gl { position: absolute; top: 0; bottom: 0; width: 1px; background: #141a28; }
#grid .gl.dy { background: #2a3350; }
#grid .we { position: absolute; top: 0; bottom: 0; background: rgba(255,255,255,.018); }
#now { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #ff3b5c;
  box-shadow: 0 0 10px #ff3b5c; pointer-events: none; z-index: 5; }
#lanes { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; cursor: grab; }
#lanes.panning { cursor: grabbing; }
.lane { position: relative; border-bottom: 1px solid var(--line); }
.lane:nth-child(odd) { background: rgba(255,255,255,.02); }
.lane.plus { border: 2px dashed #3a4670; margin: 4px 0; background: rgba(77,141,255,.06); }
.lane.plus.hot { background: rgba(77,141,255,.22); border-color: var(--accent); }
.lane.plus::after { content: "+"; position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  font-size: 26px; color: #6d84c8; }
.lh { position: absolute; left: 0; right: 0; bottom: -4px; height: 8px; cursor: ns-resize; z-index: 4; }
.lh:hover { background: rgba(77,141,255,.35); }

.tile { --c: #5b6684; position: absolute; top: 3px; bottom: 4px; min-width: 2px; overflow: hidden;
  border-radius: 6px; cursor: grab; border: 1px solid color-mix(in srgb, var(--c) 65%, #000);
  border-left: 4px solid var(--c);
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 26%, #171c29), color-mix(in srgb, var(--c) 14%, #131824)); }
.tile:hover { border-color: var(--c); }
.tile.sel { outline: 2px solid #fff; outline-offset: 1px; z-index: 3; }
.tile.ghosted { opacity: .3; }
.tile .ti { padding: 4px 8px 4px 6px; height: 100%; display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.tile .r1 { display: flex; align-items: center; gap: 6px; min-width: 0; }
.tile .tt { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.tile .tc { flex: none; background: none; border: 0; padding: 0 3px; color: var(--dim); line-height: 1; }
.tile .tc:hover { color: #fff; }
.tile .tgs { display: flex; gap: 3px; overflow: hidden; flex: none; }
.tile .tg { font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 8px; color: #0a0c11;
  white-space: nowrap; line-height: 15px; }
.tile .tg.done { background: #2fd07a; color: #06210f; letter-spacing: .05em; }
.tile .tm { font-size: 11px; color: var(--dim); white-space: nowrap; overflow: hidden; flex: none; }
.tile .td { font-size: 12px; color: #b6bdd0; white-space: pre-wrap; word-break: break-word; overflow: hidden; flex: 1; min-height: 0; }
.tile.xs .tgs, .tile.xs .td, .tile.xs .tm { display: none; }
.tile:not(.lg) .tm { display: none; }
.tile .rz { position: absolute; top: 0; bottom: 0; right: 0; width: 7px; cursor: ew-resize; z-index: 2; }
.tile .rz:hover { background: rgba(255,255,255,.25); }
.tile .ppl { position: absolute; right: 8px; bottom: 3px; display: flex; gap: 2px; pointer-events: none; }
.ava { width: 17px; height: 17px; border-radius: 50%; font-size: 9px; font-weight: 700; display: grid; place-items: center;
  color: #0a0c11; border: 1px solid #0006; }
.ava.cm { box-shadow: 0 0 0 2px #fff; }
.tile.xs .ppl { display: none; }

#ghost, .hide { display: none; }
#ghost.show { display: block; }
#hint { position: absolute; left: 0; right: 0; top: 42%; text-align: center; color: #58627e; pointer-events: none; font-size: 15px; }
#toast { position: fixed; top: 74px; left: 50%; transform: translateX(-50%); z-index: 90; background: #2b1620;
  border: 1px solid #ff3b5c; color: #ffd7de; padding: 7px 14px; border-radius: 8px; pointer-events: none; }

/* overlays */
.ov { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(5,7,12,.55); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.ov.top { z-index: 70; background: rgba(5,7,12,.35); }
.panel { width: min(520px, 92vw); max-height: 86vh; overflow: auto; background: var(--panel);
  border: 1px solid var(--line2); border-radius: 14px; padding: 20px 22px; box-shadow: 0 24px 90px #000c; user-select: none; }
.panel.wide { width: min(680px, 94vw); }
.panel h2 { margin: 0 0 2px; font-size: 22px; letter-spacing: .14em; text-transform: uppercase; }
.panel .sub { color: var(--dim); margin-bottom: 14px; }
.panel .foot { color: #66708d; margin-top: 14px; font-size: 12px; }
.item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 12px;
  border-radius: 8px; cursor: pointer; border-left: 3px solid transparent; }
.item.on { background: #1f2a4a; border-left-color: var(--accent); }
.item .r { color: var(--dim); font-size: 12px; white-space: nowrap; }
.item .l { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.dis { opacity: .4; }
.sw { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.empty { color: var(--dim); padding: 10px 12px; }
.frm label { display: block; color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; margin: 12px 0 4px; }
.frm input[type=text], .frm input[type=password], .frm input[type=number], .frm input[type=datetime-local],
.frm textarea, .frm select { width: 100%; background: #0c0f16; border: 1px solid var(--line2); border-radius: 7px;
  padding: 7px 9px; user-select: text; }
.frm textarea { resize: vertical; min-height: 90px; }
.frm input:focus, .frm textarea:focus, .frm select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.frm .row { display: flex; gap: 8px; }
.frm .row > * { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { background: #0c0f16; border: 1px solid var(--line2); border-radius: 14px; padding: 2px 10px; color: var(--dim); }
.chip[aria-pressed=true] { color: #0a0c11; font-weight: 600; background: var(--c, #dfe6ff); border-color: var(--c, #dfe6ff); }
.btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.btn { background: #1a2136; border: 1px solid var(--line2); border-radius: 8px; padding: 7px 16px; }
.btn:hover { background: #222b45; }
.btn.pri { background: #2d5bd6; border-color: #4d7bff; }
.btn.danger { background: #a3203a; border-color: #ff3b5c; }
.err { color: #ff8a9b; min-height: 18px; margin-top: 8px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; }
.swatches button[aria-pressed=true] { border-color: #fff; box-shadow: 0 0 0 2px #0008 inset; }
.kbd { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; }
.kbd b { font-family: ui-monospace, Consolas, monospace; color: #fff; font-weight: 600; }
.kbd span { color: #b6bdd0; }

/* context menu */
.ctxov { position: fixed; inset: 0; z-index: 60; }
.ctx { position: fixed; min-width: 240px; max-width: 320px; max-height: calc(100vh - 20px); overflow: auto; background: var(--panel);
  border: 1px solid var(--line2); border-radius: 10px; padding: 6px; box-shadow: 0 12px 50px #000c; user-select: none; }
.ctx .hd { padding: 4px 8px 6px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.ctx .sec { padding: 6px 8px 2px; color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.ctx .chips { padding: 2px 6px 4px; }
.ctx .mi { display: flex; width: 100%; justify-content: space-between; background: none; border: 0; border-radius: 6px; padding: 6px 8px; text-align: left; }
.ctx .mi:hover, .ctx .mi:focus-visible { background: #1f2a4a; outline: none; }
.ctx .mi.dg { color: #ff8a9b; }
.ctx .mi i { color: var(--dim); font-style: normal; font-size: 11px; }
.ctx hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; }
.login .panel { width: 340px; }
.login h1 { margin: 0 0 16px; letter-spacing: .2em; text-transform: uppercase; font-size: 26px; }

/* body: timeline column + task list */
#body { flex: 1; display: flex; min-height: 0; }
#col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#grid .gl.noon { background: #222b42; }
#side { flex: none; width: 290px; display: flex; flex-direction: column; background: var(--bar); border-left: 1px solid var(--line2); min-height: 0; }
#side.hide { display: none; }
#side .sh { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; }
#side .chips.fl { padding: 0 10px 6px; }
#side .chip { padding: 0 8px; font-size: 12px; }
.btn.sm { padding: 2px 10px; font-size: 12px; }
#side .sl { flex: 1; overflow-y: auto; padding: 4px 6px 10px; border-top: 1px solid var(--line); }
.si { padding: 6px 8px; border-radius: 7px; cursor: pointer; border-left: 3px solid transparent; }
.si:hover { background: #171e30; }
.si.on { background: #1f2a4a; border-left-color: var(--accent); }
.si .st { display: flex; align-items: center; gap: 5px; min-width: 0; }
.si .tt { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.si .sm { display: flex; justify-content: space-between; align-items: center; color: var(--dim); font-size: 11px; margin-top: 2px; }
.ppl2 { display: flex; gap: 2px; }

/* selection zone, group ghosts, selection info */
#ghost { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
#ghost .gh { position: absolute; border: 2px dashed #fff; border-radius: 6px; background: rgba(255,255,255,.12); }
#mq { position: absolute; display: none; z-index: 7; pointer-events: none; border: 1px solid #4d8dff; background: rgba(77,141,255,.16); }
#mq.show { display: block; }
#hud .l { display: flex; align-items: center; gap: 10px; }
#hud .selinfo { color: #7fb0ff; }
.frm textarea[readonly] { min-height: 140px; font-family: ui-monospace, Consolas, monospace; }

/* sidebar: sort buttons and the Due badge (sidebar only, never on timeline tiles) */
#side .sb { display: flex; gap: 6px; }
.btn.sm.on { background: #2d5bd6; border-color: #4d7bff; }
.btn.sm.dim { opacity: .45; }
.si .due { flex: none; margin-left: auto; font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 0 6px; border-radius: 8px; line-height: 15px; color: #fff; background: #d6294a; }
.si .doneb { flex: none; font-size: 9px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  padding: 0 5px; border-radius: 7px; line-height: 14px; color: #06210f; background: #2fd07a; }

.frm label.chk { display: flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--fg); margin-top: 14px; }
#hud button.tz { padding: 2px 8px; }

/* ---------- touch / mobile ---------- */
#mbar, #sidebd { display: none; }
#col { touch-action: none; }
body.mobile #mbar { display: flex; flex: none; gap: 6px; align-items: center; overflow-x: auto; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--bar); border-top: 1px solid var(--line2); }
.mb { flex: none; min-width: 48px; height: 42px; padding: 0 12px; border-radius: 10px; background: #1a2136; border: 1px solid var(--line2); white-space: nowrap; }
.mb.on { background: #2d5bd6; border-color: #4d7bff; }
.mbsep { flex: none; width: 1px; height: 26px; background: var(--line2); margin: 0 2px; }
body.mobile #hud .r { display: none; }
body.mobile #hud { height: 34px; }
body.mobile #side { position: fixed; top: 0; right: 0; bottom: 0; width: min(88vw, 340px); z-index: 40; box-shadow: -12px 0 40px #000a; }
body.mobile #sidebd.show { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(5,7,12,.5); }
body.mobile .lh { height: 18px; bottom: -8px; }
body.mobile .item { padding: 13px 12px; }
body.mobile .ctx .mi, body.mobile .chip { padding-top: 9px; padding-bottom: 9px; }
body.mobile .frm input, body.mobile .frm textarea, body.mobile .frm select { font-size: 16px; }
body.mobile .panel { padding: 16px; }
body.mobile .panel .foot { display: none; }

/* ---------- touch fixes: the timeline handles every gesture itself ---------- */
#col, #col * { touch-action: none; }
body.mobile #side { inset: 0; width: 100%; max-width: none; box-shadow: none; border-left: 0; }
body.mobile #sidebd.show { display: none; }
body.mobile #side .sh { gap: 10px; padding: 10px 12px; }
body.mobile #side .si { padding: 11px 10px; }
body.mobile #mbar.hide { display: none; }
body.mobile .tile .rz { width: 26px; }
.mbinfo { flex: 1; color: var(--dim); white-space: nowrap; padding: 0 8px; }

/* ---------- links, repeats, edge handles ---------- */
#links { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; overflow: hidden; }
#links .lnk { fill: none; stroke-width: 2.5; opacity: .9; stroke-linecap: round; }
#links .ghostlnk { stroke-dasharray: 6 5; }
#links .lnkhit { fill: none; stroke: transparent; stroke-width: 18; pointer-events: stroke; cursor: pointer; }
#links .lnkhit:hover { stroke: rgba(255,255,255,.12); }
.tile .rzl { position: absolute; top: 0; bottom: 0; left: 0; width: 7px; cursor: ew-resize; z-index: 2; }
.tile .rzl:hover { background: rgba(255,255,255,.25); }
.tile .lk { position: absolute; right: 9px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%; z-index: 3;
  background: var(--c); border: 2px solid #fff; cursor: crosshair; display: none; }
.tile:hover .lk, .tile.sel .lk, .tile.linksrc .lk { display: block; }
.tile.linksrc { outline: 2px dashed #fff; outline-offset: 1px; }
.tile.occ { opacity: .62; border-style: dashed; cursor: default; }
.tile .rpt { flex: none; color: #fff; font-weight: 700; opacity: .85; }
body.mobile .tile .lk { display: none; }
body.mobile .lh { display: none; }
body.mobile .tile .rzl { width: 24px; }
body.mobile #links .lnkhit { stroke-width: 28; }

/* ---------- touch bar (5 big buttons, no scrolling) and action sheet ---------- */
body.mobile #mbar { flex-direction: column; overflow: visible; gap: 6px; align-items: stretch; }
.mbrow { display: flex; gap: 6px; width: 100%; align-items: center; }
.mb { flex: 1 1 0; min-width: 0; height: 54px; padding: 0 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; white-space: nowrap; }
.mb .mi1 { font-size: 20px; line-height: 1; }
.mb .mi2 { font-size: 11px; color: var(--dim); }
.mb.on .mi2 { color: #fff; }
.mbinfo { flex: 3 1 0; color: var(--dim); padding: 0 6px; white-space: normal; line-height: 1.25; }
.ctx.sheet { position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: 100%; max-width: none; border-radius: 16px 16px 0 0;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); max-height: 72vh; }
.ctx.sheet .mi { padding: 14px 12px; font-size: 15px; }
body.mobile .ctxov { background: rgba(5,7,12,.55); }

/* ---------- task editor fills the workspace ---------- */
.panel.editor { width: min(1000px, 96vw); height: min(780px, 94vh); max-height: none; display: flex; flex-direction: column; overflow: hidden; }
.editor .edhead, .editor .edmeta, .editor .btns, .editor .foot, .editor .err, .editor label, .editor > input { flex: none; }
.editor .edhead .sub { margin-bottom: 8px; }
.editor > input[type=text] { font-size: 17px; font-weight: 600; padding: 10px 12px; }
.editor textarea { flex: 1 1 auto; min-height: 140px; height: auto; resize: none; font-size: 15px; line-height: 1.5; padding: 10px 12px; }
.editor .edmeta { max-height: 28%; overflow-y: auto; }
body.mobile .ov.edit { align-items: stretch; justify-content: stretch; backdrop-filter: none; background: var(--panel); }
body.mobile .panel.editor { width: 100vw; height: 100%; max-height: none; border-radius: 0; border: 0; padding: 12px; box-shadow: none; }
body.mobile .editor .foot { display: none; }

#toast.ok { background: #12301f; border-color: #1fd66b; color: #c9ffe0; }

/* ---------- AI composer ---------- */
.composer { overflow-y: auto; }
.composer .airefs { flex: none; display: flex; flex-wrap: wrap; gap: 5px; max-height: 64px; overflow-y: auto; margin-bottom: 4px; }
.composer .aibtns { flex: none; display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.composer .airow { flex: none; display: flex; gap: 8px; margin: 8px 0 2px; }
.composer .airow input { flex: 1; }
.composer .aistatus { flex: none; min-height: 18px; color: var(--dim); margin-top: 4px; }
.composer .aistatus.err { color: #ff8a9b; }
.composer button:disabled { opacity: .5; cursor: progress; }
.composer .btn.aib { text-align: left; }
.composer textarea { min-height: 120px; }
