:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --ink: #182233;
  --muted: #667085;
  --line: #d9e0ea;
  --panel: #ffffff;
  --green: #236254;
  --blue: #274c77;
  --amber: #9a5a16;
  --red: #df1d1d;
  --shadow: 0 18px 52px rgba(24, 34, 51, 0.11);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  min-height: 42px;
  padding: 0 16px;
}

button.secondary {
  background: #e9eef5;
  color: var(--ink);
}

a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 700;
}

.app-shell {
  width: min(1840px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

.topbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.topbar h1,
.panel-heading h2,
.detail-head h2,
.gate-copy h2,
.feedback-panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 28px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.muted,
.form-state {
  color: var(--muted);
}

.route-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 9px 14px;
  font-size: 13px;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gate-panel {
  min-height: calc(100vh - 150px);
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 0.7fr);
  gap: 36px;
  align-items: center;
}

.gate-copy {
  padding: 0 8px;
}

.gate-copy h2 {
  font-size: clamp(38px, 7vw, 82px);
  line-height: 0.96;
}

.gate-copy .muted {
  max-width: 620px;
  font-size: 18px;
  line-height: 1.6;
}

.gate-form,
.result-list,
.detail-panel,
.feedback-panel,
.import-panel,
.upload-panel,
.edit-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.gate-form {
  padding: 28px;
  box-shadow: var(--shadow);
}

label {
  display: block;
  margin: 0 0 8px;
  color: #344054;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
}

textarea {
  resize: vertical;
}

.password-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.result-list,
.detail-panel {
  padding: 20px;
}

.cards {
  display: grid;
  gap: 10px;
}

.result-card {
  width: 100%;
  min-height: 136px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  padding: 16px;
  display: grid;
  gap: 10px;
}

.result-card[aria-pressed="true"] {
  border-color: var(--green);
  box-shadow: inset 4px 0 0 var(--green);
}

.result-open-button {
  min-height: auto;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 0;
}

.delete-result-button,
.compact-action {
  min-height: 34px;
  justify-self: start;
  border: 1px solid rgba(223, 29, 29, 0.28);
  background: #fff1f1;
  color: #a31717;
  padding: 0 12px;
}

.card-meta,
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.pill {
  border-radius: 999px;
  background: #eef4ff;
  color: var(--blue);
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 800;
}

.import-panel {
  margin-top: 18px;
  padding: 14px;
}

.upload-panel {
  margin-top: 18px;
  padding: 14px;
}

.upload-dropzone {
  display: grid;
  place-items: center;
  min-height: 96px;
  border: 2px dashed #9fb0c4;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.upload-dropzone.dragover {
  border-color: var(--green);
  background: #edf8f4;
  color: var(--green);
}

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

.detail-head h2 {
  font-size: 28px;
}

.edit-panel {
  margin: 0 0 18px;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.guide-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 18px;
}

.guide-panel article,
.thread-panel,
.history-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

.guide-panel h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

.guide-panel ol {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.55;
}

.guide-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.compact-heading h2 {
  font-size: 20px;
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tool-row button[aria-pressed="true"] {
  background: var(--green);
  color: #fff;
}

#editTextInput {
  max-width: 360px;
}

.capture-layout {
  display: grid;
  grid-template-columns: minmax(620px, 1.7fr) minmax(420px, 0.9fr);
  gap: 22px;
  align-items: start;
}

.detail-panel.large-preview-mode .capture-layout {
  grid-template-columns: minmax(0, 1fr);
}

.detail-panel.large-preview-mode .capture-frame {
  max-width: min(100%, 1520px);
}

.detail-panel.large-preview-mode .annotation-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.capture-frame {
  position: relative;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f7;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

.capture-frame img {
  display: block;
  width: 100%;
  height: auto;
}

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

.edit-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

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

.feedback-box {
  background: rgba(223, 29, 29, 0.08);
}

.feedback-pin {
  position: absolute;
  display: grid;
  place-items: center;
  width: 0;
  height: 0;
}

.feedback-pin::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 6px 18px rgba(24, 34, 51, 0.24);
  transform: translate(-50%, -50%);
}

.drag-preview {
  background: rgba(223, 29, 29, 0.1);
}

.edit-layer {
  position: absolute;
  pointer-events: auto;
}

.edit-layer.selected {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}

.edit-pin {
  position: absolute;
  display: grid;
  place-items: center;
  width: 0;
  height: 0;
}

.edit-pin .annotation-number {
  top: -15px;
  left: -15px;
}

.edit-box {
  background: rgba(223, 29, 29, 0.06);
}

.edit-arrow {
  height: 0;
  border-top: 4px solid var(--red);
  transform-origin: 0 50%;
}

.edit-arrow::after {
  content: "";
  position: absolute;
  right: -1px;
  top: -8px;
  width: 14px;
  height: 14px;
  border-top: 4px solid var(--red);
  border-right: 4px solid var(--red);
  transform: rotate(45deg);
}

.edit-pen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.edit-text {
  max-width: 36%;
  border: 2px solid var(--red);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  padding: 6px 8px;
  font-weight: 800;
}

.edit-redact {
  border: 2px solid #111827;
  border-radius: 4px;
  background: rgba(17, 24, 39, 0.72);
  backdrop-filter: blur(8px);
}

.edit-crop {
  border: 3px dashed var(--green);
  border-radius: 4px;
  background: rgba(35, 98, 84, 0.08);
}

.original-view .edit-overlay,
.original-view .feedback-pin,
.original-view .feedback-box {
  display: none;
}

.annotation-number {
  position: absolute;
  top: -16px;
  left: -16px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  z-index: 2;
}

.annotation-list {
  display: grid;
  gap: 14px;
  align-content: start;
}

.annotation-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
}

