/* Estilos Globales - Suite Vitalia Palma del Río - Gestión e Inventario */
:root {
  --primary: #1b5e20;
  --primary-light: #2e7d32;
  --primary-dark: #003300;
  --accent: #c5a059;
  --accent-light: #dfba73;
  --bg-main: #f4f6f8;
  --bg-card: #ffffff;
  --text-dark: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --border-focus: #2e7d32;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0284c7;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition: all 0.2s ease-in-out;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-dark);
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
}

/* ==========================================================================
   PORTAL DE ACCESO (LOGIN GATE) - Ocultación Total Previa
   ========================================================================== */
#login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0d3b13 0%, #1b5e20 50%, #2e7d32 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999999;
  padding: 1rem;
}

.login-card {
  background: #ffffff;
  width: 100%;
  max-width: 440px;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  padding: 2.25rem 2rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: fadeInDown 0.3s ease-out;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-badge {
  display: inline-block;
  background: #e8f5e9;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  margin-bottom: 0.75rem;
  border: 1px solid #c8e6c9;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 0.4rem;
}

.login-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.form-group {
  margin-bottom: 1.25rem;
  text-align: left;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0.5rem;
}

.input-password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.form-input {
  width: 100%;
  height: 46px;
  padding: 0 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 1rem;
  color: var(--text-dark);
  background-color: #f9fafb;
  transition: var(--transition);
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.15);
}

.btn-toggle-pwd {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  color: #4b5563;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  user-select: none;
}
.btn-toggle-pwd:hover {
  opacity: 0.8;
}

.btn-primary {
  width: 100%;
  height: 48px;
  background-color: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  background-color: var(--primary-light);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.login-alert {
  display: none;
  padding: 0.75rem 1rem;
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
}

/* ==========================================================================
   ESTRUCTURA PRINCIPAL DE LA APLICACIÓN (OCULTA INICIALMENTE)
   ========================================================================== */
#app-layout {
  display: none !important;
  min-height: 100vh;
  flex-direction: column;
}

#app-layout.authenticated {
  display: flex !important;
}

/* Cabecera Superior */
.top-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo-badge {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  box-shadow: 0 4px 6px rgba(27, 94, 32, 0.25);
}

.brand-info h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #111827;
  line-height: 1.2;
}

.brand-info p {
  font-size: 0.775rem;
  color: var(--text-muted);
}

