/* Responsive styles for dashboard navigation */
@media (max-width: 768px) {
  /* make the header layout compact on mobile */
  .dashboard-header {
    flex-direction: column;
    align-items: stretch;
    position: relative;
    z-index: 10;
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* Mobile nav becomes a fixed overlay that slides down */
  .main-navigation {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100vw;
    max-width: 100vw;
    background: #ffffff;
    box-shadow: 0 6px 18px rgba(20,20,40,0.12);
    z-index: 9998;
    transform: translateY(-120%);
    transition: transform 0.28s cubic-bezier(.2,.9,.2,1);
    display: block;
    padding-bottom: 1rem;
    /* allow clicks only when visible */
    pointer-events: auto;
    box-sizing: border-box;
  }

  /* when expanded, slide into view */
  .main-navigation.nav-expanded {
    transform: translateY(0);
  }

  .nav-tabs {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem 0.75rem;
  }

  .nav-tab {
    justify-content: flex-start;
    padding: 0.9rem 0.75rem;
    font-size: 1.05rem;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    /* allow the text to wrap nicely and align icon at left */
    white-space: normal;
    text-align: left;
  }

  .nav-actions {
    flex-direction: column;
    gap: 0.5rem;
    margin: 1rem 0.75rem 0.5rem;
  }

  .header-main {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    max-width: 100%;
    box-sizing: border-box;
  }

  #dashboard-section {
    min-width: 0;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    overflow-x: hidden;
  }
  
  /* Asegurar que las tablas no se salgan del viewport */
  .content-area {
    overflow-x: hidden;
    max-width: 100%;
    width: 100%;
  }
  
  /* Wrapper para scroll de tablas */
  .users-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  
  /* Asegurar que todos los contenedores respeten el viewport */
  .users-section,
  .content-section,
  .analytics-section,
  .reports-section {
    max-width: 100%;
    width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
  }
}

/* Ensure hamburger menu button is visible */
.nav-toggle {
  /* Hidden by default on desktop; shown on small screens via media query */
  display: none !important;
}

@media (max-width: 768px) {
  .nav-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    background: rgba(99, 102, 241, 0.98); /* purple accent */
    color: #fff;
    border: none;
    font-size: 1.15rem;
    padding: 0.5rem 0.6rem;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 6px 14px rgba(99,102,241,0.18);
    z-index: 10001 !important;
    position: absolute;
    top: 12px;
    right: 12px;
  }
}

/* General improvements for mobile */
@media (max-width: 480px) {
  .logo-text h1 {
    font-size: 1.2rem;
  }
  .subtitle {
    font-size: 0.9rem;
  }
  .nav-tab .tab-text {
    font-size: 1rem;
  }
  .user-info {
    font-size: 1rem;
  }
  
  /* Prevenir overflow en todos los contenedores */
  body, html {
    max-width: 100vw;
    overflow-x: hidden;
  }
  
  #app {
    max-width: 100vw;
    width: 100%;
    padding: 4px;
    margin: 0;
    overflow-x: hidden;
  }
  
  .dashboard-header,
  .content-area,
  .section-header,
  .users-section,
  .content-section,
  .analytics-section {
    max-width: 100%;
    width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
  }
  
  /* Hacer que inputs y selects no excedan el viewport */
  input[type="text"],
  input[type="date"],
  input[type="password"],
  select,
  textarea {
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
  }
  
  /* Botones responsivos */
      .users-table tr {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        gap: 4px;
        margin: 0 0 12px 0;
        padding: 16px;
        border-radius: 12px;
        background: #fff;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06);
        border-left: none;
        cursor: pointer;
        transition: all 0.2s ease;
        position: relative;
        overflow: visible;
  }
}

