:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f3f3f3;
  --line: #e6e6e6;
  --line-strong: #bdbdbd;
  --text: #111111;
  --muted: #6a6a6a;
  --accent: #111111;
  --today: #e5352b;
  --group: #111111;
  --head-h: 72px;
  --gutter-w: 92px;
  --lane-w: 190px;
  --panel-w: 380px;
  color-scheme: light;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }

#app { height: 100%; display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.project { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
#projectName { font-size: 16px; font-weight: 650; white-space: nowrap; }
.tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn {
  height: 30px; padding: 0 12px; border-radius: 7px; border: 1px solid var(--line-strong);
  background: var(--surface); cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.icon { width: 30px; padding: 0; font-size: 16px; line-height: 1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: #c2453f; }
.seg { display: flex; border: 1px solid var(--line-strong); border-radius: 7px; overflow: hidden; }
.seg button { height: 28px; padding: 0 10px; border: 0; background: var(--surface); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button:hover { background: var(--surface-2); }
.zoom { display: flex; align-items: center; gap: 6px; }
.zoom input { width: 120px; accent-color: var(--accent); }

/* ---------- layout ---------- */
.main { flex: 1; display: flex; min-height: 0; }
#scroller { flex: 1; overflow: auto; min-width: 0; overscroll-behavior: contain; }
#sheet { min-width: 100%; width: max-content; }

/* ---------- sticky column header ---------- */
#head {
  position: sticky; top: 0; z-index: 20; display: flex; height: var(--head-h);
  background: var(--surface); border-bottom: 1px solid var(--line-strong);
}
.corner {
  position: sticky; left: 0; z-index: 2; flex: none; width: var(--gutter-w);
  background: var(--surface); border-right: 1px solid var(--line-strong);
  display: flex; align-items: flex-end; padding: 0 8px 8px; color: var(--muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
}
.group { flex: none; display: flex; flex-direction: column; }
.group.collapsed { border-right: 2px solid var(--line-strong); }
.group-bar {
  width: 0; min-width: 100%; overflow: hidden;   /* never wider than the columns beneath it */
  height: 28px; display: flex; align-items: center; gap: 6px; padding: 0 8px;
  background: var(--group); color: #fff; font-size: 11px; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase; white-space: nowrap;
}
.group-bar .name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.group-bar button {
  border: 0; background: none; color: inherit; cursor: pointer; opacity: .75;
  padding: 2px 4px; border-radius: 4px; font-size: 13px; line-height: 1;
}
.group-bar button:hover { opacity: 1; background: rgba(255,255,255,.15); }
.group-lanes { flex: 1; display: flex; }
.lane-head {
  width: var(--lane-w); padding: 0 6px 0 10px; display: flex; align-items: center; gap: 6px;
  border-right: 1px solid var(--line); font-weight: 600;
}
.lane-head:last-child { border-right: 2px solid var(--line-strong); }
.lane-head .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lane-head .badge {
  font-size: 10px; font-weight: 500; color: var(--muted); border: 1px solid var(--line-strong);
  border-radius: 9px; padding: 0 6px;
}
.lane-head .del { border: 0; background: none; cursor: pointer; color: var(--muted); visibility: hidden; padding: 2px; }
.lane-head:hover .del { visibility: visible; }
.lane-head .del:hover { color: #c2453f; }
.group.collapsed { width: 44px; }
.group.collapsed .group-bar { padding: 0; justify-content: center; }
.group.collapsed .name, .group.collapsed .add { display: none; }
.vname {
  flex: 1; writing-mode: vertical-rl; font-size: 10px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted); padding: 4px 0; overflow: hidden; text-align: left;
  align-self: center;
}
.add-group { align-self: center; margin: 0 14px; white-space: nowrap; }
.editable[contenteditable="true"] {
  outline: 2px solid var(--accent); border-radius: 3px; background: var(--surface); color: var(--text);
  text-overflow: clip; padding: 0 3px;
}

/* ---------- body ---------- */
#body { position: relative; display: flex; }
#gutter {
  position: sticky; left: 0; z-index: 10; flex: none; width: var(--gutter-w);
  background: var(--surface); border-right: 1px solid var(--line-strong);
}
#gutter .mo { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line-strong); }
#gutter .mo span {
  position: sticky; top: calc(var(--head-h) + 4px); display: inline-block; padding: 2px 8px;
  font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
}
#gutter .mo small { display: block; font-weight: 500; font-size: 10px; color: var(--muted); letter-spacing: 0; }
#gutter .d {
  position: absolute; right: 8px; font-size: 10px; color: var(--muted); white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#gutter .d.we { opacity: .6; }
#gutter .now {
  position: absolute; right: 0; transform: translateY(-50%); background: var(--today); color: #fff;
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 8px 0 0 8px; z-index: 1;
}
#grid { position: absolute; top: 0; bottom: 0; left: var(--gutter-w); right: 0; pointer-events: none; }
#grid i { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--line); }
#grid i.day { opacity: .55; }
#grid i.mo { border-top-color: var(--line-strong); }
#grid i.we { height: auto; border: 0; background: var(--surface-2); opacity: .7; }
#grid i.today { border-top: 2px solid var(--today); z-index: 5; }
#grid i.todayband { height: auto; border: 0; background: var(--today); opacity: .1; }

