:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #138a54;
  --green-bg: #e8f6ef;
  --orange: #b86408;
  --orange-bg: #fff4df;
  --red: #c53030;
  --red-bg: #fff0f0;
  --blue-bg: #eaf2ff;
  --shadow: 0 16px 40px rgba(20, 31, 53, 0.08);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 28px;
  padding: 34px clamp(18px, 4vw, 56px) 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(28px, 5vw, 44px);
  line-height: 1.12;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 6px;
  font-size: 22px;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 8px;
  font-size: 18px;
}

.lead {
  max-width: 830px;
  margin-bottom: 0;
  color: #344054;
  font-size: 16px;
  line-height: 1.8;
}

.usage-note {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 9px 12px;
  color: #1f3b62;
  background: var(--blue-bg);
  border: 1px solid #c8dcff;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
}

.usage-note b {
  color: var(--primary-dark);
}

.top-actions,
.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-content: flex-start;
  justify-content: flex-end;
}

main {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto 56px;
}

.panel,
.result-hero,
.final-section {
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 22px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.section-heading.compact {
  margin-bottom: 14px;
}

.section-heading p,
.settings-section p,
.risk-list-panel p,
.preview-panel p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 10px;
  color: #1f3b62;
  background: var(--blue-bg);
  border: 1px solid #c8dcff;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.dropzone {
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 28px;
  text-align: center;
  background: var(--surface-soft);
  border: 2px dashed #9bb5d8;
  border-radius: 8px;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    transform 0.18s ease;
}

.dropzone.is-dragging {
  background: #edf5ff;
  border-color: var(--primary);
  transform: translateY(-1px);
}

.dropzone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-icon {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-bottom: 10px;
  color: #ffffff;
  background: var(--primary);
  border-radius: 50%;
  font-size: 30px;
  line-height: 1;
}

.upload-title {
  display: block;
  margin-bottom: 6px;
  font-size: 19px;
  font-weight: 800;
}

.upload-help {
  color: var(--muted);
}

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.file-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  padding: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.file-toolbar[hidden] {
  display: none;
}

.select-all-control {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  min-height: 34px;
  color: #344054;
  font-weight: 800;
}

.select-all-control input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.toolbar-count {
  color: var(--muted);
  font-size: 13px;
  margin-right: auto;
}

