/* ============================================
   Pixia - Watermark PDF studio (watermark.html)
   Complements css/ai-tool.css (.at-* primitives)
   Scope: body.at-watermark
   ============================================ */

body.at-watermark {
  --wt-accent: var(--accent-primary);
  --wt-accent-2: var(--accent-primary);
  --wt-ink: var(--text-primary);
  --wt-line: var(--glass-border);
}

/* The app toggles visibility via the hidden attribute on many controls
   that also set display explicitly (drop area, stage, fields, etc.). */
body.at-watermark [hidden] { display: none !important; }

/* ---------- Layout ---------- */
.wt-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 22px;
  align-items: start;
}

.wt-main {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.wt-side {
  min-width: 0;
  position: sticky;
  inset-block-start: 84px;
  display: grid;
  gap: 16px;
}

@media (max-width: 1060px) {
  .wt-layout { grid-template-columns: 1fr; }
  .wt-side { position: static; }
}

body.at-watermark .wt-side .at-panel + .at-panel { margin-block-start: 0; }
body.at-watermark .at-panel { min-height: 0; min-width: 0; }

.wt-panel h2 {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-block-end: 2px;
}

.wt-panel h2 .wt-count {
  margin-inline-start: auto;
  font-family: var(--font-primary);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 3px 10px;
}

.wt-panel-hint {
  margin: 0 0 14px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-tertiary);
}

/* ---------- Source files ---------- */
.wt-source { display: grid; gap: 12px; }

.wt-drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 34px 20px;
  border: 1.6px dashed var(--glass-border-hover);
  border-radius: var(--at-radius-lg);
  background: var(--glass-bg);
  cursor: pointer;
  transition: border-color .2s var(--at-ease), background .2s var(--at-ease), transform .2s var(--at-ease);
}
.wt-drop:hover { border-color: var(--wt-accent); }
.wt-drop.drag {
  border-color: var(--wt-accent);
  background: color-mix(in srgb, var(--wt-accent) 10%, var(--glass-bg));
  transform: scale(1.006);
}
.wt-drop input { display: none; }
.wt-drop-icon {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: 16px;
  background: color-mix(in srgb, var(--wt-accent) 16%, transparent);
  color: var(--wt-accent);
  margin-block-end: 2px;
}
.wt-drop-icon svg { width: 26px; height: 26px; }
.wt-drop-title { font-family: var(--font-display); font-size: 1.02rem; font-weight: 600; color: var(--text-primary); }
.wt-drop-sub { font-size: 13px; color: var(--text-tertiary); }
.wt-drop-meta { display: flex; gap: 8px; margin-block-start: 4px; }
.wt-drop-meta span {
  font-size: 11px; font-weight: 600;
  color: var(--text-tertiary);
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 3px 10px;
}

.wt-files { display: none; gap: 8px; }
.wt-files[data-has="1"] { display: grid; }

