:root {
  --bg: #08090a;
  --bg-side: #0e0f10;
  --bg-elev: #141516;
  --bg-elev2: #1b1c1e;
  --bg-hover: rgba(255, 255, 255, 0.04);
  --bg-active: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #f7f8f8;
  --text-2: #b4b6bc;
  --text-3: #8a8f98;
  --text-4: #62666d;
  --accent: #5e6ad2;
  --accent-hover: #6e79d6;
  --accent-soft: rgba(94, 106, 210, 0.16);
  --red: #eb5757;
  --orange: #f2994a;
  --yellow: #f2c94c;
  --green: #4cb782;
  --blue: #4ea7fc;
  --purple: #a67bf5;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px var(--border-strong);
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ffffff; --bg-side: #f7f7f8; --bg-elev: #ffffff; --bg-elev2: #f4f4f5;
    --bg-hover: rgba(0, 0, 0, 0.035); --bg-active: rgba(0, 0, 0, 0.06);
    --border: rgba(0, 0, 0, 0.07); --border-strong: rgba(0, 0, 0, 0.12);
    --text: #1b1c1f; --text-2: #3c3f46; --text-3: #6b6f76; --text-4: #9a9ea6;
    --accent-soft: rgba(94, 106, 210, 0.12);
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 0 0 1px var(--border-strong);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #ffffff; --bg-side: #f7f7f8; --bg-elev: #ffffff; --bg-elev2: #f4f4f5;
  --bg-hover: rgba(0, 0, 0, 0.035); --bg-active: rgba(0, 0, 0, 0.06);
  --border: rgba(0, 0, 0, 0.07); --border-strong: rgba(0, 0, 0, 0.12);
  --text: #1b1c1f; --text-2: #3c3f46; --text-3: #6b6f76; --text-4: #9a9ea6;
  --accent-soft: rgba(94, 106, 210, 0.12);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 0 0 1px var(--border-strong);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 13px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "cv11", "ss01", "ss03";
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.006em;
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--accent-soft); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; height: 100vh; overflow: hidden; }
.side {
  background: var(--bg-side); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 10px 8px; gap: 2px; overflow-y: auto;
}
.ws { display: flex; align-items: center; gap: 8px; padding: 6px 8px 12px; }
.ws-logo {
  width: 22px; height: 22px; border-radius: 6px; background: var(--accent);
  display: grid; place-items: center; color: #fff; font: 600 13px Georgia, serif;
}
.ws-name { font-weight: 600; font-size: 13px; }
.ws-user { margin-left: auto; color: var(--text-3); font-size: 12px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; height: 28px; padding: 0 8px; border-radius: 6px;
  color: var(--text-2); cursor: pointer; font-weight: 500; user-select: none; white-space: nowrap;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--bg-active); color: var(--text); }
.nav-item svg { width: 15px; height: 15px; flex: none; color: var(--text-3); }
.nav-item .count { margin-left: auto; color: var(--text-4); font-size: 12px; font-weight: 400; }
.nav-section { color: var(--text-4); font-size: 11.5px; font-weight: 500; padding: 14px 8px 4px; }
.nav-sub { padding-left: 18px; font-weight: 400; }
.nav-sub .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-4); flex: none; }
.side-foot { margin-top: auto; padding-top: 8px; display: flex; gap: 4px; }

.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.topbar {
  height: 44px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 16px 0 20px;
  border-bottom: 1px solid var(--border);
}
.crumbs { display: flex; align-items: center; gap: 6px; color: var(--text-3); min-width: 0; }
.crumbs b { color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs .sep { color: var(--text-4); }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }
.content { flex: 1; overflow-y: auto; }
.split { display: flex; flex: 1; min-height: 0; }
.split > .content { flex: 1; }

