:root {
  --bg: #F7F5F0;
  --surface: #FFFFFF;
  --surface-sunken: #F1EEE6;
  --text: #221F1B;
  --text-secondary: #6B6459;
  --border: #E7E2D8;
  --accent: #2F6F5E;
  --accent-dark: #1F4A3E;
  --accent-soft: #E4EEE9;
  --danger: #B3453B;
  --danger-soft: #F7E9E7;
  --info-soft: #EEF0F3;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150F;
    --surface: #201D17;
    --surface-sunken: #29251D;
    --text: #F1EEE6;
    --text-secondary: #A69E8E;
    --border: #38332A;
    --accent: #57B79B;
    --accent-dark: #3E8B75;
    --accent-soft: #223832;
    --danger: #E48579;
    --danger-soft: #3A2420;
    --info-soft: #25272B;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Plus Jakarta Sans", -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

h1, h2, h3 {
  font-family: "Sora", "Plus Jakarta Sans", sans-serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

a { color: var(--accent-dark); }
@media (prefers-color-scheme: dark) { a { color: var(--accent); } }

.text-balance { text-wrap: balance; }

.skip-link {
  position: absolute;
  left: -999px;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  z-index: 100;
}
.skip-link:focus { left: 16px; top: 16px; }

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, label:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Estructura ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 20px 0;
}
.topbar--ancha { max-width: 960px; }

.wordmark {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "Sora", sans-serif;
  font-weight: 600;
  font-size: 15px;
}

.topbar-sesion {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 0;
}
.topbar-sesion span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 20px 40px;
}
main.ancho { max-width: 960px; }

.vista-app { display: flex; flex-direction: column; gap: 22px; }

.intro { padding: 20px 2px 4px; }
.intro h1 { font-size: 26px; line-height: 1.25; }
.intro p { color: var(--text-secondary); margin: 8px 0 0; }

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

/* ---------- Login ---------- */
.vista-login { padding-top: 48px; }
.login-card { max-width: 400px; margin: 0 auto; }
.login-card h1 { font-size: 22px; }
.login-card .sub { color: var(--text-secondary); margin: 6px 0 20px; font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-pie { text-align: center; font-size: 13px; margin-top: 18px; }

/* ---------- Avisos ---------- */
.avisos { display: flex; flex-direction: column; gap: 8px; }
.avisos:empty { display: none; }
.aviso {
  margin: 0;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  border: 1px solid transparent;
}
.aviso-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.aviso-info { background: var(--info-soft); color: var(--text); border-color: var(--border); }

/* ---------- Resumen ---------- */
.resumen { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.resumen-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.resumen-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-secondary); }

