:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --text: #1d1f22;
  --muted: #6b6f76;
  --border: #e2ded6;
  --accent: #c4561f;
  --accent-text: #ffffff;
  --focus: #2f6fdb;
  --todo: #2f6fdb;
  --updated: #b67a00;
  --changes: #c13c3c;
  --approved: #2d8a55;
  --first: #8d9097;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141517;
    --surface: #1d1f22;
    --surface-2: #24272b;
    --text: #ecebe8;
    --muted: #9ca0a7;
    --border: #33363b;
    --accent: #e0703a;
    --focus: #6c9cff;
    --todo: #6c9cff;
    --updated: #e3a72f;
    --changes: #ec6a6a;
    --approved: #4fc283;
    --first: #8d9097;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--focus); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.boot { padding: 40px; color: var(--muted); }

/* ---------- buttons and fields ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 13px; border-radius: 8px; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled, .btn.disabled { opacity: .45; cursor: default; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.approve.on { background: var(--approved); border-color: var(--approved); color: #fff; }
.btn.changes.on { background: var(--changes); border-color: var(--changes); color: #fff; }
input[type=text], input[type=password], input[type=search], select, textarea {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
textarea { width: 100%; resize: vertical; min-height: 72px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; display: grid; gap: 12px; box-shadow: var(--shadow);
}
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.login .err { color: var(--changes); font-size: 14px; min-height: 1.2em; margin: 0; }

/* ---------- frame ---------- */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; text-decoration: none; color: var(--text); white-space: nowrap; }
.brand span { color: var(--accent); }
.jump { display: flex; align-items: center; gap: 6px; flex: 1; max-width: 340px; }
.jump input { width: 100%; font-size: 16px; }
.top nav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.top nav .who { color: var(--muted); font-size: 13px; padding: 0 6px; }

.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: calc(100vh - 57px); }
.side { border-right: 1px solid var(--border); background: var(--surface); padding: 14px; overflow: auto;
  position: sticky; top: 57px; height: calc(100vh - 57px); }
.main { padding: 20px 24px 60px; min-width: 0; }
.main > * { max-width: 1100px; }

/* ---------- sidebar ---------- */
.progress { margin-bottom: 14px; }
.progress .bar { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; display: flex; }
.progress .bar i { display: block; height: 100%; }
.progress p { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.filters { display: grid; gap: 2px; margin-bottom: 12px; }
.filters button {
  display: flex; align-items: center; gap: 8px; border: 0; background: transparent; padding: 6px 8px;
  border-radius: 7px; cursor: pointer; text-align: left; font-size: 14px;
}
.filters button:hover { background: var(--surface-2); }
.filters button.on { background: var(--surface-2); font-weight: 600; }
.filters .count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.side select { width: 100%; margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chips h4 { width: 100%; margin: 10px 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--surface); font-size: 13px; cursor: pointer;
  font-variant-numeric: tabular-nums; text-decoration: none; color: var(--text);
}
.chip:hover { border-color: var(--muted); }
.chip.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.chip .n { color: var(--changes); font-weight: 600; font-size: 11px; }
.empty { color: var(--muted); font-size: 14px; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; background: var(--first); }
.dot.todo { background: var(--todo); }
.dot.updated { background: var(--updated); }
.dot.changes { background: var(--changes); }
.dot.approved { background: var(--approved); }
.dot.first { background: transparent; border: 1.5px solid var(--first); }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 2px 10px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card h2, .card h3 { margin: 0 0 10px; font-size: 16px; }
h1.page { font-size: 24px; margin: 0 0 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; cursor: pointer; text-align: left; }
.tile:hover { border-color: var(--muted); }
.tile b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile span { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* ---------- figure page ---------- */
.fighead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.fighead h1 { margin: 0; font-size: 24px; }
.fighead .nav { margin-left: auto; display: flex; gap: 6px; }
.banner { background: var(--surface-2); border: 1px solid var(--updated); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.player { background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 16 / 9; }
.player video { width: 100%; height: 100%; display: block; background: #000; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 0 4px; }
.controls .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; min-width: 110px; }
.controls label { display: inline-flex; gap: 5px; align-items: center; font-size: 14px; }
.controls .sep { flex: 1; }
.reviewbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0 16px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.reviewbar .state { margin-right: auto; display: flex; gap: 8px; align-items: center; }
.cols { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; }

.note { border-top: 1px solid var(--border); padding: 12px 0; }
.note:first-child { border-top: 0; padding-top: 4px; }
.note .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.note .meta b { color: var(--text); font-weight: 600; }
.note .body { white-space: pre-wrap; margin: 4px 0; overflow-wrap: anywhere; }
.note.resolved .body { color: var(--muted); }
.note .reply { margin: 6px 0 0; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; font-size: 14px; }
.note .reply .meta { margin-bottom: 2px; }
.note .acts { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.timelink { border: 0; background: var(--surface-2); border-radius: 6px; padding: 0 6px; cursor: pointer; color: var(--focus); font-size: 13px; font-variant-numeric: tabular-nums; }
.st { font-size: 12px; padding: 0 7px; border-radius: 99px; border: 1px solid var(--border); }
.st.open { color: var(--changes); border-color: var(--changes); }
.st.resolved { color: var(--approved); border-color: var(--approved); }
.addnote { display: grid; gap: 8px; margin-bottom: 8px; }
.addnote .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.addnote .row label { font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
.addnote .row .btn { margin-left: auto; }
.inline-form { display: grid; gap: 6px; margin-top: 8px; }
.inline-form .row { display: flex; gap: 6px; justify-content: flex-end; }

.versions { list-style: none; margin: 0; padding: 0; }
.versions li { border-top: 1px solid var(--border); padding: 10px 0; }
.versions li:first-child { border-top: 0; padding-top: 0; }
.versions .vh { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.versions .vh b { font-size: 15px; }
.versions .sum { margin: 4px 0 0; font-size: 14px; white-space: pre-wrap; }
.versions .sum.none { color: var(--muted); font-style: italic; }
.playing { color: var(--accent); font-size: 13px; font-weight: 600; }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); font-size: 14px; }
.feed li:first-child { border-top: 0; }
.feed time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.feed .what { overflow-wrap: anywhere; }
.feed a.fig { font-weight: 600; text-decoration: none; margin-right: 4px; }

table.stats { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.stats th, table.stats td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: right; }
table.stats th:first-child, table.stats td:first-child { text-align: left; }
table.stats th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
table.stats tr.total td { font-weight: 650; border-bottom: 0; }
.tablewrap { overflow-x: auto; }
.keys { font-size: 13px; color: var(--muted); margin-top: 8px; }
kbd { font: 12px ui-monospace, Menlo, monospace; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--surface-2); }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); z-index: 20; }
#toast.show { opacity: 1; }

.menu-toggle { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); display: none; }
  .side.open { display: block; }
  .menu-toggle { display: inline-flex; }
  .main { padding: 16px; }
  .cols { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; }
  .jump { order: 3; max-width: none; flex-basis: 100%; }
  .top nav .who { display: none; }
}
