:root {
  --bg: #1d2027;
  --sidebar: #1a1c22;
  --card: #262a33;
  --card-head: #232730;
  --line: #343946;
  --hover: #2d323d;
  --active: #333947;
  --text: #e7e9ee;
  --muted: #98a0ae;
  --faint: #6b7280;
  --accent: #4aa3f0;
  --brand: #4f63ff;
  --danger: #e5636b;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", "Source Sans 3", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 220px;
  flex: none;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 12px 16px 20px; }
.brand .logo { width: 22px; height: 26px; color: var(--brand); }
.brand .logo path { fill: currentColor; stroke: none; }
.brand b { display: block; font-size: 16px; }
.brand small { color: var(--muted); font-size: 13px; }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  width: calc(100% - 12px); margin: 0 6px; padding: 6px 8px;
  border-radius: 6px; color: var(--muted); text-align: left;
  position: relative;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--active); color: var(--text); }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .badge { font-size: 11px; color: var(--faint); }
.nav-item .more { opacity: 0; padding: 0 2px; color: var(--muted); }
.nav-item:hover .more { opacity: 1; }
.nav-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin: 0 4px; }
.nav-head {
  display: flex; align-items: center; gap: 6px;
  padding: 22px 16px 6px; font-size: 11px; font-weight: 700; letter-spacing: .04em; color: var(--muted);
}
.nav-head span { flex: 1; }
.nav-head button { color: var(--muted); }
.nav-head button:hover { color: var(--text); }
.sidebar-foot {
  margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--line);
  display: flex; gap: 12px; align-items: center; font-size: 12px; color: var(--faint);
}
.sidebar-foot button, .sidebar-foot a { color: var(--muted); text-decoration: none; white-space: nowrap; }
.sidebar-foot button:hover, .sidebar-foot a:hover { color: var(--text); }
.save-state { margin-left: auto; }
.save-state.error { color: var(--danger); }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 20px 8px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5; background: var(--bg);
}
.titlebar { flex: 1; min-width: 0; }
.page-title {
  font-size: 17px; font-weight: 700; border: 0; background: transparent; padding: 2px 4px; margin-left: -4px;
  border-radius: 4px; width: 100%; max-width: 520px; outline: none;
}
.page-title:hover { background: var(--hover); }
.page-title:focus { background: var(--card); }
.page-title[readonly] { pointer-events: none; }
.page-sub { display: flex; gap: 14px; color: var(--muted); font-size: 13px; margin-top: 2px; align-items: center; }
.page-sub button { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.page-sub button:hover { color: var(--text); }
.page-sub svg { width: 13px; height: 13px; }
.search {
  display: flex; align-items: center; gap: 6px; width: 240px;
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; color: var(--faint);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; }
.search kbd { font: 11px inherit; color: var(--faint); }
.icon-btn { display: none; color: var(--muted); padding: 4px; }
.content { padding: 16px 20px 80px; }

/* ---------- Sections ---------- */
.sec {
  background: var(--card); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden;
  border: 1px solid transparent;
}
.sec.drop-into { border-color: var(--accent); }
.sec-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 10px 16px; }
.sec-icon {
  width: 24px; height: 24px; border-radius: 5px; background: var(--c);
  display: grid; place-items: center; color: #1b1f27;
}
.sec-icon svg { width: 14px; height: 14px; stroke-width: 2.2; }
.sec-title {
  font-size: 16px; font-weight: 700; background: transparent; border: 0; outline: none;
  padding: 2px 4px; border-radius: 4px; min-width: 60px; flex: 0 1 auto; field-sizing: content;
}
.sec-title:hover { background: var(--hover); }
.sec-title:focus { background: var(--bg); }
.sec-title[readonly] { pointer-events: none; }
.sec-count { color: var(--faint); font-size: 12px; }
.sec-tools { margin-left: auto; display: flex; gap: 4px; }
.sec-tools button { color: var(--muted); padding: 4px 6px; border-radius: 4px; }
.sec-tools button:hover { background: var(--hover); color: var(--text); }
.sec-tools button.on { color: var(--accent); }
.sec.collapsed .grid, .sec.collapsed .add-row { display: none; }
.sec.collapsed .chev { transform: rotate(-90deg); }

.grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.grid th {
  text-align: left; font-weight: 700; color: var(--muted); background: var(--card-head);
  padding: 10px 8px; border-bottom: 1px solid var(--line);
}
.grid th + th, .grid td + td:not(.c-del) { border-left: 1px solid var(--line); }
.grid td { border-bottom: 1px solid var(--line); padding: 0; height: 36px; }
.grid tr:hover td { background: var(--hover); }
.grid tr.dragging { opacity: .4; }
.grid tr.drop-before td { box-shadow: inset 0 2px 0 var(--accent); }
.grid tr.drop-after td { box-shadow: inset 0 -2px 0 var(--accent); }
.c-handle { width: 32px; }
.c-owner { width: 110px; }
.c-status { width: 150px; }
.c-comment { width: 28%; }
.c-del { width: 36px; }
th.c-owner, th.c-status { text-align: left; }
td.handle { color: var(--faint); text-align: center; cursor: grab; opacity: 0; }
tr:hover td.handle { opacity: 1; }
.cell {
  width: 100%; height: 36px; background: transparent; border: 0; outline: none; padding: 0 8px;
  text-overflow: ellipsis;
}
.cell:focus { background: var(--bg); box-shadow: inset 0 0 0 1px var(--accent); }
.cell::placeholder { color: var(--faint); }
.where { color: var(--faint); font-size: 12px; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

td.owner { text-align: center; cursor: pointer; }
.avatar {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--c); color: #fff; font-size: 11px; font-weight: 700; vertical-align: middle;
}
.avatar.empty { background: none; color: var(--faint); }
td.status-cell { padding: 2px; }
.status {
  width: 100%; height: 30px; border-radius: 3px; background: var(--c); color: #1b1f27;
  font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px;
}
.status.empty { background: transparent; color: var(--faint); border: 1px dashed var(--line); }
.status:hover { filter: brightness(1.08); }
.row-del { color: var(--faint); opacity: 0; width: 100%; height: 36px; }
tr:hover .row-del { opacity: 1; }
.row-del:hover { color: var(--danger); }

.add-row {
  display: flex; align-items: center; gap: 6px; padding: 12px 16px 14px 48px; color: var(--text); width: 100%;
}
.add-row:hover { color: var(--accent); }
.add-section {
  display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%;
  padding: 14px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted);
}
.add-section:hover { color: var(--text); border-color: var(--muted); }

.empty-state { text-align: center; color: var(--muted); padding: 80px 20px; }
.empty-state h2 { color: var(--text); margin: 0 0 8px; }
.empty-state button {
  margin-top: 16px; background: var(--brand); color: #fff; padding: 8px 16px; border-radius: 6px; font-weight: 600;
}

/* ---------- Popover menu ---------- */
.menu {
  position: fixed; z-index: 50; min-width: 180px; max-height: 70vh; overflow-y: auto;
  background: #2b303b; border: 1px solid var(--line); border-radius: 8px; padding: 4px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 10px; border-radius: 5px; text-align: left;
}
.menu button:hover, .menu button:focus-visible { background: var(--active); outline: none; }
.menu button.danger { color: var(--danger); }
.menu button.checked::after { content: "✓"; margin-left: auto; color: var(--accent); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu .swatch { width: 14px; height: 14px; border-radius: 3px; background: var(--c); }
.menu .swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; padding: 6px; }
.menu .swatches button { width: 20px; height: 20px; padding: 0; border-radius: 4px; background: var(--c); }
.menu .swatches button:hover { outline: 2px solid var(--text); background: var(--c); }

.scrim { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 800px) {
  .sidebar { position: fixed; left: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.5); }
  .icon-btn { display: block; }
  .topbar { padding: 8px 12px; }
  .search { width: 140px; }
  .search kbd { display: none; }
  .content { padding: 12px 8px 60px; }
  .c-handle, td.handle, th.c-handle { display: none; }
  .c-owner { width: 52px; }
  .c-status { width: 108px; }
  .c-comment { display: none; }
  .grid td.comment-cell, .grid th.c-comment { display: none; }
  .add-row { padding-left: 16px; }
  .sec-count { display: none; }
}

/* No dividers next to the hover-only handle/delete columns */
.grid th.c-handle + th, .grid td.handle + td, .grid th.c-del { border-left: 0; }

/* ---------- Task cell: open button + detail indicators ---------- */
.task-cell { position: relative; }
.task-cell .cell { padding-right: 120px; }
.task-meta {
  position: absolute; right: 8px; top: 0; bottom: 0; display: flex; align-items: center; gap: 4px;
  color: var(--faint); font-size: 12px; cursor: pointer;
}
.task-meta svg { width: 14px; height: 14px; }
.open-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  display: none; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 4px;
  background: var(--card); border: 1px solid var(--line); color: var(--muted); font-size: 12px;
}
.open-btn svg { width: 12px; height: 12px; }
.open-btn:hover { color: var(--text); border-color: var(--muted); }
tr:hover .open-btn { display: inline-flex; }
tr:hover .task-meta { display: none; }
.grid tr.is-open td { background: var(--active); }

