/* ============================================================
   PixelPeel — hoja de estilos
   Paleta: grafito de editor + verde chroma (conservar) /
   magenta (borrar). El color codifica significado, no decora.
   ============================================================ */

:root {
  --bg-0: #141519;
  --bg-1: #1b1d23;
  --bg-2: #23252d;
  --bg-3: #2c2f39;
  --line: #33363f;
  --line-soft: #292c34;
  --text: #eceef2;
  --text-dim: #9aa1ae;
  --text-faint: #6a7180;

  --keep: #5fe07c;            /* verde chroma: lo que se conserva */
  --keep-soft: rgba(95, 224, 124, 0.14);
  --cut: #c77dff;             /* magenta: lo que se elimina */
  --cut-soft: rgba(199, 125, 255, 0.14);
  --danger: #ff6b6b;
  --warn: #ffcf5c;

  --radius: 10px;
  --radius-sm: 7px;
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Instrument Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

/* El atributo hidden debe ganar siempre, incluso sobre reglas
   de clase con display: flex/grid (si no, los overlays de estado
   quedan visibles permanentemente). */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-display); }
.mono { font-family: var(--font-mono); font-size: 12px; }
kbd {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--bg-3); border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px;
}

:focus-visible { outline: 2px solid var(--keep); outline-offset: 2px; }

/* ================= Barra superior ================= */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 16px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line-soft);
  flex: none;
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 30px; height: 30px; }
.mk-a { fill: var(--keep); }
.mk-b { fill: var(--bg-3); }
.mk-peel { fill: none; stroke: var(--keep); stroke-width: 2; opacity: .8; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-tag { font-size: 11.5px; color: var(--text-dim); }

.topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 11px; border-radius: 999px;
  background: var(--bg-2); border: 1px solid var(--line-soft);
  font-size: 12px; color: var(--text-dim); white-space: nowrap;
}
.chip svg { width: 14px; height: 14px; color: var(--keep); flex: none; }

.chip-model { max-width: 340px; overflow: hidden; }
.model-dot {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--warn);
}
.chip-model[data-state="loading"] .model-dot { animation: pulse 1.2s ease-in-out infinite; }
.chip-model[data-state="ready"]   .model-dot { background: var(--keep); }
.chip-model[data-state="error"]   .model-dot { background: var(--danger); }
.model-label { overflow: hidden; text-overflow: ellipsis; }
.model-bar {
  width: 90px; height: 4px; border-radius: 3px; overflow: hidden;
  background: var(--bg-3); flex: none;
}
.chip-model[data-state="ready"] .model-bar,
.chip-model[data-state="error"] .model-bar { display: none; }
.model-bar-fill {
  display: block; height: 100%; width: 0%;
  background: var(--keep); transition: width .25s ease;
}

@keyframes pulse { 50% { opacity: .35; } }

/* ================= Distribución principal ================= */

.layout {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 296px;
}

/* ================= Rail de cola ================= */

.rail {
  background: var(--bg-1);
  border-right: 1px solid var(--line-soft);
  display: flex; flex-direction: column; min-height: 0;
}
.rail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 8px;
}
.rail-head h2 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; color: var(--text-dim); }

.queue { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }

.qitem {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: var(--radius-sm);
  cursor: pointer; border: 1px solid transparent;
}
.qitem:hover { background: var(--bg-2); }
.qitem.is-active { background: var(--bg-2); border-color: var(--line); }
.qthumb {
  width: 44px; height: 44px; border-radius: 6px; object-fit: cover;
  background: var(--bg-3); flex: none;
  /* damero pequeño para thumbs con alpha */
  background-image: conic-gradient(var(--bg-3) 25%, var(--bg-2) 0 50%, var(--bg-3) 0 75%, var(--bg-2) 0);
  background-size: 12px 12px;
}
.qmeta { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 1px; }
.qname { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qstate { font-size: 11px; color: var(--text-faint); display: flex; align-items: center; gap: 5px; }
.qstate::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-faint);
}
.qitem[data-status="processing"] .qstate::before { background: var(--warn); animation: pulse 1s infinite; }
.qitem[data-status="done"] .qstate::before { background: var(--keep); }
.qitem[data-status="error"] .qstate::before { background: var(--danger); }
.qremove {
  flex: none; width: 22px; height: 22px; border-radius: 6px;
  border: none; background: transparent; color: var(--text-faint);
  cursor: pointer; font-size: 15px; line-height: 1;
  opacity: 0; transition: opacity .12s;
}
.qitem:hover .qremove { opacity: 1; }
.qremove:hover { background: var(--bg-3); color: var(--danger); }