/* Responsive table -> stacked rows on small screens */
@media (max-width: 768px) {
  /* Ocultar table wrapper scroll y usar modo de tarjetas */
  .table-wrapper {
    overflow-x: visible;
    width: 100%;
  }
  
  .content-area .responsive-table {
    border: 0;
  }

  .content-area .responsive-table thead {
    display: none; /* hide original header for stacked view */
  }

  .content-area .responsive-table, 
  .content-area .responsive-table tbody, 
  .content-area .responsive-table tr {
    display: block;
    width: 100%;
  }

  .content-area .responsive-table tr {
    background: #fff;
    margin: 0 0 12px 0;
    padding: 12px;
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(20,20,40,0.06);
  }

  .content-area .responsive-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border: 0;
    font-size: 0.95rem;
  }

  .content-area .responsive-table td::before {
    content: attr(data-label);
    flex: 0 0 45%;
    color: #6b7280; /* muted label color */
    font-size: 0.85rem;
    padding-right: 8px;
    text-align: left;
  }

  /* Make action buttons smaller inside stacked rows */
  .content-area .responsive-table td .btn,
  .content-area .responsive-table td .action-btn {
    padding: 6px 8px;
    font-size: 0.85rem;
  }
  
  /* Aplicar modo tarjeta a users-table - Grid de 2 líneas */
  .users-table thead {
    display: none;
  }
  
  .users-table,
  .users-table tbody {
    display: block;
    width: 100%;
    padding: 0;
    margin: 0;
  }
  
  .users-table tr {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 4px;
    width: 100%;
    margin: 0 0 12px 0;
    padding: 16px;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border-left: none;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: visible;
  }
  
  .users-table tr::before {
    content: '';
    position: absolute;
    left: 12px;
    top: 12px;
    bottom: 12px;
    width: 4px;
    background: #6366f1;
    border-radius: 4px;
  }
  
  .users-table tr:active {
    transform: scale(0.98);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  }
  
  .users-table tr.offensive-row {
    background: #fef2f2;
  }
  
  .users-table tr.offensive-row::before {
    background: #ef4444;
  }
  
  /* OCULTAR TODAS las columnas */
  .users-table td {
    display: none !important;
  }
  
  /* Primera línea: Username (grande, bold) */
  .users-table td:nth-child(1) {
    display: block !important;
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e293b;
    grid-row: 1;
    grid-column: 1;
    width: 100%;
    padding-left: 0 !important;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
  }
  
  /* Segunda línea: Email (más pequeño, gris) */
  .users-table td:nth-child(2) {
    display: block !important;
    font-size: 0.9rem;
    font-weight: 400;
    color: #64748b;
    grid-row: 2;
    grid-column: 1;
    width: 100%;
    padding-left: 0 !important;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
  }
  
  /* Ocultar el ::before de data-label */
  .users-table td::before {
    display: none;
  }
}
  
  /* Mejorar búsqueda y filtros en móviles */
  .search-section {
    padding: 12px;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
  }
  
  .search-row {
    gap: 8px;
    max-width: 100%;
  }
  
  .search-row input,
  .search-row select,
  .search-row button {
    font-size: 14px;
    max-width: 100%;
  }
}

/* ===== DISEÑOS ESPECÍFICOS POR TIPO DE CONTENIDO ===== */

/* POSTS: Título arriba + Descripción abajo */
@media (max-width: 768px) {
  /* Grid de 2 líneas para posts */
  #posts-list .users-table tr {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 6px;
  }
  
  /* Título: primera línea (bold, grande) */
  #posts-list .users-table td:nth-child(1) {
    display: block !important;
    font-size: 1.05rem;
    font-weight: 700;
    color: #1e293b;
    grid-row: 1;
    grid-column: 1;
    width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
  }
  
  /* Descripción: segunda línea (más pequeña, gris) */
  #posts-list .users-table td:nth-child(4) {
    display: block !important;
    font-size: 0.9rem;
    font-weight: 400;
    color: #64748b;
    grid-row: 2;
    grid-column: 1;
    width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    line-height: 1.4;
  }
}

/* COMENTARIOS: Autor arriba + Comentario completo abajo (ocupa 100% del ancho) */
@media (max-width: 768px) {
  /* Grid de 2 líneas para comentarios */
  #comments-list .users-table tr {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 6px;
    align-items: start;
  }
  
  /* Autor: primera línea (bold) */
  #comments-list .users-table td:nth-child(3) {
    display: block !important;
    font-size: 0.95rem;
    font-weight: 700;
    color: #1e293b;
    grid-row: 1;
    grid-column: 1;
    width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
  }
  
  /* Comentario: segunda línea (100% ancho, permite wrap, 3 líneas max) */
  #comments-list .users-table td:nth-child(2) {
    display: block !important;
    font-size: 0.9rem;
    font-weight: 400;
    color: #475569;
    grid-row: 2;
    grid-column: 1;
    width: 100%;
    line-height: 1.5;
    display: -webkit-box !important;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
  }
}

