/* ============================================
   Pixia - Blur & Pixelate studio (blur.html)
   Complements css/ai-tool.css (.at-* primitives)
   Scope: body.at-blur
   ============================================ */

body.at-blur {
  --lb-accent: var(--accent-primary);
  --lb-danger: #dc2626;
}

body.at-blur [hidden] { display: none !important; }

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

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

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

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

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

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

.lb-panel h2 .lb-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;
}

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

.lb-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);
}
.lb-drop:hover { border-color: var(--lb-accent); }
.lb-drop.drag {
  border-color: var(--lb-accent);
  background: color-mix(in srgb, var(--lb-accent) 10%, var(--glass-bg));
  transform: scale(1.006);
}
.lb-drop input { display: none; }
.lb-drop-icon {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: 16px;
  background: color-mix(in srgb, var(--lb-accent) 16%, transparent);
  color: var(--lb-accent);
  margin-block-end: 2px;
}
.lb-drop-icon svg { width: 26px; height: 26px; }
.lb-drop-title { font-family: var(--font-display); font-size: 1.02rem; font-weight: 600; color: var(--text-primary); }
.lb-drop-sub { font-size: 13px; color: var(--text-tertiary); }
.lb-drop-meta { display: flex; gap: 8px; margin-block-start: 4px; }
.lb-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;
}

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

.lb-source-actions { display: flex; align-items: center; gap: 8px; }
.lb-mini-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  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: 6px 11px;
  cursor: pointer;
  transition: all .2s var(--at-ease);
}
.lb-mini-btn svg { width: 14px; height: 14px; }
.lb-mini-btn:hover:not(:disabled) { color: var(--text-primary); border-color: var(--lb-accent); }
.lb-mini-btn:disabled { opacity: .5; cursor: not-allowed; }

.lb-face-btn {
  color: var(--lb-accent);
  border-color: color-mix(in srgb, var(--lb-accent) 38%, var(--glass-border));
}
.lb-face-btn:hover:not(:disabled) {
  color: var(--lb-accent);
  border-color: var(--lb-accent);
  background: color-mix(in srgb, var(--lb-accent) 10%, var(--glass-bg));
}
.lb-face-btn.is-busy svg { animation: lb-face-pulse 1s ease-in-out infinite; }
@keyframes lb-face-pulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

.lb-file-list {
  display: grid;
  gap: 8px;
  max-height: 268px;
  overflow-y: auto;
  padding-inline-end: 2px;
  scrollbar-width: thin;
}

.lb-file-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  background: var(--glass-bg);
  cursor: pointer;
  transition: border-color .2s var(--at-ease), background .2s var(--at-ease);
}
.lb-file-row:hover { border-color: color-mix(in srgb, var(--lb-accent) 45%, var(--glass-border)); }
.lb-file-row.is-sel { border-color: var(--lb-accent); background: color-mix(in srgb, var(--lb-accent) 7%, var(--glass-bg)); }
.lb-file-thumb {
  width: 40px; height: 40px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  background: var(--bg-secondary);
  display: grid; place-items: center;
  color: var(--text-tertiary);
  flex: 0 0 auto;
}
.lb-file-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lb-file-info { min-width: 0; display: grid; gap: 3px; }
.lb-file-name {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lb-file-meta {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--text-tertiary);
}
.lb-file-meta > span:first-child { direction: ltr; unicode-bidi: isolate; }
.lb-file-status { font-size: 10.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.lb-file-status.is-error { color: #dc2626; background: color-mix(in srgb, #ef4444 14%, transparent); }
.lb-file-status.is-ready { color: #16a34a; background: color-mix(in srgb, #22c55e 16%, transparent); }
.lb-file-status.is-reading { color: var(--text-tertiary); background: var(--bg-secondary); }
.lb-file-actions { display: flex; align-items: center; gap: 6px; }

.lb-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);
}
.lb-icon-btn:hover { color: var(--text-primary); border-color: var(--lb-accent); }
.lb-icon-btn.is-danger:hover { color: var(--lb-danger); border-color: color-mix(in srgb, #ef4444 45%, var(--glass-border)); background: color-mix(in srgb, #ef4444 8%, transparent); }
.lb-icon-btn svg { width: 16px; height: 16px; }

/* ---------- Viewer ---------- */
.lb-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-block: 12px 10px;
}
.lb-imgnav { display: flex; align-items: center; gap: 8px; }
.lb-imgnav 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);
}
.lb-imgnav button:hover:not(:disabled) { border-color: var(--lb-accent); color: var(--lb-accent); }
.lb-imgnav button:disabled { opacity: .4; cursor: not-allowed; }
.lb-imgnav button svg { width: 16px; height: 16px; }
.lb-image-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  min-width: 64px;
  text-align: center;
  direction: ltr;
  unicode-bidi: isolate;
}
.lb-toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.lb-hint {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 10px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-tertiary);
}
.lb-hint svg { width: 15px; height: 15px; flex: 0 0 auto; color: var(--lb-accent); }