.user-profile-bar {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

/* Simulador de Roles en Cabecera (Pilar 10) */
.role-simulator-box {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: #f3f4f6;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.role-simulator-box label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #4b5563;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.role-simulator-select {
  height: 30px;
  font-size: 0.775rem;
  font-weight: 600;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background-color: #ffffff;
  color: var(--primary);
  outline: none;
  cursor: pointer;
  padding: 0 0.4rem;
}

.user-badge-tag {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.user-tag-name {
  font-size: 0.875rem;
  font-weight: 700;
  color: #1f2937;
}

.user-tag-role {
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  display: inline-block;
}

.role-superadmin { background: #fee2e2; color: #991b1b; }
.role-tutores { background: #fef3c7; color: #92400e; }
.role-familiares { background: #dbeafe; color: #1e40af; }
.role-residencia { background: #dcfce7; color: #166534; }
.role-residente { background: #fae8ff; color: #86198f; font-weight: 700; border: 1px solid #f0abfc; }

.btn-header-action {
  height: 38px;
  padding: 0 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #ffffff;
  color: #374151;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition);
}

.btn-header-action:hover {
  background-color: #f3f4f6;
  border-color: #d1d5db;
}

.btn-logout {
  color: #dc2626;
  border-color: #fecaca;
  background-color: #fff5f5;
}

.btn-logout:hover {
  background-color: #fee2e2;
  border-color: #fca5a5;
}

/* Navegación por Pestañas Superior */
.main-nav-bar {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}

.nav-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  gap: 0.5rem;
}

.nav-tab-btn {
  padding: 0.85rem 1.15rem;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 0.925rem;
  font-weight: 600;
  color: #4b5563;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition);
}

.nav-tab-btn:hover {
  color: var(--primary);
  background-color: #f9fafb;
}

.nav-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 700;
}

/* Área de Contenido Principal */
.main-content {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem 1.25rem;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.2s ease-in-out;
}

.tab-pane.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ==========================================================================
   ESTÁNDAR UNIVERSAL DE BÚSQUEDA Y FILTRADO (Componente search-card-advanced)
   ========================================================================== */
.search-card-advanced {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.search-primary-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.search-input-box {
  flex: 1;
  min-width: 260px;
  position: relative;
}

.search-input-box input {
  width: 100%;
  height: 44px;
  padding: 0 1rem 0 2.5rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  color: var(--text-dark);
}

.search-input-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.15);
}

.search-icon-inside {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  pointer-events: none;
}

.search-mode-options {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 0.5rem;
  flex-wrap: wrap;
}

.search-mode-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.825rem;
  color: #4b5563;
  cursor: pointer;
}

.search-mode-label input[type="radio"] {
  accent-color: var(--primary);
}

.search-controls-secondary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #f3f4f6;
}

.search-scope-checkboxes {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.scope-chk-label {
  font-size: 0.825rem;
  color: #4b5563;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.scope-chk-label input[type="checkbox"] {
  accent-color: var(--primary);
}

.search-sort-dropdown {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.select-clean {
  height: 38px;
  padding: 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: #ffffff;
  font-size: 0.85rem;
  color: #374151;
  outline: none;
  cursor: pointer;
}

.select-clean:focus {
  border-color: var(--primary);
}

/* Píldoras de Filtro Rápido (Pill Tabs) */
.pill-filter-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow-x: auto;
  white-space: nowrap;
  padding: 0.5rem 0 1rem 0;
  -webkit-overflow-scrolling: touch;
}

.pill-tab {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 0.45rem 1rem;
  font-size: 0.825rem;
  font-weight: 600;
  color: #4b5563;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition);
}

.pill-tab:hover {
  background: #f9fafb;
  border-color: #d1d5db;
}

.pill-tab.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 2px 4px rgba(27, 94, 32, 0.2);
}

.pill-count {
  background: rgba(0, 0, 0, 0.08);
  font-size: 0.725rem;
  padding: 0.1rem 0.4rem;
  border-radius: 9999px;
}

.pill-tab.active .pill-count {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

/* Barra de Acciones del Módulo */
.section-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.section-title-wrap h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #111827;
}

.section-title-wrap p {
  font-size: 0.825rem;
  color: var(--text-muted);
}

.toolbar-buttons {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.btn-secondary {
  height: 40px;
  padding: 0 1rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: #374151;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: #f9fafb;
  border-color: #d1d5db;
}

.btn-accent {
  height: 40px;
  padding: 0 1.15rem;
  background: linear-gradient(135deg, #1b5e20, #2e7d32);
  border: none;
  border-radius: var(--radius-md);
  color: #ffffff;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.btn-accent:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}

.btn-danger {
  height: 38px;
  padding: 0 0.85rem;
  background: #fee2e2;
  color: #dc2626;
  border: 1px solid #fca5a5;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-danger:hover {
  background: #fecaca;
}

/* ==========================================================================
   TABLA DE DATOS ESTÁNDAR Y RESPONSIVE
   ========================================================================== */
.table-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table-responsive-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.data-table th {
  background: #f9fafb;
  padding: 0.85rem 1rem;
  font-weight: 700;
  color: #374151;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

.data-table th.sortable {
  cursor: pointer;
  transition: var(--transition);
}

.data-table th.sortable:hover {
  background: #f3f4f6;
  color: var(--primary);
}

.sort-icon {
  margin-left: 0.35rem;
  font-size: 0.75rem;
  color: #9ca3af;
}

.sort-active .sort-icon {
  color: var(--primary);
  font-weight: 800;
}

.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

.item-thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
}

.item-thumb:hover {
  transform: scale(1.08);
  box-shadow: var(--shadow-md);
}

.badge-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #f3f4f6;
  color: #1f2937;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 700;
}

.badge-cat {
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #e0f2fe;
  color: #0369a1;
}

.badge-status-ok {
  background: #dcfce7;
  color: #15803d;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-perm-yes {
  background: #ecfdf5;
  color: #047857;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-perm-no {
  background: #fef2f2;
  color: #b91c1c;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.table-row-actions {
  display: flex;
  gap: 0.35rem;
}

.btn-icon-action {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  transition: var(--transition);
}

.btn-icon-action:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

/* Paginación Dinámica Inteligente */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: #f9fafb;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 1rem;
}

.pagination-info {
  font-size: 0.85rem;
  color: #4b5563;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-page-step {
  height: 34px;
  min-width: 34px;
  padding: 0 0.5rem;
  border: 1px solid var(--border);
  background: #ffffff;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-page-step:hover:not(:disabled) {
  background: #f3f4f6;
  border-color: #d1d5db;
}

.btn-page-step:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.page-indicator-text {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0 0.5rem;
  color: #374151;
}

.pagination-size-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: #4b5563;
}

/* ==========================================================================
   VISTA DE CUADRÍCULA / GALERÍA DE FOTOS (Responsive Grid)
   ========================================================================== */
.cards-grid-layout {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 1.25rem;
}

.item-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: var(--transition);
}

.item-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

.item-card-media {
  position: relative;
  width: 100%;
  height: 200px;
  background: #f1f5f9;
  cursor: pointer;
  overflow: hidden;
}

.item-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.item-card:hover .item-card-media img {
  transform: scale(1.05);
}

.badge-card-code {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(17, 24, 39, 0.8);
  backdrop-filter: blur(4px);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
}

.item-card-body {
  padding: 1.15rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.item-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 0.35rem;
  line-height: 1.3;
}

.item-card-desc {
  font-size: 0.825rem;
  color: #4b5563;
  margin-bottom: 0.85rem;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-card-meta {
  font-size: 0.775rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  border-top: 1px solid #f3f4f6;
  padding-top: 0.65rem;
  margin-bottom: 0.85rem;
}

.item-card-actions {
  display: flex;
  gap: 0.5rem;
}

/* Lista de Documentos Anexos */
.doc-attachments-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.doc-attachment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.825rem;
}

.doc-info-part {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
}

.doc-icon {
  font-size: 1.2rem;
}

.doc-filename {
  font-weight: 600;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-filesize {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ==========================================================================
   MODALES Y VISUALIZADOR DE FOTOS
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100000;
  padding: 1rem;
}

.modal-backdrop.open {
  display: flex;
}

.modal-dialog {
  background: #ffffff;
  border-radius: var(--radius-lg);
  max-width: 650px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalScale 0.2s ease-out;
}

@keyframes modalScale {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: #111827;
}

.btn-close-modal {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #9ca3af;
  line-height: 1;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: #f9fafb;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Visor de Foto a Pantalla Completa */
#photo-viewer-modal .modal-dialog {
  max-width: 800px;
  background: #000000;
  color: #ffffff;
  text-align: center;
  overflow: hidden;
}

#photo-viewer-modal .modal-header {
  border-bottom: 1px solid #333333;
}

#photo-viewer-modal .modal-title {
  color: #ffffff;
}