.rail-empty { padding: 18px 16px; color: var(--text-faint); font-size: 12.5px; }
.rail-empty em { color: var(--text-dim); font-style: normal; }
.rail-foot { padding: 10px; border-top: 1px solid var(--line-soft); }

/* ================= Botones ================= */

.btn {
  background: var(--bg-3); border: 1px solid var(--line);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 8px 14px; cursor: pointer; font-size: 13px; font-weight: 500;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover:not(:disabled) { background: #343846; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-small { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-primary {
  background: var(--keep); border-color: var(--keep);
  color: #0c2513; font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: #74e88e; }
.btn-col { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.linklike {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--keep); text-decoration: underline; text-underline-offset: 3px;
}

/* ================= Escenario ================= */

.stage-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.toolbar {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 12px; background: var(--bg-1);
  border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.tool-group { display: flex; align-items: center; gap: 4px; }
.tool-group-right { margin-left: auto; }

.tool {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 6px 9px;
  color: var(--text-dim); cursor: pointer; font-size: 12.5px;
  transition: background .12s, color .12s;
}
.tool svg { width: 16px; height: 16px; }
.tool:hover:not(:disabled) { background: var(--bg-2); color: var(--text); }
.tool:disabled { opacity: .4; cursor: default; }
.tool.is-active { background: var(--bg-3); color: var(--text); border-color: var(--line); }
.tool-keep.is-active { color: var(--keep); border-color: var(--keep); background: var(--keep-soft); }
.tool-cut.is-active  { color: var(--cut);  border-color: var(--cut);  background: var(--cut-soft); }

.brush-group { gap: 8px; color: var(--text-dim); font-size: 12px; }
.brush-group input[type="range"] { width: 110px; }

.stage {
  position: relative; flex: 1; min-height: 0; overflow: hidden;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(95, 224, 124, 0.04), transparent 60%),
    var(--bg-0);
  touch-action: none;
  cursor: default;
}
.stage.is-pan { cursor: grab; }
.stage.is-panning { cursor: grabbing; }
.stage.is-brush { cursor: none; }

.stage-transform {
  position: absolute; top: 0; left: 0;
  transform-origin: 0 0;
}
.canvas-stack { position: relative; width: 100%; height: 100%; }
.canvas-stack.checker {
  background-image: conic-gradient(#262931 25%, #1e2027 0 50%, #262931 0 75%, #1e2027 0);
  background-size: 32px 32px;
}
.canvas-stack .layer {
  position: absolute; top: 0; left: 0; display: block;
  width: 100%; height: 100%;
}
.canvas-stack .layer-original { z-index: 2; display: none; }
.canvas-stack .layer-original.is-visible { display: block; }
.layer-overlay { z-index: 3; pointer-events: none; }

.compare-divider {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--text); opacity: .9; z-index: 5;
  cursor: ew-resize; touch-action: none;
}
.compare-divider::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: -7px; right: -7px;
}
.divider-grip {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--text); color: var(--bg-0);
  border-radius: 999px; padding: 3px 8px; font-size: 12px;
  user-select: none;
}

.brush-cursor {
  position: absolute; z-index: 6; pointer-events: none;
  border: 1.5px solid var(--keep); border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 1px rgba(0,0,0,.6);
}
.brush-cursor.is-cut { border-color: var(--cut); }

/* Estado vacío */
.empty-state {
  position: absolute; inset: 24px;
  border: 1.5px dashed var(--line);
  border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 6px; padding: 24px;
  color: var(--text-dim);
}
.empty-state h1 { margin: 14px 0 0; font-size: 24px; color: var(--text); font-weight: 600; }
.empty-state p { margin: 4px 0; }
.empty-state .hint { font-size: 12px; color: var(--text-faint); }
.peel-illo { width: 168px; height: auto; }

.stage.is-dragover .empty-state,
.stage.is-dragover { border-color: var(--keep); }
.drop-hint {
  position: absolute; inset: 12px; z-index: 10;
  border: 2px dashed var(--keep); border-radius: 16px;
  background: rgba(95, 224, 124, 0.07);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 20px; color: var(--keep);
  pointer-events: none;
}