/* ---------- Task detail panel ---------- */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 20; width: min(600px, 100vw);
  background: var(--card); border-left: 1px solid var(--line); box-shadow: -12px 0 40px rgba(0,0,0,.35);
  display: flex; flex-direction: column; transform: translateX(100%); transition: transform .18s ease;
}
body.panel-open .panel { transform: none; }
.panel.drag-over { box-shadow: inset 0 0 0 2px var(--accent), -12px 0 40px rgba(0,0,0,.35); }
.panel-head {
  display: flex; align-items: center; gap: 6px; padding: 10px 12px 10px 20px; border-bottom: 1px solid var(--line);
}
.crumb { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sec-icon.mini { width: 18px; height: 18px; border-radius: 4px; flex: none; }
.sec-icon.mini svg { width: 11px; height: 11px; }
.panel-head .icon { color: var(--muted); padding: 6px; border-radius: 5px; }
.panel-head .icon:hover { background: var(--hover); color: var(--text); }
.panel-head .icon[data-act="panel-delete"]:hover { color: var(--danger); }
.panel-body { flex: 1; overflow-y: auto; padding: 18px 24px 40px; }
.panel textarea { font-size: inherit; display: block; width: 100%; resize: none; background: transparent; border: 0; outline: none; color: inherit; font-family: inherit; overflow: hidden; }
.panel .panel-title { font-size: 22px; font-weight: 700; line-height: 1.3; padding: 4px 6px; margin: 0 -6px 12px; border-radius: 5px; }
.panel-title:hover { background: var(--hover); }
.panel-title:focus { background: var(--bg); }
.props { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; align-items: center; margin: 0 0 24px; }
.props dt { color: var(--muted); }
.props dd { margin: 0; min-height: 32px; display: flex; align-items: center; }
.props .status { width: auto; min-width: 150px; }
.prop-btn { display: inline-flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; margin-left: -4px; border-radius: 5px; }
.prop-btn:hover { background: var(--hover); }
.prop-input { width: 100%; background: transparent; border: 0; outline: none; padding: 6px 8px; margin-left: -8px; border-radius: 5px; }
.prop-input:hover { background: var(--hover); }
.prop-input:focus { background: var(--bg); box-shadow: inset 0 0 0 1px var(--accent); }
.prop-input::placeholder, .notes::placeholder, .panel-title::placeholder { color: var(--faint); }
.muted { color: var(--faint); font-weight: 400; }
.panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
.notes {
  min-height: 140px; line-height: 1.55; padding: 10px 12px; margin-bottom: 24px;
  background: var(--bg) !important; border: 1px solid var(--line) !important; border-radius: 6px;
}
.notes:focus { border-color: var(--accent) !important; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.thumb {
  position: relative; margin: 0; aspect-ratio: 4 / 3; border-radius: 6px; overflow: hidden; cursor: zoom-in;
  background: var(--bg); border: 1px solid var(--line);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:hover { border-color: var(--muted); }
.thumb-del {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%;
  display: none; place-items: center; background: rgba(0,0,0,.7); color: #fff;
}
.thumb-del svg { width: 12px; height: 12px; }
.thumb:hover .thumb-del { display: grid; }
.thumb-del:hover { background: var(--danger); }
.dropzone {
  aspect-ratio: 4 / 3; border: 1px dashed var(--line); border-radius: 6px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 10px; font-size: 12px; text-align: center;
}
.dropzone svg { width: 22px; height: 22px; }
.dropzone:hover, .panel.drag-over .dropzone { border-color: var(--accent); color: var(--text); }
.gallery:not(:has(.thumb)) .dropzone { aspect-ratio: auto; grid-column: 1 / -1; padding: 28px; }

/* ---------- Lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; }
.lightbox[hidden] { display: none; }
.lb-backdrop { position: absolute; inset: 0; background: rgba(8,9,12,.92); }
.lightbox img { position: relative; max-width: calc(100vw - 120px); max-height: calc(100vh - 110px); border-radius: 4px; box-shadow: 0 10px 50px rgba(0,0,0,.6); }
.lb-bar {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 16px;
  padding: 12px 16px; color: var(--text); font-size: 13px;
}
.lb-bar span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-bar a { color: var(--accent); text-decoration: none; }
.lb-bar button { padding: 6px; border-radius: 5px; }
.lb-bar button:hover { background: rgba(255,255,255,.1); }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(255,255,255,.08); color: #fff;
}
.lb-nav:hover { background: rgba(255,255,255,.18); }
.lb-nav svg { width: 22px; height: 22px; }
.lb-nav.prev { left: 16px; }
.lb-nav.next { right: 16px; }

@media (max-width: 800px) {
  .task-cell .cell { padding-right: 50px; }
  .open-btn { font-size: 0; gap: 0; padding: 5px; }
  .panel-body { padding: 14px 16px 40px; }
  .props { grid-template-columns: 90px 1fr; }
  .lightbox img { max-width: calc(100vw - 24px); }
  .lb-nav { top: auto; bottom: 16px; transform: none; }
}

/* ---------- Login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login {
  width: min(340px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 32px 28px; display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login .logo { width: 30px; height: 36px; margin: 0 auto; color: var(--brand); }
.login .logo path { fill: currentColor; stroke: none; }
.login h1 { font-size: 18px; margin: 0 0 8px; }
.login input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; outline: none;
}
.login input:focus { border-color: var(--accent); }
.login button { background: var(--brand); color: #fff; padding: 10px; border-radius: 6px; font-weight: 600; }
.login button:hover { filter: brightness(1.1); }
.login-error { color: var(--danger); margin: 0; font-size: 13px; }

/* ---------- Timeline ---------- */
.tl { position: relative; border-top: 1px solid var(--line); --tl-line: rgba(255,255,255,.045); --tl-weekend: rgba(0,0,0,.18); }
.tl-tools {
  position: absolute; top: 3px; right: 12px; z-index: 4; display: flex; gap: 6px; align-items: center;
  background: var(--card); padding-left: 8px;
}
.tl-btn, .tl-group button {
  display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 5px; color: var(--text); font-size: 13px;
}
.tl-btn svg { width: 13px; height: 13px; }
.tl-btn:hover, .tl-group button:hover { background: var(--hover); }
.tl-group { display: flex; }
.tl-group button { border-radius: 0; padding: 0 8px; gap: 0; }
.tl-group button + button { border-left: 0; }
.tl-group button:first-child { border-radius: 5px 0 0 5px; }
.tl-group button:last-child { border-radius: 0 5px 5px 0; }
.tl-group svg { width: 13px; height: 13px; }
.tl-group svg + svg { margin-left: -7px; }

.tl-scroll { overflow-x: auto; overflow-y: hidden; }
.tl-inner { position: relative; }
.tl-months { position: relative; height: 34px; }
.tl-month { position: absolute; top: 0; bottom: 0; }
.tl-month span { position: sticky; left: 0; display: inline-block; padding: 8px 16px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.tl-month b { color: var(--text); }
.tl-days { display: flex; border-bottom: 1px solid var(--line); }
.tl-day { flex: none; width: var(--w); text-align: center; padding: 3px 0 4px; font-size: 12px; line-height: 1.25; min-height: 34px; }
.tl-day small { display: block; font-size: 9px; color: var(--faint); }
.tl-day.we { color: var(--faint); background: var(--tl-weekend); }
.tl-day.today b { background: var(--accent); color: #fff; border-radius: 4px; padding: 0 4px; }

.tl-canvas {
  position: relative; user-select: none; -webkit-user-select: none;
  background-image:
    repeating-linear-gradient(to right, transparent 0 calc(var(--w) * 5), var(--tl-weekend) calc(var(--w) * 5) calc(var(--w) * 7)),
    repeating-linear-gradient(to right, var(--tl-line) 0 1px, transparent 1px var(--w));
}
.tl-now { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--accent); opacity: .55; pointer-events: none; }

.tl-block {
  position: absolute; height: 50px; border-radius: 3px; background: var(--c); cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); touch-action: pan-x pan-y;
}
.tl-block:hover { filter: brightness(1.07); }
.tl-block.dragging { cursor: grabbing; z-index: 3; box-shadow: 0 8px 22px rgba(0,0,0,.45); }
.tl-block.preview { opacity: .8; pointer-events: none; }
.tl-block.is-open { box-shadow: 0 0 0 2px var(--text); }
/* The label sticks to the left edge while a long block is scrolled past. */
.tl-label { position: sticky; left: 0; display: inline-block; max-width: 100%; padding: 7px 11px; pointer-events: none; }
.tl-label b, .tl-label small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-label b { font-size: 13px; }
.tl-label small { font-size: 11px; opacity: .85; margin-top: 2px; }
.tl-h { position: absolute; top: 0; bottom: 0; width: 8px; cursor: ew-resize; z-index: 1; }
.tl-h.l { left: -2px; }
.tl-h.r { right: -2px; }
.tl-canvas { cursor: crosshair; }
.tl-block { cursor: grab; }

/* ---------- Block editor (side panel) ---------- */
.date-range { gap: 6px; }
.date-range .prop-input { width: auto; margin-left: 0; color-scheme: dark; }
.date-range .prop-input:first-child { margin-left: -8px; }
.color-row { gap: 6px; flex-wrap: wrap; }
.color-dot { width: 22px; height: 22px; border-radius: 5px; background: var(--c); }
.color-dot:hover { outline: 2px solid var(--muted); outline-offset: 1px; }
.color-dot.on { outline: 2px solid var(--text); outline-offset: 1px; }

@media (max-width: 800px) {
  .tl-tools { position: static; flex-wrap: wrap; padding: 8px 12px 4px; }
}
.sec > .tl { border-top: 0; }