.photo-viewer-img {
  max-width: 100%;
  max-height: 65vh;
  object-fit: contain;
  margin: 0 auto;
  display: block;
}

/* ==========================================================================
   MÓDULO DE COMUNICACIONES / MENSAJERÍA RESIDENCIA-FAMILIARES
   ========================================================================== */
.comm-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  min-height: 580px;
}

.comm-threads-sidebar {
  border-right: 1px solid var(--border);
  background: #f9fafb;
  display: flex;
  flex-direction: column;
}

.comm-sidebar-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.comm-thread-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
}

.comm-thread-item {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
}

.comm-thread-item:hover {
  background: #f1f5f9;
}

.comm-thread-item.active {
  background: #ffffff;
  border-left: 4px solid var(--primary);
}

.thread-subject {
  font-size: 0.925rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 0.25rem;
}

.thread-preview {
  font-size: 0.8rem;
  color: #6b7280;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.thread-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 0.35rem;
  font-size: 0.725rem;
  color: #9ca3af;
}

.comm-chat-area {
  display: flex;
  flex-direction: column;
}

.comm-chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.comm-messages-stream {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: #fafafa;
}

.msg-bubble {
  max-width: 75%;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.4;
  position: relative;
}

.msg-sent {
  align-self: flex-end;
  background: #dcfce7;
  border: 1px solid #bbf7d0;
  color: #14532d;
}

.msg-received {
  align-self: flex-start;
  background: #ffffff;
  border: 1px solid var(--border);
  color: #1f2937;
}

.msg-sender {
  font-weight: 700;
  font-size: 0.75rem;
  margin-bottom: 0.25rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.comm-reply-box {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: #ffffff;
  display: flex;
  gap: 0.75rem;
}

/* ==========================================================================
   ADAPTATIVO / MOBILE NAVIGATION (S24 Ultra y Smartphones)
   ========================================================================== */
.bottom-nav-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  z-index: 9999;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-inner {
  display: flex;
  justify-content: space-around;
  padding: 0.35rem 0.5rem;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  background: none;
  border: none;
  font-size: 0.7rem;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  flex: 1;
}

.bottom-nav-item.active {
  color: var(--primary);
  font-weight: 700;
}

.bottom-nav-icon {
  font-size: 1.25rem;
}

@media (max-width: 960px) {
  .comm-layout {
    grid-template-columns: 1fr;
  }
  .main-nav-bar {
    display: none;
  }
  .bottom-nav-bar {
    display: block;
  }
  .main-content {
    padding-bottom: 5.5rem;
  }
  .role-simulator-box {
    display: none;
  }
}

/* Elevación del Visor de Fotografías sobre cualquier otro modal activo */
#photo-viewer-modal {
  z-index: 100050 !important;
}


