/* ============================================================
   XTRA Manual — design system
   Modern, clinical, pragmatic. Light + dark.
   ============================================================ */
:root {
  --bg:        #f6f8fa;
  --surface:   #ffffff;
  --surface-2: #f0f3f6;
  --border:    #e2e8f0;
  --border-2:  #cbd5e1;
  --text:      #0f172a;
  --text-2:    #475569;
  --text-3:    #94a3b8;
  --accent:    #0ea5a4;   /* teal */
  --accent-d:  #0c8483;
  --accent-soft:#e6fffb;
  --blue:      #2563eb;
  --warn-bg:   #fff7ed;
  --warn-bd:   #fdba74;
  --warn-tx:   #9a3412;
  --shadow:    0 1px 2px rgba(15,23,42,.04), 0 4px 16px rgba(15,23,42,.06);
  --shadow-lg: 0 12px 40px rgba(15,23,42,.18);
  --radius:    10px;
  --sidebar-w: 320px;
  --chat-w:    400px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}
[data-theme="dark"] {
  --bg:        #0b1120;
  --surface:   #0f172a;
  --surface-2: #16213a;
  --border:    #1e293b;
  --border-2:  #334155;
  --text:      #e8eef6;
  --text-2:    #aab6c7;
  --text-3:    #64748b;
  --accent:    #2dd4bf;
  --accent-d:  #14b8a6;
  --accent-soft:#0c2f2c;
  --blue:      #60a5fa;
  --warn-bg:   #2a1c0f;
  --warn-bd:   #7c4a17;
  --warn-tx:   #fdba74;
  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
  --shadow-lg: 0 16px 50px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-d); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  height: 56px; display: flex; align-items: center; gap: 14px;
  padding: 0 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 650; letter-spacing:-.01em; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-d)); color: #fff; font-weight: 800; font-size: 15px;
  box-shadow: 0 2px 8px rgba(14,165,164,.4);
}
/* VIRCEO platform wordmark — self-hosted Space Grotesk (no CDN; works offline) */
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../assets/fonts/SpaceGrotesk-700.woff2") format("woff2");
}
.wordmark {
  font-family: "Space Grotesk", system-ui, "Segoe UI", sans-serif;
  font-weight: 700; letter-spacing: .04em; font-size: 18px; color: var(--text); white-space: nowrap;
}
.wordmark .x { color: var(--accent); }
.wordmark .g { color: #16a34a; }                              /* green accent letter */
[data-theme="dark"] .wordmark .g { color: #34d399; }          /* a touch brighter on dark */

/* LivaNova company logo — always on white, with clear-space (area of isolation) */
.brand-logo {
  display: inline-flex; align-items: center; background: #fff;
  border: 1px solid var(--border); border-radius: 9px; padding: 8px 13px;
  box-shadow: var(--shadow); flex: 0 0 auto;
}
.brand-logo img { height: 21px; display: block; }
.brand .divider { width: 1px; height: 26px; background: var(--border); flex: 0 0 auto; }
.brand .brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand small { display:block; font-weight: 450; color: var(--text-3); font-size: 11px; margin-top:-1px; }
@media (max-width: 640px) { .brand .divider, .brand .brand-text { display: none; } }
.topbar .spacer { flex: 1; }
.iconbtn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  width: 38px; height: 38px; border-radius: 9px; cursor: pointer; display: grid; place-items: center;
  transition: .15s; font-size: 16px;
}
.iconbtn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-2); }
.btn-chat {
  display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px;
  border-radius: 9px; border: none; cursor: pointer; font-weight: 600; font-size: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-d)); color: #fff;
  box-shadow: 0 2px 10px rgba(14,165,164,.35); transition: .15s;
}
.btn-chat:hover { filter: brightness(1.05); transform: translateY(-1px); }

/* ---------- account chip (POC) ---------- */
.account {
  display: flex; align-items: center; gap: 7px; height: 38px; padding: 0 13px;
  border: 1px solid var(--border); border-radius: 9px; cursor: pointer; font-size: 13.5px;
  font-weight: 600; color: var(--text-2); background: var(--surface); transition: .15s;
}
.account:hover { background: var(--surface-2); border-color: var(--border-2); color: var(--text); }
.account .acc-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- app footer (copyright) ---------- */
.appfoot {
  margin-top: 54px; padding-top: 22px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--text-3);
}
.appfoot .wordmark { font-size: 14px; }
.appfoot .sep { color: var(--border-2); }
/* sidebar copyright line in the reader */
.nav-foot {
  padding: 12px 16px 16px; border-top: 1px solid var(--border);
  font-size: 11px; line-height: 1.5; color: var(--text-3);
}
.nav-foot .wordmark { font-size: 12px; }

/* ---------- admin console (POC) ---------- */
/* .modal.admin-modal (not just .admin-modal): the generic .modal rule appears
   later with equal specificity and would otherwise clamp this to 480px. */