/* ---------- controls ---------- */
.btn {
  height: 28px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text); cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  font-weight: 500; font-size: 12.5px; white-space: nowrap;
}
.btn:hover { background: var(--bg-elev2); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-3); }
.btn.ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn.danger { color: var(--red); }
.btn svg { width: 14px; height: 14px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.kbd {
  font: 500 11px var(--mono); color: var(--text-3); border: 1px solid var(--border-strong); border-radius: 4px;
  padding: 0 4px; line-height: 16px;
}
.input, .textarea, .select {
  width: 100%; background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 9px; outline: none; transition: border-color 0.12s, box-shadow 0.12s;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { resize: vertical; min-height: 72px; line-height: 1.55; }

/* ---------- list ---------- */
.group-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 20px;
  background: var(--bg-side); border-bottom: 1px solid var(--border); font-weight: 500;
}
.group-head .muted { font-weight: 400; }
.row {
  display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 20px; border-bottom: 1px solid var(--border);
  cursor: pointer; min-width: 0;
}
.row:hover { background: var(--bg-hover); }
.row.selected { background: var(--bg-active); }
.row .ident { color: var(--text-4); font: 500 12px var(--mono); width: 56px; flex: none; }
.row .title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .title .sub { color: var(--text-3); margin-left: 6px; }
.row .meta { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 12px; flex: none; }
.row .date { width: 64px; text-align: right; font-size: 12px; color: var(--text-3); flex: none; }
.row .date.overdue { color: var(--red); }
.row .date.soon { color: var(--orange); }
.indent-1 { padding-left: 46px; }
.indent-2 { padding-left: 72px; }
.indent-3 { padding-left: 98px; }
.muted { color: var(--text-3); }
.faint { color: var(--text-4); }

.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 11px;
  border: 1px solid var(--border-strong); color: var(--text-2); font-size: 12px; white-space: nowrap; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.chip.ball-us { border-color: rgba(235, 87, 87, 0.4); color: var(--red); }
.chip.accent { border-color: transparent; background: var(--accent-soft); color: var(--accent-hover); }
.avatar {
  width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  font-size: 9.5px; font-weight: 600; color: #fff;
}
.ico { width: 14px; height: 14px; flex: none; display: inline-block; vertical-align: -2px; }

.empty { padding: 72px 20px; text-align: center; color: var(--text-3); }
.empty h3 { color: var(--text); font-weight: 500; margin: 12px 0 4px; font-size: 14px; }
.empty svg { width: 28px; height: 28px; color: var(--text-4); }

/* ---------- case header ---------- */
.case-head { padding: 24px 20px 16px; border-bottom: 1px solid var(--border); }
.case-head h1 { font-size: 20px; font-weight: 600; margin: 0 0 10px; letter-spacing: -0.015em; }
.props { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.goal { margin-top: 14px; display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; }
.goal .k { color: var(--text-3); }
.goal .v { color: var(--text-2); white-space: pre-wrap; }

/* ---------- peek panel ---------- */
.peek {
  width: 440px; flex: none; border-left: 1px solid var(--border); background: var(--bg); overflow-y: auto;
  display: flex; flex-direction: column;
}
.peek-head { display: flex; align-items: center; gap: 6px; height: 44px; padding: 0 10px 0 16px; border-bottom: 1px solid var(--border); flex: none; }
.peek-body { padding: 16px; }
.peek-title { font-size: 17px; font-weight: 600; margin: 2px 0 14px; letter-spacing: -0.01em; outline: none; border-radius: 4px; }
.peek-title[contenteditable="true"]:hover { background: var(--bg-hover); }
.fields { display: grid; grid-template-columns: 128px 1fr; gap: 2px 8px; align-items: center; margin-bottom: 18px; }
.fields .k { color: var(--text-3); font-size: 12.5px; padding: 4px 0; align-self: start; line-height: 22px; }
.fields .v { min-width: 0; }
.prop {
  display: flex; align-items: center; gap: 6px; min-height: 30px; padding: 4px 6px; border-radius: 6px; cursor: pointer;
  flex-wrap: wrap; border: 1px solid transparent;
}
.prop:hover { background: var(--bg-hover); }
.prop.ro { cursor: default; }
.prop.ro:hover { background: transparent; }
.prop .placeholder { color: var(--text-4); }
.prop { flex-wrap: nowrap; }
.prop:has(.chip) { flex-wrap: wrap; }
.prop select, .prop input[type="date"], .prop input[type="text"], .prop input[type="email"] {
  background: transparent; border: none; outline: none; flex: 1; min-width: 0; width: auto; padding: 0; cursor: pointer;
}
.prop input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.6); cursor: pointer; }
.prop select option { background: var(--bg-elev); color: var(--text); }
.prop textarea { background: transparent; border: none; outline: none; width: 100%; resize: none; padding: 0; line-height: 1.5; min-height: 22px; }
.section-title { font-weight: 500; font-size: 12.5px; color: var(--text-3); margin: 22px 0 8px; display: flex; align-items: center; gap: 8px; }
.section-title .spacer { flex: 1; }
.body-md { color: var(--text-2); line-height: 1.6; font-size: 13.5px; }
.body-md h1, .body-md h2, .body-md h3 { color: var(--text); font-size: 14px; margin: 14px 0 6px; font-weight: 600; }
.body-md hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.body-md p { margin: 0 0 8px; }
.body-md ul { margin: 0 0 8px; padding-left: 18px; }
.comment { display: flex; gap: 10px; padding: 8px 0; }
.comment .c-body { flex: 1; }
.comment .c-meta { color: var(--text-4); font-size: 11.5px; }
.comment-box { display: flex; flex-direction: column; gap: 8px; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; background: var(--bg-elev); }
.comment-box textarea { background: transparent; border: none; outline: none; resize: none; min-height: 40px; }
.comment-box .actions { display: flex; justify-content: flex-end; }

