/* ============================================
   QR-SCA - Diseño moderno con sidebar
   ============================================ */

:root {
  --sidebar-width: 260px;
  --sidebar-bg: #1a1d29;
  --sidebar-text: rgba(255, 255, 255, 0.85);
  --sidebar-hover: rgba(255, 255, 255, 0.1);
  --sidebar-active: #6366f1;
  --topbar-height: 56px;
  --footer-height: 48px;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.12);
}

/* Base */
html {
  font-size: 16px;
  position: relative;
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  -webkit-tap-highlight-color: transparent;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.app-body {
  display: flex;
  min-height: 100vh;
}

/* ========== SIDEBAR ========== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  z-index: 1030;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.sidebar-header {
  padding: 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.25rem;
}

.sidebar-brand i {
  font-size: 1.75rem;
  color: var(--sidebar-active);
}

.sidebar-toggle {
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  padding: 0.5rem;
  cursor: pointer;
  border-radius: 8px;
}

.sidebar-toggle:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--sidebar-text);
  border-radius: var(--radius);
  transition: background 0.2s, color 0.2s;
  min-height: 44px;
}

.sidebar-nav .nav-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-nav .nav-link.active {
  background: var(--sidebar-active);
  color: #fff;
}

.sidebar-nav .nav-link i {
  font-size: 1.25rem;
  width: 1.5rem;
  text-align: center;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-user-info i {
  font-size: 2rem;
  opacity: 0.9;
}

.sidebar-user-details {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-user-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.75rem;
  opacity: 0.7;
}

/* Overlay móvil */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1029;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-overlay.show {
  display: block;
  opacity: 1;
}

/* Móvil: sidebar oculto por defecto */
@media (max-width: 767.98px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.show {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
}

/* ========== MAIN WRAPPER ========== */
.main-wrapper {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

@media (max-width: 767.98px) {
  .main-wrapper {
    margin-left: 0;
  }
}

/* Topbar móvil */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: #fff;
  border-bottom: 1px solid #eee;
  min-height: var(--topbar-height);
}

.topbar-title {
  flex: 1;
  font-weight: 600;
  font-size: 1.1rem;
}

.topbar-logout {
  margin-left: auto;
}

.topbar-logout .btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Contenido principal */
.main-content {
  flex: 1;
  padding: 1.5rem;
  background: #f8fafc;
}

@media (max-width: 576px) {
  .main-content {
    padding: 1rem;
  }
}

/* Footer */
.main-footer {
  padding: 0.75rem 1.5rem;
  background: #fff;
  border-top: 1px solid #eee;
  font-size: 0.875rem;
  color: #64748b;
}

/* ========== CARDS MODERNAS ========== */
.card {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card-body {
  padding: 1.25rem;
}

.card-header {
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  padding: 1rem 1.25rem;
  font-weight: 600;
  color: #1e293b;
  border-radius: var(--radius) var(--radius) 0 0;
}

.card-module {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.card-module .card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card-module-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.card-module-icon.primary { background: rgba(99, 102, 241, 0.15); color: #6366f1; }
.card-module-icon.success { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.card-module-icon.warning { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.card-module-icon.info { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.card-module-icon.danger { background: rgba(239, 68, 68, 0.15); color: #ef4444; }

/* ========== BOTONES ========== */
.btn {
  min-height: 44px;
  border-radius: 10px;
  font-weight: 500;
}

.btn-sm { min-height: 38px; }

.btn-primary {
  background: var(--sidebar-active);
  border-color: var(--sidebar-active);
}

.btn-primary:hover {
  background: #4f46e5;
  border-color: #4f46e5;
}

.btn-outline-primary:hover {
  background: rgba(99, 102, 241, 0.1);
  border-color: var(--sidebar-active);
  color: var(--sidebar-active);
}

/* ========== TABLAS ========== */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: #fff;
}

.table {
  margin-bottom: 0;
}

.table thead th {
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
  border-bottom: 1px solid #e2e8f0;
  padding: 1rem;
}

.table tbody td {
  padding: 1rem;
  vertical-align: middle;
}

/* ========== FORMULARIOS ========== */
.form-control, .form-select {
  min-height: 44px;
  border-radius: 10px;
  border-color: #e2e8f0;
}

.form-control:focus, .form-select:focus {
  border-color: var(--sidebar-active);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* Inputs sin zoom en iOS */
@media screen and (max-width: 768px) {
  input[type="text"], input[type="password"], input[type="email"],
  input[type="number"], input[type="date"], select, textarea {
    font-size: 16px !important;
  }
}

/* ========== PÁGINAS ========== */
.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1, .page-header h2 {
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 0.25rem;
}

.page-header .text-muted {
  color: #64748b !important;
}

/* Input groups en móvil */
@media (max-width: 576px) {
  .input-group:not(.flex-column) {
    flex-wrap: wrap;
  }
  .input-group:not(.flex-column) .form-control {
    flex: 1 1 100%;
    border-radius: 10px;
  }
  .input-group:not(.flex-column) .btn {
    flex: 1 1 100%;
    margin-top: 0.5rem;
    border-radius: 10px;
  }
}

/* Video cámara */
#qr-video {
  width: 100%;
  max-height: 50vh;
  object-fit: cover;
  border-radius: var(--radius);
}

/* Focus visible */
.btn:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

/* ========== PÁGINA DE LOGIN ========== */
.auth-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1d29 0%, #2d3142 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.auth-wrapper {
  width: 100%;
  max-width: 420px;
}

.auth-page .card {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.auth-page .btn-primary {
  background: var(--sidebar-active);
  border-color: var(--sidebar-active);
}

/* Nav tabs (pase de lista) */
.nav-tabs {
  border-bottom: 2px solid #e2e8f0;
}

.nav-tabs .nav-link {
  border: none;
  color: #64748b;
  font-weight: 500;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius) var(--radius) 0 0;
}

.nav-tabs .nav-link:hover {
  color: var(--sidebar-active);
}

.nav-tabs .nav-link.active {
  color: var(--sidebar-active);
  background: transparent;
  border-bottom: 2px solid var(--sidebar-active);
  margin-bottom: -2px;
}