.modal.admin-modal { width: 920px; max-width: 95vw; padding: 0; overflow: hidden; }
.admin-head { display: flex; align-items: center; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--border); }
.admin-head h2 { margin: 0; font-size: 18px; }
.admin-head .spacer { flex: 1; }
.poc-badge { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent-d); background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 20px; padding: 3px 9px; }
.admin-tabs { display: flex; gap: 2px; padding: 8px 18px 0; border-bottom: 1px solid var(--border); }
.admin-tabs button { border: 0; background: transparent; padding: 10px 14px; font-size: 13.5px; font-weight: 600; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; }
.admin-tabs button:hover { color: var(--text); }
.admin-tabs button.on { color: var(--accent-d); border-bottom-color: var(--accent); }
/* Fixed pane height (sized to the tallest tab, Users & Roles) so switching tabs
   doesn't make the console jump; shorter tabs simply leave empty space, taller
   content (e.g. a long audit log) scrolls. min(...,58vh) keeps short screens sane. */
.admin-body { padding: 18px 22px; height: min(460px, 58vh); overflow-y: auto; }
.admin-foot { padding: 12px 22px; border-top: 1px solid var(--border); background: var(--surface-2); font-size: 11.5px; color: var(--text-3); line-height: 1.5; }

.role-switch { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.role-switch .rs-label { font-size: 12.5px; color: var(--text-3); margin-right: 4px; }
.role-switch .my-role { border: 1px solid var(--border-2); background: var(--surface); border-radius: 20px; padding: 5px 13px; font-size: 12.5px; font-weight: 600; color: var(--text-2); cursor: pointer; transition: .12s; }
.role-switch .my-role:hover { border-color: var(--accent); }
.role-switch .my-role.on { background: var(--accent); color: #fff; border-color: var(--accent); }

.atable-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); }
.atable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.atable th, .atable td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.atable th { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 700; }
.atable td .sub { font-size: 11.5px; color: var(--text-3); }
.atable select { height: 34px; width: 100%; min-width: 152px; border-radius: 7px; border: 1px solid var(--border-2); background: var(--bg); color: var(--text); font-size: 13px; padding: 0 30px 0 12px; font-family: var(--font); cursor: pointer; }
.atable select:hover { border-color: var(--border-2); }
.atable select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
/* give the Group / Role columns room so the closed dropdowns aren't cramped */
.atable th:nth-child(2), .atable th:nth-child(3) { min-width: 168px; }
.atable .actions { white-space: nowrap; text-align: right; }
.atable.audit .ts { color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 12.5px; }
.pill-ok { color: var(--accent-d); font-weight: 600; }
.pill-off { color: var(--text-3); }
.abtn { border: 1px solid var(--border-2); background: var(--surface); border-radius: 7px; padding: 5px 10px; font-size: 12px; cursor: pointer; color: var(--text-2); margin-left: 6px; transition: .12s; }
.abtn:first-child { margin-left: 0; }
.abtn:hover { border-color: var(--accent); color: var(--accent-d); }
.abtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.abtn.primary:hover { filter: brightness(1.05); color: #fff; }
.sample-note { font-size: 11.5px; color: var(--text-3); margin: 12px 0 0; line-height: 1.5; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--surface); }
.kpi .n { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.kpi .l { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.bars { display: flex; flex-direction: column; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 190px 1fr 32px; align-items: center; gap: 10px; font-size: 13px; }
.bar-l { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-d)); }
.bar-n { text-align: right; color: var(--text-3); font-variant-numeric: tabular-nums; font-size: 12.5px; }

.admin-toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 10px; font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: .2s; z-index: 80; }
.admin-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (max-width: 600px) { .bar-row { grid-template-columns: 120px 1fr 28px; } .atable .actions { text-align: left; } }

/* ---------- library / landing ---------- */
.library { max-width: 1180px; margin: 0 auto; padding: 40px 32px 100px; }
.lib-head { margin-bottom: 30px; }
.lib-head h1 { font-size: 32px; letter-spacing: -.02em; margin: 0 0 6px; }
.lib-head p { color: var(--text-2); font-size: 15.5px; margin: 0 0 20px; max-width: 620px; }
.lib-search { position: relative; max-width: 460px; }
.lib-search .si { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.lib-search input {
  width: 100%; height: 46px; padding: 0 16px 0 40px; border-radius: 11px;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
  font-size: 15px; font-family: var(--font); outline: none; transition: .15s; box-shadow: var(--shadow);
}
.lib-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 22px; }

.manual-card {
  display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 14px;
  overflow: hidden; background: var(--surface); box-shadow: var(--shadow); text-decoration: none;
  color: inherit; transition: transform .15s, box-shadow .15s, border-color .15s;
}
.manual-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--border-2); text-decoration: none; }
.mc-cover { height: 170px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; border-bottom: 1px solid var(--border); }
.mc-cover img { width: 100%; height: 100%; object-fit: cover; }
.mc-noimg { font-size: 48px; opacity: .4; }
.mc-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.mc-device { font-size: 11.5px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--accent-d); }
.mc-title { font-size: 17px; font-weight: 650; line-height: 1.3; letter-spacing: -.01em; }
.mc-stats { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--text-3); margin-top: 4px; }
.mc-open { margin-top: auto; padding-top: 12px; font-size: 13.5px; font-weight: 600; color: var(--accent-d); }