.stage-status {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; z-index: 8;
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 16px;
  box-shadow: var(--shadow-pop); font-size: 13px;
}
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--bg-3); border-top-color: var(--keep);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stage-foot {
  display: flex; align-items: center; gap: 16px;
  padding: 6px 12px; background: var(--bg-1);
  border-top: 1px solid var(--line-soft);
  color: var(--text-dim); min-height: 36px;
}
#editHint { color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zoom-controls { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.zoom-label { min-width: 44px; text-align: center; color: var(--text-dim); }

/* ================= Inspector ================= */

.inspector {
  background: var(--bg-1);
  border-left: 1px solid var(--line-soft);
  overflow-y: auto; padding: 6px 0 12px;
  display: flex; flex-direction: column;
}
.panel { padding: 14px 16px 15px; border-bottom: 1px solid var(--line-soft); }
.panel h3 {
  margin: 0 0 10px; font-size: 12px; font-weight: 600;
  letter-spacing: .5px; text-transform: uppercase; color: var(--text-dim);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h3 { margin-bottom: 0; }
.panel-head + .control-col { margin-top: 12px; }
.panel-note { margin: 8px 0 10px; font-size: 12px; color: var(--text-faint); }
.k-keep { color: var(--keep); font-weight: 600; }
.k-cut { color: var(--cut); font-weight: 600; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.pick {
  background: var(--bg-2); border: 1px solid var(--line-soft);
  color: var(--text-dim); border-radius: 999px;
  padding: 5px 11px; font-size: 12px; cursor: pointer;
  transition: all .12s;
}
.pick:hover { color: var(--text); }
.pick.is-active { background: var(--keep-soft); border-color: var(--keep); color: var(--keep); }

.control-row {
  display: flex; align-items: center; gap: 10px; margin-top: 11px;
}
.control-row label { font-size: 12.5px; color: var(--text-dim); min-width: 68px; }
.control-row input[type="range"] { flex: 1; min-width: 0; }
.control-row output { min-width: 38px; text-align: right; color: var(--text-dim); }
.control-col { display: flex; flex-direction: column; }
.color-pair { display: flex; gap: 8px; }
.filelabel { font-size: 12px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

input[type="color"] {
  width: 34px; height: 26px; padding: 0; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg-3); cursor: pointer;
}
input[type="range"] {
  appearance: none; -webkit-appearance: none;
  height: 4px; border-radius: 3px; background: var(--bg-3);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text); border: none;
  transition: background .12s;
}
input[type="range"]:hover::-webkit-slider-thumb { background: var(--keep); }
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text); border: none;
}
input[type="range"]:disabled { opacity: .4; cursor: default; }

/* Interruptor */
.switch { position: relative; display: inline-block; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch-track {
  display: block; width: 34px; height: 19px; border-radius: 999px;
  background: var(--bg-3); border: 1px solid var(--line);
  transition: background .15s;
}
.switch-track::after {
  content: ''; position: absolute; top: 3.5px; left: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text-dim); transition: transform .15s, background .15s;
}
.switch input:checked + .switch-track { background: var(--keep-soft); border-color: var(--keep); }
.switch input:checked + .switch-track::after { transform: translateX(14px); background: var(--keep); }

.legal {
  margin: auto 16px 4px; padding-top: 12px;
  font-size: 11px; color: var(--text-faint);
}

/* ================= Toasts ================= */

.toasts {
  position: fixed; bottom: 18px; right: 18px; z-index: 50;
  display: flex; flex-direction: column; gap: 8px; max-width: 340px;
}
.toast {
  background: var(--bg-2); border: 1px solid var(--line);
  border-left: 3px solid var(--keep);
  border-radius: var(--radius-sm); padding: 10px 14px;
  font-size: 13px; box-shadow: var(--shadow-pop);
  animation: toast-in .18s ease;
}
.toast[data-kind="error"] { border-left-color: var(--danger); }
.toast[data-kind="warn"]  { border-left-color: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ================= Responsive ================= */

@media (max-width: 1060px) {
  .layout { grid-template-columns: 210px minmax(0, 1fr) 260px; }
  .chip-privacy { display: none; }
  .tool span { display: none; }
}

@media (max-width: 820px) {
  body { overflow: auto; }
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(60vh, 1fr) auto;
  }
  .rail { order: 2; border-right: none; border-top: 1px solid var(--line-soft); max-height: 34vh; }
  .stage-wrap { order: 1; min-height: 60vh; }
  .inspector { order: 3; border-left: none; border-top: 1px solid var(--line-soft); }
  .brand-tag { display: none; }
  .model-bar { width: 54px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
