/* img-lab — dark mode premium, mobile-first. Un único tema deliberado (no
   adaptativo): es la estética habitual de las apps de edición de fotos y aquí
   la usa un único operador, no un público variado. */

:root {
  --bg: #0b0d10;
  --surface: #14171c;
  --surface-2: #1b1f26;
  --border: #262b33;
  --text: #e8eaed;
  --text-dim: #9aa1ab;
  --text-faint: #6b7280;
  --accent: #6366f1;
  --accent-hover: #7678f5;
  --accent-text: #eef0ff;
  --danger: #f87171;
  --danger-bg: #2a1416;
  --success: #34d399;
  --warn: #fbbf24;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body { min-height: 100vh; min-height: 100dvh; }

h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 700; }

button, input { font-family: inherit; font-size: inherit; }

a { color: var(--accent); }

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ── Login ─────────────────────────────────────────────────────────────── */

.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-6);
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 1.25rem;
  margin-bottom: var(--space-5);
  text-align: center;
  color: var(--text);
}

.field { margin-bottom: var(--space-4); }

.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: var(--space-2);
}

.field input {
  width: 100%;
  min-height: 48px;
  padding: 0 var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.field input:focus { border-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: 0 var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: transform 150ms ease-out, background 150ms ease-out, opacity 150ms ease-out;
}

.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }

.btn-sm { min-height: 38px; padding: 0 var(--space-4); font-size: 0.85rem; }

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: var(--space-3);
  min-height: 1.2em;
}

/* ── Layout del panel ─────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  background: rgba(11, 13, 16, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar h1 { font-size: 1.05rem; }

.topbar .user-menu { position: relative; }

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-2));
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: var(--space-2);
  display: none;
}
.menu-panel.open { display: block; }
.menu-panel button {
  width: 100%;
  text-align: left;
  min-height: 44px;
  padding: 0 var(--space-3);
  background: none;
  border: none;
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.menu-panel button:hover { background: var(--surface-2); }

main {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-5);
  padding-bottom: var(--space-7);
}

section { margin-bottom: var(--space-6); }

section h2 {
  font-size: 0.95rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-4);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
}

/* ── Cuota de almacenamiento ──────────────────────────────────────────── */

.quota-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin: var(--space-3) 0;
}
.quota-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 250ms ease-out;
}
.quota-bar-fill.warn { background: var(--warn); }
.quota-bar-fill.danger { background: var(--danger); }
.quota-meta { font-size: 0.85rem; color: var(--text-dim); display: flex; justify-content: space-between; }

/* Anchos discretos en pasos del 5%: la CSP (style-src 'self', sin
   'unsafe-inline') bloquea tanto el atributo style="" como las asignaciones
   por CSSOM (element.style.x = ...), así que las barras de progreso cambian
   de ANCHO alternando esta clase por JS en vez de fijar un valor inline. */
.bar-w-0 { width: 0%; } .bar-w-5 { width: 5%; } .bar-w-10 { width: 10%; }
.bar-w-15 { width: 15%; } .bar-w-20 { width: 20%; } .bar-w-25 { width: 25%; }
.bar-w-30 { width: 30%; } .bar-w-35 { width: 35%; } .bar-w-40 { width: 40%; }
.bar-w-45 { width: 45%; } .bar-w-50 { width: 50%; } .bar-w-55 { width: 55%; }
.bar-w-60 { width: 60%; } .bar-w-65 { width: 65%; } .bar-w-70 { width: 70%; }
.bar-w-75 { width: 75%; } .bar-w-80 { width: 80%; } .bar-w-85 { width: 85%; }
.bar-w-90 { width: 90%; } .bar-w-95 { width: 95%; } .bar-w-100 { width: 100%; }

/* ── Zona de subida ───────────────────────────────────────────────────── */

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: var(--space-6);
  text-align: center;
  cursor: pointer;
  transition: border-color 150ms ease-out, background 150ms ease-out;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: rgba(99, 102, 241, 0.06); }
.dropzone p { color: var(--text-dim); margin: var(--space-2) 0 0; }
.dropzone .dz-hint { font-size: 0.8rem; }
.dropzone input[type="file"] { display: none; }
.dropzone .dz-icon { font-size: 2rem; }

.stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 28px;
  min-height: 28px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  cursor: pointer;
}
.thumb .thumb-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: var(--accent);
  transition: width 200ms ease-out;
}
.thumb.thumb-error { border-color: var(--danger); }

.batch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-5);
}
.batch-actions .btn { flex: 1 1 auto; }

.batch-status {
  display: flex;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: var(--space-3);
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Historial ────────────────────────────────────────────────────────── */

.run-card { margin-bottom: var(--space-4); }
.run-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.run-card-head .run-title { font-weight: 600; }
.run-card-head .run-meta { color: var(--text-dim); font-size: 0.85rem; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: var(--space-2);
}
.gallery-grid a {
  display: block;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}
.gallery-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }

.empty-state {
  text-align: center;
  color: var(--text-faint);
  padding: var(--space-6) var(--space-4);
}

/* ── Toasts ───────────────────────────────────────────────────────────── */

.toasts {
  position: fixed;
  left: 50%;
  bottom: var(--space-5);
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(92vw, 420px);
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  animation: toast-in 200ms ease-out;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Modal (cambiar contraseña) ───────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 40;
}
.modal {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow);
}
.modal h2 { font-size: 1.05rem; margin-bottom: var(--space-4); text-transform: none; letter-spacing: normal; color: var(--text); }
.modal-actions { display: flex; gap: var(--space-3); margin-top: var(--space-4); }
.modal-actions .btn { flex: 1; }

@media (min-width: 640px) {
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
