@import url('https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css');

/* Estilos personalizados */
:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary-color: #64748b;
  --success-color: #10b981;
  --error-color: #ef4444;
  --warning-color: #f59e0b;
  --border-color: #e5e7eb;
  --bg-color: #f8fafc;
  --text-color: #1f2937;
  --text-muted: #6b7280;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
}

/* Critical mobile overflow prevention - must be early */
@media (max-width: 768px) {
  html {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  body {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    position: relative !important;
  }
  
  /* Force box-sizing on everything */
  *, *::before, *::after {
    box-sizing: border-box !important;
  }
}

/* Botones personalizados */
.btn-primary {
  background-color: var(--primary-color);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  border: none;
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--secondary-color);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  border: none;
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
}

.btn-secondary:hover {
  background-color: #475569;
  transform: translateY(-1px);
}

.btn-outline {
  background-color: transparent;
  color: var(--primary-color);
  border: 2px solid var(--primary-color);
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
}

.btn-outline:hover {
  background-color: var(--primary-color);
  color: white;
}

/* Cards */
.card {
  background: white;
  border-radius: 0.75rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  border: 1px solid var(--border-color);
  transition: all 0.2s;
}

.card:hover {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.card-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.card-body {
  padding: 1rem;
}

.card-footer {
  padding: 1.5rem;
  border-top: 1px solid var(--border-color);
  background-color: #f9fafb;
}

/* Formularios */
.form-group {
  margin-bottom: 1.5rem;
}

.form-label {
  display: block;
  font-weight: 500;
  color: var(--text-color);
  margin-bottom: 0.5rem;
}

.form-input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  font-size: 1rem;
  transition: all 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input.error {
  border-color: var(--error-color);
}

.form-error {
  color: var(--error-color);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* Tablas */
.table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.table th {
  background-color: #f8fafc;
  padding: 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-color);
  border-bottom: 1px solid var(--border-color);
}

.table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.table tr:hover {
  background-color: #f9fafb;
}

/* Alertas */
.alert {
  padding: 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}

.alert-success {
  background-color: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-error {
  background-color: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.alert-warning {
  background-color: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.alert-info {
  background-color: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
}

/* Navegación */
.navbar {
  background: white;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid var(--border-color);
}

.navbar-brand {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
}

.nav-link {
  color: var(--text-color);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  transition: all 0.2s;
}

.nav-link:hover {
  background-color: #f3f4f6;
  color: var(--primary-color);
}

.nav-link.active {
  background-color: var(--primary-color);
  color: white;
}

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  border-right: 1px solid var(--border-color);
  min-height: 100vh;
  width: 14rem;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
  box-shadow: 2px 0 10px rgba(0,0,0,0.05);
}

.sidebar-header {
  padding: 2rem 1.5rem 1rem 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 1rem;
}

.sidebar-logo {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--primary-color);
  display: flex;
  align-items: center;
}

.sidebar-logo svg {
  width: 1.5rem;
  height: 1.5rem;
  margin-right: 0.5rem;
}

.sidebar-nav {
  padding: 0 1rem;
}

.sidebar-item {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  color: #6b7280;
  text-decoration: none;
  border-radius: 0.75rem;
  margin-bottom: 0.5rem;
  transition: all 0.3s ease;
  font-weight: 500;
  font-size: 0.95rem;
  position: relative;
}

.sidebar-item svg {
  width: 1.25rem;
  height: 1.25rem;
  margin-right: 0.75rem;
  transition: all 0.3s ease;
}

.sidebar-item:hover {
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  color: var(--primary-color);
  transform: translateX(4px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.sidebar-item:hover svg {
  transform: scale(1.1);
}

.sidebar-item.active {
  background: linear-gradient(135deg, var(--primary-color) 0%, #2563eb 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
  transform: translateX(4px);
}

.sidebar-item.active svg {
  transform: scale(1.1);
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: -1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 60%;
  background: var(--primary-color);
  border-radius: 0 4px 4px 0;
}

/* Responsive Design */
@media (max-width: 768px) {
  /* Force mobile viewport */
  html {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
  
  body {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    position: relative !important;
  }
  
  /* Mobile Navigation */
  .sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: 280px;
    height: 100vh;
    z-index: 1000;
    transition: left 0.3s ease, transform 0.3s ease;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    box-shadow: 2px 0 20px rgba(0,0,0,0.15);
    transform: translateX(-100%);
  }
  
  .sidebar.open {
    left: 0;
    transform: translateX(0);
  }
  
  .mobile-menu-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    padding: 0.75rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: all 0.3s ease;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1001;
  }
  
  .mobile-menu-btn:hover {
    background: #2563eb;
    transform: scale(1.05);
  }
  
  /* Hide duplicate mobile menu buttons outside navbar */
  .mobile-menu-btn.mobile-only {
    display: none !important;
  }
  
  /* Show only the one in navbar */
  .navbar .mobile-menu-btn {
    display: flex !important;
    position: relative;
    top: auto;
    left: auto;
    z-index: 1002;
  }
  
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    backdrop-filter: blur(2px);
  }
  
  .sidebar-overlay.open {
    display: block;
  }
  
  /* Navbar adjustments for mobile */
  .navbar {
    padding: 0.75rem 0.5rem !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
    z-index: 100;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }
  
  .navbar > div {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 0.25rem !important;
    margin: 0 !important;
    box-sizing: border-box !important;
  }
  
  .navbar .max-w-7xl {
    padding: 0 0.25rem !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  
  .navbar .px-4,
  .navbar .sm\:px-6,
  .navbar .lg\:px-8 {
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }
  
  .navbar-brand {
    font-size: 1rem !important;
    font-weight: 600;
    margin-left: 2.5rem !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
  }
  
  /* Ensure navbar content is properly spaced */
  .navbar .flex {
    width: 100% !important;
    max-width: 100% !important;
    justify-content: space-between;
    box-sizing: border-box !important;
  }
  
  .navbar .flex > * {
    max-width: calc(50% - 0.5rem) !important;
    box-sizing: border-box !important;
  }
  
  /* Main content adjustments */
  .main-content {
    margin-left: 0 !important;
    padding-top: 0.5rem !important;
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
    padding-bottom: 1rem !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
    position: relative !important;
  }
  
  .main-content .max-w-7xl {
    padding: 0 0.25rem !important;
    margin: 0 auto !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  
  /* All containers */
  .flex {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  
  /* Cards */
  .card {
    margin: 0.5rem 0 !important;
    padding: 0.5rem !important;
    border-radius: 0.5rem !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    position: relative !important;
  }

  .card-header {
    padding: 0.5rem !important;
    margin-bottom: 0.5rem !important;
    border-bottom: 1px solid #e5e7eb;
    width: 100% !important;
    box-sizing: border-box !important;
  }
  
  .card-header h2 {
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    margin: 0 !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
  }

  .card-body {
    padding: 0.5rem !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }
  
  .card-body > * {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  
  /* Form filters on mobile */
  .card-body form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  
  .card-body form .form-group {
    margin-bottom: 0;
  }
  
  /* Filters form specific styles */
  .filters-form {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.75rem !important;
    width: 100% !important;
  }
  
  .filters-form .form-group {
    width: 100% !important;
    margin: 0 !important;
  }
  
  .filters-actions {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
    width: 100% !important;
    margin-top: 0.5rem !important;
  }
  
  .filters-actions button,
  .filters-actions a {
    width: 100% !important;
    margin: 0 !important;
    padding: 0.75rem 1rem !important;
  }

  /* Stats cards for mobile */
  .stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
  }

  .stat-card {
    padding: 1.5rem 1rem;
    text-align: center;
    border-radius: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  }

  .stat-card h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
  }

  .stat-card p {
    font-size: 0.875rem;
    color: #6b7280;
    margin: 0;
  }

  /* Tables */
  .table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    border-radius: 0.5rem !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    display: block !important;
    box-sizing: border-box !important;
    position: relative !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: thin !important;
  }
  
  /* Table wrapper - keep it contained */
  .card-body .table-responsive {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .table {
    font-size: 0.65rem !important;
    min-width: 900px !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    border-collapse: collapse !important;
    table-layout: auto !important;
  }

  .table th,
  .table td {
    padding: 0.4rem 0.2rem !important;
    white-space: nowrap !important;
    font-size: 0.65rem !important;
    line-height: 1.2 !important;
  }
  
  .table th {
    font-size: 0.6rem !important;
    font-weight: 600 !important;
    background-color: #f8fafc !important;
  }
  
  /* Make action buttons smaller on mobile */
  .table td .flex {
    flex-wrap: wrap !important;
    gap: 0.2rem !important;
    justify-content: flex-start !important;
    align-items: center !important;
  }
  
  .table td a,
  .table td button {
    font-size: 0.55rem !important;
    padding: 0.15rem 0.3rem !important;
    min-width: auto !important;
    display: inline-flex !important;
    align-items: center !important;
    white-space: nowrap !important;
  }
  
  .table td a svg,
  .table td button svg {
    width: 0.7rem !important;
    height: 0.7rem !important;
    margin-right: 0.2rem !important;
  }
  
  /* Hide columns on mobile to save space */
  .table th:nth-child(4),
  .table td:nth-child(4),
  .table th:nth-child(5),
  .table td:nth-child(5) {
    display: none !important;
  }
  
  /* Show only essential columns: Ticket, RFC, Total, Fecha, Status, Acciones */
  @media (max-width: 480px) {
    .table th:nth-child(3),
    .table td:nth-child(3) {
      display: none !important;
    }
  }

  /* Forms */
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }
  
  /* Modal form grids */
  #clienteModal .form-grid {
    grid-template-columns: 1fr !important;
  }
  
  #clienteModal .md\:col-span-2 {
    grid-column: span 1 !important;
  }

  /* Buttons - Force full width on mobile */
  .btn-primary,
  .btn-secondary,
  .btn-outline,
  button.btn-primary,
  button.btn-outline,
  a.btn-primary,
  a.btn-outline {
    padding: 0.75rem 1rem !important;
    font-size: 0.875rem !important;
    border-radius: 0.5rem !important;
    margin-bottom: 0.5rem !important;
    width: 100% !important;
    max-width: 100% !important;
    font-weight: 600 !important;
    display: block !important;
    text-align: center !important;
    box-sizing: border-box !important;
  }
  
  /* Button groups */
  .flex.space-x-2,
  .flex.space-x-2 > * {
    flex-direction: column !important;
    gap: 0.5rem !important;
    width: 100% !important;
    margin: 0 !important;
  }
  
  /* All buttons in flex containers */
  .flex button,
  .flex a.btn-primary,
  .flex a.btn-outline {
    width: 100% !important;
    margin: 0 !important;
  }
  
  /* Inline buttons in tables - keep them small */
  .table .btn-primary,
  .table .btn-outline,
  .table button:not(.btn-primary):not(.btn-outline),
  .table a:not(.btn-primary):not(.btn-outline) {
    width: auto !important;
    display: inline-flex !important;
    padding: 0.2rem 0.4rem !important;
    font-size: 0.6rem !important;
    margin: 0 !important;
  }
  
  /* Buttons outside cards/tables should be full width */
  .main-content > .max-w-7xl > * > button,
  .main-content > .max-w-7xl > * > a.btn-primary,
  .main-content > .max-w-7xl > * > a.btn-outline {
    width: 100% !important;
  }

  /* Modal adjustments */
  .modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
  }
  
  .modal-content {
    background: white;
    border-radius: 0.75rem;
    width: 100%;
    max-width: 500px;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  }
  
  .modal-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  .modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
  }
  
  .modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6b7280;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .modal-close:hover {
    color: var(--text-color);
  }
  
  .modal-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
  }
  
  .btn-danger {
    background-color: var(--error-color);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    border: none;
    font-weight: 500;
    transition: all 0.2s;
    cursor: pointer;
  }
  
  .btn-danger:hover {
    background-color: #dc2626;
  }

  /* Hide desktop elements */
  .desktop-only {
    display: none !important;
  }

  /* Show mobile elements */
  .mobile-only {
    display: block !important;
  }

  /* Mobile-specific improvements */
  .main-content h1 {
    font-size: 1.5rem !important;
    margin-bottom: 0.5rem;
    line-height: 1.2;
  }

  .main-content p {
    font-size: 0.875rem;
    margin-bottom: 1rem;
  }
  
  /* Header sections on mobile */
  .main-content .mb-8 {
    margin-bottom: 1.5rem !important;
  }
  
  /* Flex headers on mobile - Force column layout */
  .flex.justify-between.items-center {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 1rem !important;
    width: 100% !important;
  }
  
  .flex.justify-between.items-center > div:first-child {
    width: 100% !important;
  }
  
  .flex.justify-between.items-center .flex.space-x-2 {
    width: 100% !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
    align-items: stretch !important;
  }
  
  .flex.justify-between.items-center .flex.space-x-2 > * {
    width: 100% !important;
    margin: 0 !important;
    flex: 1 !important;
  }
  
  /* All buttons in header sections */
  .flex.justify-between.items-center button,
  .flex.justify-between.items-center a.btn-primary,
  .flex.justify-between.items-center a.btn-outline {
    width: 100% !important;
    margin: 0 !important;
  }
  
  /* Button text on mobile */
  .btn-primary svg,
  .btn-outline svg {
    width: 1rem !important;
    height: 1rem !important;
    margin-right: 0.5rem !important;
    flex-shrink: 0 !important;
  }
  
  /* All form inputs full width */
  .form-input,
  .form-group input,
  .form-group select,
  .form-group textarea {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  
  .form-group {
    width: 100% !important;
    margin-bottom: 1rem !important;
  }
  
  /* Grid improvements */
  .grid {
    gap: 1rem !important;
  }
  
  /* Max width container */
  .max-w-7xl,
  .max-w-7xl > * {
    padding: 0 0.25rem !important;
    margin: 0 auto !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }
  
  /* All direct children of max-w-7xl */
  .max-w-7xl > div,
  .max-w-7xl > section,
  .max-w-7xl > article {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  
  /* Remove all horizontal padding classes on mobile */
  .px-4, .px-6, .px-8, .px-2,
  .sm\:px-6, .lg\:px-8 {
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }
  
  /* Remove flex-1 padding */
  .flex-1,
  .flex-1.p-4 {
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
    width: 100% !important;
    max-width: 100vw !important;
  }
  
  /* Override Tailwind padding classes - be specific */
  .p-1, .p-2, .p-3, .p-4, .p-5, .p-6, .p-8,
  .px-1, .px-2, .px-3, .px-4, .px-5, .px-6, .px-8,
  .py-1, .py-2, .py-3, .py-4, .py-5, .py-6, .py-8 {
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }
  
  /* Keep vertical padding */
  .p-4, .py-4 {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
  }
  
  .p-6, .py-6 {
    padding-top: 0.75rem !important;
    padding-bottom: 0.75rem !important;
  }
  
  /* Override margin classes */
  .mx-auto,
  .mx-1, .mx-2, .mx-3, .mx-4, .mx-6, .mx-8 {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  
  /* Card spacing on mobile */
  .card.mt-8 {
    margin-top: 1rem !important;
  }
  
  /* All mb-8, mb-6, etc reduced on mobile */
  .mb-8,
  .mb-6 {
    margin-bottom: 1rem !important;
  }
  
  /* Headers */
  h1, h2, h3 {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
  }
  
  /* Ensure no horizontal overflow - CRITICAL */
  html, body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
    position: relative !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  /* Force box-sizing on ALL elements */
  *,
  *::before,
  *::after {
    box-sizing: border-box !important;
  }
  
  /* Prevent overflow on all containers - ULTRA STRICT */
  body > * {
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
  
  .main-content,
  .main-content > *,
  .card,
  .card > *,
  .table-responsive,
  .navbar,
  .navbar > *,
  .navbar > div > *,
  .flex,
  .flex > *,
  div:not(.table):not(.table th):not(.table td),
  section,
  article,
  main,
  header,
  footer {
    max-width: 100% !important;
    overflow-x: hidden !important;
    width: auto !important;
  }
  
  /* Force specific problematic elements */
  .max-w-7xl,
  .max-w-7xl.mx-auto {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }
  
  /* All divs inside main-content */
  .main-content div,
  .main-content section,
  .main-content article {
    max-width: 100% !important;
    overflow-x: hidden !important;
  }
  
  /* CRITICAL: Force all elements to respect viewport */
  body,
  html {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
  }
  
  /* Remove any fixed widths */
  [style*="width:"]:not(.table):not(.table th):not(.table td) {
    max-width: 100% !important;
  }
  
  /* Ensure flex containers don't overflow */
  .flex {
    min-width: 0 !important;
    flex-shrink: 1 !important;
  }
  
  /* Grid containers */
  .grid {
    width: 100% !important;
    max-width: 100% !important;
  }
  
  /* Remove any padding/margin that causes overflow */
  .p-4,
  .px-4,
  .py-4,
  .p-6,
  .px-6,
  .py-6,
  .p-8,
  .px-8,
  .py-8 {
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }
  
  /* Remove margin that causes issues */
  .mx-auto {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  
  /* Pagination on mobile */
  .mt-6.flex.justify-center {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  
  .mt-6.flex.justify-center a,
  .mt-6.flex.justify-center button {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
  }
  
  /* Modal mobile adjustments */
  .modal-content {
    margin: 0;
    max-width: 100%;
    border-radius: 0.75rem 0.75rem 0 0;
  }
  
  .modal-header,
  .modal-footer {
    padding: 0.75rem;
  }
  
  .modal-header h3 {
    font-size: 1rem;
  }
  
  .modal-footer {
    flex-direction: column;
  }
  
  .modal-footer button {
    width: 100%;
    margin: 0;
  }

  /* Better spacing for mobile */
  .space-y-4 > * + * {
    margin-top: 1rem;
  }

  .space-y-6 > * + * {
    margin-top: 1.5rem;
  }
  
  /* Status badges on mobile */
  .px-2.py-1.text-xs.rounded-full {
    font-size: 0.65rem;
    padding: 0.25rem 0.5rem;
  }
  
  /* UUID column - make it smaller or hide on mobile */
  .font-mono.text-xs {
    font-size: 0.6rem;
    word-break: break-all;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
  }
  
  /* Action buttons container */
  .table td > .flex.space-x-2 {
    flex-wrap: wrap;
    gap: 0.25rem;
  }
  
  /* Modal in profile.php */
  #clienteModal {
    padding: 0.5rem;
  }
  
  #clienteModal .p-6 {
    padding: 1rem;
  }
  
  #clienteModal .max-w-2xl {
    max-width: 100%;
    margin: 0;
  }
}

@media (min-width: 769px) {
  .mobile-menu-btn {
    display: none;
  }
  
  .sidebar-overlay {
    display: none;
  }
  
  .main-content {
    margin-left: 14rem;
    padding-top: 2rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
  
  .mobile-only {
    display: none;
  }
  
  .desktop-only {
    display: block;
  }
  
  /* Filters form on desktop */
  .filters-form {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
  }
  
  .filters-actions {
    grid-column: span 4;
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
  }
  
  .filters-actions button,
  .filters-actions a {
    width: auto;
  }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .table th,
  .table td {
    padding: 0.75rem 0.5rem;
    font-size: 0.875rem;
  }
}

/* Large screens */
@media (min-width: 1200px) {
  .container {
    max-width: 1200px;
    margin: 0 auto;
  }
}

/* Animaciones */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.3s ease-out;
}

@keyframes slideIn {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

.slide-in {
  animation: slideIn 0.3s ease-out;
}

/* Utilidades */
.text-primary { color: var(--primary-color); }
.text-success { color: var(--success-color); }
.text-error { color: var(--error-color); }
.text-warning { color: var(--warning-color); }
.text-muted { color: var(--text-muted); }

.bg-primary { background-color: var(--primary-color); }
.bg-success { background-color: var(--success-color); }
.bg-error { background-color: var(--error-color); }
.bg-warning { background-color: var(--warning-color); }

.border-primary { border-color: var(--primary-color); }
.border-success { border-color: var(--success-color); }
.border-error { border-color: var(--error-color); }
.border-warning { border-color: var(--warning-color); }
