:root {
  color-scheme: light;
  --ink: #18212a;
  --muted: #64707c;
  --line: #d9dee3;
  --soft: #f4f6f7;
  --panel: #ffffff;
  --accent: #087f72;
  --accent-dark: #05675d;
  --warning: #9a6700;
  --danger: #b42318;
  --success: #247a4d;
  --focus: #d5eee9;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: #eef1f3;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  height: 66px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #cfd5da;
  background: #fff;
}

.brand-mark {
  width: 12px;
  height: 30px;
  border-radius: 6px;
  background: var(--accent);
}

.topbar h1 { margin: 0; font-size: 18px; font-weight: 650; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.service-state { margin-left: auto; color: var(--muted); font-size: 13px; }
.service-state.ok::before, .service-state.error::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--success);
}
.service-state.error::before { background: var(--danger); }

.session-controls { display: flex; align-items: center; gap: 10px; }
.session-controls[hidden] { display: none; }
[data-reauth] { color: var(--accent-dark); margin-right: 10px; font-weight: 600; }
#sessionUsername { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.login-page { background: #fff; }
.login-main { width: min(380px, calc(100% - 40px)); margin: 72px auto; }
.login-main h2 { font-size: 22px; margin: 0 0 28px; }
#loginForm { display: grid; gap: 20px; }
#loginForm input { width: 100%; }
#loginMessage { margin: 0; min-height: 40px; color: var(--danger); line-height: 1.5; }
@media (max-width: 700px) {
  .topbar:has(.session-controls:not([hidden])) { height: auto; min-height: 66px; flex-wrap: wrap; padding: 12px; }
  #sessionUsername { display: none; }
  .session-controls { margin-left: auto; }
  .login-main { margin-top: 40px; }
}

main { width: min(1280px, calc(100% - 40px)); margin: 24px auto 40px; }

.workspace {
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}
.section-heading h2 { margin: 0; font-size: 18px; font-weight: 650; }
.muted { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

#caseForm {
  display: grid;
  grid-template-columns: minmax(190px, 0.7fr) minmax(200px, 0.7fr) minmax(300px, 1.6fr) auto;
  align-items: end;
  gap: 16px;
}