.annotation-card h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

.annotation-card p {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.45;
}

.point-feedback-card {
  border-color: rgba(223, 29, 29, 0.38);
}

.deleted-feedback-card {
  border-style: dashed;
  background: #f8fafc;
}

.annotation-card textarea {
  min-height: 112px;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.danger-action {
  min-height: 38px;
  border: 1px solid rgba(223, 29, 29, 0.32);
  background: #fff1f1;
  color: #a31717;
}

.card-save-state {
  display: block;
  min-height: 20px;
  margin-top: 10px;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 12px;
}

.position-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 12px;
}

.position-meta div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.position-meta dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.position-meta dd {
  margin: 2px 0 0;
  font-size: 13px;
  font-weight: 800;
}

.feedback-panel {
  margin-top: 18px;
  padding: 22px;
  display: grid;
  gap: 14px;
}

.thread-panel,
.history-panel {
  display: grid;
  gap: 12px;
}

.thread-list,
.history-list {
  display: grid;
  gap: 10px;
}

.thread-card,
.history-item {
  border: 1px solid #e5eaf1;
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px;
}

.thread-meta,
.history-item {
  color: var(--muted);
}

.thread-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.thread-meta strong,
.history-item strong {
  color: var(--ink);
}

.thread-card p,
.history-item p {
  margin: 8px 0 0;
  color: var(--ink);
  line-height: 1.5;
}

.thread-compose {
  display: grid;
  grid-template-columns: minmax(140px, 0.25fr) minmax(260px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.feedback-panel textarea {
  min-height: 132px;
}

.feedback-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.export-output,
.save-output {
  color: var(--green);
  font-weight: 800;
}

.confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 34, 51, 0.36);
}

.confirm-panel {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 20px;
}

.confirm-panel h2 {
  margin: 0 0 10px;
  font-size: 22px;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

@media (max-width: 980px) {
  .workspace-grid,
  .capture-layout,
  .guide-panel,
  .detail-panel.large-preview-mode .annotation-list,
  .gate-panel {
    grid-template-columns: 1fr;
  }

  .app-shell {
    width: min(100vw - 20px, 1180px);
  }

  .detail-head {
    flex-direction: column;
  }

  .route-chip {
    max-width: 100%;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100vw - 20px, 1460px);
    padding-top: 12px;
  }

  .topbar,
  .password-row {
    grid-template-columns: 1fr;
    display: grid;
  }

  .gate-form,
  .result-list,
  .detail-panel,
  .edit-panel {
    padding: 14px;
  }

  .field-grid,
  .position-meta,
  .thread-compose,
  .confirm-actions {
    grid-template-columns: 1fr;
  }

  .confirm-actions {
    display: grid;
  }
}
