/* ============================================================================
   Vida Saludable · procesado de fotos — UI
   Paleta sobria con verde de marca como acento. Sin frameworks.
   ============================================================================ */

:root {
  --green: #1f9d5b;
  --green-d: #178049;
  --green-l: #e7f6ee;
  --amber: #d98a1a;
  --amber-l: #fdf3e2;
  --red: #d6453f;
  --red-l: #fceaea;
  --blue: #2563eb;

  --ink: #161b22;
  --ink-2: #46505b;
  --muted: #8a94a0;
  --line: #e6e9ee;
  --line-2: #eef1f5;
  --bg: #f6f8fa;
  --card: #ffffff;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
  --shadow: 0 4px 12px rgba(16,24,40,.08), 0 2px 4px rgba(16,24,40,.04);
  --shadow-lg: 0 24px 60px rgba(16,24,40,.22);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

/* ---- Header ---------------------------------------------------------------*/
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px;
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--green), var(--green-d));
  color: #fff; font-weight: 700; font-size: 15px; letter-spacing: .02em;
  box-shadow: var(--shadow-sm);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; font-weight: 650; }
.brand-text span { font-size: 12.5px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.lote-label {
  font-size: 12px; color: var(--ink-2); background: var(--line-2);
  padding: 5px 10px; border-radius: 999px; font-family: ui-monospace, Menlo, monospace;
}

/* Usuario + cupo en el header */
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.user-chip .uname { font-weight: 600; color: var(--ink); }
.cupo-chip {
  font-size: 12.5px; font-weight: 600; padding: 5px 11px; border-radius: 999px;
  background: var(--green-l); color: var(--green-d); white-space: nowrap;
}
.cupo-chip.bajo { background: var(--amber-l); color: var(--amber); }
.cupo-chip.agotado { background: #fdeaea; color: var(--red); }

/* ---- Login ----------------------------------------------------------------*/
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-wrap { width: min(400px, 100%); }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 30px 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.login-card h1 { margin: 4px 0 6px; font-size: 20px; font-weight: 650; }
.campo { display: flex; flex-direction: column; gap: 6px; }
.campo span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.campo input {
  padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 15px; font-family: var(--font); background: #fcfdfe; transition: border-color .14s, box-shadow .14s;
}
.campo input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-l); }
.login-btn { justify-content: center; margin-top: 6px; min-height: 44px; }
.login-error {
  margin: 4px 0 0; padding: 10px 13px; border-radius: var(--radius-sm);
  background: #fdeaea; border: 1px solid #f0c5c3; color: var(--red);
  font-size: 13.5px; font-weight: 550;
}

/* ---- Panel de administracion ---------------------------------------------*/
.admin-card {
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--blue);
  border-radius: var(--radius); padding: 20px 22px; margin-bottom: 22px; box-shadow: var(--shadow-sm);
}
.admin-head h3 { margin: 0; font-size: 16px; font-weight: 650; }
.admin-body { margin-top: 14px; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; }
.admin-stats { display: flex; gap: 12px; }
.admin-stat { border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 16px; background: #fbfcfd; min-width: 130px; }
.admin-stat b { display: block; font-size: 22px; font-weight: 700; line-height: 1; color: var(--ink); }
.admin-stat span { font-size: 12px; color: var(--muted); }
.admin-form { display: flex; align-items: flex-end; gap: 10px; }
.admin-form .campo { gap: 5px; }
.admin-form input { width: 130px; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: 15px; font-family: var(--font); background: #fcfdfe; }
.admin-form input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-l); }
.admin-msg { width: 100%; margin: 4px 0 0; font-size: 13.5px; font-weight: 550; }
.admin-msg.ok { color: var(--green-d); }
.admin-msg.err { color: var(--red); }

