@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --brand: #0f766e;
  --brand-dark: #0b5c56;
  --brand-soft: #ccfbf1;
  --accent: #f59e0b;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --ok: #067647;
  --ok-soft: #d1fadf;
  --radius: 16px;
  --shadow: 0 12px 32px rgba(16, 24, 40, 0.07);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.8;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }

h1, h2, h3 { line-height: 1.5; margin: 0 0 0.6rem; }
h1 { font-size: 1.65rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

p { margin: 0 0 0.8rem; }

.container { width: min(1120px, 100% - 2rem); margin-inline: auto; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.nowrap { white-space: nowrap; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 0.9rem; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  min-height: 64px;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  color: var(--ink);
  font-size: 1rem;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.nav { display: flex; gap: 0.25rem; margin-inline-start: auto; }
.nav a {
  padding: 0.4rem 0.8rem;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}
.nav a:hover { background: var(--bg); color: var(--ink); }
.nav a.active { color: var(--brand); background: var(--brand-soft); }

.userbox { display: flex; align-items: center; gap: 0.8rem; font-size: 0.9rem; }
.user-name { color: var(--ink); font-weight: 700; }

.subnav {
  display: flex;
  gap: 0.4rem;
  padding-block: 0.5rem;
  border-top: 1px dashed var(--line);
}
.subnav a {
  font-size: 0.85rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  color: var(--muted);
}
.subnav a.active { background: var(--ink); color: #fff; }

.main { flex: 1; padding-block: 2rem 3rem; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.4rem;
  flex-wrap: wrap;
}
.page-head h1 { margin-bottom: 0.15rem; }

.backlink { color: var(--muted); font-size: 0.85rem; display: inline-block; margin-bottom: 0.4rem; }

.footer {
  border-top: 1px solid var(--line);
  padding-block: 1.2rem;
  color: var(--muted);
  font-size: 0.82rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.4rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.2rem;
}

.grid { display: grid; gap: 1rem; }
.cards { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.two-col { grid-template-columns: 1.2fr 1fr; align-items: start; }
.stats { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); margin-bottom: 1.2rem; }
.form-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.3rem;
  box-shadow: var(--shadow);
  color: var(--ink);
  transition: transform 0.18s ease, border-color 0.18s ease;
}
.card:hover { transform: translateY(-3px); border-color: var(--brand); color: var(--ink); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.card-head h2 { font-size: 1.1rem; }
.card-desc { min-height: 3rem; font-size: 0.9rem; }
.card-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.82rem; }

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  color: var(--muted);
  font-size: 0.82rem;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--ink); line-height: 1.4; }

.pill {
  background: var(--brand-soft);
  color: var(--brand-dark);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

.bar {
  width: 100%;
  height: 9px;
  appearance: none;
  border: none;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  display: block;
}
.bar::-webkit-progress-bar { background: var(--line); border-radius: 999px; }
.bar::-webkit-progress-value { background: linear-gradient(90deg, var(--brand), #14b8a6); border-radius: 999px; }
.bar::-moz-progress-bar { background: var(--brand); border-radius: 999px; }
.bar.small { height: 6px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); border-color: #cbd5e1; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-small { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-danger { color: var(--danger); border-color: #fda29b; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-block { width: 100%; }

.linklike {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
}
.linklike:hover { color: var(--danger); }

.inline { display: inline; }
.row-form { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.row-form select { flex: 1; min-width: 180px; }

.auth-wrap { display: grid; place-items: center; padding-block: 2rem; }
.auth-card { width: min(430px, 100%); }
.auth-card h1 { margin-bottom: 0.2rem; }

.stack { display: grid; gap: 0.9rem; }
.field { display: grid; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.field input, .field select, .row-form select, .row-form input, .panel select {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  width: 100%;
}
.field input:focus, .field select:focus, .row-form select:focus, .panel select:focus {
  outline: 2px solid var(--brand-soft);
  border-color: var(--brand);
}
input[type="file"] { padding: 0.45rem; background: var(--bg); }

.flash { border-radius: 12px; padding: 0.7rem 1rem; margin-bottom: 1rem; font-size: 0.9rem; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-err { background: var(--danger-soft); color: var(--danger); }

.empty-state { text-align: center; color: var(--muted); padding: 2.4rem 1.4rem; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--brand); line-height: 1.2; }
.error-state a { margin-top: 1rem; }

.video-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.video-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.8rem 1rem;
  background: #fff;
}
.video-index {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 700;
}
.video-main { flex: 1; min-width: 0; }
.video-title { font-weight: 700; color: var(--ink); display: inline-block; margin-bottom: 0.15rem; }
.video-meta { display: flex; gap: 0.8rem; flex-wrap: wrap; font-size: 0.8rem; align-items: center; }
.badge-done { background: var(--ok-soft); color: var(--ok); border-radius: 999px; padding: 0 0.5rem; font-size: 0.75rem; }

.player-card { margin-bottom: 1rem; }
.player-wrap {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  box-shadow: var(--shadow);
}
.player-wrap video { width: 100%; height: 100%; display: block; }

.watermark {
  position: absolute;
  left: 50%;
  top: 15%;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.9rem;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
  z-index: 3;
  transition: left 1.8s ease, top 1.8s ease;
}
.player-error {
  position: absolute;
  inset: auto 1rem 1rem 1rem;
  background: rgba(180, 35, 24, 0.92);
  color: #fff;
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  z-index: 4;
}
.player-nav { display: flex; justify-content: space-between; gap: 1rem; }
.watermark-hint { text-align: center; }

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
.table th, .table td {
  text-align: start;
  padding: 0.6rem 0.6rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table th { color: var(--muted); font-weight: 700; font-size: 0.78rem; white-space: nowrap; }
.table tbody tr:hover { background: #fafcff; }
.table.compact th, .table.compact td { padding: 0.45rem 0.5rem; }
.status { display: inline-block; border-radius: 999px; padding: 0.05rem 0.55rem; font-size: 0.76rem; white-space: nowrap; }
a.status { text-decoration: none; }
.status-ready { background: var(--ok-soft); color: var(--ok); }
.status-processing { background: #fef0c7; color: #93370d; }
.status-pending { background: #e0eaff; color: #1d4ed8; }
.status-failed { background: var(--danger-soft); color: var(--danger); }
.progress-cell { min-width: 140px; display: flex; align-items: center; gap: 0.4rem; }
.progress-cell .bar { flex: 1; }
.progress-text { font-size: 0.75rem; margin-inline-start: 0.3rem; }
.error-cell { max-width: 260px; font-size: 0.78rem; overflow-wrap: anywhere; }
.detail-cell { max-width: 280px; font-size: 0.75rem; overflow-wrap: anywhere; color: var(--muted); }
.ua-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.78rem; color: var(--muted); }
.actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.kind { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.76rem; background: var(--bg); border-radius: 6px; padding: 0.05rem 0.35rem; }

.worker-state { font-size: 0.85rem; color: var(--muted); display: flex; align-items: center; gap: 0.4rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-ok { background: var(--ok); }
.dot-bad { background: var(--danger); }

.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; padding-top: 1rem; }

@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .topbar-inner { gap: 0.7rem; padding-block: 0.6rem; }
  .nav { order: 3; width: 100%; margin-inline-start: 0; }
  .userbox { margin-inline-start: auto; }
  .main { padding-block: 1.2rem 2rem; }
  .panel { padding: 1rem; }
  .video-row { gap: 0.6rem; padding: 0.7rem; }
  .video-row .btn { display: none; }
  h1 { font-size: 1.35rem; }
  .table th, .table td { padding: 0.45rem; }
}

.chapter-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.chapter-row {
  display: flex; align-items: center; gap: 1rem;
  border: 1px solid var(--line); border-radius: 14px; padding: 0.8rem 1rem; background: #fff;
}
.chapter-row.locked { background: #fbfcfe; }
.chapter-no {
  width: 38px; height: 38px; flex: 0 0 auto; border-radius: 12px;
  background: var(--brand-soft); color: var(--brand-dark);
  display: grid; place-items: center; font-weight: 700;
}
.chapter-main { flex: 1; min-width: 0; }
.chapter-title { font-weight: 700; margin-bottom: 0.1rem; }
.badge-locked { background: #f2f4f7; color: var(--muted); border-radius: 999px; padding: 0 0.45rem; font-size: 0.72rem; }

/* ---------- chapter reading workspace ---------- */
.chapter-head { margin-bottom: 1rem; }
.chapter-head-main { min-width: 0; }
.chapter-head h1 { margin-bottom: 0; }
.chapter-meta { margin: 0.2rem 0 0; font-size: 0.85rem; }

.chapter-workspace {
  --ws-split: 58;
  display: grid;
  grid-template-columns: calc(var(--ws-split) * 1%) 14px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "booklet handle tabs"
    "booklet handle rail";
  align-items: start;
  row-gap: 0.55rem;
  margin-bottom: 1.5rem;
}
.chapter-workspace .btn:focus-visible,
.chapter-workspace .ws-tab:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.ws-tabs {
  grid-area: tabs;
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 72px;
  z-index: 6;
  min-width: 0;
}
.ws-tab {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.4rem 0.5rem;
  border-radius: 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  white-space: nowrap;
}
.ws-tab:hover { background: var(--bg); color: var(--ink); }
.ws-tab:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.ws-tab.is-active { background: var(--brand-soft); color: var(--brand-dark); }
.ws-tab[data-tab="booklet"] { display: none; }
.ws-tab-count {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: 0.02rem 0.4rem;
  min-width: 1.4rem;
  text-align: center;
}
.ws-tab.is-active .ws-tab-count { background: #fff; color: var(--brand-dark); }

.booklet-pane {
  grid-area: booklet;
  position: sticky;
  top: 84px;
  align-self: start;
  min-width: 0;
  min-height: 420px;
  max-height: calc(100dvh - 104px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem;
  box-shadow: var(--shadow);
}
.booklet-pane[hidden] { display: none; }
.booklet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.booklet-title-wrap { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 700; min-width: 0; }
.booklet-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-focus-btn[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); }
.pdf-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; margin-bottom: 0.5rem; }
.pdf-page-label { font-variant-numeric: tabular-nums; }
.pdf-stage {
  flex: 1 1 auto;
  min-height: 280px;
  overflow: auto;
  background: #f8fafc;
  border-radius: 10px;
  display: grid;
  place-items: start center;
  padding: 4px;
}
.pdf-stage canvas { max-width: 100%; height: auto; box-shadow: 0 2px 8px rgba(16,24,40,.12); background: #fff; }
.pdf-foot { text-align: center; margin: 0.5rem 0 0; }

.split-handle {
  grid-area: handle;
  align-self: stretch;
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: col-resize;
  touch-action: none;
  border-radius: 8px;
}
.split-handle::before {
  content: "";
  width: 2px;
  height: 100%;
  border-radius: 2px;
  background: var(--line);
  transition: background 0.15s ease;
}
.split-handle:hover::before,
.split-handle:focus-visible::before { background: var(--brand); }
.split-handle:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.split-grip {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 56px;
  border-radius: 999px;
  background-color: var(--surface);
  background-image: radial-gradient(circle, var(--muted) 1.1px, transparent 1.7px);
  background-size: 5px 8px;
  background-position: center;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease;
}
.split-handle:hover .split-grip,
.split-handle:focus-visible .split-grip { border-color: var(--brand); }
body.ws-resizing { user-select: none; }
body.ws-resizing .split-handle,
body.ws-resizing .split-handle * { cursor: col-resize; }

.chapter-rail { grid-area: rail; min-width: 0; }
.rail-body {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  min-height: 300px;
}
.rail-panel[hidden] { display: none; }
.rail-empty { margin: 0.4rem 0; }
.chapter-rail .video-list { gap: 0.5rem; }
.chapter-rail .video-row { flex-wrap: wrap; gap: 0.5rem; padding: 0.6rem 0.7rem; }
.chapter-rail .video-main { flex: 1 1 140px; }
.chapter-rail .video-row .btn { margin-inline-start: auto; }

/* ---------- admin chapter materials ---------- */
.hint-warn { color: #93370d; background: #fef0c7; border: 1px solid #fedf89; border-radius: 10px; padding: 0.55rem 0.7rem; }
.material-delete input[type="text"] {
  font: inherit; font-size: 0.8rem; color: var(--ink); background: #fff;
  border: 1px solid #cbd5e1; border-radius: 8px; padding: 0.25rem 0.45rem;
  width: 9.5rem; max-width: 100%;
}
.material-delete input[type="text"]:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.material-edit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 1rem; }
.material-edit { border: 1px solid var(--line); border-radius: 12px; padding: 0.8rem; background: #fbfcfe; }
.material-edit-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; min-width: 0; }
.material-edit-head .small { overflow: hidden; text-overflow: ellipsis; max-width: 60%; }
.material-edit-row { display: grid; grid-template-columns: 1fr 6rem; gap: 0.6rem; }

.materials { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.materials li {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 1rem; border-bottom: 1px dashed var(--line); padding: 0.45rem 0;
}
.materials li a { overflow-wrap: anywhere; }

/* Focus mode: hide the rail and give the whole width to the booklet. */
@media (min-width: 901px) {
  .chapter-workspace.is-focus {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "booklet";
  }
  .chapter-workspace.is-focus .split-handle,
  .chapter-workspace.is-focus .chapter-rail,
  .chapter-workspace.is-focus .ws-tabs { display: none; }
  .chapter-workspace.is-focus .booklet-pane {
    position: static;
    max-height: none;
    min-height: 70vh;
  }
  .chapter-workspace.is-focus .pdf-stage { max-height: 82vh; }
}

.chapter-workspace[data-has-booklet="false"] {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "tabs" "rail";
}
.chapter-workspace[data-has-booklet="false"] .split-handle { display: none; }
.chapter-workspace[data-has-booklet="false"] .ws-tab[data-tab="booklet"] { display: none; }

@media (max-width: 900px) {
  .chapter-workspace { display: block; margin-bottom: 1rem; }
  .chapter-workspace .ws-tabs {
    position: static;
    margin-bottom: 0.75rem;
    top: auto;
  }
  .chapter-workspace .ws-tab[data-tab="booklet"] { display: inline-flex; }
  .chapter-workspace[data-has-booklet="false"] .ws-tab[data-tab="booklet"] { display: none; }
  .chapter-workspace .split-handle,
  .chapter-workspace .ws-focus-btn { display: none; }
  .booklet-pane {
    position: static;
    max-height: none;
    min-height: 0;
    padding: 0.7rem;
    margin-bottom: 0.75rem;
  }
  .chapter-workspace[data-active-tab="booklet"] .booklet-pane { display: flex; }
  .chapter-workspace .chapter-rail { display: none; }
  .chapter-workspace[data-active-tab="videos"] .chapter-rail,
  .chapter-workspace[data-active-tab="files"] .chapter-rail { display: block; }
  .pdf-stage { max-height: 72dvh; min-height: 240px; }
  .rail-body { padding: 0.8rem; min-height: 240px; }
  .chapter-rail .video-row .btn { margin-inline-start: 0; }
}

/* ---------- watch workspace: player + chapter booklet ---------- */
.watch-workspace {
  --ww-split: 38;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 14px calc(var(--ww-split) * 1%);
  grid-template-areas: "player handle booklet";
  align-items: start;
  row-gap: 0.4rem;
  margin-bottom: 1.2rem;
}
.watch-main { grid-area: player; min-width: 0; }
.watch-main[hidden] { display: none; }
.watch-main .player-card { margin-bottom: 0.8rem; }
.watch-workspace .watch-booklet {
  grid-area: booklet;
  min-height: 360px;
  max-height: calc(100dvh - 104px);
}
.watch-workspace .watch-split { grid-area: handle; }
.watch-workspace .btn:focus-visible,
.watch-workspace .ws-tab:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.watch-tabs { display: none; }

.watch-booklet-toggle[aria-expanded="true"] {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-dark);
}
.watch-booklet .booklet-head { margin-bottom: 0.4rem; }
.watch-booklet .pdf-open { margin-bottom: 0.2rem; }
.watch-panel-toggle { flex: 0 0 auto; padding: 0.15rem 0.5rem; font-size: 0.8rem; }

@media (min-width: 901px) {
  .watch-workspace.is-collapsed {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "player";
  }
  .watch-workspace.is-collapsed .watch-booklet,
  .watch-workspace.is-collapsed .watch-split { display: none; }
}

@media (max-width: 900px) {
  .watch-booklet-toggle { display: none; }
  .watch-panel-toggle { display: none; }
  .watch-workspace { display: block; margin-bottom: 1rem; }
  .watch-workspace .watch-split { display: none; }
  .watch-workspace .watch-booklet {
    display: none;
    min-height: 0;
    margin-top: 0.75rem;
  }
  .watch-workspace[data-active-tab="booklet"] .watch-booklet { display: flex; }
  .watch-workspace .watch-main { margin-bottom: 0.4rem; }
  .watch-tabs {
    display: flex;
    position: static;
    margin-bottom: 0.75rem;
  }
  .watch-tabs .ws-tab[data-tab="booklet"] { display: inline-flex; }
}

.checkbox { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; color: var(--ink); }
.upload-line { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px dashed var(--line); padding: 0.3rem 0; font-size: 0.85rem; }
.pdf-preview-tag {
  font-size: 0.68rem; font-weight: 400; color: var(--muted);
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  padding: 0.02rem 0.45rem; vertical-align: middle;
}
.pdf-open {
  display: flex; align-items: center; justify-content: center; gap: 0.4rem;
  width: 100%; margin-bottom: 0.25rem;
}
.pdf-open-hint { font-size: 0.74rem; color: var(--muted); margin: 0 0 0.55rem; line-height: 1.6; }

/* ---------- full-page booklet reader ---------- */
body:has(#pdf-reader) { height: 100dvh; overflow: hidden; }
body:has(#pdf-reader) .main { flex: 1 1 auto; min-height: 0; width: 100%; padding: 0; display: flex; }
body:has(#pdf-reader) .footer { display: none; }

.reader {
  flex: 1 1 auto; min-height: 0;
  height: calc(100dvh - 66px);
  display: flex; flex-direction: column;
  background: var(--bg);
}

.reader-bar {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  padding: 0.45rem 0.9rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.reader-bar-main { display: flex; align-items: center; gap: 0.6rem; min-width: 0; flex: 1 1 220px; }
.reader-back {
  color: var(--muted); font-size: 0.82rem; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 22ch;
}
.reader-back:hover { color: var(--brand); }
.reader-doc-title {
  font-weight: 700; font-size: 0.9rem; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reader-tools { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
.reader-group {
  display: flex; align-items: center; gap: 0.1rem;
  border: 1px solid var(--line); border-radius: 10px; padding: 0.12rem; background: #fff;
}
.reader-btn {
  appearance: none; border: 0; background: transparent; color: var(--ink);
  width: 32px; height: 30px; border-radius: 8px;
  display: grid; place-items: center;
  font: inherit; font-size: 1rem; line-height: 1; cursor: pointer;
}
.reader-btn:hover { background: var(--bg); }
.reader-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.reader-btn[disabled] { opacity: 0.3; cursor: default; }
.reader-btn[disabled]:hover { background: transparent; }
.reader-btn.is-active { background: var(--brand-soft); color: var(--brand-dark); }
.reader-pagebox {
  display: flex; align-items: center; gap: 0.25rem;
  font-size: 0.8rem; color: var(--muted); padding-inline: 0.15rem;
}
.reader-page-input {
  width: 3.1rem; padding: 0.12rem 0.2rem; text-align: center;
  border: 1px solid var(--line); border-radius: 7px;
  background: #fff; color: var(--ink); font: inherit; font-size: 0.8rem;
  direction: ltr;
}
.reader-page-input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.reader-zoom-label {
  min-width: 3.1rem; text-align: center; font-size: 0.75rem;
  color: var(--muted); direction: ltr;
}

.reader-body { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 288px minmax(0, 1fr); }
.reader.sidebar-collapsed .reader-body { grid-template-columns: 0 minmax(0, 1fr); }
.reader.sidebar-collapsed .reader-sidebar { display: none; }

.reader-sidebar {
  grid-column: 1;
  min-width: 0; min-height: 0; display: flex; flex-direction: column;
  background: var(--surface); border-inline-end: 1px solid var(--line);
}
.reader-sidebar-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.4rem;
  padding: 0.5rem 0.4rem 0.5rem 0.8rem;
  border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: 0.84rem;
}
.reader-sidebar-close { display: none; }
.reader-sidebar-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 0.55rem; }

.reader-thumbs {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.45rem; align-content: start;
}
.reader-thumb {
  appearance: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 0.2rem;
  border: 1px solid transparent; border-radius: 9px; padding: 4px;
  background: transparent; color: inherit; font: inherit;
}
.reader-thumb:hover { background: var(--bg); }
.reader-thumb:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.reader-thumb canvas {
  width: 100%; max-width: 120px; height: auto; display: block;
  background: #fff; border-radius: 2px; box-shadow: 0 1px 4px rgba(16, 24, 40, 0.16);
}
.reader-thumb-no { font-size: 0.72rem; color: var(--muted); direction: ltr; }
.reader-thumb.is-active { border-color: var(--brand); background: var(--brand-soft); }
.reader-thumb.is-active .reader-thumb-no { color: var(--brand-dark); font-weight: 700; }

.reader-outline { display: grid; gap: 1px; align-content: start; }
.reader-outline-item {
  display: block; width: 100%;
  appearance: none; border: 0; background: transparent;
  padding: 0.32rem 0.5rem; border-radius: 8px;
  font: inherit; font-size: 0.83rem; line-height: 1.65; text-align: start;
  color: var(--ink); cursor: pointer;
}
.reader-outline-item:hover { background: var(--bg); }
.reader-outline-item:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.reader-outline-item.is-active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; }
.reader-outline-item.is-disabled { color: var(--muted); cursor: default; }

.reader-scroll {
  grid-column: 2;
  position: relative; min-width: 0; min-height: 0;
  overflow: auto; background: #e8edf4; padding: 24px;
}
.reader-page-frame { width: max-content; min-width: 100%; margin: 0 auto; }
#reader-canvas {
  display: block; margin-inline: auto; background: #fff; border-radius: 2px;
  box-shadow: 0 12px 34px rgba(16, 24, 40, 0.2), 0 2px 6px rgba(16, 24, 40, 0.08);
}

.reader-state {
  position: absolute; inset: 0; z-index: 3;
  display: grid; place-items: center; padding: 1rem;
  background: rgba(232, 237, 244, 0.94);
  color: var(--muted); font-size: 0.9rem; text-align: center;
}
.reader-state[hidden] { display: none; }
.reader-error p { max-width: 32ch; margin: 0 auto 0.7rem; }

.reader-foot {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.35rem 1rem;
  background: var(--surface); border-top: 1px solid var(--line);
  font-size: 0.74rem; color: var(--muted);
}
.reader-watermark { white-space: nowrap; }
.reader-scrubber { flex: 1 1 auto; display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.reader-scrubber input[type="range"] { flex: 1 1 auto; min-width: 60px; accent-color: var(--brand); }
.reader-page-readout { white-space: nowrap; direction: ltr; font-variant-numeric: tabular-nums; }

.reader-overlay { display: none; }

#pdf-reader:fullscreen,
#pdf-reader.reader-faux-fullscreen {
  width: 100%; height: 100vh; height: 100dvh;
  background: var(--bg);
}
#pdf-reader.reader-faux-fullscreen { position: fixed; inset: 0; z-index: 100; }

@media (max-width: 900px) {
  .reader { height: calc(100dvh - 118px); }
  .reader-bar { padding: 0.35rem 0.5rem; gap: 0.35rem; position: sticky; top: 0; z-index: 6; }
  .reader-tools { gap: 0.2rem; }
  .reader-btn { width: 38px; height: 36px; font-size: 1.08rem; }
  .reader-group { padding: 0.14rem; }
  .reader-page-input { width: 3.6rem; font-size: 0.85rem; }
  .reader-scroll { padding: 8px 6px; }
  .reader-doc-title { display: none; }
  .reader-back { max-width: 18ch; font-size: 0.78rem; }
  .reader-body { grid-template-columns: minmax(0, 1fr); }
  .reader.sidebar-collapsed .reader-body { grid-template-columns: minmax(0, 1fr); }
  .reader.sidebar-collapsed .reader-sidebar { display: flex; }
  .reader-sidebar {
    position: fixed; top: 0; bottom: 0; inset-inline-start: 0;
    width: min(340px, 86vw); z-index: 60;
    transform: translateX(105%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
    box-shadow: -16px 0 40px rgba(16, 24, 40, 0.24);
  }
  .reader.sidebar-open .reader-sidebar {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.22s ease;
  }
  .reader-sidebar-close { display: grid; }
  .reader-overlay {
    display: none; position: fixed; inset: 0; z-index: 55;
    background: rgba(16, 24, 40, 0.44);
  }
  .reader.sidebar-open .reader-overlay { display: block; }
  .reader-scroll { grid-column: 1; padding: 12px; }
  .reader-foot { gap: 0.5rem; padding: 0.3rem 0.6rem; }
  .reader-watermark { display: none; }
  .reader-page-readout { display: none; }
}
.totp-secret, .totp-uri { display:block; background:var(--bg); border:1px solid var(--line); border-radius:8px; padding:0.55rem 0.7rem; font-family:ui-monospace, SFMono-Regular, Menlo, monospace; font-size:0.8rem; overflow-wrap:anywhere; }
.totp-qr { display:block; width:190px; height:190px; margin:0 auto; background:#fff; padding:8px; border:1px solid var(--line); border-radius:12px; }
.upload-file-row { display:grid; grid-template-columns:minmax(140px,1fr) minmax(160px,1.2fr); gap:0.5rem; align-items:center; }
.upload-file-name { font-size:0.8rem; color:var(--muted); overflow:hidden; text-overflow:ellipsis; }
.upload-title-input { font:inherit; font-size:0.85rem; border:1px solid #cbd5e1; border-radius:8px; padding:0.35rem 0.5rem; width:100%; }
@media (max-width:600px) { .upload-file-row { grid-template-columns:1fr; gap:0.2rem; } }

[hidden] { display: none !important; }
