/* ============================================================
   Sistema de Lotería de Animalitos — Estilos globales
   HTML + CSS puro, sin frameworks
   ============================================================ */

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

:root {
  --primary:    #1a56db;
  --primary-d:  #1041b2;
  --danger:     #e02424;
  --danger-d:   #c81e1e;
  --success:    #057a55;
  --warning:    #c27803;
  --gray-50:    #f9fafb;
  --gray-100:   #f3f4f6;
  --gray-200:   #e5e7eb;
  --gray-300:   #d1d5db;
  --gray-400:   #9ca3af;
  --gray-600:   #4b5563;
  --gray-700:   #374151;
  --gray-800:   #1f2937;
  --gray-900:   #111827;
  --sidebar-w:  240px;
  --header-h:   56px;
  --radius:     6px;
  --shadow:     0 1px 4px rgba(0,0,0,.12);
  --shadow-md:  0 4px 12px rgba(0,0,0,.15);
  --font:       'Segoe UI', system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--gray-100);
  color: var(--gray-800);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Login ── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #1a56db 100%);
}
.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 40px 36px;
  width: 360px;
  box-shadow: var(--shadow-md);
}
.login-card h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 4px;
  text-align: center;
}
.login-card .subtitle {
  text-align: center;
  color: var(--gray-400);
  font-size: 13px;
  margin-bottom: 28px;
}
.login-card .logo-area {
  text-align: center;
  margin-bottom: 20px;
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 1px;
}
.login-error {
  background: #fee2e2;
  color: #991b1b;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.login-error.show { display: block; }

/* ── App shell ── */
#app-shell { display: none; }
#app-shell.visible { display: flex; flex-direction: column; min-height: 100vh; }

/* Header */
.app-header {
  height: var(--header-h);
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow);
}
.app-header .brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--primary);
  flex: 1;
}
.app-header .user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--gray-600);
}
.badge-rol {
  background: var(--primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

/* Layout */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--gray-900);
  color: #fff;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-section { padding: 12px 0 4px; }
.sidebar-section-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 0 16px 6px;
}
.sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--gray-300);
  text-decoration: none;
  font-size: 13.5px;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s;
  cursor: pointer;
}
.sidebar a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar a.active { background: rgba(26,86,219,.25); color: #fff; border-left-color: var(--primary); }
.sidebar a .icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
}

/* Main content */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* Page */
.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--gray-900);
}

/* ── Cards / Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.stat-card.danger  { border-left-color: var(--danger); }
.stat-card.success { border-left-color: var(--success); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card .stat-val { font-size: 28px; font-weight: 700; color: var(--gray-900); }
.stat-card .stat-lbl { font-size: 12px; color: var(--gray-400); margin-top: 2px; }

/* ── Panel / Card ── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 14px;
}
.card-body { padding: 20px; }

/* ── Tabla ── */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead tr { background: var(--gray-50); }
th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-600);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }
.tbl-empty { text-align: center; color: var(--gray-400); padding: 32px !important; }

/* ── Formularios ── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 5px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  color: var(--gray-800);
  background: #fff;
  transition: border-color .15s;
  outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}
.form-row { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.form-row.cols3 { grid-template-columns: 1fr 1fr 1fr; }

/* ── Botones ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--primary-d); }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-danger:hover:not(:disabled)   { background: var(--danger-d); }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled)  { background: #046c4e; }
.btn-outline  {
  background: transparent;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}
.btn-outline:hover:not(:disabled) { background: var(--gray-100); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }

/* ── Badges estado ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.badge-on   { background: #d1fae5; color: #065f46; }
.badge-off  { background: #fee2e2; color: #991b1b; }
.badge-warn { background: #fef3c7; color: #92400e; }

/* ── Modal ── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 10px;
  width: 480px;
  max-width: 96vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  animation: slideUp .2s ease;
}
.modal.modal-lg { width: 660px; }
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 15px;
}
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: var(--gray-400); line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: var(--gray-800); }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn .25s ease;
  max-width: 320px;
  pointer-events: all;
}
.toast.ok   { background: var(--success); }
.toast.err  { background: var(--danger); }
.toast.warn { background: var(--warning); }
@keyframes toastIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Cupos grilla ── */
.cupos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.cupo-card {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
  user-select: none;
}
.cupo-card:hover { box-shadow: var(--shadow); border-color: var(--primary); }
.cupo-card .animal-id   { font-size: 10px; color: var(--gray-400); }
.cupo-card .animal-name { font-weight: 700; font-size: 13px; margin: 2px 0 8px; }
.cupo-bar-wrap {
  background: var(--gray-200);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
  margin-bottom: 4px;
}
.cupo-bar {
  height: 100%;
  border-radius: 4px;
  background: var(--success);
  transition: width .3s;
}
.cupo-bar.warn   { background: var(--warning); }
.cupo-bar.danger { background: var(--danger); }
.cupo-pct   { font-size: 11px; color: var(--gray-600); }
.cupo-monto { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

/* ── Loader ── */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 32px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Misc ── */
.text-muted   { color: var(--gray-400); font-size: 12px; }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.flex-gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 20px; }
hr.divider { border: none; border-top: 1px solid var(--gray-200); margin: 18px 0; }

/* Toggle switch */
.toggle { position: relative; width: 40px; height: 22px; display: inline-block; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--gray-300);
  border-radius: 22px;
  cursor: pointer;
  transition: background .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* Días semana */
.dias-wrap { display: flex; gap: 6px; flex-wrap: wrap; }
.dia-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid var(--gray-300);
  background: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
  color: var(--gray-600);
}
.dia-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Confirm dialog */
.confirm-msg { font-size: 14px; color: var(--gray-700); line-height: 1.6; }

@media (max-width: 768px) {
  .sidebar { display: none; }
  .form-row, .form-row.cols3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .modal { width: 98vw; }
}