.wt-file-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  background: var(--glass-bg);
}
.wt-file-thumb {
  width: 40px; height: 52px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  background: var(--bg-secondary);
  display: grid; place-items: center;
  color: var(--text-tertiary);
}
.wt-file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.wt-file-thumb svg { width: 18px; height: 18px; }
.wt-file-info { min-width: 0; display: grid; gap: 3px; }
.wt-file-name {
  font-size: 13.5px; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wt-file-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-tertiary);
}
.wt-file-status { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.wt-file-status.is-error { color: #dc2626; background: color-mix(in srgb, #ef4444 14%, transparent); }
.wt-file-status.is-ready { color: #16a34a; background: color-mix(in srgb, #22c55e 16%, transparent); }
.wt-file-status.is-reading { color: var(--text-tertiary); background: var(--bg-secondary); }
.wt-icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  background: var(--glass-bg);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color .2s var(--at-ease), border-color .2s var(--at-ease), background .2s var(--at-ease);
}
.wt-icon-btn:hover { color: #dc2626; border-color: color-mix(in srgb, #ef4444 45%, var(--glass-border)); background: color-mix(in srgb, #ef4444 8%, transparent); }
.wt-icon-btn svg { width: 16px; height: 16px; }

.wt-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: auto;
  height: auto;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  background: var(--glass-bg);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: color .2s var(--at-ease), border-color .2s var(--at-ease), background .2s var(--at-ease);
  margin-top: 20px;
}
.wt-add-btn:hover { color: var(--text-primary); border-color: var(--wt-accent); }
.wt-add-btn svg { width: 16px; height: 16px; flex: 0 0 auto; }
.wt-add-btn span { white-space: nowrap; }

/* ---------- Preview ---------- */
.wt-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-block-end: 10px;
}
.wt-preview-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wt-preview-nav button {
  min-width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  background: var(--glass-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all .2s var(--at-ease);
}
.wt-preview-nav button:hover:not(:disabled) { border-color: var(--wt-accent); color: var(--wt-accent); }
.wt-preview-nav button:disabled { opacity: .4; cursor: not-allowed; }
.wt-preview-nav button svg { width: 16px; height: 16px; }
.wt-preview-label { font-size: 12.5px; font-weight: 600; color: var(--text-tertiary); font-variant-numeric: tabular-nums; }

.wt-stage {
  position: relative;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-lg);
  background: var(--bg-secondary);
  display: grid;
  place-items: center;
  padding: 14px;
  min-height: 260px;
  overflow: hidden;
  user-select: none;
}
.wt-stage canvas {
  max-width: 100%;
  max-height: 560px;
  width: auto;
  height: auto;
  box-shadow: 0 14px 40px -18px rgba(0, 0, 0, .5);
  border-radius: 4px;
  background: #fff;
  cursor: crosshair;
}
.wt-stage-empty {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: var(--text-tertiary);
  font-size: 13.5px;
  text-align: center;
  padding: 40px 20px;
}
.wt-stage-empty svg { width: 34px; height: 34px; opacity: .7; }
.wt-stage-spinner {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg-secondary) 55%, transparent);
  backdrop-filter: blur(2px);
  z-index: 3;
}
.wt-stage-spinner[hidden] { display: none; }
.wt-spinner {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid var(--glass-border);
  border-block-start-color: var(--wt-accent);
  animation: wt-spin .8s linear infinite;
}
@keyframes wt-spin { to { transform: rotate(360deg); } }

/* apply-mode guard overlay */
.wt-stage.is-disabled { position: relative; }
.wt-stage.is-disabled::after {
  content: "";
  position: absolute; inset: 0;
  cursor: not-allowed;
}

/* ---------- Apply pages strip ---------- */
.wt-apply-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-block-end: 12px;
}
.wt-apply-right { display: flex; align-items: center; gap: 10px; }
.wt-seg {
  display: inline-flex;
  gap: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  padding: 3px;
}
.wt-seg button {
  border: 0;
  background: transparent;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-tertiary);
  padding: 6px 13px;
  border-radius: 9px;
  cursor: pointer;
  transition: all .2s var(--at-ease);
}
.wt-seg button:hover { color: var(--text-primary); }
.wt-seg button.active { background: var(--wt-accent); color: #1b1408; }

.wt-seg-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  margin-block-start: 10px;
}
.wt-seg-block button { text-align: center; }

.wt-apply-all-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-block-end: 12px;
}
.wt-mini-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 9px;
  padding: 5px 11px;
  cursor: pointer;
  transition: all .2s var(--at-ease);
}
.wt-mini-btn:hover:not(:disabled) { color: var(--text-primary); border-color: var(--wt-accent); }
.wt-mini-btn:disabled { opacity: .5; cursor: not-allowed; }

.wt-apply-all {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.wt-apply-all input { accent-color: var(--wt-accent); width: 15px; height: 15px; cursor: pointer; }

/* switch variants */
.wt-switch input {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}
.wt-switch i {
  display: inline-block;
  position: relative;
  width: 38px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--glass-border);
  transition: background .18s var(--at-ease);
}
.wt-switch i::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform .18s var(--at-ease);
}
.wt-switch input:checked + i { background: var(--wt-accent); }
.wt-switch input:checked + i::after { transform: translateX(16px); }
[dir="rtl"] .wt-switch input:checked + i::after { transform: translateX(-16px); }
.wt-switch input:focus-visible + i { outline: 2px solid var(--wt-accent); outline-offset: 2px; }
.wt-switch input:disabled + i { opacity: .45; }
.wt-switch input:disabled ~ span { opacity: .6; }
/* .wt-field > label is display:block and outranks .wt-apply-all;
   restore the row layout for switch labels inside a field */
