:root {
  --color-bg: #f4f6fa;
  --color-card: #ffffff;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-danger: #dc2626;
  --color-text: #111827;
  --color-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-disponible: #ffffff;
  --color-apartado: #fbbf24;
  --color-vendido: #16a34a;
  --color-bloqueado: #9ca3af;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

/* El atributo hidden debe ganarle a cualquier display: flex/grid */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  min-height: 100vh;
}

/* Marca de agua del logo */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("imagenes/logo.png");
  background-repeat: no-repeat;
  background-position: center center;
  background-size: min(60vw, 480px) auto;
  opacity: 0.06;
  pointer-events: none;
  z-index: 0;
}

/* Aseguramos que el contenido vaya encima de la marca de agua */
.topbar,
.container,
.modal {
  position: relative;
  z-index: 1;
}

/* Brand del topbar */
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-logo {
  height: 36px;
  width: 36px;
  object-fit: contain;
  border-radius: 6px;
  background: white;
  padding: 2px;
}

/* Logo en pantallas de login/registro */
.auth-logo {
  display: flex;
  justify-content: center;
  padding: 18px 0 8px;
}

.auth-logo img {
  max-height: 80px;
  max-width: 80%;
  object-fit: contain;
}

.topbar {
  background: var(--color-primary);
  color: white;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-greeting {
  color: white;
  font-size: 0.85rem;
  opacity: 0.9;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-link {
  color: white;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.15);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.admin-link:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Auth screen */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 75vh;
}

.auth-card {
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
  overflow: hidden;
}

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
}

.auth-tab {
  flex: 1;
  background: #f9fafb;
  border: none;
  padding: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-muted);
  cursor: pointer;
  font-family: inherit;
}

.auth-tab.active {
  background: white;
  color: var(--color-primary);
  border-bottom: 3px solid var(--color-primary);
  margin-bottom: -1px;
}

.auth-form {
  padding: 24px;
}

/* Mensaje de bienvenida */
.auth-welcome {
  text-align: center;
  font-size: 0.92rem;
  color: var(--color-muted);
  line-height: 1.45;
  margin: 0 24px 4px;
}

.auth-welcome strong {
  color: var(--color-primary);
}

/* Franja de confianza */
.trust-strip {
  border-top: 1px solid var(--color-border);
  background: #f9fafb;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.trust-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--color-text);
}

.trust-item svg {
  color: var(--color-primary);
  flex-shrink: 0;
}

/* Lista de rifas (admin y cliente) */
.section-title {
  margin: 8px 0 4px;
  color: var(--color-text);
}

.rifas-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 12px;
}

.rifa-card {
  background: white;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

.rifa-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.1);
  border-color: var(--color-primary);
}

.rifa-card h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--color-primary);
}

.rifa-card .rifa-meta {
  font-size: 0.85rem;
  color: var(--color-muted);
  line-height: 1.4;
}

.rifa-card .rifa-meta strong {
  color: var(--color-text);
}

.rifa-status {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 12px;
  letter-spacing: 0.5px;
}

.rifa-status.abierta { background: #dcfce7; color: #15803d; }
.rifa-status.cerrada { background: #f3f4f6; color: #6b7280; }
.rifa-status.finalizada { background: #fef3c7; color: #92400e; }

.rifa-progress {
  display: flex;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--color-muted);
  margin-top: 4px;
}

.rifa-progress span {
  background: #f3f4f6;
  padding: 2px 8px;
  border-radius: 8px;
}

.detail-back {
  margin-bottom: 12px;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.check-line input[type="checkbox"] {
  width: auto;
  margin: 0;
}

/* Toggle de rifa activa/cerrada (admin) */
.rifa-toggle {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #f3f4f6;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  transition: background 0.2s;
}

.rifa-toggle.active {
  background: #dcfce7;
  border-color: #16a34a;
}

.rifa-toggle-text {
  display: flex;
  flex-direction: column;
}

.rifa-toggle-text strong {
  font-size: 1rem;
}

.rifa-toggle-text small {
  font-size: 0.8rem;
  color: var(--color-muted);
  margin-top: 2px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #9ca3af;
  transition: 0.2s;
  border-radius: 28px;
}

.switch .slider::before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}

.switch input:checked + .slider {
  background-color: #16a34a;
}

.switch input:checked + .slider::before {
  transform: translateX(22px);
}

/* Pantalla rifa cerrada (cliente) */
.closed-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
}

.closed-card {
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 28px;
  text-align: center;
  max-width: 420px;
  width: 100%;
}

.closed-logo {
  max-height: 90px;
  margin-bottom: 12px;
}

.closed-card h2 {
  margin: 8px 0 12px;
  color: var(--color-primary);
}

.closed-card p {
  color: var(--color-muted);
  line-height: 1.5;
  margin: 6px 0;
}

.closed-next {
  margin-top: 16px !important;
  padding-top: 14px;
  border-top: 1px solid var(--color-border);
  font-size: 0.9rem;
  color: var(--color-text) !important;
}

/* Toggle de previsualizacion de contrasena */
.password-wrap {
  position: relative;
  margin-top: 4px;
}

.password-wrap input {
  width: 100%;
  padding-right: 44px !important;
  margin-top: 0 !important;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-muted);
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.password-toggle:hover {
  color: var(--color-primary);
  background: rgba(37, 99, 235, 0.08);
}

.password-toggle svg[hidden] {
  display: none;
}

.auth-form button[type="submit"] {
  width: 100%;
  margin-top: 8px;
}

.modal-user-info {
  background: #eff6ff;
  border-left: 3px solid var(--color-primary);
  padding: 8px 12px;
  margin: 0 0 12px;
  font-size: 0.9rem;
  border-radius: 4px;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
}

/* Info card */
.info-card {
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.info-item {
  display: flex;
  flex-direction: column;
  text-align: center;
}

.info-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--color-muted);
  letter-spacing: 0.5px;
}