.lb-stage {
  position: relative;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-lg);
  background:
    repeating-conic-gradient(from 0deg, color-mix(in srgb, var(--text-tertiary) 6%, transparent) 0% 25%, transparent 0% 50%)
    0 0 / 18px 18px,
    var(--bg-secondary);
  display: grid;
  place-items: center;
  padding: 16px;
  min-height: 260px;
  overflow: hidden;
  user-select: none;
}

.lb-image-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
  max-width: 100%;
  box-shadow: 0 14px 40px -18px rgba(0, 0, 0, .55);
  border-radius: 3px;
}
.lb-image-wrap canvas {
  display: block;
  max-width: 100%;
  max-height: 64vh;
  width: auto;
  height: auto;
  border-radius: 3px;
}

.lb-layer {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  touch-action: none;
  overflow: visible;
  border-radius: 3px;
}

/* The effect itself is drawn into the canvas, so markers only outline it. */
.lb-rect {
  position: absolute;
  border: 1.6px dashed rgba(255, 255, 255, .92);
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .4), 0 0 0 1px rgba(0, 0, 0, .28);
  box-sizing: border-box;
  cursor: grab;
  touch-action: none;
}
.lb-rect.is-moving {
  cursor: grabbing;
  border-style: solid;
  border-color: var(--lb-accent);
}
.lb-rect.is-resizing {
  border-style: solid;
  border-color: var(--lb-accent);
}
.lb-rect.is-draft {
  border-style: solid;
  border-color: var(--lb-accent);
  background: color-mix(in srgb, var(--lb-accent) 22%, transparent);
  box-shadow: none;
  pointer-events: none;
}

/* Eight grab points on the outline: resize without covering the photo. */
.lb-handle {
  position: absolute;
  width: 20px; height: 20px;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  touch-action: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s var(--at-ease);
}
.lb-handle::after {
  content: "";
  width: 9px; height: 9px;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, .55), 0 1px 3px rgba(0, 0, 0, .35);
}
.lb-handle[data-handle="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.lb-handle[data-handle="n"] { left: 50%; top: 0; cursor: ns-resize; }
.lb-handle[data-handle="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.lb-handle[data-handle="e"] { left: 100%; top: 50%; cursor: ew-resize; }
.lb-handle[data-handle="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.lb-handle[data-handle="s"] { left: 50%; top: 100%; cursor: ns-resize; }
.lb-handle[data-handle="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.lb-handle[data-handle="w"] { left: 0; top: 50%; cursor: ew-resize; }

.lb-rect:hover .lb-handle,
.lb-rect:focus-within .lb-handle,
.lb-rect.is-moving .lb-handle,
.lb-rect.is-resizing .lb-handle,
.lb-rect.is-active .lb-handle { opacity: 1; pointer-events: auto; }

.lb-rect-del {
  position: absolute;
  inset-block-start: 10px;
  inset-inline-end: 10px;
  width: 20px; height: 20px;
  display: grid; place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--lb-danger);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s var(--at-ease), transform .15s var(--at-ease);
  transform: scale(.85);
}
.lb-rect-del svg { width: 11px; height: 11px; }
.lb-rect:hover .lb-rect-del,
.lb-rect:focus-within .lb-rect-del,
.lb-rect.is-active .lb-rect-del { opacity: 1; transform: scale(1); pointer-events: auto; }
@media (hover: none) {
  .lb-handle { opacity: 1; pointer-events: auto; }
  .lb-rect-del { opacity: 1; transform: scale(1); pointer-events: auto; }
}

.lb-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;
  border-radius: var(--at-radius-lg);
}
.lb-spinner {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid var(--glass-border);
  border-block-start-color: var(--lb-accent);
  animation: lb-spin .8s linear infinite;
}
@keyframes lb-spin { to { transform: rotate(360deg); } }

/* ---------- Thumbnail strip ---------- */
.lb-strip {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  overflow-x: auto;
  padding: 12px 2px 4px;
  scroll-snap-type: x proximity;
}
.lb-thumb {
  position: relative;
  flex: 0 0 auto;
  width: 76px;
  height: 76px;
  scroll-snap-align: start;
  border: 2px solid var(--glass-border);
  border-radius: 9px;
  background: var(--bg-secondary);
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  outline: none;
  transition: border-color .2s var(--at-ease), transform .2s var(--at-ease), box-shadow .2s var(--at-ease);
}
.lb-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.lb-thumb:hover { transform: translateY(-2px); }
.lb-thumb.is-sel {
  border-color: var(--lb-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--lb-accent) 32%, transparent);
}
.lb-thumb:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--lb-accent) 55%, transparent); }
.lb-thumb-count {
  position: absolute;
  inset-block-end: 3px;
  inset-inline-end: 3px;
  min-width: 17px;
  height: 17px;
  display: none;
  place-items: center;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: var(--lb-danger);
  border-radius: 5px;
}
.lb-thumb.has-marks .lb-thumb-count { display: grid; }

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

