:root {
  color-scheme: light;
  --page: #f4f5f7;
  --surface: #ffffff;
  --surface-muted: #f7f8fa;
  --text: #20242a;
  --muted: #69717c;
  --border: #dfe3e8;
  --border-strong: #c7cdd5;
  --primary: #1769d2;
  --primary-hover: #0f57b7;
  --danger: #b42318;
  --danger-bg: #fff5f4;
  --success: #238636;
}

* { box-sizing: border-box; }
html { font-size: 14px; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

body.drawer-open { overflow: hidden; }
button, input, textarea { font: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.toolbar-inner {
  width: min(1200px, calc(100% - 32px));
  min-height: 54px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.toolbar-inner > strong { font-size: 16px; font-weight: 650; }
.toolbar-actions { display: flex; align-items: center; gap: 14px; }

.service-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.service-state i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}

.app-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 64px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: 20px; font-weight: 650; }
h2 { margin: 0; font-size: 17px; font-weight: 650; }
h3 { margin: 0; font-size: 14px; font-weight: 650; }

.button {
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 550;
  line-height: 1.2;
  text-align: center;
}

.button:hover { text-decoration: none; }
.button:disabled { cursor: not-allowed; opacity: .5; }
.button.primary { min-height: 40px; background: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-hover); }

.button.secondary {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

.button.secondary:hover { background: var(--surface-muted); }

.button.text-button {
  min-height: auto;
  padding: 4px 6px;
  border: 0;
  background: transparent;
  color: var(--primary);
}

.button.text-button:hover { text-decoration: underline; }

.button.danger-button {
  border-color: #e1aaa5;
  background: var(--surface);
  color: var(--danger);
}

.button.danger-button:hover { background: var(--danger-bg); }
.danger-text { color: var(--danger) !important; }
.toolbar-button { display: inline-flex; align-items: center; gap: 7px; }

.count-badge {
  min-width: 19px;
  padding: 1px 6px;
  border-radius: 10px;
  background: #e8f1fd;
  color: var(--primary);
  font-size: 11px;
  text-align: center;
}

.submit-panel,
.tool-section {
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}

.submit-panel { padding: 18px; }
.submit-heading { margin-bottom: 14px; }
.submit-heading p { margin: 0; color: var(--muted); font-size: 12px; }

.parse-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.parse-form input,
textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
}

