/* Staff workspace (teachers and admins): a light SaaS frame. Everything is scoped under .saas so the
   student site keeps its own look. The palette overrides the shared tokens, so older components
   (cards, pills, tables, dialogs) follow it without being rewritten. */
.saas {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #0f172a;
  --text: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --good: #15803d;
  --good-soft: #ecfdf3;
  --warn: #b45309;
  --warn-soft: #fff7ed;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --rec: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --side: 232px;
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr);
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}
.saas h1, .saas h2, .saas h3, .saas h4 { color: var(--ink); }

/* Sidebar */
.saas-side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line); }
.saas-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: var(--ink); font-weight: 800; font-size: 16px; letter-spacing: -.02em; }
.saas-brand img { width: 30px; height: 30px; border-radius: 8px; flex: none; }
.saas-brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saas-nav { flex: 1; overflow-y: auto; padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.saas-group { padding: 16px 10px 6px; font-size: 11px; font-weight: 700; letter-spacing: .06em; color: #94a3b8; text-transform: uppercase; }
.saas-nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); font-weight: 600; font-size: 14px; }
.saas-nav a svg { width: 18px; height: 18px; flex: none; color: #94a3b8; }
.saas-nav a:hover { background: #f1f5f9; }
.saas-nav a.active { background: var(--accent-soft); color: var(--accent); }
.saas-nav a.active svg { color: var(--accent); }
.saas-user { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.saas-avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 14px; flex: none; }
.saas-user div { display: grid; min-width: 0; font-size: 13px; }
.saas-user strong { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saas-user span { color: var(--muted); }

/* Top workspace bar */
.saas-main { display: flex; flex-direction: column; min-width: 0; }
.saas-top { position: sticky; top: 0; z-index: 6; display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 56px; padding: 0 28px; background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.saas-workspace { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; color: var(--muted); }
.saas-workspace strong { color: var(--ink); white-space: nowrap; }
.saas-workspace .branch { padding: 2px 8px; border-radius: 999px; background: #f1f5f9; color: var(--text); font-size: 12px; font-weight: 650; white-space: nowrap; }
.saas-top-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.saas-pcs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.saas-pcs .erp-pc { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 12px; font-weight: 650; color: var(--muted); white-space: nowrap; }
.saas-pcs .erp-pc.good { color: var(--good); border-color: #bbf7d0; background: var(--good-soft); }
.saas-pcs .erp-pc.recording { color: #fff; border-color: var(--rec); background: var(--rec); }
.saas-pcs .erp-pc.warn { color: var(--warn); border-color: #fed7aa; background: var(--warn-soft); }
.saas-top .secondary.small { min-height: 34px; padding: 4px 12px; font-size: 13px; }

/* Page title and content */
.saas-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 24px 28px 0; }
.saas-head h1 { margin: 0; font-size: 22px; letter-spacing: -.03em; }
.saas-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.saas-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.saas .erp-content { flex: 1; padding: 20px 28px 40px; }
.saas .erp-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.saas .erp-panel > h2, .saas .erp-panel .toolbar h2, .saas .panel-title { margin: 0 0 14px; font-size: 15px; font-weight: 750; display: flex; align-items: center; gap: 8px; }
.saas .panel-title .count { color: var(--muted); font-weight: 600; font-size: 13px; }
.saas .panel-title a { margin-left: auto; font-size: 13px; }

/* Controls */
.saas .primary, .saas .secondary, .saas .ghost, .saas .chip { border-radius: 8px; min-height: 40px; padding: 8px 14px; font-weight: 650; }
.saas .primary { background: var(--accent); }
.saas .primary:hover:not(:disabled) { background: #1d4ed8; }
.saas .secondary { border-color: var(--line-strong); color: var(--ink); }
.saas .secondary:hover:not(:disabled) { background: #f8fafc; }
.saas .primary.small, .saas .secondary.small, .saas .ghost.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.saas input, .saas select, .saas textarea { border-color: var(--line-strong); border-radius: 8px; min-height: 40px; }
.saas .chip { min-height: 32px; padding: 4px 12px; font-size: 13px; border-color: var(--line); color: var(--text); }
.saas .chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.saas .chips { margin-bottom: 6px; }
.saas .pill { font-size: 12px; padding: 3px 9px; background: #f1f5f9; color: var(--muted); }
.saas .tag { background: #f1f5f9; color: var(--text); }
.saas .data-table th { background: #f8fafc; color: var(--muted); font-size: 12px; text-transform: none; }
.saas .data-table th, .saas .data-table td { border-color: var(--line); }
.saas .empty { color: var(--muted); }
.saas a.secondary, .saas a.primary { display: inline-flex; align-items: center; justify-content: center; }
.saas a.primary { color: #fff; }

/* KPI cards (dashboard) */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: grid; gap: 2px; }
.kpi span { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi b { color: var(--ink); font-size: 26px; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: 12px; }
.kpi.rec b { color: var(--rec); }
.dash-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(320px, 2fr); gap: 16px; align-items: start; }
.dash-list { list-style: none; margin: 0; padding: 0; display: grid; }
.dash-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); min-width: 0; }
.dash-list li:first-child { border-top: 0; padding-top: 0; }
.dash-list .grow { flex: 1; min-width: 0; display: grid; gap: 2px; }
.dash-list .grow strong { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-list .grow span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; padding: 0; border: 0; border-radius: 50%; flex: none; background: #cbd5e1; }
.dot.good { background: #22c55e; } .dot.warn { background: #f59e0b; } .dot.bad { background: var(--bad); } .dot.rec { background: var(--rec); box-shadow: 0 0 0 3px rgba(220, 38, 38, .18); }
.todo-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex: none; font-weight: 800; font-size: 14px; }
.todo-icon.bad { background: var(--bad-soft); color: var(--bad); } .todo-icon.warn { background: var(--warn-soft); color: var(--warn); } .todo-icon.info { background: var(--accent-soft); color: var(--accent); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.media-card { display: grid; gap: 8px; color: inherit; font-weight: 400; }
.media-card strong { color: var(--ink); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.media-card > span { color: var(--muted); font-size: 12px; }
.media-card:hover strong { color: var(--accent); }

/* Title cover: the lesson's class and title on a colour picked from the class (no frame grabs yet). */
.cover { position: relative; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 8px 10px; color: #fff; background: linear-gradient(135deg, var(--c1), var(--c2)); flex: none; }
.cover .cover-class { font-size: 11px; font-weight: 750; opacity: .9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cover .cover-title { font-size: 13px; font-weight: 800; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; letter-spacing: -.02em; }
.cover .cover-time { position: absolute; right: 6px; bottom: 6px; padding: 1px 6px; border-radius: 4px; background: rgba(15, 23, 42, .72); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cover.small { width: 128px; padding: 6px 8px; }
.cover.small .cover-title { font-size: 11px; }
.cover.small .cover-class { font-size: 10px; }
.cover .cover-state { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(15, 23, 42, .55); font-size: 12px; font-weight: 800; }

/* Recording studio */
.studio { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 400px); gap: 16px; align-items: start; }
.studio .recorder-list { grid-template-columns: 1fr; gap: 16px; }
.saas .recorder-card { container-type: inline-size; padding: 0; gap: 0; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.saas .recorder-card > * { margin-left: 18px; margin-right: 18px; }
.saas .recorder-card > :first-child { margin-top: 16px; }
.saas .recorder-card > :last-child { margin-bottom: 18px; }
.saas .recorder-card > * + * { margin-top: 12px; }
.saas .recorder-card.recording { border-color: var(--rec); box-shadow: 0 0 0 3px rgba(220, 38, 38, .14); }
.saas .recorder-head h3 { font-size: 17px; }
.saas .state-chip { font-size: 13px; }
.saas .state-chip.rec { background: var(--rec); }
.device-strip { display: flex; flex-wrap: wrap; gap: 6px; }
.device-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; color: var(--text); background: #f8fafc; }
.device-chip b { color: var(--muted); font-weight: 650; }
.device-chip i { width: 7px; height: 7px; border-radius: 50%; background: #cbd5e1; flex: none; }
.device-chip.good i { background: #22c55e; } .device-chip.warn i { background: #f59e0b; } .device-chip.bad i { background: var(--bad); }
.device-chip.bad { color: var(--bad); border-color: #fecaca; background: var(--bad-soft); }
.device-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-ver { font-size: 12px; color: var(--muted); align-self: center; margin-left: auto; }
.warn-text { color: var(--warn); margin: 0; }
.studio-grid { display: grid; gap: 14px; }
.studio-stage, .studio-controls { display: grid; gap: 12px; align-content: start; min-width: 0; }
.studio-stage .state-box { margin: 0; border: 0; padding: 0; }
.studio-stage .rec-preview { border-radius: 10px; }
.studio-controls .record-form { gap: 10px; }
.studio-controls .audio-setup { margin: 0; }
.rec-panel { display: grid; gap: 12px; padding: 14px; border-radius: 10px; background: #fef2f2; }
.rec-panel .rec-clock.big { font-size: 30px; color: var(--rec); }
.rec-panel .row { flex-wrap: nowrap; }
.rec-panel .pause-button, .rec-panel .stop-button { flex: 1; min-height: 50px; font-size: 16px; }
.upload-line { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.upload-line b { color: var(--ink); font-variant-numeric: tabular-nums; }
@container (min-width: 760px) {
  .studio-grid { grid-template-columns: minmax(0, 1.55fr) minmax(280px, 1fr); align-items: start; }
}
.studio-rail .live-card { box-shadow: var(--shadow); }
.studio-rail #live-list { grid-template-columns: 1fr; }
.studio-rail .rail-note { margin: 0 0 10px; }

/* Video library */
.library { display: grid; grid-template-columns: minmax(0, 1fr) minmax(380px, 460px); gap: 16px; align-items: start; }
.library-detail { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow-y: auto; border-radius: var(--radius); }
.library-detail .erp-panel { margin: 0; }
.saas .recording-row { padding: 10px 12px; border-radius: 10px; gap: 14px; align-items: center; justify-content: flex-start; }
.saas .recording-row:hover { border-color: #93c5fd; }
.saas .recording-row.selected { background: var(--accent-soft); border-color: var(--accent); box-shadow: none; }
.saas .recording-row .row-main { display: grid; gap: 3px; min-width: 0; flex: 1; }
.saas .recording-row .row-main strong { color: var(--ink); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saas .recording-row .row-main .meta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saas .recording-row .row-side { max-width: none; flex: none; display: grid; justify-items: end; gap: 6px; }
.saas .row-badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.watch-mini { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.watch-mini .bar { width: 64px; height: 5px; border-radius: 4px; background: #e2e8f0; overflow: hidden; }
.watch-mini .bar span { display: block; height: 100%; background: var(--good); }
.saas .month-group > summary { color: var(--ink); font-size: 14px; }
.saas .bulk-bar { padding: 8px 10px; border-radius: 10px; background: #f8fafc; border: 1px solid var(--line); margin: 6px 0 10px; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.filter-row select { min-height: 34px; padding: 4px 10px; font-size: 13px; }
.filter-row input[type="search"] { flex: 1; min-width: 200px; min-height: 36px; }
.saas .detail-card .video-wrap { margin: 0 0 14px; }
.detail-section { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 14px; }
.detail-section > h3 { margin: 0 0 10px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.saas .lesson-edit { margin: 0; background: #f8fafc; border-color: var(--line); }
.saas .lesson-access { border-top: 0; margin: 0; padding: 0; }

/* Responsive: iPad landscape keeps the sidebar; narrower screens move the menu to a top strip. */
@media (max-width: 1280px) {
  .saas { --side: 208px; }
  .studio { grid-template-columns: minmax(0, 1fr) minmax(300px, 340px); }
  .library { grid-template-columns: minmax(0, 1fr) minmax(340px, 400px); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .studio, .library, .dash-grid { grid-template-columns: 1fr; }
  .library-detail { position: static; max-height: none; }
}
@media (max-width: 900px) {
  .saas { display: block; }
  .saas-side { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
  .saas-brand { padding: 10px 12px; }
  .saas-brand span, .saas-group, .saas-user { display: none; }
  .saas-nav { flex-direction: row; overflow: visible; padding: 6px; }
  .saas-nav a { white-space: nowrap; padding: 8px 10px; }
  .saas-top { position: static; height: auto; padding: 10px 16px; flex-wrap: wrap; }
  .saas-head { padding: 16px 16px 0; }
  .saas .erp-content { padding: 14px 16px 32px; }
}
@media (max-width: 640px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi b { font-size: 22px; }
  .saas-top-right { width: 100%; justify-content: space-between; }
  .saas .recording-row { flex-wrap: wrap; }
  .saas .recording-row .cover.small { width: 96px; }
  .saas .recording-row .row-side { justify-items: start; width: 100%; }
  .saas .row-badges { justify-content: flex-start; }
  .saas .recorder-card > * { margin-left: 14px; margin-right: 14px; }
  .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.detail-cover .cover { width: 100%; margin-bottom: 8px; }
.detail-cover .cover .cover-title { font-size: 20px; }
.this-pc-note:empty { display: none; }
/* The row beside a small cover already shows the title; the cover keeps the class and duration. */
.cover.small .cover-title { display: none; }
@media (max-width: 640px) {
  .saas-top button, .saas-top .secondary { white-space: nowrap; }
}
.lesson-move { display: flex; align-items: flex-end; gap: 8px; margin-top: 10px; }
.lesson-move label { flex: 1; min-width: 0; display: grid; gap: 4px; }
.lesson-move select { min-height: 36px; padding: 4px 8px; border: 1px solid #ced5df; border-radius: 8px; background: var(--surface); }