.wt-field > .wt-apply-all {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
}

/* shared themed colour picker hooks */
.ce-cp-wrap { display: inline-flex; align-items: center; gap: 8px; }
.ce-cp-swatch:disabled { opacity: .5; cursor: default; }
.ce-cp-native { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; border: 0; padding: 0; margin: 0; }

.wt-strip {
  position: relative;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 6px 2px 14px;
  scroll-snap-type: x proximity;
}
.wt-strip.is-disabled { opacity: .55; pointer-events: none; }

.wt-page {
  position: relative;
  flex: 0 0 auto;
  width: 82px;
  scroll-snap-align: start;
  border: 2px solid var(--glass-border);
  border-radius: 10px;
  background: var(--bg-secondary);
  overflow: hidden;
  cursor: pointer;
  outline: none;
  transition: border-color .2s var(--at-ease), transform .2s var(--at-ease), box-shadow .2s var(--at-ease);
}
.wt-page img { display: block; width: 100%; height: auto; }
.wt-page.is-sel {
  border-color: var(--wt-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--wt-accent) 32%, transparent);
}
.wt-page:hover { transform: translateY(-2px); }
.wt-page:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--wt-accent) 55%, transparent); }

.wt-page-num {
  position: absolute;
  inset-block-start: 4px;
  inset-inline-start: 4px;
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  padding: 0 4px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-primary);
  background: rgba(255, 255, 255, .92);
  border-radius: 6px;
}
.wt-page-check {
  position: absolute;
  inset-block-start: 4px;
  inset-inline-end: 4px;
  width: 20px; height: 20px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--glass-bg);
  border: 1.5px solid var(--glass-border);
  color: #fff;
  transition: all .18s var(--at-ease);
}
.wt-page-check svg { width: 11px; height: 11px; display: none; }
.wt-page.is-sel .wt-page-check { background: var(--wt-accent); border-color: var(--wt-accent); }
.wt-page.is-sel .wt-page-check svg { display: block; }

/* ---------- Controls panel ---------- */
.wt-field { margin-block-end: 16px; }
.wt-field:last-child { margin-block-end: 2px; }
.wt-field > label {
  display: block;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .01em;
  color: var(--text-secondary);
  margin-block-end: 8px;
}
.wt-inline-label {
  display: block;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .01em;
  color: var(--text-secondary);
  margin-block-end: 8px;
}

.wt-input, .wt-select, .wt-number {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--at-radius-md);
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  transition: border-color .2s var(--at-ease), box-shadow .2s var(--at-ease);
}
.wt-input:focus, .wt-select:focus, .wt-number:focus {
  outline: none;
  border-color: var(--wt-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--wt-accent) 20%, transparent);
}
.wt-input::placeholder { color: var(--text-tertiary); }

.wt-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.wt-row-auto { display: flex; align-items: center; gap: 10px; }

.wt-range-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}
.wt-range { width: 100%; accent-color: var(--wt-accent); cursor: pointer; }
.wt-range-val {
  min-width: 46px;
  text-align: end;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* color swatches */
.wt-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.wt-swatch {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--glass-border);
  cursor: pointer;
  padding: 0;
  transition: transform .18s var(--at-ease), border-color .18s var(--at-ease), box-shadow .18s var(--at-ease);
}
.wt-swatch:hover { transform: scale(1.12); }
.wt-swatch.active { border-color: var(--text-primary); box-shadow: 0 0 0 2px var(--wt-accent); }
.wt-swatch-custom {
  position: relative;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--glass-border);
  overflow: hidden;
  cursor: pointer;
  background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
}
.wt-swatch-custom input {
  position: absolute; inset: 0;
  opacity: 0; cursor: pointer;
}
.wt-swatch-custom { overflow: visible; }
.wt-swatch-custom .ce-cp-wrap { display: block; width: 100%; height: 100%; position: relative; }
.wt-swatch-custom .ce-cp-swatch {
  width: calc(100% - 6px) !important;
  height: calc(100% - 6px) !important;
  margin: 3px;
  border-radius: 50%;
  border: 0;
}

