:root {
  --bg: #f5f5f7; --surface: #fff; --fill: rgba(120, 120, 128, .12); --fill-2: rgba(120, 120, 128, .07);
  --line: rgba(60, 60, 67, .13); --text: #1d1d1f; --muted: #6e6e73; --faint: #aeaeb2;
  --accent: #0071e3; --accent-soft: rgba(0, 113, 227, .1); --danger: #d70015; --ok: #30b94d;
  --warn: #b25000; --warn-soft: rgba(255, 149, 0, .13); --folder: #4fa3e8;
  --radius: 12px;
  --shadow: 0 0 0 .5px rgba(0, 0, 0, .05), 0 1px 3px rgba(0, 0, 0, .05);
  --pop: 0 0 0 .5px rgba(0, 0, 0, .08), 0 12px 40px rgba(0, 0, 0, .16);
  --ease: cubic-bezier(.2, .9, .3, 1);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  color-scheme: light;
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); }
.muted, small { color: var(--muted); }
small { font-size: 12px; }
svg { fill: currentColor; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit; font-size: 13px; font-weight: 500; height: 30px; padding: 0 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 8px; background: var(--fill); color: var(--text);
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: transform .1s ease-out, background-color .15s;
}
button:hover, .btn:hover { background: rgba(120, 120, 128, .18); }
button:active, .btn:active { transform: scale(.97); }
button:disabled { opacity: .45; cursor: default; transform: none; }
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: #0077ed; }
button.danger { color: var(--danger); }
.danger-fill, .danger-fill:hover { background: var(--danger); color: #fff; }
button.icon { width: 30px; padding: 0; background: none; color: var(--muted); }
button.icon:hover { background: var(--fill); color: var(--text); }
button.icon svg { width: 18px; height: 18px; }
button.link { height: auto; padding: 0; background: none; color: var(--accent); font-weight: 400; }
button.link:hover { text-decoration: underline; }
button.plain { height: auto; padding: 0; background: none; border-radius: 99px; }

input, select {
  font: inherit; color: inherit; height: 32px; padding: 0 10px; min-width: 0;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0, 113, 227, .22); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: inline-flex; gap: 2px; padding: 2px; background: var(--fill); border-radius: 9px; }
