* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  min-height: 100dvh;
}

/* --- Login --- */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
}

#login-box {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.login-icon {
  font-size: 3rem;
}

#login-box h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1e293b;
}

#login-box p {
  color: #64748b;
  font-size: 0.95rem;
}

#login-error {
  color: #ef4444;
  font-size: 0.85rem;
  min-height: 1.2em;
}

/* --- App --- */

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 0 80px 0;
}

header {
  background: #2563eb;
  color: white;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#btn-admin {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

#btn-limpiar {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
}

#btn-limpiar:active,
#btn-admin:active {
  background: rgba(255,255,255,0.35);
}

#form-agregar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: white;
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 56px;
  z-index: 9;
}

#input-item {
  flex: 1;
  padding: 12px 14px;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  font-size: 1rem;
  outline: none;
  background: white;
  color: #1e293b;
}

#input-item:focus {
  border-color: #2563eb;
}

#input-cantidad {
  flex: 0 0 42px;
  width: 42px;
  max-width: 42px;
  padding: 12px 4px;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  font-size: 1rem;
  text-align: center;
  outline: none;
  background: white;
  color: #1e293b;
}

#input-cantidad:focus {
  border-color: #2563eb;
}

#form-agregar button[type="submit"] {
  width: 44px;
  height: 44px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#form-agregar button[type="submit"]:active {
  background: #1d4ed8;
}

#lista {
  list-style: none;
  padding: 8px 0;
}

#lista li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: white;
  border-bottom: 1px solid #f1f5f9;
  user-select: none;
}

#lista li:active {
  background: #f8fafc;
}

#lista li.checked .nombre {
  text-decoration: line-through;
  color: #94a3b8;
}

#lista li .nombre {
  flex: 1;
  font-size: 1rem;
}

#lista li .btn-check {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #cbd5e1;
  background: white;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

#lista li.checked .btn-check {
  background: #22c55e;
  border-color: #22c55e;
  color: white;
}

.cantidad-ctrl {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.qty {
  min-width: 20px;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  color: #475569;
}

li.checked .qty {
  color: #cbd5e1;
}

.btn-qty {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1.5px solid #e2e8f0;
  background: #f8fafc;
  color: #475569;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.btn-qty:active {
  background: #e2e8f0;
}

#lista li .btn-del {
  background: none;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px;
  line-height: 1;
}

#lista li .btn-del:active {
  color: #ef4444;
}

#estado {
  text-align: center;
  padding: 20px;
  color: #94a3b8;
  font-size: 0.85rem;
}

/* --- Admin modal --- */

#admin-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}

#admin-overlay.visible {
  display: flex;
}

#admin-modal {
  background: white;
  width: 100%;
  max-width: 480px;
  border-radius: 16px 16px 0 0;
  padding: 20px;
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.admin-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

#btn-cerrar-admin {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #94a3b8;
  cursor: pointer;
  line-height: 1;
}

#lista-usuarios {
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#lista-usuarios li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #f1f5f9;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
}

.avatar-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.usuario-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.usuario-nombre {
  font-size: 0.9rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.usuario-email {
  font-size: 0.75rem;
  color: #94a3b8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-admin {
  font-size: 0.7rem;
  background: #dbeafe;
  color: #2563eb;
  padding: 2px 8px;
  border-radius: 99px;
  flex-shrink: 0;
}

.btn-quitar {
  background: none;
  border: none;
  color: #cbd5e1;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}

.btn-quitar:active {
  color: #ef4444;
}

#form-usuario {
  display: flex;
  gap: 8px;
}

#input-email {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  font-size: 0.95rem;
  outline: none;
}

#input-email:focus {
  border-color: #2563eb;
}

#form-usuario button {
  padding: 10px 16px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
}

.admin-footer {
  border-top: 1px solid #f1f5f9;
  padding-top: 8px;
}

#btn-logout {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 0;
}

#btn-logout:active {
  color: #ef4444;
}

/* --- Dark mode --- */

@media (prefers-color-scheme: dark) {
  body {
    background: #0f172a;
    color: #e2e8f0;
  }

  #login-box h1 {
    color: #e2e8f0;
  }

  #login-box p {
    color: #94a3b8;
  }

  #form-agregar {
    background: #1e293b;
    border-bottom-color: #334155;
  }

  #input-item,
  #input-cantidad {
    background: #0f172a;
    color: #e2e8f0;
    border-color: #334155;
  }

  #input-item:focus,
  #input-cantidad:focus {
    border-color: #3b82f6;
  }

  #lista li {
    background: #1e293b;
    border-bottom-color: #0f172a;
  }

  #lista li:active {
    background: #263348;
  }

  #lista li.checked .nombre {
    color: #475569;
  }

  #lista li .btn-check {
    background: #0f172a;
    border-color: #475569;
  }

  .btn-qty {
    background: #0f172a;
    border-color: #334155;
    color: #94a3b8;
  }

  .btn-qty:active {
    background: #1e293b;
  }

  .qty {
    color: #94a3b8;
  }

  li.checked .qty {
    color: #334155;
  }

  #lista li .btn-del {
    color: #334155;
  }

  #admin-modal {
    background: #1e293b;
  }

  #lista-usuarios li {
    border-bottom-color: #0f172a;
  }

  .avatar-placeholder {
    background: #334155;
  }

  .badge-admin {
    background: #1e3a5f;
    color: #93c5fd;
  }

  #input-email {
    background: #0f172a;
    color: #e2e8f0;
    border-color: #334155;
  }

  .admin-footer {
    border-top-color: #334155;
  }
}