.field, .source-pane { min-width: 0; }
label, legend { display: block; margin-bottom: 7px; color: #394550; font-weight: 600; font-size: 13px; }
fieldset { margin: 0; padding: 0; border: 0; }

input[type="text"], input[type="password"], input:not([type]) {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid #bcc5cc;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }

.segmented {
  height: 40px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid #bcc5cc;
  border-radius: 4px;
  background: var(--soft);
}
.segment { border: 0; border-radius: 3px; background: transparent; color: #4d5964; cursor: pointer; }
.segment.active { background: #fff; color: var(--accent-dark); box-shadow: 0 1px 3px rgba(20, 35, 45, .15); font-weight: 650; }

.file-picker {
  height: 40px;
  margin: 0;
  display: flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid #bcc5cc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}
.file-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-action { align-self: stretch; display: flex; align-items: center; padding: 0 13px; border-right: 1px solid var(--line); background: var(--soft); color: #34414c; }
.file-name { min-width: 0; padding: 0 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-weight: 400; }

.upload-progress { height: 3px; margin-top: 4px; overflow: hidden; background: #dbe1e5; }
.upload-progress div { height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }

.submit-row { display: flex; align-items: center; gap: 10px; min-height: 40px; }
button, .button-link {
  height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
button:disabled { cursor: not-allowed; opacity: .55; }
.primary { height: 40px; background: var(--accent); color: #fff; font-weight: 650; }
.primary:hover:not(:disabled) { background: var(--accent-dark); }
.secondary { border-color: #b9c2c9; background: #fff; color: #34414c; }
.secondary:hover { background: var(--soft); }
.text-button { height: auto; padding: 2px 0; border: 0; background: none; color: var(--danger); }
.form-message { max-width: 220px; color: var(--danger); font-size: 12px; }

.current-job { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.progress-head, .progress-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.progress-head > div { display: flex; align-items: center; gap: 10px; }
.stage-badge, .status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 3px;
  background: #e8eeef;
  color: #41505b;
  font-size: 12px;
  white-space: nowrap;
}
.status-badge.running { background: #e2f1ee; color: #08675e; }
.status-badge.completed { background: #e7f3eb; color: var(--success); }
.status-badge.failed { background: #fbe9e7; color: var(--danger); }
.status-badge.queued { background: #fff3d9; color: var(--warning); }
.status-badge.canceled { background: #eceff1; color: #5b6670; }
.progress-track { height: 8px; margin: 11px 0 8px; overflow: hidden; border-radius: 4px; background: #dde3e6; }
.progress-track div { width: 0; height: 100%; background: var(--accent); transition: width .3s ease; }
.progress-foot { color: var(--muted); font-size: 12px; }

.history { margin-top: 24px; }
.history-heading { align-items: center; margin-bottom: 10px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
table { width: 100%; min-width: 1080px; border-collapse: collapse; table-layout: fixed; }
th, td { height: 48px; padding: 9px 12px; border-bottom: 1px solid #e2e6e9; text-align: left; vertical-align: middle; }
th { height: 40px; background: #f5f7f8; color: #52606b; font-size: 12px; font-weight: 650; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfb; }
td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
th:nth-child(1) { width: 15%; }
th:nth-child(2) { width: 7%; }
th:nth-child(3) { width: 9%; }
th:nth-child(4) { width: 10%; }
th:nth-child(5) { width: 13%; }
th:nth-child(6) { width: 7%; }
th:nth-child(7) { width: 14%; }
.actions-column { width: 25%; text-align: right; }
td.actions { text-align: right; overflow: visible; }
.action-button { height: 30px; padding: 0 8px; margin-left: 4px; border-color: #c4ccd2; background: #fff; color: #35424d; font-size: 12px; }
.action-button:hover { background: var(--soft); }
.action-button.danger { color: var(--danger); }
.empty-row { height: 90px; text-align: center; color: var(--muted); }

dialog { padding: 0; border: 1px solid #9faab2; border-radius: 6px; background: #fff; box-shadow: 0 18px 50px rgba(18, 30, 40, .3); }
dialog::backdrop { background: rgba(18, 30, 40, .5); }
.viewer-dialog { width: min(1180px, 94vw); height: 92vh; }
.log-dialog { width: min(980px, 92vw); height: min(720px, 86vh); }
.review-dialog { width: min(1480px, 98vw); height: 96vh; max-width: none; max-height: none; }
.image-dialog, .video-context-dialog { width: min(1420px, 96vw); height: 94vh; max-width: none; max-height: none; }
.dialog-head { height: 52px; padding: 0 14px 0 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.dialog-head > div { display: flex; align-items: center; gap: 8px; }
.icon-button { width: 36px; padding: 0; border-color: transparent; background: transparent; color: #4c5964; font-size: 25px; }
.icon-button:hover { background: var(--soft); }
#pdfFrame { display: block; width: 100%; height: calc(100% - 52px); border: 0; }
#logContent { height: calc(100% - 52px); margin: 0; padding: 16px; overflow: auto; background: #111820; color: #dce5ec; font: 12px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; }

.review-shell { height: 100%; display: grid; grid-template-rows: 52px minmax(0, 1fr) 60px; }
.review-head { min-width: 0; }
.review-head > div:first-child { min-width: 0; }
.review-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-body { overflow: auto; background: #f5f7f8; }
.review-band, .review-findings-band { padding: 20px 24px; border-bottom: 1px solid var(--line); background: #fff; }
.review-findings-band { padding-bottom: 40px; }
.review-section-head, .review-findings-toolbar {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 14px;
}
.review-section-head h2, .review-findings-toolbar h2 { margin: 0; font-size: 16px; }
.review-section-head p, .review-findings-toolbar p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.reviewer-field { width: min(360px, 45vw); }
.reviewer-field label { margin-bottom: 5px; }
.reviewer-field input, .review-field input, .search-field input {
  width: 100%; height: 38px; padding: 0 10px; border: 1px solid #bcc5cc;
  border-radius: 4px; background: #fff; color: var(--ink); outline: none;
}
.review-exam-grid { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); gap: 12px; }
.review-exam-grid .review-field:nth-child(1), .review-exam-grid .review-field:nth-child(2) { grid-column: span 2; }
.review-field { display: block; min-width: 0; margin: 0; }
.review-field > span { display: block; min-height: 18px; margin-bottom: 5px; color: #394550; font-size: 12px; font-weight: 600; }
.review-field textarea {
  display: block; width: 100%; min-height: 68px; padding: 9px 10px; resize: vertical;
  border: 1px solid #bcc5cc; border-radius: 4px; background: #fff; color: var(--ink); outline: none;
  line-height: 1.5;
}
.review-text-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.review-text-grid .review-field:first-child { grid-column: 1 / -1; }
.review-findings-toolbar { position: sticky; top: 0; z-index: 3; align-items: center; margin: -20px -24px 0; padding: 14px 24px; border-bottom: 1px solid var(--line); background: #fff; }
.search-field { width: min(320px, 28vw); margin: 0 0 0 auto; }
.search-field span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.compact-check, .finding-toggle, .evidence-toggle { display: inline-flex; align-items: center; gap: 7px; margin: 0; cursor: pointer; }
.compact-check input, .finding-toggle input, .evidence-toggle input { width: 17px; height: 17px; accent-color: var(--accent); }
.review-findings { max-width: 1320px; margin: 0 auto; }
.review-finding-editor { padding: 20px 0 22px; border-bottom: 1px solid #cfd5da; transition: opacity .15s ease; }
.review-finding-editor.excluded { opacity: .58; }
.review-finding-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.review-finding-head h3 { margin: 0; font-size: 15px; }
.review-finding-head p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.finding-toggle { min-height: 34px; padding: 0 9px; border: 1px solid #b9c2c9; border-radius: 4px; background: #fff; color: #34414c; font-size: 12px; }
.review-finding-fields { display: grid; grid-template-columns: 1fr 2fr .8fr .8fr 2fr 2fr; gap: 10px; align-items: start; }
.review-finding-fields textarea { min-height: 62px; }
.review-evidence-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 16px; }
.review-evidence { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 9px 12px; margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 5px; background: #fafbfb; }
.evidence-image-button { grid-row: 1 / span 5; width: 150px; height: 150px; padding: 0; overflow: hidden; border: 1px solid #aeb8c0; border-radius: 3px; background: #111; }
.evidence-image-button:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.evidence-image-button img { display: block; width: 100%; height: 100%; object-fit: contain; }
.evidence-toggle { align-self: start; font-size: 12px; }
.review-evidence .review-field > span { min-height: auto; }
.review-evidence .review-field input { height: 34px; }
.evidence-meta { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.35; }
.evidence-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.evidence-actions button { height: 30px; padding: 0 9px; font-size: 12px; }
.review-footer { padding: 10px 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-top: 1px solid #cfd5da; background: #fff; }
.review-footer > span { min-width: 0; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.review-footer > div { display: flex; gap: 10px; }
.status-badge.review-draft { background: #fff3d9; color: var(--warning); }
.status-badge.review-finalized { background: #e7f3eb; color: var(--success); }
.status-badge.review-not_started { background: #eceff1; color: #5b6670; }

.image-toolbar { height: 48px; padding: 0 16px; display: flex; align-items: center; justify-content: center; gap: 9px; border-bottom: 1px solid var(--line); background: #f8f9fa; }
.icon-tool { width: 38px; height: 38px; padding: 0; border-color: #b9c2c9; background: #fff; color: #26333d; font-size: 22px; line-height: 1; }
.icon-tool:hover:not(:disabled) { border-color: var(--accent); background: var(--focus); }
.image-toolbar output { width: 64px; color: #34414c; text-align: center; font-variant-numeric: tabular-nums; }
.image-viewport { height: calc(100% - 100px); overflow: auto; overscroll-behavior: contain; background: #15191d; cursor: grab; touch-action: none; }
.image-viewport.dragging { cursor: grabbing; user-select: none; }
.image-viewport img { display: block; max-width: none; margin: 16px auto; user-select: none; }

.video-context-body { height: calc(100% - 52px); padding: 12px 18px 16px; display: grid; grid-template-rows: 38px minmax(0, 1fr); gap: 10px; overflow: hidden; background: #f4f6f7; }
.video-mode-tabs { display: flex; align-items: end; gap: 20px; border-bottom: 1px solid #c9d0d6; }
.video-mode-tabs button { height: 38px; padding: 0 4px; border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; color: #53606b; }
.video-mode-tabs button.active { border-bottom-color: var(--accent); color: var(--accent-dark); font-weight: 650; }
.video-frame-pane { min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto auto; gap: 10px; }
.video-compare { min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.video-compare figure { min-width: 0; min-height: 0; margin: 0; display: grid; grid-template-rows: 28px minmax(0, 1fr); border: 1px solid var(--line); background: #fff; }
.video-compare figcaption { padding: 6px 10px; color: #45525d; font-size: 12px; font-weight: 650; }
.video-compare figure > img, .video-frame-stage { min-width: 0; min-height: 0; width: 100%; height: 100%; object-fit: contain; background: #111; }
.video-frame-stage { position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.video-frame-stage img { display: block; width: 100%; height: 100%; object-fit: contain; transition: opacity .1s ease; }
.video-frame-stage img.loading { opacity: .55; }
.frame-loading { position: absolute; z-index: 2; left: 50%; top: 50%; min-width: 72px; padding: 7px 10px; transform: translate(-50%, -50%); border-radius: 3px; background: rgba(16, 24, 31, .82); color: #fff; text-align: center; font-size: 12px; }
.video-frame-meta { min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: #44515c; font-size: 12px; }
.video-frame-meta strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.video-frame-meta span { white-space: nowrap; }
.video-navigation { display: flex; align-items: center; justify-content: center; gap: 8px; }
.video-navigation button { min-width: 70px; }
.video-navigation .icon-tool { min-width: 38px; }
.video-navigation .active-anchor { border-color: var(--accent); background: var(--focus); color: var(--accent-dark); }
.video-playback-pane { min-height: 0; height: 100%; display: grid; grid-template-rows: minmax(0, 1fr) 44px; gap: 10px; }
.video-playback-pane[hidden] { display: none; }
.video-playback-pane video { display: block; width: 100%; height: 100%; min-height: 0; background: #111; }
.video-playback-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.video-playback-footer span { color: #44515c; font-size: 12px; font-variant-numeric: tabular-nums; }

@media (max-width: 980px) {
  #caseForm { grid-template-columns: 1fr 1fr; }
  .submit-row { grid-column: 1 / -1; }
  .review-exam-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .review-exam-grid .review-field:nth-child(1), .review-exam-grid .review-field:nth-child(2) { grid-column: auto; }
  .review-finding-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .review-evidence-list { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .topbar { height: 62px; padding: 0 16px; }
  .topbar h1 { font-size: 16px; }
  .service-state { font-size: 0; }
  .service-state::before { margin-right: 0; }
  main { width: calc(100% - 24px); margin-top: 12px; }
  .workspace { padding: 18px 16px; }
  #caseForm { grid-template-columns: 1fr; }
  .submit-row { grid-column: auto; align-items: flex-start; flex-direction: column; }
  .primary { width: 100%; }
  .viewer-dialog, .log-dialog, .review-dialog { width: 100vw; max-width: none; height: 100vh; max-height: none; border-radius: 0; }
  .review-band, .review-findings-band { padding: 16px; }
  .review-section-head { align-items: stretch; flex-direction: column; }
  .reviewer-field { width: 100%; }
  .review-text-grid, .review-exam-grid, .review-finding-fields { grid-template-columns: 1fr; }
  .review-text-grid .review-field:first-child { grid-column: auto; }
  .review-findings-toolbar { position: static; align-items: stretch; flex-direction: column; margin: -16px -16px 0; padding: 14px 16px; }
  .search-field { width: 100%; margin: 0; }
  .review-evidence { grid-template-columns: 110px minmax(0, 1fr); }
  .evidence-image-button { width: 110px; height: 110px; }
  .review-shell { grid-template-rows: 52px minmax(0, 1fr) auto; }
  .review-footer { align-items: stretch; flex-direction: column; height: auto; min-height: 84px; }
  .review-footer > span { white-space: normal; }
  .review-footer > div { display: grid; grid-template-columns: 1fr 1fr; }
  .image-dialog, .video-context-dialog { width: 100vw; height: 100vh; max-width: none; max-height: none; border-radius: 0; }
  .video-context-body { padding: 10px; overflow: auto; grid-template-rows: 38px auto; }
  .video-frame-pane { grid-template-rows: auto auto auto; }
  .video-compare { grid-template-columns: 1fr; }
  .video-compare figure { min-height: 300px; }
  .video-frame-meta { align-items: flex-start; flex-direction: column; gap: 4px; }
  .video-navigation { display: grid; grid-template-columns: repeat(4, 1fr); }
  .video-navigation button { min-width: 0; width: 100%; padding: 0 6px; }
}
