/* ============================================================
   ASIST — Mobile-First Design System
   Estrategia: base = mobile, se expande con min-width
   ============================================================ */

/* ── Variables ───────────────────────────────────────────── */
:root {
  --primary:      #1e3a5f;
  --primary-lt:   #2a5298;
  --primary-dk:   #152b47;
  --accent:       #27ae60;
  --accent-lt:    #2ecc71;
  --danger:       #e74c3c;
  --warning:      #f39c12;
  --info:         #2980b9;
  --light:        #f5f7fa;
  --white:        #ffffff;
  --border:       #e2e8f0;
  --text:         #2d3748;
  --text-muted:   #718096;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 2px 12px rgba(0,0,0,.10);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.18);
  --topbar-h:     56px;
  --bottomnav-h:  64px;
  --sidebar-w:    260px;
  /* touch targets mínimo 44px */
  --touch:        44px;
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
  background: var(--light);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport */
  overscroll-behavior: none;
}
a { color: var(--primary-lt); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
input, select, textarea, button { font-family: inherit; }

/* ── Layout base (mobile) ────────────────────────────────── */
.layout { display: flex; min-height: 100vh; min-height: 100dvh; }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--primary);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem;
  position: sticky; top: 0; z-index: 200;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.topbar-brand {
  display: flex; align-items: center; gap: .5rem;
  color: #fff; font-weight: 700; font-size: 1.1rem;
}
.topbar-brand small { font-weight: 400; opacity: .7; font-size: .75rem; }
.topbar-right { display: flex; align-items: center; gap: .5rem; }