.add-card { border-style: dashed; border-color: var(--border-2); box-shadow: none; cursor: pointer; min-height: 280px; }
.add-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.add-inner { margin: auto; text-align: center; padding: 24px; color: var(--text-3); }
.add-plus { font-size: 40px; color: var(--accent); line-height: 1; }
.add-text { font-weight: 650; color: var(--text-2); margin-top: 10px; font-size: 15px; }
.add-sub { font-size: 12px; margin-top: 6px; line-height: 1.5; }

/* ---------- library toolbar (view / sort / favorites) ---------- */
.lib-toolbar { display: flex; align-items: center; gap: 12px; margin: 0 0 22px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border-2); border-radius: 9px; overflow: hidden; background: var(--surface); }
.seg-btn { border: none; background: transparent; padding: 7px 14px; font-size: 13px; font-weight: 600;
  color: var(--text-2); cursor: pointer; display: flex; align-items: center; gap: 6px; transition: .12s; }
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn:hover:not(.on) { background: var(--surface-2); color: var(--text); }
.seg-btn.on { background: var(--accent-soft); color: var(--accent-d); }
.tb-spacer { flex: 1; }
.tb-btn { border: 1px solid var(--border-2); background: var(--surface); border-radius: 9px; padding: 7px 13px;
  font-size: 13px; font-weight: 600; color: var(--text-2); cursor: pointer; transition: .12s;
  display: flex; align-items: center; gap: 6px; }
.tb-btn:hover { background: var(--surface-2); color: var(--text); }
.fav-toggle.on { color: #b8860b; border-color: #e6c200; background: #fffae6; }
.fav-toggle b { background: rgba(0,0,0,.07); border-radius: 10px; padding: 0 6px; font-size: 11px; }
[data-theme=dark] .fav-toggle.on { background: rgba(242,183,5,.12); }
.tb-sort { font-size: 12.5px; color: var(--text-3); font-weight: 600; display: flex; align-items: center; gap: 7px; }
.tb-sort select { height: 34px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--surface);
  color: var(--text); font-size: 13px; padding: 0 8px; font-family: var(--font); cursor: pointer; }

/* ---------- card star + drag affordances ---------- */
.mc-cover { position: relative; }
.mc-star { position: absolute; top: 8px; right: 8px; z-index: 2; width: 32px; height: 32px; border-radius: 50%;
  border: none; background: rgba(255,255,255,.92); color: #c9ad3a; font-size: 17px; line-height: 1; cursor: pointer;
  display: grid; place-items: center; box-shadow: var(--shadow); opacity: .85; transition: transform .12s, opacity .12s; }
.mc-star:hover { transform: scale(1.12); opacity: 1; }
.mc-star.on { color: #f2b705; background: #fff; opacity: 1; }
[data-theme=dark] .mc-star { background: rgba(18,26,38,.85); }
[data-theme=dark] .mc-star.on { background: rgba(18,26,38,.95); }
.mc-grip { position: absolute; top: 9px; left: 11px; z-index: 2; color: #fff; opacity: .8; font-size: 16px;
  text-shadow: 0 1px 4px rgba(0,0,0,.55); cursor: grab; pointer-events: none; }
.manual-card[draggable="true"] { cursor: grab; }
.manual-card.dragging { opacity: .45; transform: scale(.98); box-shadow: var(--shadow-lg); }

/* ---------- list view ---------- */
.lib-grid.view-list { display: flex; flex-direction: column; gap: 12px; }
.lib-grid.view-list .manual-card { flex-direction: row; }
.lib-grid.view-list .manual-card:hover { transform: translateX(2px); }
.lib-grid.view-list .mc-cover { height: auto; width: 132px; flex: 0 0 132px; border-bottom: none; border-right: 1px solid var(--border); }
.lib-grid.view-list .mc-body { padding: 15px 20px; }
.lib-grid.view-list .mc-title { font-size: 16px; }
.lib-grid.view-list .mc-open { padding-top: 8px; }
.lib-grid.view-list .add-card { min-height: 0; }
.lib-grid.view-list .add-card .add-inner { display: flex; align-items: center; gap: 14px; padding: 18px 24px; text-align: left; }
.lib-grid.view-list .add-card .add-plus { font-size: 30px; }
.lib-grid.view-list .add-card .add-text { margin-top: 0; }

/* ---------- layout ---------- */
.layout { display: flex; height: calc(100vh - 56px); }

/* ---------- sidebar ---------- */
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.search-wrap { padding: 14px; border-bottom: 1px solid var(--border); }
.search-box {
  position: relative; display: flex; align-items: center;
}
.search-box input {
  width: 100%; height: 40px; padding: 0 36px 0 36px; border-radius: 9px;
  border: 1px solid var(--border-2); background: var(--bg); color: var(--text);
  font-size: 14px; font-family: var(--font); outline: none; transition: .15s;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box .si { position: absolute; left: 11px; color: var(--text-3); pointer-events:none; }
.search-box .clear { position: absolute; right: 8px; color: var(--text-3); cursor: pointer; display:none; border:0; background:0; font-size:16px; }
.search-meta { font-size: 12px; color: var(--text-3); padding: 8px 2px 0; }

.nav { flex: 1; overflow-y: auto; padding: 8px 8px 40px; }
.nav::-webkit-scrollbar { width: 10px; }
.nav::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 8px; border: 3px solid var(--surface); }

.chapter { margin-bottom: 2px; }
.chapter > .nav-item { font-weight: 650; }
.nav-item {
  display: grid; grid-template-columns: 16px 1fr auto; align-items: start;
  column-gap: 7px; padding: 7px 10px; border-radius: 8px;
  cursor: pointer; color: var(--text-2); font-size: 13.5px; line-height: 1.4;
  transition: background .12s, color .12s; user-select: none;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-d); font-weight: 600; }
