/* Reusable UI components. */

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  background: transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
}
.btn .icon {
  width: 16px;
  height: 16px;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-s);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}
.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--primary-border);
  color: var(--primary);
}
.btn-ghost {
  color: var(--text-2);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
}
.btn-danger {
  background: var(--surface);
  border-color: #f0c2c8;
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
}
.btn-danger-solid {
  background: var(--danger);
  color: #fff;
}
.btn-danger-solid:hover:not(:disabled) {
  background: #ad2133;
}
.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}
.btn-block {
  width: 100%;
}
.btn:disabled,
.icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
}
.icon-btn[aria-pressed='true'] {
  background: var(--primary-soft);
  color: var(--primary);
}
.icon-btn.sm {
  width: 26px;
  height: 26px;
}
.icon-btn.sm .icon {
  width: 15px;
  height: 15px;
}
.icon-btn.danger:hover:not(:disabled) {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Toolbar tool buttons (icon + label) */
.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}
.tool-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}
.tool-btn[aria-pressed='true'] {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary-border);
}

.spinner {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  animation: spin 0.7s linear infinite;
}
.spinner.lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}
.btn-primary .spinner {
  border-color: rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 1.6s !important;
    animation-iteration-count: infinite !important;
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 20px;
  background: var(--surface-3);
  color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge .icon {
  width: 12px;
  height: 12px;
}
.badge-primary {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary);
}
.badge-success {
  background: var(--success-soft);
  border-color: #b4e2cf;
  color: var(--success);
}
.count-pill {
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
  padding: 1px 6px;
  border-radius: 20px;
  background: var(--primary-soft);
  color: var(--primary);
}

/* ── Form controls ───────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 0;
}
.label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
}
.input,
.select {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 13.5px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input:hover,
.select:hover {
  border-color: #aeb8c9;
}
.input:focus,
.select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.input[readonly] {
  background: var(--surface-2);
  color: var(--text-2);
}
.hint {
  font-size: 12px;
  color: var(--text-3);
  margin: 6px 0 0;
}
.row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.seg {
  display: flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-3);
  border-radius: var(--radius);
}
.seg-btn {
  flex: 1;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.seg-btn:hover {
  color: var(--text);
}
.seg-btn[aria-checked='true'] {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-s);
}

.range-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.value-pill {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 1px 9px;
  border-radius: 20px;
  font-variant-numeric: tabular-nums;
}
input[type='range'] {
  width: 100%;
  margin: 0;
  height: 22px;
  accent-color: var(--primary);
  cursor: pointer;
}
input[type='range']:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
}
.switch {
  position: relative;
  width: 38px;
  height: 22px;
  flex: none;
}
.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  background: #c3cbd9;
  transition: background 0.15s;
}
.switch span::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-s);
  transition: transform 0.15s;
}
.switch input:checked + span {
  background: var(--primary);
}
.switch input:checked + span::after {
  transform: translateX(16px);
}
.switch input:focus-visible + span {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.preset {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 7px 10px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 12.5px;
}
.preset small {
  font-weight: 500;
  font-size: 11px;
  color: var(--text-3);
}
.preset:hover {
  border-color: var(--primary-border);
  background: var(--surface-2);
}
.preset[aria-pressed='true'] {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}
.preset[aria-pressed='true'] small {
  color: var(--primary);
}

.lock-btn {
  width: 34px;
  height: 34px;
  flex: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  display: grid;
  place-items: center;
  color: var(--text-3);
}
.lock-btn[aria-pressed='true'] {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.name-preview {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font: 12px/1.7 var(--mono);
  color: var(--text-2);
  overflow-wrap: anywhere;
}
.name-preview .zip {
  color: var(--accent);
  font-weight: 600;
}
.name-preview .more {
  color: var(--text-3);
}

/* ── Accordion (controls sections) ───────────────────────────────────────── */
.acc-item {
  border-bottom: 1px solid var(--border);
}
.acc-head {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 12px 14px;
  background: transparent;
  border: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
  text-align: left;
}
.acc-head:hover {
  background: var(--surface-2);
}
.acc-head .icon {
  color: var(--primary);
  width: 16px;
  height: 16px;
}
.acc-head .chev {
  margin-left: auto;
  color: var(--text-3);
  transition: transform 0.15s;
}
.acc-head[aria-expanded='true'] .chev {
  transform: rotate(180deg);
}
.acc-body {
  padding: 4px 14px 16px;
}