.btn-topbar {
  background: rgba(255,255,255,.12);
  border: none; border-radius: var(--radius-sm);
  color: #fff; cursor: pointer;
  width: var(--touch); height: var(--touch);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
  text-decoration: none;
}
.btn-topbar:hover { background: rgba(255,255,255,.22); color: #fff; text-decoration: none; }

/* ── Sidebar drawer (mobile) ─────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--primary);
  z-index: 300;
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 299;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex; align-items: center; justify-content: space-between;
  min-height: var(--topbar-h);
}
.sidebar-header .brand {
  display: flex; align-items: center; gap: .5rem;
  color: #fff; font-weight: 700; font-size: 1.1rem;
}
.sidebar-close {
  background: rgba(255,255,255,.1); border: none;
  color: #fff; border-radius: var(--radius-sm);
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

.sidebar-user {
  padding: 1rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-user .user-name { color: #fff; font-weight: 600; font-size: .95rem; }
.sidebar-user .user-role {
  color: rgba(255,255,255,.5); font-size: .78rem;
  text-transform: capitalize; margin-top: .1rem;
}

.sidebar-nav { flex: 1; padding: .5rem 0; }
.nav-section {
  padding: .75rem 1.1rem .25rem;
  font-size: .68rem; text-transform: uppercase;
  letter-spacing: .09em; color: rgba(255,255,255,.35);
}
.sidebar-nav a {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1.1rem;
  color: rgba(255,255,255,.8);
  font-size: .95rem;
  min-height: var(--touch);
  transition: background .15s;
  border-radius: 0;
}
.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255,255,255,.12);
  color: #fff; text-decoration: none;
}
.sidebar-nav a.active {
  border-right: 3px solid var(--accent);
}
.sidebar-nav a i { flex-shrink: 0; width: 20px; height: 20px; }

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,.1);
}
.sidebar-logout {
  display: flex; align-items: center; gap: .5rem;
  color: rgba(255,255,255,.7); font-size: .875rem;
  background: none; border: none; cursor: pointer;
  padding: .5rem 0; width: 100%;
  min-height: var(--touch);
  text-decoration: none;
}
.sidebar-logout:hover { color: #fff; text-decoration: none; }

/* ── Main content ────────────────────────────────────────── */
.main-wrap {
  flex: 1;
  display: flex; flex-direction: column;
  width: 100%;
  /* espacio para bottom nav en mobile */
  padding-bottom: var(--bottomnav-h);
}

/* ── Bottom Nav (mobile) ─────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottomnav-h);
  background: var(--white);
  border-top: 1px solid var(--border);
  display: flex; align-items: stretch;
  z-index: 190;
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .2rem;
  color: var(--text-muted);
  font-size: .65rem;
  text-decoration: none;
  transition: color .15s;
  padding: .5rem .25rem;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav a i { width: 22px; height: 22px; }
.bottom-nav a.active { color: var(--primary-lt); }
.bottom-nav a.active i { stroke: var(--primary-lt); }
.bottom-nav a.scan-btn {
  color: #fff;
  background: var(--primary-lt);
  border-radius: 14px;
  margin: .4rem .25rem;
  flex: 1.2;
}
.bottom-nav a.scan-btn.active { background: var(--primary); }

/* ── Page content ────────────────────────────────────────── */
.page-content {
  padding: 1rem;
  flex: 1;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  overflow: hidden;
}
.card-header {
  padding: .875rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; font-size: .95rem;
  gap: .5rem;
}
.card-body { padding: 1rem; }

/* ── Stats grid ──────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .75rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  display: flex; flex-direction: column;
}
.stat-card .stat-label { font-size: .75rem; color: var(--text-muted); margin-bottom: .25rem; }
.stat-card .stat-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); line-height: 1; }
.stat-card.green .stat-value { color: var(--accent); }
.stat-card.red   .stat-value { color: var(--danger); }
.stat-card.blue  .stat-value { color: var(--info); }
.stat-card .stat-icon {
  margin-bottom: .5rem;
  color: var(--text-muted);
  opacity: .5;
}

/* ── Botones ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1rem;
  border: none; border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 500;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
  min-height: var(--touch);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn:hover  { opacity: .88; text-decoration: none; }
.btn-primary   { background: var(--primary-lt); color: #fff; }
.btn-success   { background: var(--accent);     color: #fff; }
.btn-danger    { background: var(--danger);      color: #fff; }
.btn-warning   { background: var(--warning);     color: #fff; }
.btn-secondary { background: #6c757d;            color: #fff; }
.btn-outline   { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-sm  { padding: .4rem .75rem; font-size: .8rem; min-height: 36px; }
.btn-lg  { padding: .85rem 1.5rem; font-size: 1rem; min-height: 52px; }
.btn-block { width: 100%; }
.btn-icon { width: var(--touch); height: var(--touch); padding: 0; border-radius: var(--radius-sm); }

/* ── Tablas → Cards en mobile ────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th, td { padding: .7rem .85rem; text-align: left; }
th { background: var(--light); font-weight: 600; border-bottom: 2px solid var(--border); font-size: .8rem; }
tr:not(:last-child) td { border-bottom: 1px solid var(--border); }
tr:hover td { background: #f0f4ff; }

/* Card-rows: convierte filas en tarjetas en pantallas chicas */
.card-rows thead { display: none; }
.card-rows tbody tr {
  display: block;
  padding: .875rem 1rem;
  border-bottom: 1px solid var(--border);
}
.card-rows tbody tr:last-child { border-bottom: none; }
.card-rows td {
  display: flex; justify-content: space-between; align-items: center;
  padding: .2rem 0;
  font-size: .875rem;
}
.card-rows td::before {
  content: attr(data-label);
  font-weight: 600;
  color: var(--text-muted);
  font-size: .75rem;
  flex-shrink: 0;
  margin-right: .75rem;
}
.card-rows td:last-child { margin-top: .5rem; justify-content: flex-end; }
.card-rows td:last-child::before { display: none; }

/* ── Formularios ─────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block; font-size: .875rem;
  font-weight: 600; margin-bottom: .4rem;
}
.form-control {
  width: 100%; padding: .7rem .875rem;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 1rem; /* 16px evita zoom en iOS */
  background: #fff; color: var(--text);
  transition: border-color .15s;
  min-height: var(--touch);
  appearance: none;
  -webkit-appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary-lt);
  box-shadow: 0 0 0 3px rgba(42,82,152,.15);
}
select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23718096' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .875rem center;
  padding-right: 2.5rem;
}
.form-grid { display: grid; grid-template-columns: 1fr; gap: .75rem; }
.form-row  { display: flex; gap: .75rem; }
.form-row .form-group { flex: 1; }