.nav-item .twirl {
  color: var(--text-3); transition: transform .15s; font-size: 9px; text-align: center;
  line-height: 1.9;   /* nudge the caret onto the first text line */
}
.nav-item.open > .twirl, .nav-item.open .twirl { transform: rotate(90deg); }
.nav-item .t { min-width: 0; overflow-wrap: anywhere; }
.nav-item .pg {
  font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums;
  line-height: 1.7; padding-left: 4px;
}
.lvl-2 { padding-left: 14px; }
.lvl-3 { padding-left: 28px; font-size: 13px; }
.lvl-4 { padding-left: 42px; font-size: 12.5px; }
.children { display: none; }
.children.open { display: block; }

/* ---------- search results ---------- */
.results { padding: 6px; }
.result {
  padding: 10px 12px; border-radius: 9px; cursor: pointer; margin-bottom: 4px;
  border: 1px solid transparent;
}
.result:hover { background: var(--surface-2); border-color: var(--border); }
.result .r-title { font-weight: 600; font-size: 14px; color: var(--text); }
.result .r-crumb { font-size: 11.5px; color: var(--text-3); margin: 2px 0 4px; }
.result .r-snip { font-size: 12.5px; color: var(--text-2); line-height: 1.45; }
.result mark, .content mark { background: #fde68a; color: #7c2d12; border-radius: 3px; padding: 0 2px; }
[data-theme="dark"] .result mark, [data-theme="dark"] .content mark { background: #a16207; color: #fff; }

/* ---------- reading pane ---------- */
.main { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
/* reading area: prose column (capped for readability) + sticky "on this page" rail */
.reading {
  display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 44px;
  max-width: 1240px; margin: 0 auto; padding: 0 40px; align-items: start;
}
.content {
  max-width: 860px; padding: 40px 0 120px; min-width: 0;
}

/* ---------- on-this-page rail ---------- */
.onpage { position: sticky; top: 0; padding: 46px 0 40px; font-size: 13px; }
.onpage .op-title {
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-3); margin: 0 0 12px; padding-left: 12px;
}
.onpage .op-group { margin-bottom: 18px; }
.onpage .op-group h4 {
  font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-3); margin: 0 0 6px; padding-left: 12px;
}
.onpage a {
  display: block; padding: 5px 12px; border-left: 2px solid var(--border);
  color: var(--text-2); line-height: 1.35; cursor: pointer; transition: .12s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.onpage a:hover { color: var(--accent-d); border-left-color: var(--accent); background: var(--surface-2); text-decoration: none; }
.onpage a.op-pg { font-variant-numeric: tabular-nums; color: var(--text-3); }
.onpage .op-empty { padding-left: 12px; color: var(--text-3); font-size: 12.5px; line-height: 1.5; }

@media (max-width: 1240px) { .onpage { display: none; } .reading { grid-template-columns: 1fr; max-width: 900px; } }
/* give the prose room when the rail is hidden or the chat panel is open */
.reading.no-rail { grid-template-columns: 1fr; max-width: 900px; }
.reading.no-rail .onpage { display: none; }
.crumbs { font-size: 12.5px; color: var(--text-3); margin-bottom: 10px; display:flex; gap:6px; flex-wrap:wrap; }
.crumbs span.sep { color: var(--border-2); }
.content h1 {
  font-size: 30px; line-height: 1.2; letter-spacing: -.02em; margin: 0 0 6px;
  font-weight: 700;
}
.pageref {
  display: inline-flex; align-items:center; gap:5px; font-size: 12px; color: var(--text-3);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; padding: 3px 10px;
  margin-bottom: 24px;
}
.content p { margin: 0 0 14px; }
.content ul, .content ol { margin: 0 0 16px; padding-left: 24px; }
.content li { margin-bottom: 7px; }
.content ol { counter-reset: none; }
.content ol > li { padding-left: 4px; }
.content ol > li::marker { color: var(--accent-d); font-weight: 650; }
.content .lead { font-size: 16.5px; color: var(--text-2); }

/* figure callout legend */
.content ul.legend {
  list-style: none; padding: 0; margin: 4px 0 20px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 6px 18px;
}
.content ul.legend li {
  display: grid; grid-template-columns: 26px 1fr; align-items: start; gap: 9px;
  margin: 0; font-size: 14px; color: var(--text-2);
}
.content ul.legend .n {
  display: inline-grid; place-items: center; width: 24px; height: 24px;
  background: var(--accent-soft); color: var(--accent-d); border: 1px solid var(--accent);
  border-radius: 6px; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
}

.callout {
  border: 1px solid var(--warn-bd); background: var(--warn-bg); color: var(--warn-tx);
  border-radius: var(--radius); padding: 12px 16px; margin: 0 0 16px; font-size: 14px;
  display: flex; gap: 10px;
}
.callout .ci { font-size: 16px; }

/* generated Table of Contents / List of Figures index */
.toc-gen { margin: 8px 0 8px; }
.toc-entry {
  display: flex; align-items: baseline; gap: 4px; cursor: pointer;
  padding: 5px 8px; border-radius: 7px; color: var(--text-2); transition: background .12s, color .12s;
}
.toc-entry:hover { background: var(--surface-2); color: var(--accent-d); }
.toc-entry .t { flex: 0 1 auto; }
.toc-entry .leader { flex: 1 1 auto; border-bottom: 1.5px dotted var(--border-2); transform: translateY(-3px); min-width: 24px; }
.toc-entry .p { flex: 0 0 auto; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text-3); }
.toc-entry.lvl-1 { font-weight: 650; color: var(--text); margin-top: 10px; }
.toc-entry.lvl-1 .p { color: var(--text-2); }
.toc-entry.lvl-2 { padding-left: 22px; }
.toc-entry.lvl-3 { padding-left: 40px; font-size: 13.5px; }
.toc-entry.lvl-4 { padding-left: 58px; font-size: 13px; }

/* physical page break (keeps the printed page number) */
.pbreak { display: flex; align-items: center; gap: 12px; margin: 30px 0 26px; user-select: none; }
.pbreak .pb-rule { flex: 1; height: 1px; background: repeating-linear-gradient(to right, var(--border-2) 0 6px, transparent 6px 11px); }
.pbreak .pb-label {
  font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-3); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 12px; white-space: nowrap; font-variant-numeric: tabular-nums;
}