.chip {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  font-size: 12.5px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.chip-pendiente { background: var(--danger-soft); color: var(--danger); }
.chip-ok { background: var(--accent-soft); color: var(--accent-dark); }
.chip-neutro { background: var(--surface-sunken); color: var(--text-secondary); }
@media (prefers-color-scheme: dark) { .chip-ok { color: var(--accent); } }

/* ---------- Pasos ---------- */
.step-head { display: flex; gap: 14px; align-items: flex-start; }
.step-badge {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  justify-content: center;
}
@media (prefers-color-scheme: dark) { .step-badge { color: var(--accent); } }
.step-head h2 { font-size: 17px; }
.step-head p { color: var(--text-secondary); margin: 4px 0 0; font-size: 13.5px; }

.step-body {
  margin-top: 16px;
  padding-left: 48px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}
.step-body--fila { flex-direction: row; align-items: center; flex-wrap: wrap; }

/* ---------- Botones ---------- */
.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 120ms ease, background 150ms ease, border-color 150ms ease, opacity 150ms ease;
}
.btn:hover { border-color: var(--text-secondary); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn-primario { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primario:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-secundario { background: var(--surface-sunken); }
.btn-peligro { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-bloque { width: 100%; }
.btn-chico { padding: 7px 12px; font-size: 13px; }

.btn-link {
  background: none;
  border: none;
  padding: 4px 0;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent-dark);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
@media (prefers-color-scheme: dark) { .btn-link { color: var(--accent); } }
.btn-link--peligro { color: var(--danger); }
.btn-link:disabled { opacity: 0.5; cursor: default; }

/* ---------- QR ---------- */
.qr-frame {
  width: 100%;
  max-width: 240px;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #fff;
  overflow: hidden;
}
.qr-frame img { width: 100%; height: 100%; object-fit: contain; display: block; }

/* ---------- Grupos ---------- */
.lista-grupos {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  max-height: 420px;
  overflow-y: auto;
}
.grupos-herramientas { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.grupos-herramientas input[type="search"] {
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.grupos-botones { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.grupos-cuenta { margin-left: auto; font-size: 12.5px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.estado-vacio { margin: 0; padding: 18px; color: var(--text-secondary); font-size: 13.5px; text-align: center; }

.grupo-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  cursor: pointer;
}
.grupo-item:last-child { border-bottom: none; }
.grupo-item:hover { background: var(--surface-sunken); }
.grupo-item input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.grupo-nombre { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.grupo-miembros { color: var(--text-secondary); font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.skeleton-row {
  height: 46px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, var(--surface-sunken) 25%, var(--surface) 37%, var(--surface-sunken) 63%);
  background-size: 400% 100%;
  animation: skeleton 1.4s ease infinite;
}
.skeleton-row:last-child { border-bottom: none; }
@keyframes skeleton { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .skeleton-row { animation: none; } }

/* ---------- Formularios ---------- */
.form-fotos { width: 100%; display: flex; flex-direction: column; gap: 14px; }

.dropzone {
  width: 100%;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  padding: 12px;
  transition: border-color 150ms ease;
}
.dropzone:hover { border-color: var(--accent); }
#dropzone-texto {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13.5px;
  padding: 12px;
}
.dropzone-previas { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.dropzone-previas img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--radius-sm); }
.previa-mas {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--text-secondary);
}

.campo { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.campo label { font-size: 13px; color: var(--text-secondary); }
.campo input, .campo select, .foto-programar select, .foto-programar input, .fila-accion input, .fila-accion select {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  min-width: 0;
}
.campo input:focus, .campo select:focus { border-color: var(--accent); }

.fechas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }

.check { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

.error { color: var(--danger); font-size: 13px; margin: 0; }
.estado { font-size: 13px; min-height: 18px; margin: 0; color: var(--text-secondary); }
.estado.ok { color: var(--accent-dark); }
.estado.error { color: var(--danger); }
@media (prefers-color-scheme: dark) { .estado.ok { color: var(--accent); } }

/* ---------- Galería ---------- */
.galeria-cabecera { width: 100%; margin-top: 8px; }
.galeria-cabecera h3 { font-size: 15px; }
.cuenta { color: var(--text-secondary); font-weight: 500; font-variant-numeric: tabular-nums; }

.galeria {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.galeria .estado-vacio { grid-column: 1 / -1; border: 1px solid var(--border); border-radius: var(--radius-md); }

.foto {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}
.foto img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--surface-sunken); }
.foto-cuerpo { padding: 10px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.foto-texto { margin: 0; font-size: 12.5px; color: var(--text-secondary); overflow-wrap: anywhere; }
.foto-acciones { display: flex; justify-content: space-between; gap: 8px; margin-top: auto; }
.foto-programar { display: flex; flex-direction: column; gap: 8px; }
.foto-programar .fechas { grid-template-columns: 1fr; }
.foto-programar select, .foto-programar input { padding: 8px 10px; font-size: 13px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 14, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-caja {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 460px;
  width: 100%;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-caja h2 { font-size: 19px; }
.modal-caja p { margin: 0; font-size: 14px; }
.lista-puntos { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }

/* ---------- Admin ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}
.tile-numero { font-family: "Sora", sans-serif; font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; display: block; }
.tile-label { font-size: 12px; color: var(--text-secondary); }
.tile--alerta .tile-numero { color: var(--danger); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.form-grid .campo--doble { grid-column: 1 / -1; }
.con-boton { display: flex; gap: 8px; }
.con-boton input { flex: 1; }

.credenciales {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  font-size: 14px;
}
.credenciales code { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 13.5px; }

.lista-clientes { display: flex; flex-direction: column; gap: 12px; }
.cliente {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cliente--problema { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.cliente-cabecera { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.cliente-cabecera h3 { font-size: 16px; }
.cliente-sub { font-size: 12.5px; color: var(--text-secondary); margin: 2px 0 0; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cliente-datos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin: 0;
}
.cliente-datos dt { font-size: 12px; }
.cliente-datos dd { margin: 0; }
.cliente-datos strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.cliente-acciones { display: flex; flex-wrap: wrap; gap: 8px; }
.fila-accion { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; width: 100%; }
.fila-accion input, .fila-accion select { width: auto; flex: 1; min-width: 140px; padding: 8px 10px; font-size: 13px; }

.seccion-titulo { font-size: 17px; margin: 8px 0 12px; }

/* ---------- Página de términos ---------- */
.legal { padding-top: 20px; }
.legal h1 { font-size: 24px; margin-bottom: 4px; }
.legal h2 { font-size: 17px; margin: 24px 0 8px; }
.legal p, .legal li { font-size: 14.5px; }
.legal .actualizado { color: var(--text-secondary); font-size: 13px; margin-top: 0; }

.footer { text-align: center; padding: 10px 20px 34px; color: var(--text-secondary); font-size: 12.5px; }

@media (max-width: 560px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .step-body { padding-left: 0; }
  .intro h1 { font-size: 22px; }
  .resumen { gap: 6px; }
  .resumen-item { padding: 10px; }
}