#lanes { position: relative; display: flex; flex: 1; }
.lane { position: relative; flex: none; width: var(--lane-w); border-right: 1px solid var(--line); }
.lane.last { border-right: 2px solid var(--line-strong); }
.lane.collapsed { width: 44px; background: var(--surface-2); cursor: pointer; }
.lane.drop { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.strip { position: absolute; left: 14px; right: 14px; border-radius: 3px; background: var(--c); opacity: .55; }

/* ---------- events ---------- */
.ev {
  position: absolute; z-index: 2; background: var(--c); color: #fff; border-radius: 6px;
  cursor: grab; user-select: none; touch-action: none;
  box-shadow: 0 1px 2px rgba(0,0,0,.18);
}
.ev:hover { filter: brightness(1.07); z-index: 3; }
.ev.sel { outline: 2px solid var(--text); outline-offset: 1px; z-index: 4; }
.ev .lbl {
  position: sticky; top: calc(var(--head-h) + 4px); padding: 4px 8px; overflow: hidden;
  max-height: 100%;
}
.ev .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev .m { font-size: 11px; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.tiny .lbl { padding: 0 8px; }
.ev.tiny .t { font-size: 11px; line-height: var(--h); }
.ev.tiny .m, .ev.micro .lbl { display: none; }
.ev .bar {
  position: absolute; left: 0; bottom: 0; height: 3px; border-radius: 0 0 0 6px;
  background: rgba(255,255,255,.75); pointer-events: none;
}
.ev .h { position: absolute; left: 0; right: 0; height: 6px; cursor: ns-resize; }
.ev .h[data-h="top"] { top: 0; }
.ev .h[data-h="bottom"] { bottom: 0; }
.ev.micro .h { display: none; }
body.dragging, body.dragging .ev { cursor: grabbing; }
body.resizing, body.resizing .ev { cursor: ns-resize; }

/* ---------- to-do panel ---------- */
#panel {
  flex: none; width: var(--panel-w); background: var(--surface); border-left: 1px solid var(--line-strong);
  display: flex; flex-direction: column; overflow: hidden;
}
#panel[hidden] { display: none; }
.p-head { display: flex; align-items: flex-start; gap: 8px; padding: 14px 14px 10px; border-top: 5px solid var(--c); }
.p-head input {
  flex: 1; min-width: 0; font-size: 17px; font-weight: 650; border: 1px solid transparent; border-radius: 6px;
  padding: 4px 6px; background: none;
}
.p-head input:hover, .p-head input:focus { border-color: var(--line-strong); outline: 0; }
.p-body { flex: 1; overflow: auto; padding: 0 14px 14px; }
.p-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.p-meta label, .p-sec > label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.p-meta .wide { grid-column: 1 / -1; }
.p-meta input, .p-meta select, .p-sec textarea, .todo-add input {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; padding: 5px 7px; background: var(--surface);
}
.p-sec textarea { resize: vertical; min-height: 56px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent; background: var(--c); cursor: pointer; padding: 0; }
.swatches button.on { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface); }
.p-sec { margin-top: 14px; }
.todo-top { display: flex; align-items: baseline; justify-content: space-between; }
.todo-top h3 { margin: 0; font-size: 13px; }
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); margin: 6px 0 8px; overflow: hidden; }
.progress div { height: 100%; background: var(--c); transition: width .15s; }
.todo { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.todo input[type="checkbox"] { width: 16px; height: 16px; flex: none; accent-color: var(--accent); cursor: pointer; }
.todo input[type="text"] { flex: 1; min-width: 0; border: 1px solid transparent; border-radius: 5px; padding: 4px 6px; background: none; }
.todo input[type="text"]:hover, .todo input[type="text"]:focus { border-color: var(--line-strong); outline: 0; }
.todo.done input[type="text"] { text-decoration: line-through; color: var(--muted); }
.todo button, .p-head .x { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; padding: 4px; }
.todo button { visibility: hidden; }
.todo:hover button { visibility: visible; }
.todo button:hover { color: #c2453f; }
.todo-add { margin-top: 6px; }
.p-foot { padding: 10px 14px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }

@media (max-width: 760px) {
  #panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--panel-w), 100vw); z-index: 50; box-shadow: -8px 0 24px rgba(0,0,0,.25); }
  :root { --lane-w: 150px; --gutter-w: 72px; }
}

/* ---------- home page ---------- */
#home { min-height: 100%; max-width: 1100px; margin: 0 auto; padding: 40px 24px; }
.home-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 20px; border-bottom: 2px solid var(--text); }
.home-head h1 { margin: 0; font-size: 26px; letter-spacing: -.01em; }
#projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-top: 24px; }
.card {
  border: 1px solid var(--line-strong); border-radius: 10px; padding: 16px; background: var(--surface);
  cursor: pointer; display: flex; flex-direction: column; gap: 6px; min-height: 150px; text-align: left;
}
.card:hover { border-color: var(--text); box-shadow: 4px 4px 0 var(--text); }
.card-colors { display: flex; gap: 3px; height: 6px; margin-bottom: 6px; }
.card-colors i { flex: 1; max-width: 28px; border-radius: 3px; }
.card-name { font-size: 17px; font-weight: 650; color: var(--text); text-decoration: none; }
.card .progress { margin: auto 0 0; }
.card .progress div { background: var(--text); }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; }
.link { border: 0; background: none; cursor: pointer; padding: 2px 6px; color: var(--muted); text-decoration: underline; }
.link:hover { color: var(--text); }
.link.danger:hover { color: #c2453f; }
.card.new { align-items: center; justify-content: center; border-style: dashed; color: var(--muted); font-weight: 600; }
.card.new b { font-size: 28px; font-weight: 400; line-height: 1; }
.card.new:hover { color: var(--text); }
.center { min-height: 100%; display: grid; place-items: center; padding: 24px; text-align: center; }
.center h1 { margin: 0 0 16px; font-size: 24px; }
#gateForm { display: flex; flex-direction: column; gap: 8px; width: min(300px, 100%); text-align: left; }
#gateForm h1 { text-align: center; }
#gateForm input { height: 36px; border: 1px solid var(--line-strong); border-radius: 7px; padding: 0 10px; }
#gateForm input:focus { outline: 2px solid var(--text); outline-offset: 1px; }
#gateForm .btn { height: 36px; }
.err { color: var(--today); margin: 0; }