/* image upload tile */
.wt-img-tile {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1.6px dashed var(--glass-border-hover);
  border-radius: var(--at-radius-md);
  background: var(--glass-bg);
  cursor: pointer;
  transition: border-color .2s var(--at-ease), background .2s var(--at-ease);
}
.wt-img-tile:hover { border-color: var(--wt-accent); }
.wt-img-thumb {
  width: 64px; height: 64px;
  border-radius: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  display: grid; place-items: center;
  overflow: hidden;
  color: var(--text-tertiary);
}
.wt-img-thumb svg { width: 22px; height: 22px; }
.wt-img-thumb img { width: 100%; height: 100%; object-fit: contain; }
.wt-img-body { min-width: 0; display: grid; gap: 3px; }
.wt-img-name {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wt-img-hint { font-size: 12px; color: var(--text-tertiary); }
.wt-img-clear { width: 30px; height: 30px; display: grid; place-items: center; border: 0; background: transparent; color: var(--text-tertiary); cursor: pointer; border-radius: 8px; }
.wt-img-clear:hover { color: #dc2626; background: color-mix(in srgb, #ef4444 10%, transparent); }
.wt-img-clear svg { width: 15px; height: 15px; }

/* position 3x3 grid */
.wt-posgrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.wt-posbtn {
  aspect-ratio: 2 / 1;
  border: 1px solid var(--glass-border);
  border-radius: 9px;
  background: var(--glass-bg);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: all .18s var(--at-ease);
}
.wt-posbtn:hover { border-color: var(--wt-accent); }
.wt-posbtn.active { background: color-mix(in srgb, var(--wt-accent) 14%, var(--glass-bg)); border-color: var(--wt-accent); }
.wt-posbtn span {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--text-tertiary);
  transition: background .18s var(--at-ease);
}
.wt-posbtn.active span { background: var(--wt-accent); }

/* arrangement seg + gap */
.wt-sub-hint { font-size: 11.5px; color: var(--text-tertiary); margin-block-start: 7px; line-height: 1.55; }

/* ---------- Run / progress ---------- */
.wt-run-panel .wt-run-btn { width: 100%; }
.wt-run-actions { display: grid; gap: 9px; }
.wt-actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.wt-btn { justify-content: center; }

/* ---------- Result ---------- */
.wt-success {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border-radius: var(--at-radius-md);
  background: color-mix(in srgb, #22c55e 10%, transparent);
  border: 1px solid color-mix(in srgb, #22c55e 38%, transparent);
  margin-top: 15px;
}
.wt-success-icon {
  width: 36px; height: 36px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 50%;
  background: #22c55e;
  color: #fff;
}
.wt-success-icon svg { width: 17px; height: 17px; }
.wt-success-body { min-width: 0; display: grid; gap: 3px; }
.wt-success-title { font-size: 14.5px; font-weight: 700; color: var(--text-primary); }
.wt-success-desc { font-size: 12.5px; color: var(--text-tertiary); }
.wt-outfiles { margin-block-start: 12px; display: grid; gap: 8px; max-height: 210px; overflow: auto; }
.wt-outfile {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  background: var(--glass-bg);
}
.wt-outfile-name {
  min-width: 0;
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wt-outfile-size { font-weight: 500; color: var(--text-tertiary); font-size: 12px; }
.wt-result-actions { margin-block-start: 12px; display: grid; gap: 9px; }

/* ---------- misc ---------- */
.wt-muted { color: var(--text-tertiary); }
.wt-inline-flex { display: inline-flex; align-items: center; gap: 6px; }
.wt-caption { font-size: 11.5px; color: var(--text-tertiary); line-height: 1.6; margin-block-start: 10px; }

/* ---------- progress / run ---------- */
.wt-progress {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  background: var(--glass-bg);
}
.wt-progress.show { display: flex; }
.wt-progress-track {
  position: relative;
  flex: 1 1 auto;
  height: 8px;
  border-radius: 999px;
  background: var(--bg-secondary);
  overflow: hidden;
}
.wt-progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--wt-accent);
  transition: width .25s var(--at-ease);
}
.wt-progress-msg {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
.wt-cancel {
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--at-radius-md);
  cursor: pointer;
  transition: all .2s var(--at-ease);
}
.wt-cancel:hover:not([disabled]) { color: var(--text-primary); border-color: var(--wt-accent); }

@media (max-width: 620px) {
  .wt-row2 { grid-template-columns: 1fr; }
  .wt-actions-row { grid-template-columns: 1fr; }
}