/* ==========================================================================
   DISEÑO WEB 100% ADAPTATIVO Y RESPONSIVE (Móvil, Tablet, Galaxy S24 Ultra y PC)
   ========================================================================== */

/* Botón hamburguesa móvil */
.btn-mobile-menu {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.4rem 0.65rem;
  color: var(--text-dark);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  transition: var(--transition);
}
.btn-mobile-menu:hover {
  background-color: #f3f4f6;
  border-color: #cbd5e1;
}

/* Cajón Lateral Móvil (Drawer) */
.mobile-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 100010;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.mobile-drawer-overlay.open {
  display: block;
  opacity: 1;
}

.mobile-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(85vw, 320px);
  background: #ffffff;
  z-index: 100020;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.mobile-drawer.open {
  transform: translateX(0);
}

.mobile-drawer-header {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
}

.btn-close-drawer {
  background: none;
  border: none;
  font-size: 1.75rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-drawer-user-info {
  padding: 0.85rem 1rem;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mobile-drawer-nav {
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.drawer-nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  color: #374151;
  text-align: left;
  cursor: pointer;
  min-height: 44px;
  transition: var(--transition);
}
.drawer-nav-item:hover {
  background-color: #f1f5f9;
  color: var(--primary);
}
.drawer-nav-item.active {
  background-color: #e8f5e9;
  color: var(--primary);
  font-weight: 700;
}
.btn-drawer-logout {
  color: #dc2626 !important;
}
.btn-drawer-logout:hover {
  background-color: #fee2e2 !important;
}

/* Reglas Adaptativas Generales */
@media (max-width: 960px) {
  .btn-mobile-menu {
    display: inline-flex;
  }
  .main-nav-bar {
    display: none !important;
  }
  .bottom-nav-bar {
    display: block !important;
  }
  .main-content {
    padding: 1rem 0.75rem 5.5rem 0.75rem;
  }
  .comm-layout {
    grid-template-columns: 1fr;
    min-height: 500px;
  }
  .role-simulator-box {
    display: none;
  }
  .hide-mobile {
    display: none !important;
  }
}

@media (max-width: 768px) {
  .header-container {
    padding: 0.5rem 0.75rem;
  }
  .brand-logo-badge {
    width: 38px;
    height: 38px;
    font-size: 1.2rem;
  }
  .brand-info h1 {
    font-size: 1rem;
  }
  .brand-info p {
    font-size: 0.7rem;
  }
  .section-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  .toolbar-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.5rem;
    width: 100%;
  }
  .toolbar-buttons .btn-accent,
  .toolbar-buttons .btn-secondary {
    width: 100%;
    justify-content: center;
    padding: 0 0.5rem;
    font-size: 0.8rem;
    text-align: center;
  }
  .search-controls-secondary {
    flex-direction: column;
    align-items: stretch;
  }
  .search-scope-checkboxes {
    justify-content: flex-start;
  }
  .pagination-bar {
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    text-align: center;
  }
  .cards-grid-layout {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
    gap: 0.85rem;
  }
  .modal-dialog {
    max-width: 95vw !important;
    margin: 0.5rem auto;
    max-height: 94vh;
  }
  .modal-header, .modal-body, .modal-footer {
    padding: 1rem;
  }
  /* Prevenir zoom brusco en móviles fijando font-size a 16px */
  input.form-input, select.form-input, textarea.form-input {
    font-size: 16px !important;
    min-height: 44px;
  }
}

@media (max-width: 480px) {
  .search-input-box {
    min-width: 100%;
  }
  .brand-info p {
    display: none;
  }
  .user-badge-tag {
    display: none;
  }
  .bottom-nav-item span:not(.bottom-nav-icon) {
    font-size: 0.65rem;
  }
  .bottom-nav-icon {
    font-size: 1.15rem;
  }
  .btn-primary, .btn-secondary, .btn-accent {
    min-height: 44px;
  }
}

@media (max-width: 360px) {
  .header-container {
    padding: 0.4rem 0.5rem;
  }
  .brand-info h1 {
    font-size: 0.9rem;
  }
  .bottom-nav-item {
    padding: 0.25rem 0.2rem;
  }
  .bottom-nav-item span:not(.bottom-nav-icon) {
    font-size: 0.6rem;
  }
}


/* Responsive para el Modal de Lote de Visita */
.visit-item-body-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
}