/* ── Stats + estimate ────────────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}
.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  min-width: 0;
}
.stat-k {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
}
.stat-v {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.estimate {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-2);
  padding: 8px 10px;
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  min-height: 36px;
}
.estimate b {
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.actions {
  display: flex;
  gap: 8px;
}
.actions .btn {
  flex: 1;
}

/* ── File panel ──────────────────────────────────────────────────────────── */
.dropzone {
  margin: 12px;
  padding: 18px 12px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-l);
  background: var(--surface-2);
  text-align: center;
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  display: block;
  width: calc(100% - 24px);
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.dropzone .icon {
  width: 24px;
  height: 24px;
  color: var(--primary);
  margin-bottom: 4px;
}
.dropzone b {
  display: block;
  font-size: 13px;
  color: var(--text);
}
.dropzone small {
  font-size: 11.5px;
  color: var(--text-3);
}

.batch-bar {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 0 14px 8px;
  font-size: 12px;
  color: var(--text-2);
}
.batch-bar b {
  color: var(--text);
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 0 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 6px 7px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  min-width: 0;
}
.file-item:hover {
  border-color: var(--primary-border);
  background: var(--surface-2);
}
.file-item[aria-current='true'] {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.file-item[data-status='error'] {
  border-color: #f0c2c8;
  background: var(--danger-soft);
}
.thumb {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-3);
  flex: none;
  display: grid;
  place-items: center;
  color: var(--text-3);
}
.file-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.file-name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-sub {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-item[data-status='error'] .file-sub {
  color: var(--danger);
}
.file-state {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
}
.file-state .icon {
  width: 16px;
  height: 16px;
}
.file-state.done {
  color: var(--success);
}
.file-state.err {
  color: var(--danger);
}
.file-select {
  all: unset;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
  border-radius: var(--radius-s);
}
.file-select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.empty-hint {
  padding: 4px 22px 22px;
  text-align: center;
  color: var(--text-3);
  font-size: 12.5px;
}
.panel-left .panel-foot-actions {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

/* ── Canvas ──────────────────────────────────────────────────────────────── */
.canvas {
  position: relative;
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
}
.viewport {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  display: flex;
  padding: 24px;
}
.stage {
  margin: auto;
  flex: none;
  line-height: 0;
  border-radius: 4px;
  box-shadow: 0 0 0 1px var(--border-strong), var(--shadow-m);
  background-color: #fff;
  background-image: conic-gradient(#eef0f4 25%, transparent 0 50%, #eef0f4 0 75%, transparent 0);
  background-size: 16px 16px;
}
.stage img {
  display: block;
  border-radius: 4px;
  image-rendering: auto;
  user-select: none;
  -webkit-user-drag: none;
}
.canvas-badge {
  position: absolute;
  left: 14px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-s);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  pointer-events: none;
}
.canvas-badge b {
  color: var(--primary);
}
.canvas-busy {
  position: absolute;
  right: 14px;
  top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-s);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

.state {
  margin: auto;
  max-width: 400px;
  text-align: center;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.state h2 {
  margin: 6px 0 0;
  font-size: 20px;
  letter-spacing: -0.01em;
}
.state p {
  margin: 0;
  color: var(--text-2);
}
.state .illus {
  width: 88px;
  height: 88px;
  border-radius: 22px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
}
.state .illus .icon {
  width: 40px;
  height: 40px;
  stroke-width: 1.6;
}
.state.error .illus {
  background: var(--danger-soft);
  color: var(--danger);
}
.state .meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 4px;
}

/* ── Queue ───────────────────────────────────────────────────────────────── */
.q-summary {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
}
.progress {
  height: 6px;
  width: 140px;
  background: var(--surface-3);
  border-radius: 6px;
  overflow: hidden;
  flex: none;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--primary);
  transition: width 0.2s;
}
.q-list {
  list-style: none;
  margin: 0;
  padding: 6px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.q-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  min-width: 0;
}
.q-row[data-status='error'] {
  border-color: #f0c2c8;
  background: var(--danger-soft);
}
.q-ico {
  width: 22px;
  display: grid;
  place-items: center;
  flex: none;
  color: var(--text-3);
}
.q-row[data-status='done'] .q-ico {
  color: var(--success);
}
.q-row[data-status='error'] .q-ico {
  color: var(--danger);
}
.q-main {
  flex: 1;
  min-width: 0;
}
.q-name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.q-name .arrow {
  color: var(--text-3);
  font-weight: 400;
  margin: 0 4px;
}
.q-sub {
  font-size: 11.5px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.q-row[data-status='error'] .q-sub {
  color: var(--danger);
  white-space: normal;
}
.q-empty {
  margin: auto;
  padding: 18px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

/* ── Toasts ──────────────────────────────────────────────────────────────── */
.toasts {
  position: fixed;
  left: 50%;
  top: calc(var(--topbar-h) + 56px);
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 8px 11px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-m);
  animation: toast-in 0.18s ease-out;
}
.toast.leaving {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.15s, transform 0.15s;
}
.toast-info {
  border-left-color: var(--primary);
}
.toast-info > .icon {
  color: var(--primary);
}
.toast-success {
  border-left-color: var(--success);
}
.toast-success > .icon {
  color: var(--success);
}
.toast-warning {
  border-left-color: #d98b1f;
}
.toast-warning > .icon {
  color: var(--warning);
}
.toast-error {
  border-left-color: var(--danger);
}
.toast-error > .icon {
  color: var(--danger);
}
.toast > .icon {
  margin-top: 1px;
}
.toast-body {
  flex: 1;
  min-width: 0;
}
.toast-title {
  font-weight: 700;
  font-size: 13px;
}
.toast-msg {
  font-size: 12.5px;
  color: var(--text-2);
  overflow-wrap: anywhere;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
}

/* ── Dialog ──────────────────────────────────────────────────────────────── */
dialog.dialog {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-l);
  background: var(--surface);
  color: var(--text);
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  overflow: hidden;
}
dialog.dialog.wide {
  width: min(720px, calc(100vw - 32px));
}
dialog.dialog[open] {
  display: flex;
  flex-direction: column;
}
dialog.dialog::backdrop {
  background: rgba(20, 28, 48, 0.4);
}
.dialog-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 12px 12px 20px;
}
.dialog-head h2 {
  margin: 0;
  font-size: 16px;
  flex: 1;
}
.dialog-body {
  padding: 0 20px 18px;
  overflow: auto;
  color: var(--text-2);
}
.dialog-body p {
  margin: 0 0 10px;
}
.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.help-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}
.help-cols h3 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}
.kb-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--surface-3);
}
.mig-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 13px;
}
.mig-list li {
  display: flex;
  gap: 8px;
  padding: 3px 0;
}
.mig-list .icon {
  width: 15px;
  height: 15px;
  margin-top: 2px;
  color: var(--success);
}
.link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}
.link:hover {
  text-decoration: underline;
}

