:root {
  color-scheme: light;
  --bg: #f5f6f7;
  --surface: #ffffff;
  --ink: #17191d;
  --muted: #66707a;
  --line: #d9dde2;
  --line-strong: #b7bec7;
  --accent: #176b51;
  --accent-hover: #115640;
  --accent-pale: #eaf5f0;
  --danger: #b42318;
  --warning: #9a6700;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, select, input, textarea { border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface); color: var(--ink); }
button { min-height: 36px; padding: 7px 13px; cursor: pointer; font-weight: 600; }
button:hover { background: #f0f2f3; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
button.primary:hover { background: var(--accent-hover); }
button.quiet { border-color: transparent; background: transparent; }
button.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
button.danger-quiet { color: var(--danger); }
input, select, textarea { width: 100%; min-height: 36px; padding: 7px 9px; }
textarea { resize: vertical; line-height: 1.45; }
label { display: grid; gap: 5px; color: #3c444d; font-size: .84rem; font-weight: 650; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.wide { width: 100%; }
.stack { display: grid; gap: 16px; }

.topbar { height: 54px; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { color: var(--ink); font-weight: 750; }
.brand:hover { text-decoration: none; }
.topbar-actions { display: flex; align-items: center; gap: 14px; font-size: .9rem; }
.save-status { color: var(--muted); min-width: 92px; text-align: right; }
.save-status.dirty { color: var(--warning); }
.save-status.saved { color: var(--accent); }
.save-status.failed { color: var(--danger); }

.login-page { min-height: 100vh; display: grid; place-items: center; background: #eef1f2; }
.login-panel { width: min(400px, calc(100vw - 32px)); padding: 36px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; color: #fff; background: var(--accent); border-radius: 5px; font-weight: 800; }
.login-panel h1 { margin: 18px 0 4px; font-size: 1.45rem; }
.login-panel > p { margin: 0 0 24px; }

.page { width: min(1500px, calc(100% - 40px)); margin: 24px auto; }
.summary { display: grid; grid-template-columns: repeat(5, minmax(100px, 1fr)); border: 1px solid var(--line); background: var(--surface); }
.summary div { padding: 15px 18px; border-right: 1px solid var(--line); }
.summary div:last-child { border-right: 0; }
.summary strong, .summary span { display: block; }
.summary strong { font-size: 1.4rem; }
.summary span { margin-top: 2px; color: var(--muted); font-size: .78rem; }
.toolbar { margin: 18px 0 12px; display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)) minmax(190px, 1.4fr) auto auto; gap: 8px; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: .86rem; }
th { color: #4a535c; background: #f7f8f8; font-size: .76rem; text-transform: uppercase; }
tbody tr:hover { background: #fafbfb; }
.preview-cell { width: 142px; min-width: 142px; padding: 7px 10px; }
.poster-thumb { display: block; width: 128px; height: 72px; object-fit: cover; background: #e7eaed; border: 1px solid var(--line); border-radius: 4px; }
.poster-unavailable { width: 128px; height: 72px; display: grid; place-items: center; color: var(--muted); background: #f0f2f3; border: 1px dashed var(--line-strong); border-radius: 4px; font-size: .72rem; }
.video-id-cell { max-width: 310px; overflow: hidden; text-overflow: ellipsis; }
.pagination { min-height: 58px; display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--line); }
.pagination > span:first-child { margin-right: auto; }
.pagination label { display: flex; grid-auto-flow: column; align-items: center; gap: 7px; }
.pagination select { width: auto; min-width: 68px; }
.pagination button { min-width: 84px; }
.status { display: inline-block; min-width: 78px; padding: 3px 7px; border-radius: 4px; text-align: center; font-size: .75rem; font-weight: 700; background: #eef0f2; }
.status.finalized { color: #0e6349; background: #e4f4ed; }
.status.draft { color: #825a00; background: #fff3d4; }
.status.unusable { color: #8e251d; background: #fde9e7; }
.empty { padding: 48px; color: var(--muted); text-align: center; }
.alert { margin: 10px 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 5px; white-space: pre-line; }
.alert.error { color: #7c1d16; background: #fff0ef; border-color: #efb7b2; }

.annotate-layout { min-height: calc(100vh - 54px); display: grid; grid-template-columns: minmax(420px, 43%) 1fr; }
.video-column { padding: 20px; border-right: 1px solid var(--line); background: #eef0f1; position: sticky; top: 54px; height: calc(100vh - 54px); overflow-y: auto; }
.video-shell { width: 100%; aspect-ratio: 16 / 9; display: grid; place-items: center; background: #101214; }
.video-shell video { width: 100%; height: 100%; object-fit: contain; }
.playback-bar { min-height: 52px; display: grid; grid-template-columns: 42px 42px 86px 1fr; align-items: center; gap: 7px; padding: 8px 0; }
.playback-bar select { height: 36px; }
.playback-bar output { color: #424b54; text-align: right; font-variant-numeric: tabular-nums; }
.video-meta { margin: 8px 0; border-top: 1px solid var(--line-strong); }
.video-meta div { display: grid; grid-template-columns: 105px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.video-meta dt { color: var(--muted); }
.video-meta dd { margin: 0; overflow-wrap: anywhere; }
.metadata-details { margin-top: 12px; }
.metadata-details pre { max-height: 260px; overflow: auto; padding: 10px; background: var(--surface); border: 1px solid var(--line); font-size: .75rem; white-space: pre-wrap; }

.editor-column { min-width: 0; padding: 20px 24px 92px; }
.condition-strip { display: grid; grid-template-columns: repeat(5, minmax(110px, 1fr)); gap: 9px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.level-tabs { display: flex; gap: 0; margin: 18px 0 0; border-bottom: 1px solid var(--line-strong); }
.level-tabs button { min-width: 76px; border-radius: 0; border: 0; border-bottom: 3px solid transparent; background: transparent; }
.level-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.question-level { display: none; padding: 18px 0; }
.question-level.active { display: block; }
.question-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.question-header h2 { margin: 0; font-size: 1.15rem; }
.question-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.question-grid .full { grid-column: 1 / -1; }
.options { display: grid; gap: 7px; }
.option-row { display: grid; grid-template-columns: 34px 1fr; align-items: center; }
.option-row span { height: 36px; display: grid; place-items: center; color: #535d67; background: #f0f2f3; border: 1px solid var(--line-strong); border-right: 0; border-radius: 5px 0 0 5px; font-weight: 750; }
.option-row input { border-radius: 0 5px 5px 0; }
.time-field { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.time-field button { min-width: 54px; }
.time-warning { grid-column: 1 / -1; color: var(--warning); font-size: .8rem; }
.annotation-notes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-top: 18px; border-top: 1px solid var(--line); }
.annotation-notes label:last-child { grid-column: 1 / -1; }
.actionbar { position: fixed; bottom: 0; right: 0; width: 57%; min-height: 66px; padding: 12px 24px; display: flex; gap: 9px; align-items: center; background: rgba(255,255,255,.97); border-top: 1px solid var(--line); z-index: 15; }
.action-spacer { flex: 1; }
dialog { width: min(720px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line-strong); border-radius: 7px; box-shadow: 0 20px 60px rgba(0,0,0,.18); }
dialog::backdrop { background: rgba(20,24,28,.35); }
.dialog-form { padding: 22px; }
.dialog-form h2 { margin: 0 0 16px; font-size: 1.2rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

@media (max-width: 1000px) {
  .toolbar { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .annotate-layout { display: block; }
  .video-column { position: static; height: auto; border-right: 0; }
  .actionbar { width: 100%; }
  .condition-strip { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
}
@media (max-width: 640px) {
  .topbar { padding: 0 12px; }
  .topbar-actions > span:not(.save-status) { display: none; }
  .page { width: calc(100% - 20px); margin: 12px auto; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .summary div { border-bottom: 1px solid var(--line); }
  .toolbar { grid-template-columns: 1fr; }
  .pagination { justify-content: center; flex-wrap: wrap; }
  .pagination > span:first-child { width: 100%; margin-right: 0; text-align: center; }
  .video-column, .editor-column { padding: 12px; }
  .question-grid, .annotation-notes, .condition-strip { grid-template-columns: 1fr; }
  .question-grid .full, .annotation-notes label:last-child { grid-column: auto; }
  .actionbar { padding: 9px 10px; overflow-x: auto; }
}