/* Fallback: allow horizontal scroll for tables on narrow devices */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Offensive highlighting styles */
.offensive-row {
  background: linear-gradient(90deg, rgba(254,226,226,0.6), rgba(255,255,255,0));
  border-left: 4px solid #ef4444; /* red indicator */
}

.offensive-item .btn-small {
  min-width: 84px;
}

.offensive-item div > div:first-child {
  word-break: break-word;
}

/* Login screen styles */
.login-section {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  box-sizing: border-box;
  background: linear-gradient(135deg, #0f172a 0%, #0b1220 40%, #071127 100%);
  color: #0f172a;
}
.login-bg {
  position: absolute; inset: 0; z-index: 0;
  background-image: radial-gradient(rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 24px 24px;
  opacity: 0.6;
}
.login-card {
  position: relative; z-index: 2;
  width: 420px; max-width: 96%;
  /* make the card visually integrate with the background: subtle, no harsh border */
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border-radius: 14px;
  padding: 28px 26px;
  box-shadow: 0 8px 20px rgba(2,6,23,0.18);
  color: #e6eef8;
  border: none;
}
.login-brand { display:flex; gap:14px; align-items:center; margin-bottom: 18px; }
.login-logo { width:56px; height:56px; border-radius:12px; background: linear-gradient(135deg,#7c3aed,#06b6d4); display:flex;align-items:center;justify-content:center;font-size:26px;box-shadow:0 6px 18px rgba(124,58,237,0.18); }
.login-logo img.login-logo-img { width:100%; height:100%; border-radius:12px; object-fit:cover; display:block; }
.login-logo .login-logo-fallback { display:inline-block; }
.login-card h1 { margin:0; font-size:20px; color:#e6eef8; }
.login-sub { margin:0; font-size:13px; color:#cbd5e1; }
.login-form { display:flex; flex-direction:column; gap:12px; margin-top:6px; }
.login-form input { width:100%; padding:12px 14px; border-radius:10px; border:1px solid rgba(255,255,255,0.06); background: rgba(255,255,255,0.02); color: #e6eef8; font-size:15px; }
.login-form input::placeholder { color: #9aa6bf; }
.btn-primary.large { display:inline-block; padding:10px 18px; background: linear-gradient(90deg,#7c3aed,#06b6d4); border:none; color:white; border-radius:10px; font-weight:600; box-shadow: 0 8px 24px rgba(99,102,241,0.16); cursor:pointer; }
.login-actions { display:flex; justify-content:flex-end; margin-top:8px; }
.login-error { margin-top:12px; color:#fecaca; background: rgba(153,27,27,0.08); padding:10px 12px; border-radius:8px; border:1px solid rgba(255,255,255,0.03); }
.login-footer { margin-top:14px; font-size:13px; color:#9aa6bf; text-align:center; }

/* Small screens adjustments for login */
@media (max-width: 480px) {
  .login-card { padding: 18px; }
  .login-logo { width:48px; height:48px; font-size:22px; }
  .login-card h1 { font-size:18px; }
}

/* Animation for card */
.login-card.enter {
  animation: cardEnter 420ms cubic-bezier(.2,.9,.2,1) both;
}
@keyframes cardEnter {
  from { opacity: 0; transform: translateY(12px) scale(0.995); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Theme toggle button */
.theme-toggle { margin-left: 12px; background: transparent; border: 0; font-size:18px; cursor:pointer; color: inherit; }

/* Light theme overrides */
.login-section.theme-light { background: linear-gradient(135deg, #f8fafc 0%, #edf2f7 40%, #ffffff 100%); color: #0b1220; }
.login-section.theme-light .login-bg { opacity: 0.18; background-image: none; }
.login-section.theme-light .login-card {
  background: #ffffff; color: #0b1220; border: none; box-shadow: 0 6px 20px rgba(11,20,34,0.06);
}
.login-section.theme-light .login-logo { box-shadow: 0 6px 18px rgba(124,58,237,0.08); }
.login-section.theme-light .login-sub { color: #475569; }
.login-section.theme-light .login-form input { background: #fff; color: #0b1220; border: 1px solid #e6edf3; }
.login-section.theme-light .login-form input::placeholder { color: #94a3b8; }
.login-section.theme-light .btn-primary.large { box-shadow: 0 8px 20px rgba(124,58,237,0.12); }
.login-section.theme-light .login-error { color:#9b1c1c; background: #fff1f0; border:1px solid rgba(255,0,0,0.06); }

/* input error style */
.input-error { color: #fecaca; font-size: 13px; margin-top:6px; }
.login-section.theme-light .input-error { color: #dc2626; }

/* Make the login title/subtitle visible in light theme (override defaults) */
.login-section.theme-light .login-card h1 { color: #0b1220 !important; }
.login-section.theme-light .login-sub { color: #475569 !important; }

/* Dark theme: reduce white areas and style cards/widgets/inputs for consistency */
body.theme-dark .login-card,
body.theme-dark .card,
body.theme-dark .panel,
body.theme-dark .widget,
body.theme-dark .stats-card,
body.theme-dark .box,
body.theme-dark .content-area .responsive-table tr {
  background: #071127; /* deep navy */
  border: 1px solid rgba(255,255,255,0.03);
  color: #dbeafe;
  box-shadow: 0 6px 18px rgba(2,6,23,0.6);
}

/* Inputs in dark theme: darker background, light text */
body.theme-dark input,
body.theme-dark textarea,
body.theme-dark .login-form input {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.04);
  color: #e6eef8;
}

/* Buttons: invert look a bit in dark mode */
body.theme-dark .btn-primary.large {
  box-shadow: 0 8px 24px rgba(124,58,237,0.14);
}

/* Navigation tabs in dark theme */
body.theme-dark .main-navigation,
body.theme-dark .nav-tabs,
body.theme-dark .nav-tab {
  background: rgba(2,6,23,0.6);
  color: #e6eef8;
}

/* Ensure small stat boxes are darker */
body.theme-dark .stat-box, body.theme-dark .stats-card { background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01)); }

/* Header and top bar in dark theme: remove white bars and make subtle */
body.theme-dark .dashboard-header {
  background: transparent;
}
body.theme-dark .dashboard-header .header-main {
  background: rgba(255,255,255,0.02);
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 6px 18px rgba(2,6,23,0.5);
}

/* Content cards default to dark subtle panels in dark theme */
body.theme-dark .content-area > .card,
body.theme-dark .content-area .card,
body.theme-dark .content-area .panel {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.03);
}

/* More aggressive dark-mode overrides to remove remaining white surfaces */
body.theme-dark .card, body.theme-dark .panel, body.theme-dark .widget, body.theme-dark .box, body.theme-dark .stats-card {
  background: rgba(255,255,255,0.02) !important;
  color: #dbeafe !important;
  border: 1px solid rgba(255,255,255,0.03) !important;
}

/* Buttons and action elements */
body.theme-dark .btn, body.theme-dark .button, body.theme-dark .action-btn, body.theme-dark .btn-primary {
  color: #fff !important;
}
body.theme-dark .btn-muted, body.theme-dark .btn-secondary { background: rgba(255,255,255,0.03); color: #dbeafe; border: 1px solid rgba(255,255,255,0.03); }

/* Tables: make tds and stacked cards dark */
body.theme-dark .content-area .responsive-table tr, body.theme-dark .content-area .responsive-table td {
  background: rgba(255,255,255,0.02) !important;
  color: #dbeafe !important;
}

/* Nav tabs/active state */
body.theme-dark .nav-tab { background: transparent; color: #dbeafe; }
body.theme-dark .nav-tab.active { background: linear-gradient(90deg,#7c3aed,#06b6d4); color: #fff; box-shadow: 0 6px 18px rgba(124,58,237,0.12); }

/* Small stat boxes */
body.theme-dark .stat-box, body.theme-dark .stats-card { background: rgba(255,255,255,0.02); border:1px solid rgba(255,255,255,0.03); }

/* Make sure health check card and other wide white containers are dark */
body.theme-dark .empty-state, body.theme-dark .welcome-card, body.theme-dark .health-card { background: rgba(255,255,255,0.02); color: #dbeafe; border:1px solid rgba(255,255,255,0.03); }

/* --- Aggressive grid/table dark-mode overrides --- */
/* Apply to any table-like structures used across the admin UI */
body.theme-dark table,
body.theme-dark .table,
body.theme-dark .data-table,
body.theme-dark .datatable,
body.theme-dark .grid,
body.theme-dark .grid-table,
body.theme-dark .table-responsive,
body.theme-dark .responsive-table {
  background: transparent !important;
  color: #dbeafe !important;
}

/* Table header and cells */
body.theme-dark table thead th,
body.theme-dark .responsive-table thead th,
body.theme-dark table th,
body.theme-dark .table thead th {
  background: rgba(255,255,255,0.02) !important;
  color: #94a3b8 !important;
  border-bottom: 1px solid rgba(255,255,255,0.04) !important;
}

body.theme-dark table tbody tr,
body.theme-dark .responsive-table tbody tr,
body.theme-dark table td,
body.theme-dark .responsive-table td {
  background: rgba(255,255,255,0.02) !important;
  color: #e6eef8 !important;
  border: none !important;
}

/* Action cells/buttons inside tables */
body.theme-dark .responsive-table td .btn,
body.theme-dark .responsive-table td .action-btn,
body.theme-dark .table td .btn {
  background: rgba(255,255,255,0.03) !important;
  color: #e6eef8 !important;
  border: 1px solid rgba(255,255,255,0.04) !important;
}

/* Pagination, filters and toolbars often sit near grids */
body.theme-dark .pagination,
body.theme-dark .page-item,
body.theme-dark .page-link,
body.theme-dark .grid-toolbar,
body.theme-dark .table-toolbar {
  background: transparent !important;
  color: #dbeafe !important;
}

/* Ensure form controls used for filtering/search in grids follow dark theme */
body.theme-dark .form-control,
body.theme-dark input[type="search"],
body.theme-dark select,
body.theme-dark textarea {
  background: rgba(255,255,255,0.03) !important;
  color: #e6eef8 !important;
  border: 1px solid rgba(255,255,255,0.04) !important;
}

/* Make sure any modal content opened from grids is dark */
body.theme-dark .modal,
body.theme-dark .modal-content,
body.theme-dark .dialog,
body.theme-dark .popover {
  background: rgba(255,255,255,0.02) !important;
  color: #e6eef8 !important;
  border: 1px solid rgba(255,255,255,0.03) !important;
}

/* Fix for any library-specific classes that often force white bg */
body.theme-dark .panel-white, body.theme-dark .card-white, body.theme-dark .box-white {
  background: rgba(255,255,255,0.02) !important;
  color: #e6eef8 !important;
  border: 1px solid rgba(255,255,255,0.03) !important;
}

/* If some elements still appear with strong white background, reduce their opacity */
body.theme-dark *[style*="background:#fff"],
body.theme-dark *[style*="background:white"] {
  background: rgba(255,255,255,0.02) !important;
}

/* Clickable row affordance: hover, focus and small lift for rows that have data-id (added by JS) */
.users-table tbody tr[data-id], .content-area .responsive-table tr[data-id] {
  transition: background 0.18s ease, transform 0.12s ease, box-shadow 0.12s ease;
}
.users-table tbody tr[data-id]:hover,
.users-table tbody tr[data-id]:focus {
  background: #f3f4f6; /* light neutral */
  transform: translateY(-2px);
  outline: none;
}
.content-area .responsive-table tr[data-id]:hover {
  background: #fbfdfe;
}
.users-table tbody tr[data-id]:focus {
  box-shadow: inset 0 0 0 2px rgba(99,102,241,0.08);
}

/* Keep offensive highlight visible on hover but slightly darker */
.users-table tbody tr.offensive-row[data-id]:hover,
.content-area .responsive-table tr.offensive-row[data-id]:hover {
  background: linear-gradient(90deg, rgba(254,226,226,0.75), rgba(255,255,255,0.02));
}

/* Touch feedback for devices without hover capability */
@media (hover: none) {
  .users-table tbody tr[data-id]:active,
  .content-area .responsive-table tr[data-id]:active {
    background: #eef2f7 !important;
    transform: translateY(0) !important;
    transition: none !important;
  }
  /* remove tap highlight on webkit */
  .users-table tbody tr[data-id], .content-area .responsive-table tr[data-id] {
    -webkit-tap-highlight-color: rgba(0,0,0,0);
  }
}

/* Global theme classes applied to <body> to propagate theme after login */
body.theme-dark { background: linear-gradient(135deg, #071127 0%, #0b1220 40%, #071127 100%); color: #e6eef8; }
body.theme-dark .dashboard-header, body.theme-dark .content-area { color: #e6eef8; }
body.theme-dark .main-navigation { background: rgba(2,6,23,0.6); }

body.theme-light { background: linear-gradient(135deg, #f8fafc 0%, #edf2f7 40%, #ffffff 100%); color: #0b1220; }
body.theme-light .dashboard-header, body.theme-light .content-area { color: #0b1220; }
body.theme-light .main-navigation { background: rgba(255,255,255,0.96); }