/* ── Global drop overlay ─────────────────────────────────────────────────── */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 800;
  display: none;
  place-items: center;
  background: rgba(234, 241, 255, 0.88);
  border: 3px dashed var(--primary);
  margin: 10px;
  border-radius: var(--radius-l);
  pointer-events: none;
}
.drop-overlay.show {
  display: grid;
}
.drop-overlay div {
  text-align: center;
  color: var(--primary);
  font-weight: 700;
  font-size: 18px;
}
.drop-overlay .icon {
  width: 44px;
  height: 44px;
  display: block;
  margin: 0 auto 8px;
}

.tb-text {
  font: 700 11px/1 var(--mono);
  letter-spacing: -0.02em;
}

/* ── Crop overlay ─────────────────────────────────────────────────────────── */
.stage {
  position: relative;
}
.stage canvas {
  display: block;
  border-radius: 4px;
  user-select: none;
}
.crop-overlay {
  position: absolute;
  inset: 0;
  touch-action: none;
  cursor: default;
}
.crop-overlay[hidden] {
  display: none;
}
.crop-dim {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 4px;
  pointer-events: none;
}
.crop-dimbox {
  position: absolute;
  box-shadow: 0 0 0 100vmax rgba(31, 41, 55, 0.5);
}
.crop-box {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid var(--primary);
  cursor: move;
  outline: none;
}
.crop-box:focus-visible {
  box-shadow: 0 0 0 3px var(--focus-ring, rgba(37, 99, 235, 0.45));
}
.crop-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, transparent calc(33.333% - 0.5px), rgba(255, 255, 255, 0.7) calc(33.333% - 0.5px), rgba(255, 255, 255, 0.7) calc(33.333% + 0.5px), transparent calc(33.333% + 0.5px), transparent calc(66.666% - 0.5px), rgba(255, 255, 255, 0.7) calc(66.666% - 0.5px), rgba(255, 255, 255, 0.7) calc(66.666% + 0.5px), transparent calc(66.666% + 0.5px)),
    linear-gradient(to bottom, transparent calc(33.333% - 0.5px), rgba(255, 255, 255, 0.7) calc(33.333% - 0.5px), rgba(255, 255, 255, 0.7) calc(33.333% + 0.5px), transparent calc(33.333% + 0.5px), transparent calc(66.666% - 0.5px), rgba(255, 255, 255, 0.7) calc(66.666% - 0.5px), rgba(255, 255, 255, 0.7) calc(66.666% + 0.5px), transparent calc(66.666% + 0.5px));
  opacity: 0;
  transition: opacity 0.12s;
}
.crop-overlay.dragging .crop-grid,
.crop-box:focus-visible .crop-grid,
.crop-box:hover .crop-grid {
  opacity: 1;
}
.crop-readout {
  position: absolute;
  left: 50%;
  top: 6px;
  transform: translateX(-50%);
  padding: 2px 8px;
  font: 600 11px/1.5 var(--font);
  color: #fff;
  background: rgba(31, 41, 55, 0.72);
  border-radius: 10px;
  pointer-events: none;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.12s;
}
.crop-overlay.dragging .crop-readout {
  opacity: 1;
}
.crop-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  background: #fff;
  border: 2px solid var(--primary);
  border-radius: 50%;
  box-sizing: border-box;
}
.crop-handle::after {
  /* larger invisible hit target, important on touch screens */
  content: '';
  position: absolute;
  inset: -10px;
}
.h-nw { left: 0; top: 0; cursor: nwse-resize; }
.h-n { left: 50%; top: 0; cursor: ns-resize; }
.h-ne { left: 100%; top: 0; cursor: nesw-resize; }
.h-e { left: 100%; top: 50%; cursor: ew-resize; }
.h-se { left: 100%; top: 100%; cursor: nwse-resize; }
.h-s { left: 50%; top: 100%; cursor: ns-resize; }
.h-sw { left: 0; top: 100%; cursor: nesw-resize; }
.h-w { left: 0; top: 50%; cursor: ew-resize; }