/* ---------- overlays ---------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 50; display: flex; align-items: flex-start;
  justify-content: center; padding-top: 12vh; animation: fade 0.12s ease-out;
}
.modal {
  width: min(640px, calc(100vw - 32px)); background: var(--bg-elev); border-radius: 12px; box-shadow: var(--shadow);
  animation: pop 0.14s ease-out; overflow: hidden;
}
.modal-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px 0; color: var(--text-3); font-size: 12.5px; }
.modal-body { padding: 10px 16px 14px; }
.modal-title-input { width: 100%; border: none; outline: none; background: transparent; font-size: 18px; font-weight: 500; padding: 6px 0; }
.modal-desc { width: 100%; border: none; outline: none; background: transparent; resize: none; min-height: 64px; color: var(--text-2); line-height: 1.55; }
.modal-props { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0 2px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); }
.modal-foot .spacer { flex: 1; }
.pchip {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 9px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: transparent; cursor: pointer; color: var(--text-2); font-size: 12px;
}
.pchip:hover { background: var(--bg-hover); color: var(--text); }
.pchip.set { color: var(--text); }
.pchip.req { border-style: dashed; }
.pchip select, .pchip input { background: transparent; border: none; outline: none; cursor: pointer; font-size: 12px; max-width: 170px; }

.popover {
  position: fixed; z-index: 60; width: 300px; max-height: 340px; background: var(--bg-elev); border-radius: 10px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; animation: pop 0.1s ease-out;
}
.popover input { border: none; border-bottom: 1px solid var(--border); background: transparent; outline: none; padding: 10px 12px; }
.popover .opts { overflow-y: auto; padding: 4px; }
.opt { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px; border-radius: 6px; cursor: pointer; }
.opt:hover, .opt.hl { background: var(--bg-active); }
.opt .check { margin-left: auto; color: var(--accent-hover); }
.opt .hint { color: var(--text-4); font-size: 11.5px; margin-left: auto; white-space: nowrap; }

.cmdk { width: min(620px, calc(100vw - 32px)); }
.cmdk input { width: 100%; border: none; outline: none; background: transparent; padding: 16px 18px; font-size: 15px; border-bottom: 1px solid var(--border); }
.cmdk .opts { max-height: 380px; overflow-y: auto; padding: 6px; }

#toasts { position: fixed; bottom: 16px; right: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-elev2); box-shadow: var(--shadow); border-radius: 8px; padding: 10px 14px; max-width: 380px;
  animation: pop 0.14s ease-out; display: flex; gap: 8px; align-items: flex-start;
}
.toast.err { border-left: 3px solid var(--red); }

/* ---------- login ---------- */
.login { height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); text-align: center; }
.login-card .ws-logo { width: 40px; height: 40px; font-size: 22px; border-radius: 10px; margin: 0 auto 18px; }
.login-card h1 { font-size: 20px; font-weight: 600; margin: 0 0 6px; letter-spacing: -0.015em; }
.login-card p { color: var(--text-3); margin: 0 0 24px; }
.login-card .input { height: 38px; margin-bottom: 10px; text-align: center; font-family: var(--mono); font-size: 12.5px; }
.login-card .btn { width: 100%; height: 38px; justify-content: center; }

/* ---------- users ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 500; color: var(--text-3); font-size: 12px; padding: 0 20px; height: 34px; border-bottom: 1px solid var(--border); }
.table td { padding: 0 20px; height: 44px; border-bottom: 1px solid var(--border); }
.table tr:hover td { background: var(--bg-hover); }
.token-box {
  font: 500 12.5px var(--mono); background: var(--bg-elev2); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 12px; word-break: break-all; margin: 10px 0; user-select: all;
}
.note { color: var(--text-3); font-size: 12.5px; line-height: 1.55; }
.warn { color: var(--orange); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--text-2); border-radius: 50%; animation: spin 0.7s linear infinite; }
.loading { display: flex; justify-content: center; padding: 60px; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(0.985); } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform 0.18s; }
  .shell.nav-open .side { transform: none; box-shadow: var(--shadow); }
  .btn.menu-btn { display: inline-flex; }
  .peek { position: fixed; inset: 0; width: 100%; z-index: 45; }
  .row .meta .chip { display: none; }
  .row .ident { display: none; }
  .row, .group-head, .case-head { padding-left: 16px; padding-right: 16px; }
  .indent-1 { padding-left: 36px; } .indent-2 { padding-left: 56px; } .indent-3 { padding-left: 76px; }
  .table .hide-m { display: none; }
  .table th, .table td { padding: 0 12px; }
}

.group-head { height: auto; min-height: 36px; white-space: nowrap; }
.group-head > span:first-child { overflow: hidden; text-overflow: ellipsis; min-width: 0; display: inline-flex; align-items: center; gap: 8px; }
@media (max-width: 860px) {
  .group-head .chip:not(.ball-us), .group-head .muted { display: none; }
  .group-head > span:first-child { flex: 1; }
  .group-head > span:first-child + span { display: none; }
  .goal { grid-template-columns: 1fr; gap: 2px; }
  .goal .v { margin-bottom: 8px; }
}
