/* ── Reset & Variables ─────────────────────────────── */
:root {
  --primary:    #1B4FD8;
  --primary-d:  #1440B8;
  --secondary:  #0E9F6E;
  --accent:     #F5A623;
  --porteria:   #7C3AED;
  --bg:         #F4F7FF;
  --surface:    #FFFFFF;
  --text:       #111827;
  --muted:      #6B7280;
  --border:     #E5E7EB;
  --error:      #EF4444;
  --success:    #10B981;
  --radius:     14px;
  --shadow:     0 2px 12px rgba(27,79,216,.08);
  --safe-top:   env(safe-area-inset-top, 0px);
  --safe-bot:   env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%; overflow: hidden;
  font-family: -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ─────────────────────────────────────── */
#app {
  height: 100%; display: flex; flex-direction: column;
  padding-top: var(--safe-top);
}

/* Screens */
.screen { display: none; flex-direction: column; height: 100%; }
.screen.active { display: flex; }

/* ── Top Bar ───────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--primary);
  color: #fff; flex-shrink: 0;
  padding-top: calc(12px + var(--safe-top));
}
.topbar.secondary  { background: var(--secondary); }
.topbar.porteria   { background: var(--porteria); }
.topbar.orange     { background: #EA580C; }

.topbar-back {
  background: rgba(255,255,255,.15); border: none; border-radius: 10px;
  width: 36px; height: 36px; display: flex; align-items: center;
  justify-content: center; cursor: pointer; color: #fff; flex-shrink: 0;
}
.topbar-title { flex: 1; }
.topbar-title h1 { font-size: 1rem; font-weight: 700; }
.topbar-title p  { font-size: .72rem; opacity: .75; margin-top: 1px; }
.topbar-action {
  background: rgba(255,255,255,.15); border: none; border-radius: 10px;
  width: 36px; height: 36px; display: flex; align-items: center;
  justify-content: center; cursor: pointer; color: #fff;
}

/* ── Tabs ──────────────────────────────────────────── */
.tabs {
  display: flex; background: rgba(255,255,255,.15);
  margin: 8px 12px; border-radius: 10px; padding: 3px; flex-shrink: 0;
}
.tab {
  flex: 1; padding: 8px; border: none; background: transparent;
  color: rgba(255,255,255,.7); font-size: .8rem; font-weight: 600;
  border-radius: 8px; cursor: pointer; transition: all .2s;
}
.tab.active { background: #fff; color: var(--primary); }

.tab-content { display: none; flex: 1; overflow-y: auto; }
.tab-content.active { display: block; }

/* ── Scroll area ───────────────────────────────────── */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: 16px; }

/* ── Bottom Nav ────────────────────────────────────── */
.bottom-nav {
  display: flex; background: #fff;
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bot);
  flex-shrink: 0;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 10px 4px; border: none; background: transparent; cursor: pointer;
  color: var(--muted); font-size: .65rem; gap: 3px; transition: color .2s;
}
.nav-item.active { color: var(--primary); }
.nav-item svg { width: 22px; height: 22px; }

/* ── Cards ─────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 16px;
  margin-bottom: 12px; box-shadow: var(--shadow);
}
.card-title { font-weight: 700; font-size: .95rem; margin-bottom: 4px; }
.card-sub   { font-size: .78rem; color: var(--muted); }

/* ── Grid de módulos (home portería/empleado) ──────── */
.module-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; padding: 16px;
}
.module-card {
  background: var(--surface); border-radius: 16px;
  border: 1px solid var(--border); padding: 18px 14px;
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; cursor: pointer; transition: all .15s;
  box-shadow: var(--shadow); text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.module-card:active { transform: scale(.97); }
.module-icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
}
.module-name  { font-weight: 700; font-size: .85rem; }
.module-desc  { font-size: .72rem; color: var(--muted); }

/* ── Forms ─────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: .75rem; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border);
  border-radius: 10px; font-family: inherit; font-size: .95rem;
  background: #F9FAFB; color: var(--text); outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(27,79,216,.1);
  background: #fff;
}
.field textarea { resize: vertical; min-height: 80px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── Buttons ───────────────────────────────────────── */
.btn {
  width: 100%; padding: 14px; border-radius: 12px; border: none;
  font-family: inherit; font-size: .95rem; font-weight: 700;
  cursor: pointer; transition: all .2s; display: flex;
  align-items: center; justify-content: center; gap: 8px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-d); }