/* ── Compare view ─────────────────────────────────────────────────────────── */
.cmp-layer {
  --split: 50%;
  position: absolute;
  inset: 0;
  border-radius: 4px;
  overflow: hidden;
  cursor: ew-resize;
  touch-action: none;
}
.cmp-layer[hidden] {
  display: none;
}
.cmp-result {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  clip-path: inset(0 0 0 var(--split));
  user-select: none;
}
.cmp-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--split);
  width: 2px;
  margin-left: -1px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(31, 41, 55, 0.35);
  outline: none;
}
.cmp-grip {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 4px;
  background: #fff;
  color: var(--primary);
  border-radius: 15px;
  box-shadow: var(--shadow-m);
}
.cmp-handle:focus-visible .cmp-grip {
  box-shadow: 0 0 0 3px var(--focus-ring, rgba(37, 99, 235, 0.45));
}
.cmp-tag {
  position: absolute;
  top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  font: 600 11px/1.4 var(--font);
  color: var(--text-2);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 12px;
  pointer-events: none;
}
.cmp-tag.left { left: 8px; }
.cmp-tag.right { right: 8px; color: var(--primary); }

/* ── Crop / compression controls ──────────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.compress-grid,
.chip-grid-x {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.chip-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.preset.compact {
  align-items: center;
  padding: 7px 4px;
  text-align: center;
}
.estimate {
  flex-wrap: wrap;
}
.estimate-warn {
  flex-basis: 100%;
  margin-top: 4px;
  font-size: 12px;
  color: var(--danger);
}

/* ── Toolbar: shed labels as the centre column narrows ────────────────────── */
.toolbar {
  container: toolbar / inline-size;
}
@container toolbar (max-width: 1060px) {
  .toolbar-file {
    display: none;
  }
}
@container toolbar (max-width: 900px) {
  /* Eight tools no longer fit with labels: icons only (the open tool is shown by its pressed state; every button keeps its tooltip and aria-label). */
  .toolbar .tool-btn .tool-label {
    display: none;
  }
  .toolbar .tool-btn {
    padding: 0 8px;
  }
  .toolbar-group {
    gap: 2px;
  }
}
@container toolbar (max-width: 760px) {
  /* Narrow centre column: keep tools, navigation, compare and fit; zoom +/− stay on the keyboard (+ / −, Ctrl+wheel). */
  .toolbar .mobile-hide {
    display: none;
  }
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  padding: 3px 9px;
  font: 600 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  border-radius: 12px;
}
.chip:hover {
  background: var(--surface);
}