.info-value {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 4px;
}

/* Countdown */
.countdown-card {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: white;
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}

.countdown-label {
  display: block;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.85;
  margin-bottom: 10px;
}

.countdown-blocks {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.cd-block {
  background: rgba(255, 255, 255, 0.15);
  padding: 8px 10px;
  border-radius: 8px;
  min-width: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cd-block span {
  font-size: 1.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.cd-block small {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
  opacity: 0.85;
}

.cd-sep {
  font-size: 1.5rem;
  font-weight: 700;
  opacity: 0.5;
}

.countdown-card.terminado {
  background: linear-gradient(135deg, #7c2d12, #b91c1c);
}

@media (max-width: 420px) {
  .cd-block { min-width: 48px; padding: 6px 8px; }
  .cd-block span { font-size: 1.4rem; }
  .cd-sep { font-size: 1.1rem; }
}

/* Winner banner */
.winner-banner {
  background: linear-gradient(135deg, #16a34a, #15803d);
  color: white;
  padding: 14px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
}

.winner-banner strong {
  font-size: 1.4rem;
}

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-bottom: 12px;
  padding: 8px;
}

.chip {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  vertical-align: middle;
  margin-right: 4px;
}
.chip-disponible { background: var(--color-disponible); }
.chip-apartado { background: var(--color-apartado); }
.chip-vendido { background: var(--color-vendido); }
.chip-bloqueado { background: var(--color-bloqueado); }

/* Numbers grid */
.grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
  background: var(--color-card);
  padding: 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

@media (max-width: 600px) {
  .grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
  }
}

.cell {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  border: 2px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-disponible);
  cursor: pointer;
  user-select: none;
  transition: transform 0.1s, box-shadow 0.1s;
}

.cell:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.cell.apartado {
  background: var(--color-apartado);
  color: #78350f;
  border-color: #f59e0b;
  cursor: not-allowed;
}

.cell.vendido {
  background: var(--color-vendido);
  color: white;
  border-color: #15803d;
  cursor: not-allowed;
}

.cell.bloqueado {
  background: var(--color-bloqueado);
  color: white;
  border-color: #6b7280;
  cursor: not-allowed;
  text-decoration: line-through;
}

.cell.ganador {
  outline: 3px solid #facc15;
  outline-offset: 2px;
  box-shadow: 0 0 12px rgba(250, 204, 21, 0.7);
}

.hint {
  text-align: center;
  color: var(--color-muted);
  font-size: 0.9rem;
  margin-top: 12px;
}

/* Forms */
form label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--color-text);
}

form input[type="text"],
form input[type="tel"],
form input[type="number"],
form input[type="date"],
form input[type="password"],
form input[type="file"] {
  width: 100%;
  padding: 10px 12px;
  margin-top: 4px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 1rem;
  background: white;
}

form input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn-primary, .btn-secondary, .btn-danger, .btn-link {
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-primary:disabled { background: #93c5fd; cursor: wait; }

.btn-secondary {
  background: #e5e7eb;
  color: var(--color-text);
}
.btn-secondary:hover { background: #d1d5db; }

.btn-danger {
  background: var(--color-danger);
  color: white;
}
.btn-danger:hover { background: #b91c1c; }

.btn-link {
  background: transparent;
  color: white;
  text-decoration: underline;
  padding: 4px 8px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  animation: fadeIn 0.15s ease-out;
}

.modal[hidden] {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.modal-content h2 {
  margin: 0 0 16px;
  font-size: 1.25rem;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  color: var(--color-muted);
  line-height: 1;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.modal-actions.stacked {
  flex-direction: column;
}

.modal-actions.stacked button {
  width: 100%;
}

.preview-wrap {
  margin: 12px 0;
  text-align: center;
}

.preview-wrap img {
  max-width: 100%;
  max-height: 280px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
}

.modal-result-body {
  background: #f9fafb;
  padding: 16px;
  border-radius: 8px;
  text-align: center;
}

.modal-result-body .big {
  font-size: 3rem;
  font-weight: 800;
  color: var(--color-primary);
  letter-spacing: 4px;
}

/* Admin */
.admin-section {
  background: var(--color-card);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.admin-section h2 {
  margin-top: 0;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.grid-form .form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
}

.admin-tools {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.admin-tools button {
  font-size: 0.8rem;
  padding: 6px 10px;
}

/* Login */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
}

.login-card {
  background: var(--color-card);
  padding: 28px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 360px;
}

.login-card h2 {
  margin-top: 0;
  text-align: center;
}

.login-card button {
  width: 100%;
  margin-top: 8px;
}

.error-msg {
  background: #fee2e2;
  color: var(--color-danger);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  margin-bottom: 10px;
}

#mn-estado-info, #mn-cliente-info {
  font-size: 0.95rem;
  margin-bottom: 10px;
  line-height: 1.6;
}

#mn-cliente-info strong {
  color: var(--color-primary);
}

.edit-cliente-form {
  background: #f9fafb;
  padding: 12px;
  border-radius: 8px;
  margin: 12px 0;
  border: 1px dashed var(--color-border);
}

.edit-cliente-form label {
  margin-bottom: 8px;
}

.edit-cliente-form button {
  width: 100%;
  margin-top: 4px;
}