.btn-primary:disabled { background: #9CA3AF; cursor: not-allowed; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-orange    { background: #EA580C; color: #fff; }
.btn-ghost { background: transparent; color: var(--primary); border: 1.5px solid var(--border); }
.btn-red   { background: var(--error); color: #fff; }
.btn-sm {
  padding: 8px 16px; font-size: .82rem; border-radius: 9px;
  width: auto; display: inline-flex;
}

/* ── List items ────────────────────────────────────── */
.list-item {
  background: var(--surface); border-radius: 14px;
  border: 1px solid var(--border); padding: 14px;
  margin-bottom: 10px; display: flex; align-items: center;
  gap: 12px; cursor: pointer; transition: all .15s;
}
.list-item:active { transform: scale(.99); }
.list-item-avatar {
  width: 46px; height: 46px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
}
.list-item-av-placeholder {
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.1rem; color: #fff; flex-shrink: 0;
  background: var(--primary);
}
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-weight: 700; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub   { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.list-item-trail { flex-shrink: 0; text-align: right; }

/* ── Badges ────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; padding: 3px 9px;
  border-radius: 20px; font-size: .72rem; font-weight: 700;
}
.badge-green  { background: #D1FAE5; color: #065F46; }
.badge-orange { background: #FEF3C7; color: #92400E; }
.badge-red    { background: #FEE2E2; color: #991B1B; }
.badge-blue   { background: #DBEAFE; color: #1E40AF; }
.badge-purple { background: #EDE9FE; color: #5B21B6; }

/* ── Alerts ────────────────────────────────────────── */
.alert {
  padding: 12px 14px; border-radius: 10px; font-size: .85rem;
  display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px;
}
.alert-error   { background: #FEF2F2; border: 1px solid #FECACA; color: #B91C1C; }
.alert-success { background: #ECFDF5; border: 1px solid #A7F3D0; color: #065F46; }
.alert-info    { background: #EFF6FF; border: 1px solid #BFDBFE; color: #1D4ED8; }
.alert-warn    { background: #FFFBEB; border: 1px solid #FDE68A; color: #92400E; }

/* ── Empty state ───────────────────────────────────── */
.empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 24px; gap: 12px; text-align: center;
}
.empty-icon { font-size: 3.5rem; opacity: .3; }
.empty h3 { font-size: .95rem; color: var(--muted); }
.empty p  { font-size: .8rem; color: #9CA3AF; }

/* ── Modal / Sheet ─────────────────────────────────── */
.overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 100; align-items: flex-end;
}
.overlay.open { display: flex; animation: fadeIn .2s; }
.sheet {
  background: #fff; border-radius: 24px 24px 0 0; width: 100%;
  max-height: 90vh; overflow-y: auto; padding: 20px;
  padding-bottom: calc(20px + var(--safe-bot));
  animation: slideUp .25s ease;
}
.sheet-handle {
  width: 40px; height: 4px; background: var(--border);
  border-radius: 2px; margin: 0 auto 16px;
}

/* ── Fullscreen image viewer ───────────────────────── */
.img-viewer {
  display: none; position: fixed; inset: 0;
  background: #000; z-index: 200; align-items: center; justify-content: center;
}
.img-viewer.open { display: flex; }
.img-viewer img  { max-width: 100%; max-height: 100%; object-fit: contain; }
.img-viewer-close {
  position: absolute; top: 50px; right: 16px; background: rgba(255,255,255,.2);
  border: none; border-radius: 50%; width: 40px; height: 40px; color: #fff;
  font-size: 1.3rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* ── Stats row ─────────────────────────────────────── */
.stats-row {
  display: flex; gap: 8px; padding: 12px 16px;
  background: #fff; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.stat-chip {
  flex: 1; padding: 10px 8px; border-radius: 10px; text-align: center;
}
.stat-chip .val { font-size: 1.3rem; font-weight: 800; display: block; }
.stat-chip .lbl { font-size: .65rem; opacity: .75; }

/* ── Loading ───────────────────────────────────────── */
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 40px auto;
}
.spinner-sm { width: 18px; height: 18px; border-width: 2px; margin: 0; }

/* ── Animations ────────────────────────────────────── */
@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ── Info rows ─────────────────────────────────────── */
.info-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.info-row:last-child { border-bottom: none; }
.info-row .lbl { font-size: .8rem; color: var(--muted); width: 110px; flex-shrink: 0; }
.info-row .val { font-size: .85rem; font-weight: 600; flex: 1; }

/* ── Foto grid ─────────────────────────────────────── */
.foto-grid { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.foto-thumb {
  width: 80px; height: 80px; border-radius: 10px; object-fit: cover;
  flex-shrink: 0; cursor: pointer; border: 2px solid var(--border);
}

/* ── Toggle / Switch ───────────────────────────────── */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0;
}
.toggle-label { font-size: .9rem; }
input[type=checkbox].toggle {
  width: 44px; height: 24px; appearance: none;
  background: var(--border); border-radius: 12px; cursor: pointer;
  position: relative; transition: background .2s;
}
input[type=checkbox].toggle:checked { background: var(--primary); }
input[type=checkbox].toggle::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: transform .2s;
}
input[type=checkbox].toggle:checked::after { transform: translateX(20px); }

/* ── Login ─────────────────────────────────────────── */
.login-bg {
  min-height: 100vh; background: linear-gradient(145deg, #1B4FD8, #6D28D9);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  background: #fff; border-radius: 24px; padding: 32px 24px; width: 100%; max-width: 400px;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 1.8rem; font-weight: 800; color: var(--primary); }
.login-logo p  { font-size: .85rem; color: var(--muted); }

/* ── Mis clases utilitarias ────────────────────────── */
.flex    { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8   { margin-top: 8px; }
.mt-12  { margin-top: 12px; }
.mt-16  { margin-top: 16px; }
.mb-12  { margin-bottom: 12px; }
.fw-bold { font-weight: 700; }
.text-sm { font-size: .82rem; }
.text-xs { font-size: .72rem; }
.text-muted { color: var(--muted); }
.text-center { text-align: center; }
.hidden { display: none !important; }

/* iOS PWA specific */
@media (display-mode: standalone) {
  .topbar { padding-top: calc(20px + var(--safe-top)); }
}