/* data tables */
.table-wrap { margin: 18px 0 22px; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.content table { border-collapse: collapse; width: 100%; font-size: 13.5px; background: var(--surface); }
.content table th, .content table td {
  text-align: left; vertical-align: top; padding: 9px 13px;
  border-bottom: 1px solid var(--border); border-right: 1px solid var(--border);
}
.content table th:last-child, .content table td:last-child { border-right: none; }
.content table tr:last-child td { border-bottom: none; }
.content table th {
  background: var(--surface-2); color: var(--text); font-weight: 650;
  position: sticky; top: 0; border-bottom: 2px solid var(--border-2);
}
.content table tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.content table td { color: var(--text-2); }

.figs { margin: 26px 0; display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
figure.fig, .table-wrap, .pbreak { scroll-margin-top: 20px; }
.fig {
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface); box-shadow: var(--shadow);
  max-width: 100%;                 /* never exceed the column            */
}
/* small UI icons / symbols keep their native size; large diagrams fill   */
.fig img { display: block; max-width: 100%; height: auto; background: #fff; cursor: zoom-in; }
.fig.wide { flex: 1 1 100%; }       /* captioned figures get their own row */
.fig.wide img { width: 100%; }
.fig figcaption { padding: 9px 14px; font-size: 12.5px; color: var(--text-2); border-top: 1px solid var(--border); background: var(--surface-2); }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 48px; border-top: 1px solid var(--border); padding-top: 24px; }
.pager a {
  flex: 1; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px;
  background: var(--surface); color: var(--text); transition: .15s; box-shadow: var(--shadow);
}
.pager a:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.pager .dir { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }
.pager .t { font-weight: 600; font-size: 14px; }
.pager .next { text-align: right; }
.pager .empty { visibility: hidden; }

/* ---------- chat panel ---------- */
.chat {
  width: var(--chat-w); flex: 0 0 var(--chat-w);
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; transition: margin-right .25s ease;
}
.chat.hidden { margin-right: calc(-1 * var(--chat-w)); }
.chat-head {
  padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px;
}
.chat-head .ch-logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg,var(--blue),#1e40af); display:grid; place-items:center; color:#fff; font-size:15px; }
.chat-head .ch-title { font-weight: 650; font-size: 14.5px; }
.chat-head .ch-sub { font-size: 11.5px; color: var(--text-3); }
.chat-head .spacer { flex:1; }

.chat-log { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 100%; }
.msg .av { width: 28px; height: 28px; border-radius: 8px; flex: 0 0 28px; display:grid; place-items:center; font-size: 13px; font-weight:700; }
.msg.user { flex-direction: row-reverse; }
.msg.user .av { background: var(--accent); color:#fff; }
.msg.bot .av { background: var(--surface-2); border:1px solid var(--border); }
.bubble {
  padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.55;
  background: var(--surface-2); border: 1px solid var(--border);
}
.msg.user .bubble { background: var(--accent); color: #fff; border-color: transparent; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin: 0; }
.bubble ul { margin: 6px 0; padding-left: 18px; }
.bubble .cite {
  display:inline-block; margin: 6px 6px 0 0; font-size: 11.5px; color: var(--accent-d);
  background: var(--accent-soft); border:1px solid var(--accent); border-radius: 14px; padding: 2px 9px; cursor: pointer;
}
.bubble .cite:hover { background: var(--accent); color:#fff; }
.typing { display:inline-flex; gap:4px; padding: 4px 0; }
.typing i { width:7px; height:7px; border-radius:50%; background: var(--text-3); animation: blink 1.2s infinite both; }
.typing i:nth-child(2){animation-delay:.2s} .typing i:nth-child(3){animation-delay:.4s}
@keyframes blink { 0%,80%,100%{opacity:.25} 40%{opacity:1} }

.suggest { display:flex; flex-wrap:wrap; gap:8px; padding: 0 16px 12px; }
.suggest button {
  font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border:1px solid var(--border);
  border-radius: 16px; padding: 6px 12px; cursor:pointer; transition:.12s;
}
.suggest button:hover { border-color: var(--accent); color: var(--accent-d); }

.chat-input { padding: 12px 14px; border-top: 1px solid var(--border); }
.chat-input .row { display:flex; gap:8px; align-items:flex-end; background: var(--bg); border:1px solid var(--border-2); border-radius: 12px; padding: 6px 6px 6px 12px; }
.chat-input .row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chat-input textarea {
  flex:1; border:0; outline:0; resize:none; background:transparent; color:var(--text);
  font-family: var(--font); font-size: 14px; max-height: 120px; line-height:1.5; padding: 5px 0;
}
.chat-input .send { width:36px; height:36px; flex:0 0 36px; border-radius:9px; border:0; cursor:pointer; background: var(--accent); color:#fff; display:grid; place-items:center; transition:.15s; }
.chat-input .send:hover { background: var(--accent-d); }
.chat-input .send:disabled { opacity:.4; cursor:default; }
.chat-input .mic {
  width:36px; height:36px; flex:0 0 36px; border-radius:9px; border:1px solid var(--border-2);
  cursor:pointer; background:var(--surface); color:var(--text-2); display:grid; place-items:center;
  font-size:15px; transition:.15s; align-self:flex-end;
}
.chat-input .mic:hover { border-color:var(--accent); color:var(--accent-d); }
.chat-input .mic.on { background:#ef4444; color:#fff; border-color:#ef4444; animation: micpulse 1.2s infinite; }
@keyframes micpulse { 0%{ box-shadow:0 0 0 0 rgba(239,68,68,.5);} 70%{ box-shadow:0 0 0 8px rgba(239,68,68,0);} 100%{ box-shadow:0 0 0 0 rgba(239,68,68,0);} }

/* hands-free toggle (header) + status banner */
#voiceToggle.on { background: var(--accent); color:#fff; border-color: var(--accent); }
.voice-banner {
  display:flex; align-items:center; gap:9px; padding:9px 16px; font-size:13px; font-weight:600;
  color:var(--accent-d); background:var(--accent-soft); border-bottom:1px solid var(--border);
}
.voice-banner .vb-dot { width:9px; height:9px; border-radius:50%; background:var(--accent); animation: micpulse 1.4s infinite; flex:0 0 auto; }
.voice-banner .vb-state { flex:0 0 auto; }
/* live transcript caption — shows the recognized words as they arrive (key reel visual) */
.voice-banner .vb-heard {
  flex:1 1 auto; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
  font-style:italic; font-weight:600; opacity:.92;
}
.voice-banner .vb-heard:empty { display:none; }
.voice-banner #voiceStop {
  margin-left:auto; border:1px solid currentColor; background:transparent; color:inherit;
  border-radius:14px; padding:3px 12px; font-size:12px; font-weight:600; cursor:pointer; flex:0 0 auto; opacity:.85;
}
.voice-banner #voiceStop:hover { background:rgba(0,0,0,.06); opacity:1; }

/* phase coloring so the command visibly progresses: listening → heard → speaking */
.voice-banner.listening .vb-dot { background:#ef4444; }                 /* red = mic live */
.voice-banner.heard { color:#15803d; background:#ecfdf5; }              /* green = captured */
.voice-banner.heard .vb-dot { background:#16a34a; animation:none; }
.voice-banner.speaking { color:var(--blue); background:#eff6ff; }       /* blue = answering */
.voice-banner.speaking .vb-dot { background:var(--blue); }
.voice-banner.error { color:var(--warn-tx); background:var(--warn-bg); }
.voice-banner.error .vb-dot { background:var(--warn-bd); animation:none; }
[data-theme=dark] .voice-banner.heard { background:rgba(22,163,74,.14); color:#4ade80; }
[data-theme=dark] .voice-banner.speaking { background:rgba(37,99,235,.16); color:#93c5fd; }
.chat-disclaimer { font-size: 10.5px; color: var(--text-3); text-align:center; margin-top: 8px; line-height:1.4; }

/* ---------- settings / key modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); display:none; place-items:center; z-index: 60; backdrop-filter: blur(2px); }
.modal-backdrop.open { display: grid; }
.modal {
  width: 480px; max-width: 92vw; background: var(--surface); border:1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 24px;
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal p { color: var(--text-2); font-size: 13.5px; margin: 0 0 16px; }
.modal label { font-size: 12.5px; font-weight: 600; color: var(--text-2); display:block; margin-bottom: 6px; }
.modal input[type=password], .modal input[type=text] {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 9px; border:1px solid var(--border-2);
  background: var(--bg); color: var(--text); font-size: 14px; font-family: var(--mono); outline:none;
}
.modal input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal .actions { display:flex; gap:10px; justify-content:flex-end; margin-top: 20px; }
.modal .seg { display:flex; gap:0; border:1px solid var(--border-2); border-radius:9px; overflow:hidden; margin-bottom:16px; }
.modal .seg button { flex:1; border:0; background:var(--surface); color:var(--text-2); padding:9px; cursor:pointer; font-size:13px; font-weight:600; }
.modal .seg button.on { background: var(--accent); color:#fff; }
.btn-primary { height:40px; padding:0 18px; border:0; border-radius:9px; background: var(--accent); color:#fff; font-weight:600; cursor:pointer; font-size:14px; }
.btn-primary:hover { background: var(--accent-d); }
.btn-ghost { height:40px; padding:0 16px; border:1px solid var(--border-2); border-radius:9px; background:var(--surface); color:var(--text-2); cursor:pointer; font-size:14px; }
.note { font-size:12px; color:var(--text-3); background:var(--surface-2); border:1px solid var(--border); border-radius:9px; padding:10px 12px; margin-top:14px; line-height:1.5; }
.vsec { margin-top:20px; padding-top:18px; border-top:1px solid var(--border); }
.vsec h3 { margin:0 0 12px; font-size:14.5px; }
.modal select {
  width:100%; height:40px; padding:0 10px; border-radius:9px; border:1px solid var(--border-2);
  background:var(--bg); color:var(--text); font-size:13.5px; font-family:var(--font); outline:none; margin-bottom:4px;
}
.modal select:focus { border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-soft); }
.vrow { display:flex; gap:8px; align-items:center; }
.vrow select { flex:1; }
.vrow .vtest { height:40px; white-space:nowrap; flex:0 0 auto; }

/* ---------- lightbox ---------- */
.lightbox { position:fixed; inset:0; background:rgba(8,12,22,.88); display:none; place-items:center; z-index:70; cursor:zoom-out; padding:30px; }
.lightbox.open { display:grid; }
.lightbox img { max-width:95vw; max-height:92vh; border-radius:8px; box-shadow: var(--shadow-lg); }

/* ---------- floating prev/next ---------- */
.floatnav {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px; z-index: 32;
  background: var(--surface); border: 1px solid var(--border-2); border-radius: 999px;
  padding: 4px; box-shadow: var(--shadow-lg); opacity: .82; transition: opacity .18s, transform .18s;
}
.floatnav:hover { opacity: 1; }
.floatnav .fn-btn {
  display: inline-flex; align-items: center; gap: 2px; border: 0; background: transparent;
  color: var(--text-2); font-family: var(--font); font-size: 13.5px; font-weight: 600;
  padding: 8px 16px; border-radius: 999px; cursor: pointer; transition: .12s; white-space: nowrap;
}
.floatnav .fn-btn span { font-weight: 600; }
.floatnav .fn-btn:hover { background: var(--surface-2); color: var(--accent-d); }
.floatnav .fn-btn.disabled { opacity: .35; pointer-events: none; }
.floatnav .fn-div { width: 1px; align-self: stretch; background: var(--border); margin: 4px 0; }
@media (max-width: 820px) { .floatnav { bottom: 14px; } .floatnav .fn-btn { padding: 9px 18px; } }

/* ---------- roles, annotations & editing (POC) ---------- */
.rolechip {
  display: flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 9px; cursor: pointer; font-size: 13px;
  font-weight: 600; color: var(--text-2); background: var(--surface); transition: .15s; white-space: nowrap;
}
.rolechip:hover { background: var(--surface-2); border-color: var(--border-2); color: var(--text); }
.rolechip .rc-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.rolechip[data-role="Annotator"] .rc-dot { background: #f59e0b; }
.rolechip[data-role="Author"] .rc-dot { background: var(--blue); }
.rolechip[data-role="Admin"] .rc-dot { background: var(--accent); }

.role-menu {
  position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--border-2);
  border-radius: 11px; box-shadow: var(--shadow-lg); padding: 6px; min-width: 215px;
}
.role-menu .rm-head { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); padding: 6px 10px 4px; }
.role-menu .rm-head span { opacity: .7; }
.role-menu button { display: flex; flex-direction: column; gap: 1px; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.role-menu button:hover { background: var(--surface-2); }
.role-menu button.on { background: var(--accent-soft); }
.role-menu .rm-r { font-size: 13.5px; font-weight: 650; color: var(--text); }
.role-menu .rm-d { font-size: 11.5px; color: var(--text-3); }

.role-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 20px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.role-actions .ra-hint { font-size: 12.5px; color: var(--text-3); margin-left: auto; }

.cbadge { display: inline-block; margin: 0 0 18px 10px; font-size: 11.5px; font-weight: 600; border-radius: 20px; padding: 3px 11px; vertical-align: middle; }
.cbadge.draft { color: var(--warn-tx); background: var(--warn-bg); border: 1px solid var(--warn-bd); }
.cbadge.pub { color: var(--accent-d); background: var(--accent-soft); border: 1px solid var(--accent); }

.edit-wrap { margin-top: 6px; }
.edit-wrap textarea { width: 100%; min-height: 360px; padding: 16px; border: 1px solid var(--border-2); border-radius: 10px; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.6; resize: vertical; outline: none; }
.edit-wrap textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.edit-actions { display: flex; gap: 10px; margin-top: 12px; }

/* annotation highlights */
mark.anno { background: #fde68a; color: inherit; border-radius: 3px; padding: 0 1px; cursor: pointer; box-shadow: inset 0 -2px 0 rgba(217,119,6,.4); }
mark.anno.has-note { background: #bfdbfe; box-shadow: inset 0 -2px 0 rgba(37,99,235,.45); }
[data-theme="dark"] mark.anno { background: #92670c; color: #fff; }
[data-theme="dark"] mark.anno.has-note { background: #1e40af; color: #fff; }

.anno-bar { position: fixed; z-index: 65; display: none; gap: 2px; background: var(--text); border-radius: 9px; padding: 4px; box-shadow: var(--shadow-lg); }
.anno-bar.show { display: flex; }
.anno-bar button { border: 0; background: transparent; color: #fff; font-size: 12.5px; font-weight: 600; padding: 6px 11px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.anno-bar button:hover { background: rgba(255,255,255,.16); }
.anno-bar input { border: 0; outline: 0; background: rgba(255,255,255,.12); color: #fff; border-radius: 6px; padding: 6px 10px; font-size: 13px; width: 200px; }
.anno-bar input::placeholder { color: rgba(255,255,255,.6); }

.anno-pop { position: fixed; z-index: 65; background: var(--surface); border: 1px solid var(--border-2); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 12px 14px; max-width: 280px; }
.anno-pop .ap-note { font-size: 13.5px; color: var(--text); line-height: 1.5; }
.anno-pop .ap-note.ap-hl { color: var(--text-3); font-style: italic; }
.anno-pop .ap-meta { font-size: 11.5px; color: var(--text-3); margin-top: 8px; }
.anno-pop .ap-del { border: 0; background: 0; color: #ef4444; font-weight: 600; cursor: pointer; font-size: 11.5px; padding: 0; }
.anno-pop .ap-del:hover { text-decoration: underline; }

/* ---------- misc ---------- */
.hidden { display: none !important; }
.empty-state { text-align:center; color: var(--text-3); padding: 80px 20px; }
.empty-state .big { font-size: 40px; margin-bottom: 12px; }
.kbd { font-family: var(--mono); font-size: 11px; background: var(--surface-2); border:1px solid var(--border-2); border-bottom-width:2px; border-radius:5px; padding: 1px 5px; color: var(--text-2); }

/* ---------- responsive ---------- */
.scrim { position: fixed; inset:0; background: rgba(15,23,42,.4); z-index: 35; display:none; }
@media (max-width: 1100px) {
  .chat { position: fixed; right: 0; top: 56px; bottom: 0; z-index: 50; box-shadow: var(--shadow-lg); }
}
@media (max-width: 820px) {
  :root { --sidebar-w: 290px; }
  .sidebar { position: fixed; left:0; top:56px; bottom:0; z-index: 45; transform: translateX(-100%); transition: transform .25s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .scrim.show { display:block; }
  .content { padding: 28px 20px 100px; }
  .chat { width: 100vw; flex-basis: 100vw; }
  .menu-toggle { display: grid !important; }
}
.menu-toggle { display: none; }