/* ── Smart crop (P4-C) ─────────────────────────────────────────────────── */
.smart-block { display: grid; gap: 8px; padding: 10px; border: 1px solid var(--accent-border, #ddd6fe); background: var(--accent-soft, #f5f3ff); border-radius: var(--radius, 10px); }
.smart-block .label { display: flex; align-items: center; gap: 6px; color: var(--accent, #6d28d9); }
.smart-block .label .icon { width: 14px; height: 14px; }
.smart-block .hint { margin: 0; }
.smart-chip.warn { border-color: #f59e0b; color: #92400e; background: #fffbeb; }
.smart-chip.warn[aria-pressed='true'] { background: #fef3c7; }
.file-state.warn { color: #b45309; }
.crop-subject { position: absolute; box-sizing: border-box; border: 2px dashed var(--accent, #7c3aed); pointer-events: none; border-radius: 4px; }
.crop-subject span { position: absolute; left: 0; top: -20px; font-size: 11px; line-height: 16px; padding: 0 6px; border-radius: 4px; background: var(--accent, #7c3aed); color: #fff; white-space: nowrap; }
.crop-faces { position: absolute; inset: 0; pointer-events: none; }
.crop-face { position: absolute; box-sizing: border-box; border: 2px solid #f59e0b; border-radius: 50%; }

.smart-chip { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; line-height: 1.2; min-height: 44px; }
.smart-chip .pct { font-size: 11px; opacity: .8; font-variant-numeric: tabular-nums; }

/* ── P4-D: optimisation report ───────────────────────────────────────────── */
.opt-report {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 10px);
  background: var(--surface-2, #f7f8fa);
  font-size: 12.5px;
}
.opt-report[hidden] { display: none; }
.opt-row { display: flex; justify-content: space-between; gap: 8px; }
.opt-row b.ok { color: var(--success, #15803d); }
.opt-row b.warn { color: var(--danger); }
.opt-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 12px; }
.opt-table caption { text-align: left; color: var(--text-3); padding-bottom: 2px; }
.opt-table th, .opt-table td { text-align: right; padding: 2px 4px; border-top: 1px solid var(--border); }
.opt-table th:first-child, .opt-table td:first-child { text-align: left; }
.opt-table tr.win td { font-weight: 600; color: var(--primary, #2563eb); }
.opt-table td.miss { color: var(--danger); }

/* ── P4-E: presets, folder saving, batch profile ─────────────────────────── */
.preset-bar { display: grid; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.preset-row { display: flex; gap: 8px; }
.preset-row .select { flex: 1; min-width: 0; }
.preset-tools { display: flex; gap: 2px; justify-content: flex-end; }
.folder-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.folder-row[hidden] { display: none; }
.folder-name { font-size: 12.5px; color: var(--text-2); overflow-wrap: anywhere; }
.batch-profile { display: grid; gap: 4px; padding: 8px 10px; margin: 8px 0; border: 1px solid var(--border); border-radius: var(--radius-md, 10px); background: var(--surface-2, #f7f8fa); font-size: 12.5px; }
.batch-profile[hidden] { display: none; }
.batch-profile h4 { margin: 0; font-size: 12px; font-weight: 600; color: var(--text-2); }
.bp-row { display: flex; justify-content: space-between; gap: 8px; }
.bp-row b { font-variant-numeric: tabular-nums; }
.bp-note { color: var(--text-3); font-size: 11.5px; }

/* ── P4-F: fine rotation, adjustments, watermark ─────────────────────────── */
.range-field { display: block; }
.range-val { display: inline-flex; align-items: center; gap: 4px; }
.range-num { width: 64px; padding: 3px 6px; text-align: right; font-variant-numeric: tabular-nums; }
.range-val .unit { font-size: 12px; color: var(--text-3); min-width: 16px; }
.straighten-block { border-top: 1px solid var(--border); padding-top: 12px; }
.color-input { width: 100%; min-width: 36px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
.chip-grid .color-input { height: auto; grid-column: auto; }
.logo-row { display: flex; gap: 8px; flex-wrap: wrap; }
.logo-name { font-size: 12px; color: var(--text-2); word-break: break-all; }
.override-box { border: 1px dashed var(--border); border-radius: 10px; padding: 10px; background: var(--surface-2, #fafbfc); }
.pos-grid { display: grid; grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(3, 34px); gap: 4px; }
.pos-btn { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; display: grid; place-items: center; padding: 0; }
.pos-btn span { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); }
.pos-btn[aria-checked='true'] { border-color: var(--primary); background: var(--primary-soft); }
.pos-btn[aria-checked='true'] span { background: var(--primary); }
.pos-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.crop-guide { position: absolute; inset: 0; pointer-events: none; background-image: linear-gradient(rgba(37, 99, 235, 0.35) 1px, transparent 1px), linear-gradient(90deg, rgba(37, 99, 235, 0.35) 1px, transparent 1px); background-size: 10% 10%; }
.crop-guide[hidden] { display: none; }
.horizon-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.horizon-line { stroke: #7c3aed; stroke-width: 2; stroke-dasharray: 6 4; }
.crop-overlay.horizon-mode { cursor: crosshair; }
.crop-overlay.horizon-mode .crop-box { pointer-events: none; }

h1.brand-name {
  margin: 0;
}
