/* ==========================================
   1. RESET Y VARIABLES GLOBALES
   ========================================== */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #64748b;
  --success: #10b981;
  --success-hover: #059669;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --background: #f8fafc;
  --surface: #ffffff;
  --sidebar-bg: #1e293b;
  --sidebar-active: #0f172a;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
}

/* Candado global: La pantalla entera NUNCA se desplaza horizontalmente */
html,
body {
  width: 100%;
  max-width: 100vw;
  height: 100%;
  overflow-x: hidden !important;
}

body {
  display: flex;
  min-height: 100vh;
  background-color: var(--background);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================
   2. ESTRUCTURA BASE (INDEX.PHP)
   ========================================== */

/* Menú Lateral */
.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: #ffffff;
  padding: 1.5rem 1rem;
  flex-shrink: 0;
  transition: var(--transition);
}

.sidebar-brand h2 {
  color: #ffffff;
  font-size: 1.4rem;
  text-align: center;
  margin-bottom: 2rem;
  font-weight: 700;
}

.sidebar-menu {
  list-style: none;
}

.sidebar-menu li {
  margin-bottom: 0.5rem;
}

.sidebar-menu a {
  display: block;
  color: #94a3b8;
  text-decoration: none;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  transition: var(--transition);
  font-weight: 500;
}

.sidebar-menu a:hover,
.sidebar-menu a.active {
  background: var(--sidebar-active);
  color: #ffffff;
}

/* Wrapper Principal: Restringido para no estirar la página */
.main-wrapper {
  flex: 1 1 0% !important;
  min-width: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  display: flex;
  flex-direction: column;
  overflow-x: hidden !important;
}

/* Barra Superior */
.topbar {
  background: var(--surface);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}

.btn-logout {
  background: var(--danger);
  color: #ffffff;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-logout:hover {
  background: var(--danger-hover);
}

/* Área Dinámica de Contenido (#main-content) */
.content,
#main-content {
  padding: 2rem;
  flex: 1 1 0% !important;
  min-width: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  overflow-x: hidden !important;
}

/* ==========================================
   3. AISLAMIENTO ABSOLUTO DE TABLAS (SPA JS)
   ========================================== */

/* Tarjetas o contenedores que envuelven la tabla */
.card-container,
.table-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  overflow: hidden !important;
}

/* Si usas un div envoltorio .table-responsive */
.table-responsive {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  display: block !important;
}

/* REGLA MAESTRA: Se aplica a CUALQUIER tabla inyectada por JS dentro de #main-content */
#main-content table,
.table-responsive table {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  /* El scroll horizontal se queda atrapado DENTRO de la tabla */
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
  -webkit-overflow-scrolling: touch;
}

#main-content thead,
#main-content tbody,
#main-content tr {
  display: table;
  width: 100%;
  table-layout: fixed;
}

/* Restablece las celdas para que mantengan su ancho según el contenido */
#main-content table {
  display: table !important;
  white-space: nowrap !important;
}

#main-content thead,
#main-content tbody,
#main-content tr {
  display: table-row !important;
}

/* Envoltorio forzado para asegurar aislamiento directo en la tabla */
#main-content table {
  display: block !important;
  overflow-x: auto !important;
  white-space: nowrap !important;
}

th,
td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
  vertical-align: middle;
  white-space: nowrap !important;
}

th {
  background-color: #f1f5f9;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background-color: #f8fafc;
}

table img {
  width: 45px;
  height: 45px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}

/* ==========================================
   4. FORMULARIOS E INPUTS
   ========================================== */
.module-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.module-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
}

.form-group {
  margin-bottom: 1.25rem;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: var(--surface);
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
  min-height: 44px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.form-row>div {
  flex: 1;
}

/* ==========================================
   5. BOTONES
   ========================================== */
.btn-primary,
.btn-success,
.btn-eliminar,
.btn-eliminar-noticia,
.btn-eliminar-pedimos,
.btn-eliminar-abandonado,
.btn-eliminar-logro,
.btn-eliminar-comite,
.btn-eliminar-galeria,
.btn-eliminar-usuario,
.btn-eliminar-contacto {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: var(--transition);
}

.btn-primary,
button[type="submit"] {
  background-color: var(--primary);
  color: #ffffff;
}

.btn-success {
  background-color: var(--success);
  color: #ffffff;
}

.btn-eliminar,
.btn-eliminar-noticia,
.btn-eliminar-pedimos,
.btn-eliminar-abandonado,
.btn-eliminar-logro,
.btn-eliminar-comite,
.btn-eliminar-galeria,
.btn-eliminar-usuario,
.btn-eliminar-contacto {
  background-color: var(--danger);
  color: #ffffff;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
}

/* ==========================================
   6. RESPONSIVE (MÓVILES Y TABLETS)
   ========================================== */
@media (max-width: 900px) {
  body {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    padding: 1rem;
  }

  .sidebar-brand h2 {
    margin-bottom: 0.75rem;
    font-size: 1.2rem;
  }

  .sidebar-menu {
    display: flex;
    overflow-x: auto;
    gap: 0.5rem;
    padding-bottom: 0.5rem;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-menu li {
    margin-bottom: 0;
    flex-shrink: 0;
  }

  .sidebar-menu a {
    padding: 0.5rem 0.85rem;
    font-size: 0.85rem;
    white-space: nowrap;
  }

  .topbar {
    padding: 0.85rem 1rem;
  }

  .content,
  #main-content {
    padding: 1rem;
  }
}

@media (max-width: 600px) {
  .module-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .card-container,
  .table-card {
    padding: 0.75rem;
  }

  button[type="submit"],
  .btn-primary,
  .btn-success {
    width: 100%;
    margin-top: 0.5rem;
  }
}
