/* ============================================================
   Sistema de Asistencia QR — Estilos
   ============================================================ */

:root {
  --color-primary:   #1D6F42;
  --color-primary-d: #155233;
  --color-accent:    #2563EB;
  --color-success:   #16a34a;
  --color-danger:    #dc2626;
  --color-warning:   #d97706;
  --color-muted:     #6b7280;
  --color-bg:        #F1F5F1;
  --color-surface:   #ffffff;
  --color-border:    #d1fae5;
  --radius:          12px;
  --touch:           52px;
  --shadow:          0 2px 8px rgba(0,0,0,.08);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: #1a1a1a;
}

/* --- Offline bar --- */
#offline-bar {
  display: none;
  background: var(--color-danger);
  color: #fff;
  text-align: center;
  font-size: .85rem;
  padding: 6px;
}
body.offline #offline-bar { display: block; }

/* --- Toast --- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1f2937;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: .9rem;
  transition: transform .3s ease;
  z-index: 999;
  max-width: 90vw;
  text-align: center;
  pointer-events: none;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--color-danger); }
#toast.success { background: var(--color-success); }

/* --- Botones --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: 0 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, filter .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:not(:disabled):active { filter: brightness(.92); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-accent  { background: var(--color-accent);  color: #fff; }
.btn-ghost   { background: transparent; color: var(--color-primary); border: 1.5px solid var(--color-primary); }
.btn-full    { width: 100%; }

/* --- Inputs --- */
.input-field {
  width: 100%;
  min-height: var(--touch);
  padding: 0 14px;
  border: 1.5px solid #d1d5db;
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
  background: #fff;
  transition: border-color .15s;
}
.input-field:focus { border-color: var(--color-primary); }
.input-group { display: flex; flex-direction: column; gap: 6px; }
.input-group label { font-size: .85rem; font-weight: 600; color: var(--color-muted); }

/* --- Card / surface --- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

/* ============================================================
   PANTALLA ESCANEO (index.html / scan)
   ============================================================ */
.scan-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  gap: 24px;
}

.scan-header {
  text-align: center;
}
.scan-header h1 {
  font-size: 1.5rem;
  color: var(--color-primary);
}
.scan-header .branch-name {
  font-size: 1rem;
  color: var(--color-muted);
  margin-top: 4px;
}

.scan-box {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Keypad numérico */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 8px;
}
.keypad-btn {
  min-height: 58px;
  background: #fff;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  font-size: 1.4rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .1s;
}
.keypad-btn:active { background: #f0fdf4; }
.keypad-btn.action { font-size: 1rem; color: var(--color-muted); }
.keypad-btn.confirm { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.keypad-btn.confirm:active { background: var(--color-primary-d); }

.pin-display {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 12px 0;
}
.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #e5e7eb;
  transition: background .15s;
}
.pin-dot.filled { background: var(--color-primary); }

/* Estado de carga / error en scan */
.scan-status {
  text-align: center;
  padding: 32px 16px;
}
.scan-status .icon {
  font-size: 3rem;
  margin-bottom: 12px;
}
.scan-status h2 { font-size: 1.3rem; margin-bottom: 8px; }
.scan-status p { color: var(--color-muted); font-size: .9rem; }

/* Resultado del scan */
.result-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  text-align: center;
}
.result-card .result-icon { font-size: 3.5rem; margin-bottom: 12px; }
.result-card .result-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; }
.result-card .result-msg { font-size: .9rem; color: var(--color-muted); margin-bottom: 16px; }
.result-card .result-meta { font-size: .8rem; color: var(--color-muted); }
.result-card.late   .result-title { color: var(--color-warning); }
.result-card.on_time .result-title { color: var(--color-success); }
.result-card.check_out .result-title { color: var(--color-accent); }

/* --- Cámara --- */
.camera-preview-wrap {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 4/3;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}
.camera-preview-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* espejo — más natural para selfie */
}

/* ============================================================
   PANTALLA ADMIN (admin.html)
   ============================================================ */
.admin-layout {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.admin-topbar {
  background: var(--color-primary);
  color: #fff;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
}
.admin-topbar h1 { font-size: 1.1rem; flex: 1; }
.admin-topbar .btn-ghost {
  color: #fff;
  border-color: rgba(255,255,255,.4);
  min-height: 36px;
  font-size: .85rem;
  padding: 0 12px;
}

.admin-body {
  padding: 20px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* Tabs */
.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 2px solid #e5e7eb;
  padding-bottom: 0;
}
.admin-tab {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: .95rem;
  font-weight: 600;
  color: var(--color-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.admin-tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.admin-panel { display: none; }
.admin-panel.active { display: block; }

/* Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.data-table th {
  text-align: left;
  padding: 10px 12px;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  color: var(--color-muted);
  font-weight: 600;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}
.data-table tr:hover td { background: #f9fafb; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: .75rem;
  font-weight: 700;
}
.badge-on_time { background: #dcfce7; color: #166534; }
.badge-late    { background: #fef9c3; color: #854d0e; }
.badge-early   { background: #dbeafe; color: #1e40af; }
.badge-absent  { background: #fee2e2; color: #991b1b; }

/* Summary cards */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.summary-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.summary-card .num { font-size: 2rem; font-weight: 800; }
.summary-card .lbl { font-size: .8rem; color: var(--color-muted); margin-top: 4px; }
.summary-card.present .num { color: var(--color-success); }
.summary-card.absent  .num { color: var(--color-danger);  }
.summary-card.late    .num { color: var(--color-warning); }

/* Form inline */
.form-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
}
.form-row .input-group { flex: 1; min-width: 140px; }
.form-row .btn { flex-shrink: 0; }

/* Login admin */
.admin-login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.admin-login-box {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 360px;
}
.admin-login-box h1 {
  color: var(--color-primary);
  margin-bottom: 4px;
}
.admin-login-box .subtitle {
  color: var(--color-muted);
  font-size: .9rem;
  margin-bottom: 24px;
}
.admin-login-box .input-group + .input-group { margin-top: 12px; }
.admin-login-box .btn { margin-top: 20px; }

/* Error inline */
.error-msg {
  background: #fee2e2;
  color: var(--color-danger);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .88rem;
  margin-top: 12px;
}
.hidden { display: none !important; }

/* Days of week selector */
.dow-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin: 8px 0;
}
.dow-btn {
  padding: 8px 4px;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  background: #fff;
  text-align: center;
  transition: background .1s, border-color .1s;
}
.dow-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

@media (max-width: 480px) {
  .admin-body { padding: 12px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
}