.seg > * {
  height: 26px; padding: 0 14px; display: inline-flex; align-items: center;
  border: 0; border-radius: 7px; background: none; color: var(--text);
  font: inherit; font-size: 13px; font-weight: 500; text-decoration: none; cursor: pointer;
}
.seg > *:hover { background: rgba(255, 255, 255, .5); }
.seg > .on, .seg > .on:hover { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 30; height: 52px; padding: 0 20px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  background: rgba(245, 245, 247, .72); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.signed-out .top { display: none; }
.logo { font-size: 15px; font-weight: 600; letter-spacing: -.01em; color: var(--text); text-decoration: none; }
.top-right { display: flex; justify-content: flex-end; align-items: center; gap: 14px; }

.avatar {
  --size: 28px; position: relative; flex: none; display: inline-grid; place-items: center;
  width: var(--size); height: var(--size); border-radius: 50%;
  background: hsl(var(--h) 52% 52%); color: #fff;
  font-size: calc(var(--size) * .42); font-weight: 600; line-height: 1;
}
.avatar.xs { --size: 20px; }
.avatar.on::after {
  content: ""; position: absolute; right: -1px; bottom: -1px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 2px var(--surface);
}
.avatar.xs.on::after { width: 6px; height: 6px; }
.avatar.away { opacity: .45; }
.avatar.pending, .avatar.more { background: var(--fill); color: var(--muted); }
.avatar.more { font-size: 11px; }
.stack .avatar { box-shadow: 0 0 0 2px var(--bg); }
.stack .avatar + .avatar { margin-left: -7px; }

/* ---------- menus ---------- */
.menu-wrap { position: relative; display: inline-flex; }
.menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 40; min-width: 190px; padding: 5px;
  display: flex; flex-direction: column;
  background: rgba(255, 255, 255, .88); backdrop-filter: blur(24px) saturate(180%); -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-radius: 10px; box-shadow: var(--pop);
  transform-origin: top right; animation: pop .16s var(--ease);
}
.menu[hidden] { display: none; }
.menu > button { justify-content: flex-start; height: 30px; padding: 0 10px; border-radius: 6px; background: none; font-weight: 400; }
.menu > button:hover, .menu > button:focus-visible { background: var(--accent); color: #fff; outline: none; }
.menu > button.danger:hover, .menu > button.danger:focus-visible { background: var(--danger); }
.menu-head { display: flex; flex-direction: column; padding: 6px 10px 9px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
#presence .menu { min-width: 280px; }
.person { display: flex; align-items: center; gap: 10px; padding: 7px 8px; }
.person > div { display: flex; flex-direction: column; min-width: 0; }
@keyframes pop { from { opacity: 0; transform: scale(.95); } }

/* ---------- page ---------- */
main { max-width: 1440px; margin: 0 auto; padding: 24px 24px 96px; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; margin-bottom: 16px; }
.path { display: flex; align-items: baseline; gap: 6px; min-width: 0; font-size: 22px; font-weight: 600; letter-spacing: -.02em; line-height: 1.25; }
.path a, .path span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.path a { flex: 0 1 auto; min-width: 3ch; color: var(--muted); text-decoration: none; }
.path a:hover { color: var(--text); }
.path .sep { font-style: normal; color: var(--faint); font-weight: 400; }
.tools { display: flex; align-items: center; gap: 8px; flex: none; }
.narrow { max-width: 760px; margin: 0 auto; }
.empty { padding: 64px 20px; text-align: center; color: var(--muted); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- projects ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.card {
  position: relative; min-height: 128px; padding: 18px; display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .2s var(--ease), box-shadow .2s;
}
.card:hover { box-shadow: 0 0 0 .5px rgba(0, 0, 0, .05), 0 8px 28px rgba(0, 0, 0, .09); }
.card:active { transform: scale(.985); }
.card .stretch { display: flex; flex-direction: column; gap: 12px; color: var(--text); text-decoration: none; font-size: 15px; }
.card .stretch::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.card .ico.folder { width: 38px; height: 38px; }
.card small { margin-top: auto; }
.card .menu-wrap { position: absolute; top: 10px; right: 10px; z-index: 1; opacity: 0; transition: opacity .15s; }
.card:hover .menu-wrap, .card:focus-within .menu-wrap, .card .menu-wrap:has(.menu:not([hidden])) { opacity: 1; }

/* ---------- files ---------- */
.files { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 28px; align-items: start; }
.files.has-insp { grid-template-columns: 210px minmax(0, 1fr) 320px; }
.tree, .insp { position: sticky; top: 76px; max-height: calc(100vh - 100px); overflow: auto; }
.tree { z-index: 5; display: flex; flex-direction: column; gap: 1px; padding-top: 52px; }
.tree a {
  display: flex; align-items: center; gap: 5px; height: 30px; padding: 0 8px 0 calc(4px + var(--d, 0) * 14px);
  border-radius: 7px; color: var(--text); text-decoration: none; font-size: 13px; white-space: nowrap;
}
.tree a span { overflow: hidden; text-overflow: ellipsis; }
.tree .t-row { position: relative; }
.tree .t-row:has(.menu-wrap) a { padding-right: 30px; }
.tree .t-row:hover a { background: var(--fill-2); }
.tree a.on, .tree .t-row:hover a.on { background: var(--fill); font-weight: 600; }
.tree .menu-wrap { position: absolute; top: 3px; right: 3px; opacity: 0; transition: opacity .15s; }
.tree .t-row:hover .menu-wrap, .tree .t-row:focus-within .menu-wrap, .tree .menu-wrap:has(.menu:not([hidden])) { opacity: 1; }
.tree button.icon { width: 24px; height: 24px; border-radius: 6px; }
.tree button.icon:hover { background: rgba(0, 0, 0, .07); }
.tree button.icon svg { width: 16px; height: 16px; }
.chev { display: inline-block; flex: none; width: 12px; height: 12px; color: var(--faint); transition: transform .2s var(--ease); }
.chev.open { transform: rotate(90deg); }
.ico.folder { flex: none; width: 18px; height: 18px; fill: var(--folder); }

.list { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list th { white-space: nowrap; padding: 10px 14px; text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--line); }
.list td { height: 44px; padding: 0 14px; font-size: 13px; border-bottom: 1px solid var(--line); }
.list tr:last-child td { border-bottom: 0; }
.list th:nth-child(2) { width: 22%; }
.list th:nth-child(3) { width: 18%; }
.list .num { width: 64px; text-align: right; font-variant-numeric: tabular-nums; }
.list tbody tr { cursor: default; transition: background-color .12s; }
.list tbody tr:hover { background: var(--fill-2); }
.list tbody tr.sel { background: var(--accent-soft); }
.list tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.list .act { width: 44px; padding: 0 8px 0 0; text-align: right; }
.list .act .menu-wrap { opacity: 0; transition: opacity .15s; }
.list tr:hover .act .menu-wrap, .list tr:focus-within .act .menu-wrap, .list .act .menu-wrap:has(.menu:not([hidden])) { opacity: 1; }
.name { display: flex; align-items: center; gap: 10px; font-weight: 500; min-width: 0; }
.name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { padding: 0 7px; border-radius: 99px; background: var(--fill); font-weight: 500; }
td .avatar.xs + .avatar.xs { margin-left: -5px; box-shadow: 0 0 0 2px var(--surface); }
.lock { display: inline-flex; align-items: center; gap: 7px; color: var(--warn); font-weight: 500; }
.lock.mine { color: var(--accent); }

.ext {
  flex: none; display: inline-grid; place-items: center; width: 30px; height: 20px; border-radius: 5px;
  background: #8e8e93; color: #fff; font-size: 9px; font-weight: 700; letter-spacing: .02em;
}
.ext.cad { background: #d6252b; }
.ext.pdf { background: #f07322; }
.ext.img { background: #34a853; }
.ext.doc { background: #2b7cd3; }
.ext.xls { background: #1e7145; }
.ext.lg { width: 44px; height: 30px; border-radius: 7px; font-size: 11px; }

/* ---------- inspector ---------- */
.insp { display: flex; flex-direction: column; gap: 16px; padding: 18px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.insp.enter { animation: slide .28s var(--ease); }
@keyframes slide { from { opacity: 0; transform: translateX(14px); } }
.insp-head { display: flex; align-items: flex-start; gap: 12px; }
.insp-title { flex: 1; min-width: 0; }
.insp-title h2 { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.status { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); }
.status.mine { background: var(--accent-soft); }
.status > div { display: flex; flex-direction: column; }
.insp-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.insp-acts > * { flex: 1 1 calc(50% - 4px); }
.insp-acts > .primary { flex-basis: 100%; height: 36px; font-size: 14px; }
.insp h3 { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: -8px; }
.versions { list-style: none; margin: 0; padding: 0; }
.versions li { padding: 10px 0; border-top: 1px solid var(--line); }
.versions li:first-child { border-top: 0; }
.v-head { display: flex; align-items: baseline; gap: 8px; font-size: 13px; }
.v-head span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.v-head time { font-size: 12px; color: var(--muted); }
.versions p { margin-top: 3px; font-size: 13px; }
.versions li.working .v-head b { color: var(--accent); }
.cmds { list-style: none; margin: 6px 0 0; padding: 0 0 0 10px; border-left: 2px solid var(--line); font-size: 12px; }
.cmds li { display: flex; align-items: baseline; gap: 6px; padding: 2px 0; border: 0; }
.cmds b { font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; }
.cmds span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.cmds time { color: var(--muted); font-size: 11px; }
.cmds .more { color: var(--muted); }
.v-acts { display: flex; gap: 14px; margin-top: 6px; font-size: 12px; opacity: 0; transition: opacity .15s; }
.versions li:hover .v-acts, .versions li:focus-within .v-acts { opacity: 1; }

/* ---------- people & activity ---------- */
.invite { display: flex; gap: 8px; margin-bottom: 16px; }
.invite input { flex: 1; }
.group { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.group li { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-top: 1px solid var(--line); }
.group li:first-child { border-top: 0; }
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.who b, .who small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people select { border-color: transparent; background: none; color: var(--muted); }
.people select:hover { background: var(--fill-2); }
.role { font-size: 13px; color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.filters select { max-width: 240px; }
.day { padding: 18px 4px 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.feed li { align-items: flex-start; }
.ev { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ref { font-weight: 500; overflow-wrap: anywhere; }
.feed time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 2px; }

/* ---------- notes ---------- */
.notes li { align-items: flex-start; cursor: default; transition: background-color .12s; }
.notes li:hover { background: var(--fill-2); }
.notes li:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.notes .excerpt { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.nowrap { white-space: nowrap; padding-top: 2px; }
.chip { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 99px; background: var(--fill); color: var(--muted); font-size: 11px; font-weight: 500; vertical-align: 1px; }
.chip.ai { background: var(--accent-soft); color: var(--accent); }
.filters input[type=search] { flex: 1; }

/* ---------- sign in ---------- */
.auth { max-width: 340px; margin: 14vh auto 0; display: flex; flex-direction: column; gap: 22px; text-align: center; }
.auth h1 { font-size: 30px; font-weight: 700; letter-spacing: -.025em; }
.auth p { margin: -14px 0 0; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack input, .stack button { height: 40px; font-size: 15px; }
.stack button { margin-top: 6px; }

/* ---------- dialog, toasts ---------- */
dialog { width: min(380px, 92vw); padding: 22px; border: 0; border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--pop); }
dialog[open] { animation: pop .2s var(--ease); }
dialog::backdrop { background: rgba(0, 0, 0, .22); }
.ask { display: flex; flex-direction: column; gap: 12px; }
.ask h2 { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.ask p { color: var(--muted); white-space: pre-line; }
.acad-help ul { margin: 6px 0 0 18px; display: grid; gap: 6px; color: var(--muted); }
.ask input, .ask select { width: 100%; height: 36px; }
dialog:has(.wide) { width: min(640px, 94vw); }
.ask textarea { width: 100%; padding: 8px 10px; font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); resize: vertical; }
.ask textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0, 113, 227, .22); }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 60vh; overflow: auto; }
.ask-foot { display: flex; flex-direction: row-reverse; gap: 8px; margin-top: 6px; }
.ask-foot button { flex: 1; height: 34px; }

#toasts { position: fixed; left: 50%; bottom: 22px; z-index: 50; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  max-width: min(460px, 90vw); padding: 10px 16px; border-radius: 12px; font-size: 13px;
  background: rgba(29, 29, 31, .88); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); color: #fff;
  box-shadow: var(--pop); animation: rise .25s var(--ease);
}
.toast:empty { display: none; }
.toast.err { background: rgba(215, 0, 21, .94); }
.toast.up { width: min(360px, 90vw); display: flex; flex-direction: column; gap: 7px; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-num { color: rgba(255, 255, 255, .7); font-size: 12px; font-variant-numeric: tabular-nums; }
.toast progress { appearance: none; -webkit-appearance: none; width: 100%; height: 4px; border: 0; border-radius: 2px; overflow: hidden; background: rgba(255, 255, 255, .22); }
.toast progress::-webkit-progress-bar { background: transparent; }
.toast progress::-webkit-progress-value { background: var(--accent); transition: width .2s linear; }
.toast progress::-moz-progress-bar { background: var(--accent); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
#stale { position: fixed; top: 64px; left: 50%; z-index: 35; transform: translateX(-50%); height: 32px; border-radius: 16px; background: var(--accent); color: #fff; box-shadow: var(--pop); }
#stale:active { transform: translateX(-50%) scale(.97); }

/* ---------- adapt ---------- */
@media (hover: none) {
  .card .menu-wrap, .tree .menu-wrap, .list .act .menu-wrap, .v-acts { opacity: 1; }
}
@media (max-width: 1000px) {
  .files, .files.has-insp { grid-template-columns: minmax(0, 1fr); }
  .tree { display: none; }
  .insp {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 25; max-height: 75vh;
    border-radius: 16px 16px 0 0; box-shadow: 0 -10px 40px rgba(0, 0, 0, .18);
  }
  .insp.enter { animation-name: sheet; }
  @keyframes sheet { from { opacity: 0; transform: translateY(30px); } }
}
@media (max-width: 700px) {
  main { padding: 16px 12px 96px; }
  .top { padding: 0 12px; gap: 8px; }
  .logo { display: none; }
  .list th:nth-child(3), .list td:nth-child(3) { display: none; }
  .list th:nth-child(2) { width: auto; }
  .lock > span:not(.avatar) { display: none; }
  .bar { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .top { background: var(--bg); backdrop-filter: none; }
  .menu { background: var(--surface); backdrop-filter: none; }
  .toast { background: #1d1d1f; backdrop-filter: none; }
}
