:root {
  color-scheme: light;
  --bg: #f5f6f7;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --border: #d7dce1;
  --text: #171b20;
  --muted: #66717d;
  --accent: #1f6feb;
  --accent-dark: #174ea6;
  --danger: #d7263d;
  --success: #2f7d4f;
  --warning: #a76300;
  --shadow: 0 8px 24px rgba(18, 28, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #aeb7c2;
}

button:disabled {
  color: #9aa3ad;
  cursor: not-allowed;
  background: #f1f3f5;
}

button.active,
.actions button:first-child {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.active:hover,
.actions button:first-child:hover {
  background: var(--accent-dark);
}

button.active:disabled,
.actions button:first-child:disabled {
  border-color: var(--border);
  background: #f1f3f5;
  color: #9aa3ad;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
  background: #fff;
  color: var(--text);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 58px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  white-space: nowrap;
}

.brand strong {
  font-size: 15px;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(270px, 330px) minmax(420px, 1fr) minmax(260px, 310px);
  height: calc(100vh - 58px);
}

.queuePane,
.settingsPane {
  overflow-y: auto;
  background: var(--panel);
}

.queuePane {
  border-right: 1px solid var(--border);
  padding: 14px;
}

.settingsPane {
  border-left: 1px solid var(--border);
  padding: 16px;
}

.previewPane {
  min-width: 0;
  overflow-y: auto;
  padding: 18px;
}

.dropZone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 128px;
  border: 1.5px dashed #aab4bf;
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted);
  text-align: center;
}

.dropZone.dragging {
  border-color: var(--accent);
  background: #eef5ff;
}

.dropZone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.queueHeader,
.gridHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 16px 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.imageList {
  display: grid;
  gap: 8px;
}

.queueItem {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-soft);
}

.queueItem.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 111, 235, 0.12);
}

.queueItemTop {
  display: flex;
  align-items: center;
  gap: 9px;
}

.thumb {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  object-fit: contain;
  background-color: #fff;
}

.queueText {
  min-width: 0;
  flex: 1;
}

.queueName {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 650;
}

.queueMeta {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  background: #edf0f3;
  color: #59636e;
}

.status.processed {
  background: #e7f4ec;
  color: var(--success);
}

.status.needs_review,
.status.failed {
  background: #fff0f2;
  color: var(--danger);
}

.queueFields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.queueFields label,
.fieldGrid label,
.selectedEditor label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.labelWithHint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.infoHint {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 15px;
  height: 15px;
  border: 1px solid #aeb7c2;
  border-radius: 50%;
  color: #59636e;
  background: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  cursor: help;
}

.infoHint::after {
  content: attr(aria-label);
  position: absolute;
  right: 50%;
  bottom: calc(100% + 8px);
  z-index: 5;
  width: min(240px, 68vw);
  border: 1px solid #202832;
  border-radius: 6px;
  background: #171b20;
  color: #fff;
  padding: 8px 9px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  text-transform: none;
  transform: translateX(50%) translateY(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
}

.infoHint:hover::after,
.infoHint:focus-visible::after {
  opacity: 1;
  transform: translateX(50%) translateY(0);
}

.previewHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.previewControls {
  display: grid;
  justify-items: end;
  gap: 8px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 12px;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0;
}

.previewHeader p {
  margin-top: 4px;
  color: var(--muted);
}

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.segmented button {
  border: 0;
  border-radius: 0;
}

.previewStage {
  display: grid;
  grid-template-columns: minmax(300px, 560px) minmax(220px, 1fr);
  gap: 16px;
  align-items: start;
}

.canvasPreview {
  position: relative;
  aspect-ratio: 1;
  width: min(100%, 560px);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.canvasPreview img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.checker {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e4e8ec 25%, transparent 25%),
    linear-gradient(-45deg, #e4e8ec 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e4e8ec 75%),
    linear-gradient(-45deg, transparent 75%, #e4e8ec 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.previewBgTransparent {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e4e8ec 25%, transparent 25%),
    linear-gradient(-45deg, #e4e8ec 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e4e8ec 75%),
    linear-gradient(-45deg, transparent 75%, #e4e8ec 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.previewBgWhite {
  background: #fff;
}

.previewBgBlack {
  background: #15191f;
}

.guideBox {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 57.6%;
  height: 57.6%;
  transform: translate(-50%, -50%);
  border: 2px solid var(--danger);
  pointer-events: none;
}

.guideBox.hidden {
  display: none;
}

.warningPanel {
  display: grid;
  gap: 8px;
}

.warning {
  border-left: 3px solid var(--warning);
  border-radius: 6px;
  background: #fff8ec;
  padding: 9px 10px;
  color: #5b3b00;
}

.previewGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.previewCard {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
  cursor: pointer;
}

.previewCard.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 111, 235, 0.12);
}

.previewThumb {
  position: relative;
  aspect-ratio: 1;
}

.previewThumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.previewInfo {
  display: grid;
  gap: 5px;
  padding: 9px;
}

.previewInfo strong {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.settingsPane h2:not(:first-child) {
  margin-top: 24px;
}

.toggleRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  border-bottom: 1px solid #eef1f4;
}

.fieldGrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.selectedEditor {
  margin-top: 24px;
}

.selectedEditor label + label {
  margin-top: 10px;
}

.stats {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.statLine {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #eef1f4;
  padding-bottom: 6px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(24px);
  max-width: min(540px, calc(100vw - 32px));
  border-radius: 8px;
  background: #171b20;
  color: #fff;
  padding: 10px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 290px minmax(360px, 1fr);
  }

  .settingsPane {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--border);
    height: auto;
  }
}

@media (max-width: 760px) {
  .toolbar {
    height: auto;
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .workspace {
    display: block;
    height: auto;
  }

  .queuePane,
  .previewPane,
  .settingsPane {
    border: 0;
  }

  .previewStage {
    grid-template-columns: 1fr;
  }

  .previewHeader {
    display: grid;
  }

  .previewControls {
    justify-items: start;
  }
}