/* ── Alertas flash ───────────────────────────────────────── */
.alert {
  padding: .875rem 1rem; border-radius: var(--radius-sm);
  margin-bottom: .875rem; font-size: .875rem;
  display: flex; align-items: flex-start; gap: .5rem;
  border-left: 4px solid transparent;
}
.alert-success { background: #d4edda; color: #155724; border-color: var(--accent); }
.alert-error,
.alert-danger  { background: #f8d7da; color: #721c24; border-color: var(--danger); }
.alert-warning { background: #fff3cd; color: #856404; border-color: var(--warning); }
.alert-info    { background: #d1ecf1; color: #0c5460; border-color: var(--info); }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: .25em .6em;
  border-radius: 20px; font-size: .73rem; font-weight: 600;
  white-space: nowrap;
}
.badge-success   { background: #d4edda; color: #155724; }
.badge-danger    { background: #f8d7da; color: #721c24; }
.badge-warning   { background: #fff3cd; color: #856404; }
.badge-secondary { background: #e2e8f0; color: #4a5568; }
.badge-dark      { background: #cbd5e0; color: #2d3748; }

/* ── Búsqueda ────────────────────────────────────────────── */
.search-bar { display: flex; gap: .5rem; margin-bottom: 1rem; }
.search-bar .form-control { flex: 1; }

/* ── Scanner QR ──────────────────────────────────────────── */
.scanner-container { max-width: 520px; margin: 0 auto; }
#qr-video { width: 100%; border-radius: var(--radius); display: block; }
.scanner-overlay {
  position: relative; background: #000;
  border-radius: var(--radius); overflow: hidden;
  border: 3px solid var(--primary-lt);
}
.scan-line {
  position: absolute; top: 0; left: 0; right: 0;
  height: 3px; background: var(--accent);
  animation: scanAnim 2s linear infinite;
}
@keyframes scanAnim { 0%{top:0} 100%{top:calc(100% - 3px)} }
.scan-result {
  margin-top: .875rem; padding: 1rem; border-radius: var(--radius);
  font-size: 1rem; font-weight: 600; text-align: center; transition: all .3s;
}
.scan-result.ok      { background: #d4edda; color: #155724; }
.scan-result.error   { background: #f8d7da; color: #721c24; }
.scan-result.warning { background: #fff3cd; color: #856404; }

/* ── QR Card ─────────────────────────────────────────────── */
.qr-card {
  display: inline-block; border: 2px solid var(--border);
  border-radius: var(--radius); padding: 1rem; text-align: center;
  background: #fff; box-shadow: var(--shadow);
}
.qr-card .qr-name { font-weight: 700; font-size: .95rem; margin-top: .5rem; }
.qr-card .qr-sub  { font-size: .78rem; color: var(--text-muted); }

/* ── Paginación ──────────────────────────────────────────── */
.pagination { display: flex; gap: .3rem; margin-top: 1rem; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: .45rem .8rem; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); font-size: .85rem; color: var(--text);
  min-height: 40px; display: flex; align-items: center;
}
.pagination a:hover   { background: var(--light); text-decoration: none; }
.pagination .active   { background: var(--primary-lt); color: #fff; border-color: var(--primary-lt); }
.pagination .disabled { opacity: .5; pointer-events: none; }

/* ── Acciones inline (botones en tabla) ──────────────────── */
.row-actions { display: flex; gap: .375rem; flex-wrap: wrap; justify-content: flex-end; }

/* ── Helpers ─────────────────────────────────────────────── */
.mt-1 { margin-top: .5rem; }   .mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }.mb-2 { margin-bottom: 1rem; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); font-size: .85rem; }
.d-flex      { display: flex; }
.align-center{ align-items: center; }
.gap-1 { gap: .5rem; } .gap-2 { gap: 1rem; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }

/* ── Divider ─────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 400;
  align-items: flex-end; /* bottom sheet en mobile */
  backdrop-filter: blur(2px);
}
.modal-backdrop.show { display: flex; }
.modal-sheet {
  background: #fff; border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.25rem 1rem 2rem;
  width: 100%; max-height: 90vh; overflow-y: auto;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from{transform:translateY(100%)} to{transform:translateY(0)} }
.modal-handle {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--border); margin: 0 auto .875rem;
}
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 1rem; }

/* ══════════════════════════════════════════════════════════
   DESKTOP — min-width: 768px
   ══════════════════════════════════════════════════════════ */
@media (min-width: 768px) {

  /* Sidebar fijo, siempre visible */
  .sidebar {
    transform: none !important;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    box-shadow: 2px 0 12px rgba(0,0,0,.12);
  }
  .sidebar-overlay { display: none !important; }

  /* Main desplazada */
  .main-wrap {
    margin-left: var(--sidebar-w);
    padding-bottom: 0;
  }

  /* Topbar desktop */
  .topbar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 0 1.5rem;
  }
  .topbar-brand { color: var(--text); }
  .topbar-brand i { color: var(--primary) !important; }
  .btn-hamburger { display: none; }
  .btn-topbar {
    background: transparent;
    color: var(--text-muted);
  }
  .btn-topbar:hover { background: var(--light); color: var(--text); }

  /* Sin bottom nav */
  .bottom-nav { display: none; }

  /* Contenido más espacioso */
  .page-content { padding: 1.5rem; }

  /* Stats: 4 columnas */
  .stats-grid { grid-template-columns: repeat(4, 1fr); gap: 1rem; }

  /* Formulario en grid */
  .form-grid { grid-template-columns: repeat(2, 1fr); gap: 1rem; }

  /* Tablas normales (sin card-rows override) */
  .card-rows thead { display: table-header-group; }
  .card-rows tbody tr { display: table-row; padding: 0; border-bottom: none; }
  .card-rows td { display: table-cell; padding: .7rem .85rem; }
  .card-rows td::before { display: none; }
  .card-rows td:last-child { margin-top: 0; justify-content: flex-start; }

  /* Modal centrado en desktop */
  .modal-backdrop { align-items: center; }
  .modal-sheet {
    border-radius: var(--radius);
    max-width: 480px;
    max-height: 80vh;
    margin: auto;
  }
  .modal-handle { display: none; }

  /* Topbar title */
  .topbar-title { font-size: 1rem; font-weight: 600; color: var(--text); }
}

@media (min-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .form-grid  { grid-template-columns: repeat(3, 1fr); }
  .page-content { padding: 2rem; }
}