.lb-seg {
  display: inline-flex;
  gap: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  padding: 3px;
}
.lb-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);
}
.lb-seg button:hover { color: var(--text-primary); }
.lb-seg button.active { background: var(--lb-accent); color: #1b1408; }

.lb-seg-3 { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; margin-block-start: 10px; }
.lb-seg-3 button { text-align: center; }

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

.lb-reset-btn { width: 100%; margin-block-start: 16px; }

/* ---------- Warning ---------- */
.lb-warning {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 14px;
  border-radius: var(--at-radius-md);
  border: 1px solid color-mix(in srgb, #22c55e 34%, transparent);
  background: color-mix(in srgb, #22c55e 8%, transparent);
  margin-block-end: 14px;
}
.lb-warning-icon {
  width: 30px; height: 30px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, #22c55e 16%, transparent);
  color: #16a34a;
}
.lb-warning-icon svg { width: 16px; height: 16px; }
.lb-warning-body { min-width: 0; display: grid; gap: 3px; }
.lb-warning-title { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.lb-warning-desc { font-size: 11.5px; line-height: 1.5; color: var(--text-tertiary); }

/* ---------- Run / progress ---------- */
.lb-run-panel .lb-run-btn { width: 100%; }
.lb-run-actions { display: grid; gap: 9px; }

.lb-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);
}
.lb-progress.show { display: flex; }
.lb-progress-track {
  position: relative;
  flex: 1 1 auto;
  height: 8px;
  border-radius: 999px;
  background: var(--bg-secondary);
  overflow: hidden;
}
.lb-progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--lb-accent);
  transition: width .25s var(--at-ease);
}
.lb-progress-msg {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
.lb-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);
}
.lb-cancel:hover:not([disabled]) { color: var(--text-primary); border-color: var(--lb-accent); }

.lb-caption { font-size: 11.5px; color: var(--text-tertiary); line-height: 1.6; margin-block-start: 10px; }

/* ---------- Results ---------- */
.lb-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 16px;
  border-radius: var(--at-radius-lg);
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  margin-block-end: 12px;
}
.lb-summary-main { display: flex; align-items: baseline; gap: 8px; }
.lb-summary-num {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.lb-summary-label { font-size: 13px; font-weight: 600; color: var(--text-tertiary); }
.lb-summary-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }

.lb-result-list { display: grid; gap: 8px; }
.lb-result-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  background: var(--glass-bg);
}
.lb-result-info { min-width: 0; display: grid; gap: 5px; }
.lb-result-name {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lb-result-meta { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-tertiary); flex-wrap: wrap; }
.lb-result-meta > span { direction: ltr; unicode-bidi: isolate; }
.lb-badge { font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.lb-badge-info { color: var(--lb-accent); background: color-mix(in srgb, var(--lb-accent) 14%, transparent); }
.lb-badge-danger { color: var(--lb-danger); background: color-mix(in srgb, #ef4444 12%, transparent); }
.lb-badge-muted { color: var(--text-tertiary); background: var(--bg-secondary); }
.lb-icon-btn-dl { text-decoration: none; color: var(--lb-accent); }
.lb-icon-btn-dl:hover { color: var(--lb-accent); border-color: var(--lb-accent); background: color-mix(in srgb, var(--lb-accent) 10%, transparent); }
.lb-result-actions { margin-block-start: 14px; display: grid; gap: 9px; }

@media (max-width: 620px) {
  .lb-toolbar { gap: 8px; }
  .lb-image-wrap canvas { max-height: 56vh; }
  .lb-file-list { max-height: 220px; }
  .lb-result-item { grid-template-columns: minmax(0, 1fr) auto; }
}

/* ---------- RTL ---------- */
/* Numeric values keep Latin order inside RTL layouts. */
.lb-range-val,
.lb-image-label,
.lb-summary-num,
.lb-result-meta > span {
  direction: ltr;
  unicode-bidi: isolate;
}
