:root {
  --bg: #ffffff;
  --surface: #f9f9fb;
  --surface-2: #f3f3f6;
  --border: #e8e8ec;
  --text: #1e1f21;
  --muted: #6d6e6f;
  --faint: #a2a0a2;          /* icons and borders only, never text */
  --accent: #4573d2;
  --accent-hover: #3a63b8;
  --on-accent: #ffffff;
  --focus: #2f5fc4;
  --ok: #1a7a43;
  --late: #c92f54;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1f21;
    --surface: #252628;
    --surface-2: #2e2f31;
    --border: #3a3b3d;
    --text: #f5f4f3;
    --muted: #a2a0a2;
    --faint: #6d6e6f;
    --accent: #6a94e6;
    --accent-hover: #82a6ec;
    --on-accent: #111214;
    --focus: #8fb0f0;
    --ok: #4fc183;
    --late: #f06a8a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-family: var(--font); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app { max-width: 1080px; margin: 0 auto; padding: 32px 24px 64px; }

/* Header */
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.title { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -.015em; overflow-wrap: anywhere; }
.top-right { display: flex; align-items: center; gap: 12px; }
.meta { margin: 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meta b { color: var(--text); font-weight: 600; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); font-size: 13px; font-weight: 500; text-decoration: none; color: var(--text); cursor: pointer; box-shadow: var(--shadow); transition: background .12s ease, border-color .12s ease; }
.btn svg { width: 14px; height: 14px; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn[disabled] { opacity: .6; cursor: default; }
#refresh.is-spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Banner */
.banner { margin: 16px 0 0; padding: 10px 14px; border-radius: var(--radius); background: rgba(201, 47, 84, .08); color: var(--late); font-size: 13px; }

/* List */
.list { margin-top: 4px; }
.colhead { display: grid; grid-template-columns: 1fr 132px; gap: 12px; padding: 10px 16px 10px 58px; font-size: 12px; font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--border); }

.group { border-bottom: 1px solid var(--border); }
.ghead-h { margin: 0; font: inherit; }
.rows { list-style: none; margin: 0; padding: 0; }
.ghead { display: flex; align-items: center; gap: 10px; width: 100%; padding: 16px 12px 10px; background: none; border: 0; text-align: left; cursor: pointer; }
.chev { width: 16px; height: 16px; flex: none; color: var(--muted); transition: transform .15s ease; }
.group.is-collapsed .chev { transform: rotate(-90deg); }
.group.is-collapsed .rows { display: none; }
.group[data-special="blocked"].has-tasks .ghead .count { color: var(--late); font-weight: 600; }
.count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.pill { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 6px; font-size: 13px; font-weight: 500; white-space: nowrap; background: var(--surface-2); color: var(--text); }
.pill[data-tone="blocked"] { background: #fde2e4; color: #b3261e; }
.pill[data-tone="progress"] { background: var(--surface-2); color: var(--muted); }
.pill[data-tone="0"] { background: #dbe7fd; color: #2556b8; }
.pill[data-tone="1"] { background: #fde9c8; color: #8f5200; }
.pill[data-tone="2"] { background: #ece0fb; color: #6e35b8; }
.pill[data-tone="3"] { background: #fbdcec; color: #a42c6b; }
.pill[data-tone="4"] { background: #fbdede; color: #ad2f2f; }
.pill[data-tone="5"] { background: #d6f2e1; color: #19733f; }
@media (prefers-color-scheme: dark) {
  .pill[data-tone="blocked"] { background: rgba(240, 90, 90, .22); color: #f5a5a5; }
  .pill[data-tone="0"] { background: rgba(106, 148, 230, .2); color: #9dbbf3; }
  .pill[data-tone="1"] { background: rgba(240, 166, 50, .2); color: #f3c27a; }
  .pill[data-tone="2"] { background: rgba(168, 112, 240, .2); color: #c9a6f6; }
  .pill[data-tone="3"] { background: rgba(236, 92, 160, .2); color: #f3a0c8; }
  .pill[data-tone="4"] { background: rgba(236, 92, 92, .2); color: #f3a3a3; }
  .pill[data-tone="5"] { background: rgba(79, 193, 131, .2); color: #8fdcb1; }
}

.rows { padding-bottom: 8px; }
.row { border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.rowbtn { display: grid; grid-template-columns: 20px 1fr 132px; gap: 12px; align-items: center; width: 100%; min-height: 40px; padding: 8px 16px 8px 26px; background: none; border: 0; text-align: left; cursor: pointer; }
.rowbtn:hover { background: var(--surface); }
.row.is-open .rowbtn { background: var(--surface); }
.check { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--faint); display: inline-flex; align-items: center; justify-content: center; color: var(--faint); }
.check svg { width: 10px; height: 10px; }
.row.is-done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.is-done .name { color: var(--muted); }
.row.is-open .name { white-space: normal; }
.due { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.due.is-late { color: var(--late); }
.due.is-today { color: var(--ok); font-weight: 500; }
.empty { padding: 6px 16px 14px 58px; font-size: 13px; color: var(--muted); }

/* Detail */
.detail { padding: 6px 20px 20px 58px; background: var(--surface); border-top: 1px solid var(--border); }
.fields { display: grid; grid-template-columns: 110px 1fr; gap: 10px 16px; margin: 12px 0 18px; font-size: 13px; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; }
.status { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.dot[data-s="assigned to client"] { background: var(--accent); }
.dot[data-s="valerian reviewing"] { background: #e8a23a; }
.dot[data-s="complete"] { background: var(--ok); }
.desc-label { margin: 0 0 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
.fields dd, .fields dt { line-height: 1.5; }
.desc { white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.55; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; max-height: 360px; overflow: auto; }
.desc a { color: var(--accent); }
.desc.is-empty { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* Focus and screen-reader helpers */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.rowbtn:focus-visible, .ghead:focus-visible { outline-offset: -2px; }
#groups:focus { outline: none; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 12px; top: -48px; z-index: 20; padding: 8px 12px; border-radius: 6px; background: var(--bg); color: var(--text); border: 1px solid var(--border); text-decoration: none; font-weight: 500; }
.skip:focus { top: 12px; }
@media (forced-colors: active) {
  .pill, .btn, .check { border: 1px solid CanvasText; }
  .row.is-done .check { background: CanvasText; }
}

/* Loading */
.skeleton-group { display: flex; flex-direction: column; gap: 10px; padding: 18px 12px; border-bottom: 1px solid var(--border); }
.sk { display: block; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s ease-in-out infinite; }
.sk-pill { width: 140px; height: 24px; }
.sk-row { height: 18px; margin-left: 32px; max-width: 520px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 10px 16px; border-radius: 8px; background: #1e1f21; color: #fff; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.18); z-index: 10; }
.toast.is-error { background: var(--late); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 560px) {
  .app { padding: 20px 14px 48px; }
  .colhead { display: none; }
  .rowbtn { grid-template-columns: 20px 1fr 76px; padding-left: 12px; }
  .detail { padding-left: 16px; padding-right: 16px; }
  .fields { grid-template-columns: 88px 1fr; }
  .empty { padding-left: 16px; }
}
