/* Rm - Soft UI, light gray + dark. Semantic tokens only; lane color comes in as --c on each card. */
:root,
:root[data-theme="light"] {
  --bg: #eceef1;
  --surface: #ffffff;
  --surface-2: #f5f6f8;
  --surface-3: #e9ecf0;
  --border: #d9dde3;
  --border-strong: #c3c9d1;
  --grid: #eceef1;
  --grid-major: #d9dde3;
  --text: #1d2229;
  --muted: #5b6573;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --on-primary: #ffffff;
  --primary-soft: #e3ecfd;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --today: #e5484d;
  --overload: rgba(229, 72, 77, .09);
  --overload-text: #b42318;
  --done-bg: #e6e8ec;
  --done-border: #d3d7dd;
  --done-text: #7a8390;
  --card-mix: 22%;
  --card-border-mix: 55%;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, .12), 0 2px 6px rgba(16, 24, 40, .06);
  --scrim: rgba(15, 23, 42, .18);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #101317;
  --surface: #171b21;
  --surface-2: #1d222a;
  --surface-3: #252b34;
  --border: #2c333d;
  --border-strong: #3a434f;
  --grid: #1f242b;
  --grid-major: #2c333d;
  --text: #e7eaee;
  --muted: #9aa4b1;
  --primary: #5b8cff;
  --primary-hover: #7aa2ff;
  --on-primary: #0b1020;
  --primary-soft: #1d2a45;
  --danger: #ff7b72;
  --danger-soft: #3a1d1d;
  --today: #ff5c61;
  --overload: rgba(255, 92, 97, .1);
  --overload-text: #ff8a8e;
  --done-bg: #242930;
  --done-border: #313843;
  --done-text: #808a97;
  --card-mix: 26%;
  --card-border-mix: 60%;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .35);
  --scrim: rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg.ic { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- controls ---------- */
.btn, .seg button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 9px; cursor: pointer; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  box-shadow: var(--shadow-sm); transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn.icon { width: 34px; padding: 0; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { background: transparent; box-shadow: none; border-color: transparent; color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn:disabled { opacity: .45; cursor: default; }

.seg { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { height: 28px; border: none; background: transparent; box-shadow: none; color: var(--muted); padding: 0 11px; border-radius: 7px; font-weight: 500; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.seg button.icon { width: 28px; padding: 0; }
.seg.year #yearLabel { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; min-width: 56px; }

input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; min-width: 0; color: var(--text);
}
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
select { cursor: pointer; }
.muted { color: var(--muted); font-size: 12.5px; margin: 0 0 10px; }

.switch { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); cursor: pointer; user-select: none; font-size: 13px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 28px; height: 16px; border-radius: 99px; background: var(--border-strong); position: relative; transition: background .15s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(12px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- layout ---------- */
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand {
  font-weight: 800; font-size: 16px; letter-spacing: -.3px; color: var(--on-primary);
  background: var(--primary); border-radius: 9px; height: 34px; padding: 0 11px; display: grid; place-items: center; margin-right: 4px;
}
.spacer { flex: 1; }
.search { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 0 10px; height: 34px; color: var(--muted); }
.search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search input { border: none; background: transparent; padding: 0; width: 170px; box-shadow: none !important; }
.badge-host { position: relative; }
.count:not(:empty) { position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 99px; background: var(--today); color: #fff; font-size: 10.5px; display: grid; place-items: center; font-weight: 700; }

.subbar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.legend { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; min-width: 200px; }
.opts { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.opts select { height: 30px; padding: 0 8px; font-size: 13px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 99px; cursor: pointer; user-select: none;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 12.5px; transition: background .15s, border-color .15s, opacity .15s;
}
.chip:hover { border-color: var(--border-strong); }
.chip i { width: 8px; height: 8px; border-radius: 50%; }
.chip small { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.on { background: var(--primary-soft); border-color: var(--primary); }
.chip.off { opacity: .4; text-decoration: line-through; }

.selbar { display: flex; align-items: center; gap: 8px; padding: 7px 16px; background: var(--primary-soft); border-bottom: 1px solid var(--primary); }
.selbar span { color: var(--primary); font-weight: 600; margin-right: 6px; }

#timeline { flex: 1; min-height: 0; overflow: hidden; background: var(--surface); }
.hintbar { padding: 5px 16px; font-size: 11.5px; color: var(--muted); background: var(--surface); border-top: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- vis-timeline theming ---------- */
.vis-timeline { border: none !important; font-family: inherit; color: var(--text); }
.vis-panel.vis-center, .vis-panel.vis-left, .vis-panel.vis-right, .vis-panel.vis-top, .vis-panel.vis-bottom { border-color: var(--border) !important; }
.vis-panel.vis-top, .vis-panel.vis-bottom { background: var(--surface-2); }
.vis-panel.vis-left { background: var(--surface); }
.vis-time-axis .vis-text { color: var(--muted); font-size: 12px; }
.vis-time-axis .vis-text.vis-major { color: var(--text); font-weight: 700; font-size: 12.5px; }
.vis-time-axis .vis-grid.vis-minor { border-color: var(--grid); }
.vis-time-axis .vis-grid.vis-major { border-color: var(--grid-major); }
.vis-labelset .vis-label { color: var(--text) !important; border-bottom-color: var(--border) !important; }
.vis-foreground .vis-group { border-bottom-color: var(--border) !important; }
.vis-current-time { background: var(--today); width: 2px; z-index: 3; }
.vis-tooltip { background: var(--surface) !important; color: var(--text) !important; border: 1px solid var(--border) !important; border-radius: 8px !important; box-shadow: var(--shadow-md) !important; font-family: inherit !important; font-size: 12.5px !important; padding: 7px 10px !important; }

.lane-label { display: flex; align-items: center; gap: 9px; padding: 0 14px 0 10px; min-width: 128px; }
.lane-label i { width: 4px; height: 30px; border-radius: 3px; }
.lane-label b { display: block; font-weight: 600; font-size: 13.5px; }
.lane-label small { display: block; color: var(--muted); font-size: 11.5px; }

.vis-item.card {
  --fill: color-mix(in srgb, var(--c) var(--card-mix), var(--surface));
  background: var(--fill); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--c) var(--card-border-mix), var(--surface));
  border-radius: 7px; font-size: 12.5px; line-height: 1.25;
  box-shadow: inset 3px 0 0 var(--c), var(--shadow-sm);
  transition: opacity .15s, box-shadow .15s;
}
.vis-item.card .vis-item-overflow { overflow: hidden; }
.vis-item.card .vis-item-content { padding: 4px 8px 4px 10px; width: 100%; }
.vis-item.card .p { display: flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.vis-item.card .p i { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.vis-item.card .t { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vis-item.card .who { font-size: 10.5px; color: var(--muted); }
.vis-item.card.st-work { --fill: color-mix(in srgb, var(--c) calc(var(--card-mix) + 14%), var(--surface)); }
.vis-item.card.st-hold { background-image: repeating-linear-gradient(135deg, color-mix(in srgb, var(--c) 30%, transparent) 0 5px, transparent 5px 11px); }
.vis-item.card.st-done {
  background: var(--done-bg); border-color: var(--done-border); color: var(--done-text);
  box-shadow: inset 3px 0 0 var(--done-border);
}
.vis-item.card.st-done .t { font-weight: 500; }
.vis-item.card.st-done .p i { filter: grayscale(1); opacity: .6; }
.vis-item.card.dim { opacity: .18; }
.vis-timeline .vis-item.card.vis-selected {   /* beat vis default yellow selection */
  background: var(--fill); border-color: color-mix(in srgb, var(--c) var(--card-border-mix), var(--surface));
  outline: 2px solid var(--primary); outline-offset: 1px; z-index: 5;
}
.vis-timeline .vis-item.card.st-done.vis-selected { background: var(--done-bg); border-color: var(--done-border); }
.vis-item.card.dep-hl { outline: 2px dashed var(--primary); outline-offset: 1px; }
.vis-item .badge { position: absolute; right: 4px; top: 3px; background: var(--text); color: var(--surface); border-radius: 5px; padding: 0 5px; font-size: 10px; font-weight: 700; }
.vis-item .badge.early { background: #16a34a; color: #fff; }
.vis-item.vis-background.overload { background: var(--overload); }
.vis-item.vis-background.overload .vis-item-content { color: var(--overload-text); font-size: 10.5px; font-weight: 700; padding: 2px 5px; }
body.alt-held .vis-item.card { cursor: copy; }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 400px; max-width: 100vw;
  background: var(--surface); border-left: 1px solid var(--border); padding: 18px 20px 24px; overflow-y: auto; z-index: 50;
  box-shadow: var(--shadow-md); animation: slide-in .2s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer h2 { margin: 2px 0 14px; font-size: 18px; letter-spacing: -.2px; }
.drawer h3 { margin: 22px 0 6px; font-size: 15px; }
.drawer .close { position: absolute; top: 12px; right: 12px; box-shadow: none; border-color: transparent; }
.drawer form { display: flex; flex-direction: column; gap: 12px; }
.drawer label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 12.5px; font-weight: 500; }
.drawer label > input, .drawer label > select, .drawer label > textarea { color: var(--text); font-size: 14px; font-weight: 400; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.actions #itemDelete { margin-left: auto; }

.deps-box { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px 10px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.deps-box legend { color: var(--muted); font-size: 12.5px; font-weight: 500; padding: 0 4px; }
.deps { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
.deps:empty { display: none; }
.deps div { display: flex; justify-content: space-between; gap: 6px; align-items: center; background: var(--surface-2); border-radius: 7px; padding: 4px 4px 4px 9px; }
.deps .lbl { color: var(--muted); }
.dep-add { display: flex; gap: 6px; }
.dep-add select { flex: 1; font-size: 13px; }

.plist { display: flex; flex-direction: column; gap: 6px; }
.prow { display: grid; grid-template-columns: 30px 1fr auto; gap: 6px; align-items: center; }
.prow.lane { grid-template-columns: 30px 1fr 62px auto; }
.prow input[type="color"] { width: 30px; height: 30px; padding: 2px; border-radius: 8px; cursor: pointer; }
.prow input[type="text"], .prow input[type="number"] { height: 32px; padding: 0 8px; }
.prow .tools { display: flex; gap: 2px; }
.prow .tools .btn { width: 28px; height: 28px; box-shadow: none; border-color: transparent; background: transparent; color: var(--muted); }
.prow .tools .btn:hover { background: var(--surface-3); color: var(--text); }
.prow .tools .btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.prow small { grid-column: 2 / -1; color: var(--muted); font-size: 11.5px; margin-top: -4px; }
.add-row { display: flex !important; flex-direction: row !important; gap: 6px; margin-top: 10px; }
.add-row input { flex: 1; height: 32px; }

.hist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.hist li { background: var(--surface-2); border-radius: 10px; padding: 9px 11px; border-left: 3px solid var(--border-strong); }
.hist li.agent { border-left-color: var(--primary); }
.hist li.undone { opacity: .5; text-decoration: line-through; }
.hist .meta { color: var(--muted); font-size: 11.5px; margin-bottom: 3px; }
.hist .reason { color: var(--primary); font-size: 12.5px; margin-bottom: 3px; font-weight: 500; }
.hist .ln { font-size: 12.5px; }

.prop { background: var(--surface-2); border-radius: 12px; padding: 11px 13px; margin-bottom: 10px; border: 1px solid var(--border); }
.prop.pending { border-color: var(--primary); background: var(--primary-soft); }
.prop .meta { color: var(--muted); font-size: 11.5px; }
.prop .reason { margin: 4px 0 6px; font-weight: 600; }
.prop ul { margin: 0 0 10px; padding-left: 16px; font-size: 12.5px; }

.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); z-index: 99; max-width: min(720px, 90vw);
  background: var(--text); color: var(--surface); border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow-md);
  display: flex; align-items: center; gap: 12px; font-size: 13px;
}
.toast.err { background: var(--danger); color: #fff; }
.toast button { background: transparent; border: 1px solid currentColor; color: inherit; border-radius: 7px; padding: 3px 10px; cursor: pointer; font-weight: 600; }

@media (max-width: 900px) {
  .search input { width: 110px; }
  .hintbar { display: none; }
}
@media (max-width: 640px) {
  .topbar { gap: 6px; padding: 8px 10px; }
  #openProjects, #today { padding: 0 8px; }
  .drawer { width: 100vw; }
}