.file-card {
  position: relative;
  display: block;
  min-width: 0;
  padding: 10px;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.file-card.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.file-select {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  min-width: 0;
  padding: 0;
  color: inherit;
  text-align: left;
  background: transparent;
  border: 0;
}

.file-check {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
}

.file-check input {
  position: absolute;
  opacity: 0;
}

.file-check span {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #b8c4d6;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.file-check input:checked + span {
  background: var(--primary);
  border-color: var(--primary);
}

.file-check input:checked + span::after {
  content: "";
  width: 8px;
  height: 12px;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translateY(-1px);
}

.file-check input:disabled + span {
  cursor: not-allowed;
  opacity: 0.5;
}

.thumb {
  width: 76px;
  height: 76px;
  object-fit: cover;
  background: #edf1f6;
  border-radius: 6px;
}

.file-info {
  display: block;
  min-width: 0;
  overflow: hidden;
}

.file-name {
  display: block;
  max-width: 100%;
  overflow: hidden;
  margin-bottom: 6px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status-pending {
  color: #344054;
  background: #eef2f7;
}

.status-running {
  color: #174ea6;
  background: var(--blue-bg);
}

.status-done {
  color: var(--green);
  background: var(--green-bg);
}

.status-failed {
  color: var(--red);
  background: var(--red-bg);
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(170px, 1fr) minmax(180px, 0.7fr);
  gap: 14px;
  align-items: end;
}

label span {
  display: block;
  margin-bottom: 7px;
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  min-height: 44px;
  padding: 0 18px;
  color: #ffffff;
  background: var(--primary);
}

.primary-button:hover {
  background: var(--primary-dark);
}

.primary-button:disabled {
  cursor: not-allowed;
  background: #9fb2d4;
}

.primary-button.small {
  min-height: 38px;
  padding: 0 14px;
}

.secondary-button,
.ghost-button {
  min-height: 38px;
  padding: 0 14px;
  color: #24324b;
  background: #eef2f7;
}

.secondary-button:hover,
.ghost-button:hover {
  background: #e1e8f2;
}

.secondary-button.danger {
  color: var(--red);
  background: var(--red-bg);
}

.secondary-button.danger:hover {
  background: #ffe1e1;
}

.detect-button {
  width: 100%;
  height: 44px;
}

.result-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 24px;
  border-left: 8px solid #98a2b3;
}

.result-hero h2 {
  font-size: 30px;
}

.result-hero p:last-child {
  margin-bottom: 0;
  color: #344054;
  line-height: 1.7;
}

.result-hero.level-low {
  border-left-color: var(--green);
  background: linear-gradient(90deg, var(--green-bg), #ffffff 56%);
}

.result-hero.level-medium {
  border-left-color: var(--orange);
  background: linear-gradient(90deg, var(--orange-bg), #ffffff 56%);
}

.result-hero.level-high {
  border-left-color: var(--red);
  background: linear-gradient(90deg, var(--red-bg), #ffffff 56%);
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(96px, 1fr));
  gap: 10px;
}

.result-stats div {
  min-width: 108px;
  padding: 14px;
  text-align: center;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.result-stats span {
  display: block;
  margin-bottom: 4px;
  font-size: 22px;
  font-weight: 900;
}

.result-stats small {
  color: var(--muted);
}

.preview-layout,
.insight-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.85fr);
  gap: 18px;
}

.image-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 460px;
  overflow: hidden;
  background:
    linear-gradient(45deg, #eef2f7 25%, transparent 25%),
    linear-gradient(-45deg, #eef2f7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef2f7 75%),
    linear-gradient(-45deg, transparent 75%, #eef2f7 75%);
  background-color: #f9fbfd;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.image-stage img {
  display: block;
  max-width: 100%;
  max-height: 580px;
  object-fit: contain;
}

.annotation-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.annotation-box {
  position: absolute;
  border: 3px solid var(--primary);
  border-radius: 4px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.02);
}

.annotation-box.level-high {
  border-color: var(--red);
}

.annotation-box.level-medium {
  border-color: var(--orange);
}

.annotation-box.level-low {
  border-color: var(--primary);
}

.annotation-label {
  position: absolute;
  left: -3px;
  top: -30px;
  max-width: 220px;
  padding: 4px 8px;
  overflow: hidden;
  color: #ffffff;
  background: #1f2937;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.risk-list,
.risk-cards,
.rewrite-list,
.history-list {
  display: grid;
  gap: 12px;
}

.risk-row,
.risk-card,
.rewrite-item,
.history-item,
.explain-item {
  padding: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.risk-row {
  border-left: 5px solid var(--primary);
}

.risk-row.level-high,
.risk-card.level-high {
  border-left-color: var(--red);
}

.risk-row.level-medium,
.risk-card.level-medium {
  border-left-color: var(--orange);
}

.risk-row.level-low,
.risk-card.level-low {
  border-left-color: var(--primary);
}

.risk-row h3,
.risk-card h3 {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  font-size: 16px;
}

.level-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.level-chip.level-high {
  color: var(--red);
  background: var(--red-bg);
}

.level-chip.level-medium {
  color: var(--orange);
  background: var(--orange-bg);
}

.level-chip.level-low {
  color: var(--green);
  background: var(--green-bg);
}

.kv-list {
  display: grid;
  gap: 7px;
  margin: 0;
}

.kv-list div {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 10px;
  line-height: 1.6;
}

.kv-list dt {
  color: var(--muted);
  font-weight: 800;
}

.kv-list dd {
  margin: 0;
}

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

.explain-item strong,
.rewrite-item strong {
  display: block;
  margin-bottom: 6px;
}

.rewrite-arrow {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.rewrite-arrow span {
  padding: 5px 8px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-weight: 800;
}

.final-section {
  padding: 24px;
  background: #172033;
  color: #ffffff;
}

.final-section .eyebrow {
  color: #9ec5ff;
}

.final-section h2 {
  font-size: 28px;
}

.final-section ol {
  margin: 10px 0 0;
  padding-left: 22px;
  line-height: 1.8;
}

.inline-message {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 96px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
  background: var(--surface-soft);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

dialog {
  width: min(560px, calc(100% - 28px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.22);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin: 0;
}

.icon-button {
  width: 36px;
  height: 36px;
  color: var(--text);
  background: #eef2f7;
  font-size: 22px;
}

.guide-content {
  padding: 20px;
  color: #344054;
  line-height: 1.8;
}

.guide-content p:last-child {
  margin-bottom: 0;
}

@media (max-width: 900px) {
  .topbar,
  .result-hero,
  .preview-layout,
  .insight-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .result-stats {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  main {
    width: min(100% - 20px, 1180px);
    margin-top: 12px;
  }

  .topbar {
    padding: 24px 16px 18px;
  }

  .panel,
  .result-hero,
  .final-section {
    padding: 16px;
  }

  .section-heading {
    display: grid;
  }

  .file-card {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .thumb {
    width: 64px;
    height: 64px;
  }

  .image-stage {
    min-height: 320px;
  }

  .kv-list div {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

@media print {
  .top-actions,
  .upload-section,
  .settings-section,
  #history,
  dialog {
    display: none !important;
  }

  body {
    background: #ffffff;
  }

  main {
    width: 100%;
    margin: 0;
  }

  .panel,
  .result-hero,
  .final-section {
    break-inside: avoid;
    box-shadow: none;
  }
}
