:root {
  --navy: #073763; --green: #3d7a28; --green-bg: #e8f3e3; --ka: #1865f2; --ka-bg: #eaf1fe;
  --ink: #21242c; --ink2: #3b3e48; --muted: #5f6370; --line: #dadce0; --soft: #f5f6f8; --bg: #ffffff;
  --red: #b3261e; --red-bg: #fdecea; --amber: #8a5a00; --amber-bg: #fff4dc; --violet: #6b3fa0; --violet-bg: #f2ecfa;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--soft);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--soft); }
a { color: var(--ka); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.pad { padding: 24px; }
.small { font-size: 13px; }
h1, h2, h3 { line-height: 1.25; }

/* top bar */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  background: var(--navy); color: #fff; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; min-width: 0; flex: 1 1 380px; }
.brand-mark { background: #fff; color: var(--navy); font-weight: 800; font-size: 12px; padding: 4px 6px; border-radius: 6px; flex: none; }
.brand-text { font-weight: 650; font-size: 15px; }
#nav { display: flex; gap: 4px; flex-wrap: wrap; }
#nav a { color: #dbe6f3; text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: 14px; }
#nav a.on, #nav a:hover { background: rgba(255,255,255,.14); color: #fff; }
#who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #dbe6f3; }
#who button { background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff; border-radius: 8px; padding: 4px 10px; cursor: pointer; }

main { max-width: 1500px; margin: 0 auto; padding: 20px; outline: none; }
.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 18px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

/* buttons & inputs */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: #9aa0a6; }
.btn.primary { background: var(--ka); border-color: var(--ka); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #0f4fc4; }
.btn.good { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 3px 8px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
label.f { display: block; margin: 0 0 12px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink2); margin-bottom: 4px; }
label.f > small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
input[type=text], input[type=email], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: #fff; font-size: 14px; }
textarea { resize: vertical; line-height: 1.5; }
textarea.code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--ka); outline-offset: 1px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset:disabled textarea, fieldset:disabled input, fieldset:disabled select { background: var(--soft); }

/* status chips */
.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-not_started { color: var(--muted); background: #eef0f2; }
.st-not_started::before { background: transparent; border: 1.5px solid currentColor; width: 5px; height: 5px; }
.st-drafting { color: var(--ka); background: var(--ka-bg); }
.st-in_review { color: var(--violet); background: var(--violet-bg); }
.st-changes_requested { color: var(--amber); background: var(--amber-bg); }
.st-changes_requested::before { border-radius: 1px; }
.st-approved { color: var(--green); background: var(--green-bg); }
.st-approved::before { content: "\2713"; background: none; width: auto; height: auto; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: #eef0f2; color: var(--ink2); }
.tag.prod { background: var(--amber-bg); color: var(--amber); }
.count { display: inline-block; min-width: 18px; text-align: center; font-size: 11px; font-weight: 700; padding: 0 5px; border-radius: 9px; background: var(--ink2); color: #fff; }
.count.err { background: var(--red); }
.count.warn { background: var(--amber); }

/* tables */
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.list td { padding: 8px; border-bottom: 1px solid #eceef1; vertical-align: top; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #f7f9fc; }
.grp td { background: var(--soft); font-weight: 700; font-size: 13px; color: var(--navy); }
.clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pieces { display: flex; gap: 6px; flex-wrap: wrap; }
.pieces a { text-decoration: none; }
.bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: #eef0f2; min-width: 120px; }
.bar span { display: block; height: 100%; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

/* lesson page */
.lesson-head h1 { font-size: 20px; margin: 4px 0 6px; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 0; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 9px 14px; cursor: pointer; border-bottom: 3px solid transparent; font-size: 14px;
  display: inline-flex; gap: 8px; align-items: center; color: var(--ink2); }
.tabs button.on { border-bottom-color: var(--ka); color: var(--ink); font-weight: 650; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .workspace { grid-template-columns: 1fr; } }
.pane { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.pane > .pane-body { padding: 16px; }
.side { position: sticky; top: 70px; max-height: calc(100vh - 90px); display: flex; flex-direction: column; }
.side > .pane-body { overflow: auto; }
@media (max-width: 1000px) { .side { position: static; max-height: none; } }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--line); background: #fafbfc;
  border-radius: var(--radius) var(--radius) 0 0; }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.info { background: var(--ka-bg); }
.banner.warn { background: var(--amber-bg); }
.banner.lock { background: var(--violet-bg); }
.group { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; background: #fcfcfd; }
.group > .group-head { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.group > .group-head strong { flex: 1; font-size: 14px; }
.opt { display: grid; grid-template-columns: 28px 1fr; gap: 6px 8px; padding: 8px; border-radius: 8px; border: 1px solid #eceef1; margin-bottom: 6px; background: #fff; }
.opt.key { border-color: var(--green); background: #f6fbf4; }
.opt .letter { font-weight: 700; text-align: center; padding-top: 6px; }
.opt .opt-tools { grid-column: 2; display: flex; gap: 8px; align-items: center; font-size: 13px; }
details.sec > summary { cursor: pointer; font-weight: 650; margin: 8px 0; }

/* preview (KA-like) */
.ka { font-family: "Lato", -apple-system, "Segoe UI", Roboto, Arial, sans-serif; font-size: 16px; line-height: 1.6; color: #21242c; }
.ka h1 { font-size: 26px; margin: 0 0 12px; }
.ka h2 { font-size: 21px; margin: 22px 0 8px; }
.ka h3 { font-size: 18px; margin: 18px 0 6px; }
.ka blockquote { margin: 12px 0; padding: 4px 16px; border-left: 4px solid #d6d8da; background: #fafafa; }
.ka .tbl { overflow-x: auto; }
.ka table { border-collapse: collapse; margin: 10px 0; font-size: 15px; }
.ka th, .ka td { border: 1px solid #d6d8da; padding: 6px 10px; text-align: left; vertical-align: top; }
.ka th { background: #f3f4f6; }
.q { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin: 14px 0; }
.q .qmeta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.q .stem { font-weight: 700; margin: 10px 0; }
.q ol.opts { list-style: none; padding: 0; margin: 0; }
.q ol.opts li { border: 1px solid #e3e5e8; border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.q ol.opts li.key { border: 2px solid var(--green); }
.q .keymark { font-size: 12px; font-weight: 700; color: var(--green); margin-left: 6px; }
.q .rat { font-size: 14px; color: var(--ink2); margin-top: 6px; padding-top: 6px; border-top: 1px dashed #e3e5e8; }
.story { width: 100%; border-collapse: collapse; font-size: 14px; }
.story th { text-align: left; background: #f3f4f6; padding: 6px 8px; font-size: 12px; }
.story td { border-top: 1px solid var(--line); padding: 8px; vertical-align: top; }
.story ul { margin: 0; padding-left: 18px; }
.beat { display: flex; gap: 6px; margin: 3px 0; }
.beat .n { color: var(--muted); min-width: 22px; text-align: right; }
.beat .wc { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
.beat .wc.over { color: var(--red); font-weight: 700; }
.pause { display: inline-block; font-size: 11px; font-weight: 700; color: var(--violet); background: var(--violet-bg); border-radius: 4px; padding: 1px 6px; margin: 3px 0 3px 28px; }
.takeaway { border: 2px solid var(--navy); border-radius: 10px; padding: 10px 14px; margin: 10px 0; }

/* checks / comments / review */
.issue { display: grid; grid-template-columns: 70px 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px solid #eceef1; font-size: 14px; }
.lvl { font-size: 11px; font-weight: 800; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; height: fit-content; text-align: center; }
.lvl.error { background: var(--red-bg); color: var(--red); }
.lvl.warn { background: var(--amber-bg); color: var(--amber); }
.lvl.info { background: #eef0f2; color: var(--ink2); }
.issue .where { font-weight: 650; }
.thread { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 10px 0; background: #fff; }
.thread.resolved { opacity: .65; }
.cmt { font-size: 14px; margin: 4px 0 8px; white-space: pre-wrap; }
.cmt-head { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.reply { margin-left: 16px; border-left: 3px solid #eceef1; padding-left: 10px; }
.dim { border-bottom: 1px solid #eceef1; padding: 10px 0; }
.dim .dim-title { font-weight: 650; font-size: 14px; }
.dim .dim-desc { font-size: 13px; color: var(--muted); margin: 2px 0 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg label { padding: 4px 10px; cursor: pointer; font-size: 13px; border-right: 1px solid var(--line); }
.seg label:last-child { border-right: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { font-weight: 800; text-decoration: underline; }
.seg label:has(input:checked) { background: var(--ka-bg); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--ka); }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px;
  border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.bad { background: var(--red); }
dialog { border: 0; border-radius: 12px; padding: 0; max-width: min(900px, 94vw); width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog .dlg-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
dialog .dlg-body { padding: 16px; max-height: 75vh; overflow: auto; }
.signin { max-width: 440px; margin: 60px auto; }
@media (max-width: 640px) { main { padding: 12px; } .brand-text { font-size: 13px; } }