/* ---- Stepper --------------------------------------------------------------*/
.stepper { max-width: 1180px; margin: 22px auto 0; padding: 0 28px; }
.stepper ol {
  list-style: none; margin: 0; padding: 0; display: flex; gap: 8px;
}
.stepper li {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 550; color: var(--muted);
  padding: 6px 14px 6px 6px; border-radius: 999px;
}
.stepper li .dot {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--line); color: var(--ink-2); font-size: 12px; font-weight: 700;
}
.stepper li.active { color: var(--green-d); background: var(--green-l); }
.stepper li.active .dot { background: var(--green); color: #fff; }
.stepper li.done .dot { background: var(--green-d); color: #fff; }

/* ---- Layout ---------------------------------------------------------------*/
main { max-width: 1180px; margin: 0 auto; padding: 22px 28px 80px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 30px; box-shadow: var(--shadow-sm);
}
.card h2 { margin: 0 0 4px; font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.sub { margin: 0 0 22px; color: var(--ink-2); font-size: 14px; }
.mono { font-family: ui-monospace, Menlo, monospace; }

/* ---- Botones --------------------------------------------------------------*/
.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 16px; border-radius: var(--radius-sm); font-size: 14px;
  font-weight: 600; font-family: var(--font);
  transition: background .14s, border-color .14s, box-shadow .14s, transform .05s;
}
.btn:hover:not(:disabled) { background: #f8fafc; border-color: #d8dde4; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--green-d); border-color: var(--green-d); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--line-2); }
.btn-danger { background: #fff; border-color: #f0c5c3; color: var(--red); }
.btn-danger:hover:not(:disabled) { background: #fdecec; border-color: var(--red); }
.btn .ico { width: 16px; height: 16px; }
.btn-sm { padding: 6px 11px; font-size: 13px; }

.icon-btn {
  border: none; background: transparent; cursor: pointer; color: var(--muted);
  width: 32px; height: 32px; border-radius: 8px; font-size: 16px;
}
.icon-btn:hover { background: var(--line-2); color: var(--ink); }

.actions-row { display: flex; gap: 12px; margin-top: 24px; }
.spacer { flex: 1; }

/* ---- Dropzone -------------------------------------------------------------*/
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 2px dashed #cfd6df; border-radius: var(--radius); padding: 46px 24px;
  text-align: center; cursor: pointer; transition: border-color .15s, background .15s;
  background: #fcfdfe;
}
.dropzone:hover { border-color: var(--green); background: var(--green-l); }
.dropzone.drag { border-color: var(--green); background: var(--green-l); }
.dz-ico { width: 42px; height: 42px; color: var(--green); margin-bottom: 6px; }
.dz-title { margin: 6px 0 2px; font-weight: 600; font-size: 16px; }
.dz-sub { margin: 0; color: var(--ink-2); font-size: 14px; }
.dz-sub .link { color: var(--green-d); text-decoration: underline; font-weight: 550; }
.dz-count { margin: 12px 0 0; font-size: 13px; color: var(--green-d); font-weight: 600; min-height: 18px; }

/* ---- Límite por bloque + aviso de validación ------------------------------*/
.limite-banner {
  display: flex; align-items: center; gap: 9px;
  margin: 0 0 18px; padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--green-l); border: 1px solid #cdecd9; color: var(--green-d);
  font-size: 13.5px; font-weight: 550; line-height: 1.4;
}
.limite-banner .ico { width: 18px; height: 18px; flex: 0 0 auto; }
.sel-warning {
  display: flex; align-items: flex-start; gap: 8px;
  margin: 14px 0 0; padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--amber-l); border: 1px solid #f1e0bf; color: #9a6712;
  font-size: 13.5px; font-weight: 550; line-height: 1.45;
}

/* ---- Barras de progreso ---------------------------------------------------*/
.progress-box { margin-top: 22px; padding: 18px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: #fbfcfd; }
.progress-box.big { padding: 22px; }
.progress-head { display: flex; justify-content: space-between; align-items: baseline;
  font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.progress-head .mono { color: var(--ink-2); font-weight: 600; }
.progress { height: 12px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-bar {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--green), #34c47a);
  transition: width .35s ease;
}
.progress-file { margin: 10px 0 0; font-size: 12.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-last { margin: 4px 0 0; font-size: 13px; color: var(--ink-2); }
.progress-last .tag { font-weight: 650; }

.mini-stats { display: flex; gap: 12px; margin-top: 20px; }
.mini-stat { flex: 1; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px 16px; background: #fff; }
.mini-stat b { display: block; font-size: 24px; font-weight: 700; line-height: 1; }
.mini-stat span { font-size: 12.5px; color: var(--muted); }
.mini-stat.ok b { color: var(--green); }
.mini-stat.rev b { color: var(--amber); }
.mini-stat.err b { color: var(--red); }

/* ---- Galería en grupos ----------------------------------------------------*/
.grupo { margin-bottom: 30px; }
.grupo-head { margin-bottom: 14px; }
.grupo-head h3 { display: flex; align-items: center; gap: 10px;
  margin: 0; font-size: 17px; font-weight: 650; }
.grupo-sub { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.dot-ok, .dot-warn { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-ok { background: var(--green); }
.dot-warn { background: var(--amber); }

.pill { font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px; }
.pill-ok { background: var(--green-l); color: var(--green-d); }
.pill-warn { background: var(--amber-l); color: var(--amber); }

.grupo-revisar {
  border: 1px solid #f1e3c8; border-left: 4px solid var(--amber);
  background: #fffdf8; border-radius: var(--radius); padding: 20px 22px;
}
.grupo-ok {
  border: 1px solid var(--line); border-left: 4px solid var(--green);
  background: #fff; border-radius: var(--radius); padding: 20px 22px;
}

.galeria { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 16px; }

.tarjeta {
  position: relative; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--shadow-sm);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.tarjeta:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.tarjeta.is-revisar { border-color: #eed9b0; }
.tarjeta .thumb {
  width: 100%; aspect-ratio: 1/1; object-fit: contain; display: block;
  background: repeating-conic-gradient(#f2f4f7 0% 25%, #fbfcfd 0% 50%) 50% / 18px 18px;
  cursor: pointer;
}
.tarjeta .meta { display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 9px 11px; border-top: 1px solid var(--line-2); }
.tarjeta .name { font-size: 11.5px; font-family: ui-monospace, Menlo, monospace;
  color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* badges de estado */
.badge { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 3px 8px; border-radius: 999px; color: #fff; background: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--green); }
.badge.corregida { background: var(--blue); }
.badge.revisar { background: var(--amber); }
.badge.rechazada { background: #9aa3ad; }
.badge.error { background: var(--red); }
.badge.pendiente { background: #9aa3ad; }
.badge.sin_cupo { background: #b06a12; }

/* acciones al hover sobre la tarjeta de revisión */
.card-actions {
  position: absolute; inset: 0 0 auto 0; display: flex; gap: 8px; justify-content: center;
  padding: 10px; opacity: 0; transition: opacity .14s;
  background: linear-gradient(180deg, rgba(16,24,40,.55), rgba(16,24,40,0));
}
.tarjeta:hover .card-actions { opacity: 1; }
.card-actions .btn { backdrop-filter: blur(2px); }

.vacio { text-align: center; color: var(--muted); font-size: 14px; padding: 26px 0; margin: 0; }

/* ---- Modal editor ---------------------------------------------------------*/
.modal { position: fixed; inset: 0; z-index: 60; display: flex;
  align-items: center; justify-content: center; padding: 24px;
  background: rgba(16,24,40,.55); backdrop-filter: blur(3px); }
.modal[hidden] { display: none !important; }
.modal-box {
  background: #fff; border-radius: 16px; width: min(1080px, 96vw); max-height: 94vh;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-title { display: flex; align-items: center; gap: 12px; font-size: 14px; }

.editor-body { display: grid; grid-template-columns: 1.45fr 1fr; gap: 22px;
  padding: 20px; overflow: auto; }
.col-label { margin: 0 0 8px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.canvas-wrap, .resultado-wrap {
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px;
  background: repeating-conic-gradient(#f2f4f7 0% 25%, #fbfcfd 0% 50%) 50% / 20px 20px;
  display: grid; place-items: center;
}
#editor-canvas { max-width: 100%; max-height: 64vh; border-radius: 6px;
  cursor: crosshair; display: block; touch-action: none; }
#editor-resultado { max-width: 100%; max-height: 52vh; border-radius: 6px; display: block; }
.editor-msg { margin: 10px 0 0; font-size: 13px; color: var(--ink-2); min-height: 18px; }
.editor-msg.err { color: var(--red); }
.editor-msg.work { color: var(--green-d); }

.modal-actions { display: flex; align-items: center; gap: 10px;
  padding: 16px 20px; border-top: 1px solid var(--line); }

/* ===========================================================================
   RESPONSIVE — solo para pantallas chicas. En desktop (anchos > 820px) NO se
   aplica ninguna de estas reglas, asi que la UI de escritorio queda idéntica.
   =========================================================================== */

/* ---- Tablet (≤ 820px) -----------------------------------------------------*/
@media (max-width: 820px) {
  main { padding: 18px 18px 64px; }
  .stepper { padding: 0 18px; }
  .card { padding: 22px; }

  /* El editor pasa a una sola columna (imagen arriba, resultado abajo). */
  .editor-body { grid-template-columns: 1fr; }
  #editor-canvas { max-height: 56vh; }
  #editor-resultado { max-height: 40vh; }

  .mini-stats { flex-wrap: wrap; }

  /* Grilla con tarjetas algo mas chicas en tablet. */
  .galeria { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
}

/* ---- Celular (≤ 520px) ----------------------------------------------------*/
@media (max-width: 520px) {
  body { font-size: 14.5px; }

  /* Header: marca arriba, acciones abajo; nada se encima. */
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  .brand-text span { display: none; }            /* oculta el subtítulo */
  .topbar-actions { width: 100%; flex-wrap: wrap; justify-content: flex-start; }
  .topbar-actions .btn { flex: 1 1 auto; justify-content: center; }
  .lote-label { order: 3; }

  main { padding: 14px 14px 56px; }
  .stepper { padding: 0 14px; }
  .stepper ol { gap: 4px; }
  .stepper li { padding: 5px 10px 5px 5px; font-size: 12px; }

  .card { padding: 18px 16px; }
  .card h2 { font-size: 18px; }

  /* Dropzone y botones cómodos para el dedo (target táctil ≥ 44px). */
  .dropzone { padding: 34px 16px; }
  .btn { padding: 11px 16px; min-height: 44px; }
  .actions-row { flex-direction: column; }
  .actions-row .btn { width: 100%; justify-content: center; }

  /* Progreso y contadores sin desbordes. */
  .progress-head { flex-wrap: wrap; gap: 2px; }
  .mini-stats { gap: 10px; }
  .mini-stat { flex: 1 1 calc(50% - 10px); }

  /* Grupos legibles y grilla a 1 columna en celular. */
  .grupo-revisar, .grupo-ok { padding: 16px 14px; }
  .galeria { grid-template-columns: 1fr; gap: 12px; }
  .tarjeta .thumb { aspect-ratio: 4/3; }          /* miniaturas menos altas */

  /* Modal a pantalla casi completa, con scroll si hace falta. */
  .modal { padding: 0; align-items: stretch; }
  .modal-box { width: 100vw; max-width: 100vw; max-height: 100vh; border-radius: 0; }
  .modal-head { padding: 14px 16px; }
  .editor-body { padding: 16px; gap: 16px; }
  #editor-canvas { max-height: 50vh; }
  /* Botones del editor en columna, full-width, fáciles de tocar. */
  .modal-actions { flex-wrap: wrap; gap: 8px; padding: 14px 16px; }
  .modal-actions .spacer { display: none; }
  .modal-actions .btn { flex: 1 1 calc(50% - 8px); justify-content: center; min-height: 44px; }
}

/* ---- Dispositivos sin hover (táctiles): las acciones de cada tarjeta de
   revisión SIEMPRE visibles (en touch no hay hover que las revele). ----------*/
@media (hover: none) {
  .card-actions { opacity: 1; }
}