.visit-item-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.visit-item-photos-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.visit-item-thumbnails-wrap {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 300px;
}

@media (max-width: 768px) {
  .visit-item-body-grid {
    grid-template-columns: 1fr !important;
  }
  .visit-item-fields-grid {
    grid-template-columns: 1fr !important;
  }
  .visit-item-thumbnails-wrap {
    max-width: 100% !important;
    justify-content: center;
  }
  .visit-item-photos-container {
    align-items: center;
    text-align: center;
  }
}


/* ==========================================================================
   ERGONOMÍA Y USABILIDAD MÓVIL AVANZADA (Mobile First - S24 Ultra & Tablets)
   ========================================================================== */

/* Botón de Acción Rápida Flotante (FAB) para Móvil */
.mobile-fab-btn {
  display: none;
  position: fixed;
  bottom: calc(65px + env(safe-area-inset-bottom, 0px));
  right: 18px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1b5e20, #2e7d32);
  color: #ffffff;
  border: none;
  box-shadow: 0 4px 14px rgba(27, 94, 32, 0.45);
  font-size: 1.6rem;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.mobile-fab-btn:active {
  transform: scale(0.92);
}

/* Acordeón de Filtros Avanzados Colapsables en Móvil */
.btn-toggle-advanced-filters {
  display: none;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  justify-content: center;
  margin-top: 0.5rem;
}

/* Modales en Móvil estilo Bottom Sheet / Full-Screen */
@media (max-width: 640px) {
  .mobile-fab-btn {
    display: flex;
  }
  .btn-toggle-advanced-filters {
    display: flex;
  }
  .search-collapsible-content {
    display: none;
    padding-top: 0.75rem;
  }
  .search-collapsible-content.open {
    display: block;
  }

  /* Modales a Pantalla Completa en Móviles */
  .modal-backdrop {
    padding: 0 !important;
    align-items: flex-end !important;
  }
  .modal-dialog {
    max-width: 100vw !important;
    width: 100vw !important;
    height: 94vh !important;
    max-height: 94vh !important;
    margin: 0 !important;
    border-radius: 20px 20px 0 0 !important;
    display: flex !important;
    flex-direction: column !important;
    animation: slideUpModal 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }
  @keyframes slideUpModal {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .modal-header {
    padding: 1rem 1.25rem !important;
    position: sticky;
    top: 0;
    background: #ffffff;
    z-index: 10;
    border-bottom: 1.5px solid var(--border);
  }
  .modal-body {
    flex: 1 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 1.15rem 1rem 2rem 1rem !important;
  }
  .modal-footer {
    position: sticky;
    bottom: 0;
    background: #ffffff;
    border-top: 1.5px solid var(--border);
    padding: 0.85rem 1rem calc(0.85rem + env(safe-area-inset-bottom, 0px)) 1rem !important;
    z-index: 10;
    display: flex;
    gap: 0.5rem;
  }
  .modal-footer button {
    flex: 1;
    min-height: 46px;
    font-size: 0.9rem;
    justify-content: center;
  }

  /* Vista de tarjetas en móvil */
  .item-card {
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  }
  .item-card-media {
    height: 180px;
  }

  /* Scroll táctil horizontal para chips y filtros */
  .pill-filter-container {
    padding-bottom: 0.5rem;
    scrollbar-width: none;
  }
  .pill-filter-container::-webkit-scrollbar {
    display: none;
  }
  .pill-tab {
    padding: 0.5rem 0.9rem;
    font-size: 0.825rem;
    min-height: 38px;
  }

  /* Visor de fotos táctil a pantalla completa */
  #photo-viewer-modal .modal-dialog {
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    background: #000000 !important;
  }
  #photo-viewer-modal .photo-viewer-img {
    max-height: 75vh;
  }
  
  /* Paginación ergonómica móvil */
  .pagination-bar {
    padding: 0.75rem 0.5rem;
  }
  .pagination-controls {
    width: 100%;
    justify-content: space-between;
  }
  .btn-page-step {
    min-height: 42px;
    min-width: 42px;
  }
  .pagination-size-selector {
    display: none;
  }
}