.parse-form input { min-height: 40px; padding: 8px 11px; }
.parse-form input::placeholder,
textarea::placeholder { color: #9299a2; }

.form-message {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.current-task-section:not(:empty) {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.inline-section-heading,
.section-header,
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.inline-section-heading { margin-bottom: 10px; }
.inline-section-heading > span,
.section-header span,
.drawer-header span { color: var(--muted); font-size: 12px; }

.current-task-list { display: grid; gap: 10px; }

.current-task {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
}

.current-task-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 9px;
}

.task-kind {
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.task-info { min-width: 0; }
.task-info strong, .task-info small { display: block; }
.task-info strong { overflow: hidden; font-size: 13px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.task-info small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.progress-value { color: var(--muted); font-size: 11px; }
.task-progress { height: 5px; overflow: hidden; border-radius: 3px; background: #e4e8ed; }
.task-progress i { display: block; height: 100%; background: var(--primary); }

.current-counts,
.current-waiting {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.current-video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.current-video-card {
  min-width: 0;
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
}

.current-video-media { min-width: 0; display: flex; flex-direction: column; align-items: stretch; gap: 3px; }

.current-video-thumbnail {
  aspect-ratio: 1;
  overflow: hidden;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: #e9edf2;
  color: var(--muted);
  font-size: 10px;
}

.current-video-thumbnail img { width: 100%; height: 100%; object-fit: contain; }
.current-image-preview { min-height: 24px; padding: 2px 4px; font-size: 10px; }
.current-video-copy { min-width: 0; align-self: center; }
.current-video-copy strong, .current-video-copy small, .current-video-copy > span { display: block; }
.current-video-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.current-video-copy small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.current-video-copy > span { margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }

.section-header {
  min-height: 54px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}

.section-header > div { display: flex; align-items: baseline; gap: 10px; }

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  padding: 14px;
}

.history-card {
  min-width: 0;
  align-self: start;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.history-card[open] { grid-column: 1 / -1; }
.history-card > summary { cursor: pointer; list-style: none; }
.history-card > summary::-webkit-details-marker { display: none; }

.history-card > summary {
  min-width: 0;
  display: block;
  padding: 0;
}

.history-thumbnail {
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  display: grid;
  place-items: center;
  border-bottom: 1px solid var(--border);
  border-radius: 5px 5px 0 0;
  background: #e8ebef;
}

.history-thumbnail img { width: 100%; height: 100%; display: block; object-fit: contain; }
.thumbnail-placeholder { color: #7c8490; font-size: 13px; }

.history-card-copy { min-width: 0; display: block; padding: 11px 12px 12px; }
.history-card-copy strong, .history-card-copy small, .history-card-copy > span { display: block; }
.history-card-copy strong { overflow: hidden; font-size: 13px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.history-card-copy small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.history-card-copy > span { margin-top: 8px; color: var(--muted); font-size: 10px; }
.card-metrics { display: flex !important; flex-wrap: wrap; gap: 5px 10px; }
.card-metrics b { color: var(--text); font-weight: 650; }

.history-card[open] > summary {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  align-items: stretch;
  border-bottom: 1px solid var(--border);
}

.history-card[open] > summary .history-thumbnail {
  aspect-ratio: auto;
  min-height: 120px;
  max-height: 160px;
  border: 0;
  border-right: 1px solid var(--border);
  border-radius: 5px 0 0;
}

.history-card[open] > summary .history-card-copy { align-self: center; }
.profile-content, .video-content { padding: 16px; background: var(--surface-muted); }
.profile-content > .result-actions { margin-bottom: 12px; }
.nested-history-grid { padding: 0; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }

.video-meta-row { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 12px; color: var(--muted); font-size: 11px; }
.detail-metrics { display: grid; grid-template-columns: repeat(6, minmax(64px, 1fr)); gap: 8px; margin-bottom: 14px; }
.detail-metrics span { padding: 8px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); color: var(--muted); font-size: 10px; text-align: center; }
.detail-metrics b { display: block; color: var(--text); font-size: 13px; font-weight: 650; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.result-actions .button { font-size: 12px; }
.detail-copy-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }

.text-field { min-width: 0; margin-bottom: 14px; }
.field-header { min-height: 28px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-header label { font-size: 12px; font-weight: 650; }
textarea { min-height: 88px; resize: vertical; padding: 9px 10px; line-height: 1.55; }
textarea[readonly] { background: var(--surface); }
.field-note { margin: 5px 0 0; color: var(--muted); font-size: 11px; }

.frame-section { margin-top: 4px; }
.frame-section h3 { margin-bottom: 10px; }
.frame-section h3 span { margin-left: 6px; color: var(--muted); font-size: 11px; font-weight: 400; }
.screenshot-strip { display: flex; flex-wrap: nowrap; gap: 10px; padding: 2px 2px 10px; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x proximity; scrollbar-width: thin; overscroll-behavior-inline: contain; }
.screenshot-card { min-width: 0; flex: 0 0 clamp(112px, 11vw, 132px); overflow: hidden; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); scroll-snap-align: start; }
.screenshot-image { width: 100%; aspect-ratio: 4 / 5; padding: 0; display: grid; place-items: center; border: 0; background: #eef0f3; cursor: zoom-in; }
.screenshot-image img { width: 100%; height: 100%; display: block; object-fit: contain; }
.screenshot-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 7px 9px; }
.screenshot-actions span { flex: 0 0 100%; color: var(--muted); font-size: 11px; }
.screenshot-actions .button { padding: 0; font-size: 11px; }
.screenshot-actions a { font-size: 11px; }
.screenshot-strip > .empty-message { flex: 1 0 100%; }
.empty-message { grid-column: 1 / -1; margin: 0; padding: 22px 4px; color: var(--muted); text-align: center; }
.empty-message.compact { padding: 12px 0; }

.task-drawer-layer { display: none; position: fixed; inset: 0; z-index: 60; }
.task-drawer-layer.is-open { display: block; }
.drawer-overlay { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(25, 30, 36, .38); cursor: default; }

.task-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: min(460px, 100%);
  height: 100%;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border-strong);
  background: var(--surface);
}

.drawer-header { min-height: 62px; padding: 13px 16px; border-bottom: 1px solid var(--border); }
.drawer-header > div { display: flex; align-items: baseline; gap: 9px; }
.icon-button { width: 34px; height: 34px; padding: 0; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); color: var(--text); cursor: pointer; font-size: 22px; line-height: 1; }
.drawer-content { min-height: 0; flex: 1; overflow-y: auto; }
.drawer-tools { position: sticky; top: 0; z-index: 1; display: flex; justify-content: flex-end; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.drawer-task-list { padding: 0 14px 16px; }

.drawer-task-list .task-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px 10px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.drawer-task-list .task-row > .task-progress { grid-column: 2; }
.drawer-task-list .task-row > .progress-value { grid-column: 3; grid-row: 2; }
.drawer-task-list .task-actions { grid-column: 2 / -1; display: flex; flex-wrap: wrap; justify-content: flex-end; }
.task-item-error { grid-column: 1 / -1; padding: 7px 9px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-left: 3px solid var(--danger); background: var(--danger-bg); color: var(--danger); font-size: 11px; }

.delete-dialog {
  width: min(440px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  color: var(--text);
  background: var(--surface);
}

.delete-dialog::backdrop { background: rgba(25, 30, 36, .46); }
.delete-dialog form { padding: 20px; }
.delete-dialog h2 { margin-bottom: 12px; }
.delete-dialog p { margin-bottom: 10px; color: var(--muted); }
.delete-warning { padding: 9px 10px; border-left: 3px solid var(--danger); background: var(--danger-bg); color: var(--danger) !important; font-size: 12px; }
.dialog-error { min-height: 18px; color: var(--danger) !important; font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.image-preview-dialog {
  width: min(1100px, calc(100% - 32px));
  max-width: none;
  max-height: calc(100vh - 32px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}

.image-preview-dialog::backdrop { background: rgba(20, 24, 29, .72); }
.image-preview-dialog form { display: flex; max-height: calc(100vh - 34px); flex-direction: column; }
.image-preview-header { min-height: 52px; padding: 9px 12px 9px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.image-preview-body { min-height: 0; padding: 12px; display: grid; place-items: center; overflow: auto; background: #eef0f3; }
.image-preview-body img { display: block; max-width: 100%; max-height: calc(100vh - 125px); object-fit: contain; }
.image-preview-caption { min-height: 20px; margin: 0; padding: 7px 16px; color: var(--muted); font-size: 11px; }

.compat-page-header { margin-bottom: 16px; }
.compat-page-header h1 { margin-top: 10px; }
.compat-page-header + .history-card { width: 100%; }

@media (max-width: 820px) {
  .service-state { display: none; }
  .history-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 12px; }
  .history-card[open] { grid-column: 1 / -1; }
  .detail-copy-grid { grid-template-columns: 1fr; }
  .detail-metrics { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 540px) {
  .toolbar-inner, .app-shell { width: min(100% - 20px, 1200px); }
  .app-shell { padding-top: 12px; }
  .toolbar-actions { gap: 8px; }
  .toolbar-button { padding-inline: 9px; }
  .submit-panel { padding: 14px; }
  .parse-form { grid-template-columns: 1fr; }
  .history-grid { grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px; }
  .history-card-copy { padding: 9px; }
  .history-card-copy strong { font-size: 12px; }
  .history-card[open] { grid-column: 1 / -1; }
  .history-card[open] > summary { grid-template-columns: 96px minmax(0, 1fr); }
  .history-card[open] > summary .history-thumbnail { min-height: 96px; }
  .profile-content, .video-content { padding: 12px; }
  .nested-history-grid { grid-template-columns: 1fr; padding: 0; }
  .detail-metrics { grid-template-columns: repeat(2, 1fr); }
  .current-task-head { grid-template-columns: auto minmax(0, 1fr) auto; }
  .current-task-head > .progress-value { display: none; }
  .current-task-head > .text-button { grid-column: 3; }
  .current-video-grid { grid-template-columns: 1fr; }
  .drawer-task-list .task-row { grid-template-columns: auto minmax(0, 1fr); }
  .drawer-task-list .task-row > .progress-value { display: none; }
  .drawer-task-list .task-actions { grid-column: 2; }
  .task-item-error { align-items: flex-start; flex-direction: column; }
}
