/* ==========================================
   ESTILOS COMUNES - BASE DEL SISTEMA
   ========================================== */

/* Reset y Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: Arial, sans-serif;
  background: #f5f5f5;
  color: #333;
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ==========================================
   SIDEBAR
   ========================================== */

.sidebar {
  width: 280px;
  background: linear-gradient(180deg, #1a1a1a 0%, #2d2d2d 100%);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
  z-index: 1000;
}

.sidebar-header {
  padding: 30px 20px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 5px;
  letter-spacing: 2px;
}

.sidebar-header p {
  font-size: 13px;
  opacity: 0.8;
  font-weight: 300;
}

.sidebar-menu {
  list-style: none;
  padding: 20px 0;
  flex: 1;
  overflow-y: auto;
}

.sidebar-menu li {
  margin: 0;
}

.sidebar-menu a {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  transition: all 0.3s ease;
  border-left: 3px solid transparent;
  font-size: 14px;
  font-weight: 500;
}

.sidebar-menu a:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border-left-color: #888;
}

.sidebar-menu a.active {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border-left-color: #fbbf24;
  font-weight: 600;
}

.sidebar-menu .icon {
  font-size: 20px;
  margin-right: 12px;
  min-width: 24px;
  text-align: center;
}

/* Submenús desplegables */
.sidebar-menu .has-submenu {
  position: relative;
}

.sidebar-menu .submenu-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.sidebar-menu .submenu-toggle .arrow {
  font-size: 10px;
  transition: transform 0.3s ease;
  margin-left: auto;
  padding-left: 10px;
}

.sidebar-menu .has-submenu.open .submenu-toggle .arrow {
  transform: rotate(180deg);
}

.sidebar-menu .submenu {
  list-style: none;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  background: rgba(0, 0, 0, 0.2);
}

.sidebar-menu .has-submenu.open .submenu {
  max-height: 500px;
}

.sidebar-menu .submenu li {
  margin: 0;
}

.sidebar-menu .submenu a {
  padding: 12px 20px 12px 56px;
  font-size: 13px;
  border-left: 3px solid transparent;
}

.sidebar-menu .submenu a:hover {
  background: rgba(255, 255, 255, 0.15);
  border-left-color: #999;
}

.sidebar-menu .submenu a.active {
  background: rgba(255, 255, 255, 0.2);
  border-left-color: #fbbf24;
}

/* Separador visual en submenú (Mantenedores) */
.sidebar-menu .submenu .submenu-separator {
  padding: 10px 20px 8px 56px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.5px;
  cursor: default;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 5px;
}

.sidebar-menu .submenu .submenu-separator:hover {
  background: transparent;
}

.sidebar-footer {
  padding: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
  font-size: 12px;
  opacity: 0.7;
}

/* ==========================================
   MAIN CONTAINER
   ========================================== */

.main-container {
  margin-left: 280px;
  flex: 1;
  padding: 40px;
  min-height: 100vh;
  width: calc(100% - 280px);
}

/* ==========================================
   TARJETAS Y SECCIONES
   ========================================== */

.card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 30px;
  margin-bottom: 30px;
}

.card-header {
  margin-bottom: 25px;
  padding-bottom: 15px;
  border-bottom: 2px solid #e5e7eb;
}

.card-header h2 {
  font-size: 24px;
  color: #1e3a8a;
  font-weight: 600;
}

.card-header p {
  font-size: 14px;
  color: #6b7280;
  margin-top: 5px;
}

/* ==========================================
   TABLAS
   ========================================== */

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
}

thead {
  background: linear-gradient(180deg, #f3f4f6 0%, #e5e7eb 100%);
}

th {
  padding: 14px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid #d1d5db;
}

td {
  padding: 12px;
  border-bottom: 1px solid #e5e7eb;
  font-size: 14px;
  color: #4b5563;
}

tr:hover {
  background: #f9fafb;
}

tbody tr:last-child td {
  border-bottom: none;
}

td[contenteditable="true"] {
  cursor: text;
  min-height: 20px;
}

td[contenteditable="true"]:hover {
  background: #fef3c7;
  outline: 1px solid #fbbf24;
}

td[contenteditable="true"]:focus {
  background: #fff;
  outline: 2px solid #3b82f6;
}

/* ==========================================
   BOTONES
   ========================================== */

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  transform: translateY(-1px);
}

.btn-success {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
  transform: translateY(-1px);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: white;
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* Botones en tablas */
.btn-eliminar,
.btn-eliminar-local,
.btn-eliminar-segmento,
.btn-eliminar-operador {
  padding: 6px 12px;
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.btn-eliminar:hover,
.btn-eliminar-local:hover,
.btn-eliminar-segmento:hover,
.btn-eliminar-operador:hover {
  background: #dc2626;
  transform: scale(1.05);
}

/* ==========================================
   FORMULARIOS
   ========================================== */

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: #374151;
  font-size: 14px;
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: Arial, sans-serif;
  transition: all 0.3s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

input[readonly] {
  background: #f3f4f6;
  cursor: not-allowed;
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

textarea {
  resize: vertical;
  min-height: 80px;
}

/* Checkboxes */
input[type="checkbox"] {
  cursor: pointer;
  width: 18px;
  height: 18px;
  accent-color: #3b82f6;
}

/* ==========================================
   UTILIDADES
   ========================================== */

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.mt-20 {
  margin-top: 20px;
}

.mb-20 {
  margin-bottom: 20px;
}

.flex {
  display: flex;
}

.gap-10 {
  gap: 10px;
}

.justify-between {
  justify-content: space-between;
}

.align-center {
  align-items: center;
}

/* ==========================================
   MENSAJES Y ALERTAS
   ========================================== */

.alert {
  padding: 15px 20px;
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 14px;
  font-weight: 500;
}

.alert-info {
  background: #dbeafe;
  color: #1e40af;
  border-left: 4px solid #3b82f6;
}

.alert-success {
  background: #d1fae5;
  color: #065f46;
  border-left: 4px solid #10b981;
}

.alert-warning {
  background: #fef3c7;
  color: #92400e;
  border-left: 4px solid #f59e0b;
}

.alert-danger {
  background: #fee2e2;
  color: #991b1b;
  border-left: 4px solid #ef4444;
}

/* ==========================================
   HAMBURGER MENU (MOBILE ONLY)
   ========================================== */

.hamburger-btn {
  display: none;
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 2000;
  background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
  border: none;
  border-radius: 8px;
  width: 50px;
  height: 50px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.hamburger-btn:hover {
  background: linear-gradient(135deg, #2d2d2d 0%, #3d3d3d 100%);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.hamburger-btn span {
  display: block;
  width: 24px;
  height: 3px;
  background: white;
  border-radius: 2px;
  transition: all 0.3s ease;
}

.sidebar-open .hamburger-btn span:nth-child(1) {
  transform: rotate(45deg) translate(7px, 7px);
}

.sidebar-open .hamburger-btn span:nth-child(2) {
  opacity: 0;
}

.sidebar-open .hamburger-btn span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -7px);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
  opacity: 1;
}

/* ==========================================
   RESPONSIVE DESIGN
   ========================================== */

/* Mobile (<640px) */
@media (max-width: 639px) {
  /* Mostrar hamburger button */
  .hamburger-btn {
    display: flex;
  }

  /* Sidebar oculto por defecto */
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    height: 100vh;
    width: 280px;
    z-index: 1000;
    transition: left 0.3s ease;
  }

  .sidebar.open {
    left: 0;
  }

  /* Main container ocupa todo el ancho con padding mínimo */
  .main-container {
    margin-left: 0;
    margin-right: 0;
    width: 100%;
    max-width: 100%;
    padding: 70px 0 20px 0; /* Sin padding lateral para llegar hasta el borde */
    box-sizing: border-box;
  }

  /* Overlay visible cuando sidebar está abierto */
  .sidebar-open .sidebar-overlay {
    display: block;
  }

  /* Cards más compactas con padding reducido */
  .card {
    padding: 12px 8px;
    margin-bottom: 16px;
    margin-left: 0;
    margin-right: 0;
    width: 100vw;
    max-width: 100vw;
    box-sizing: border-box;
    border-radius: 0; /* Sin bordes redondeados para llegar hasta el borde */
  }

  .card-header h2 {
    font-size: 20px;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  .card-header p {
    font-size: 14px; /* Aumentado de 13px a 14px */
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  /* Tablas con scroll horizontal */
  table {
    min-width: 600px;
    font-size: 14px; /* Asegurar tamaño mínimo legible */
  }

  .table-wrap,
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -20px;
    padding: 0 20px;
    position: relative;
  }

  /* Indicador de scroll para tablas */
  .table-wrap::after,
  .table-container::after {
    content: '👉 Desliza para ver más';
    display: block;
    text-align: center;
    color: #6b7280;
    font-size: 13px;
    padding: 8px;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
    margin-top: 8px;
  }

  /* Botones touch-friendly */
  .btn {
    min-height: 44px;
    padding: 12px 20px;
    font-size: 15px;
  }

  .btn-primary,
  .btn-success,
  .btn-danger {
    width: 100%;
    margin-bottom: 8px;
  }

  /* Inputs touch-friendly */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  select,
  textarea {
    font-size: 16px; /* Evita zoom en iOS */
    padding: 12px;
  }

  /* Alertas más compactas */
  .alert {
    padding: 12px 16px;
    font-size: 14px; /* Aumentado de 13px a 14px */
  }

  /* Headers de tabla más legibles */
  th {
    font-size: 13px;
  }

  /* Celdas de tabla */
  td {
    font-size: 14px;
  }
}

/* Tablet (640px - 1023px) */
@media (min-width: 640px) and (max-width: 1023px) {
  /* Sidebar colapsado (solo íconos) */
  .sidebar {
    width: 80px;
  }

  .sidebar-header h1 {
    font-size: 22px;
    writing-mode: horizontal-tb; /* Texto horizontal normal */
    text-align: center;
    letter-spacing: 1px;
    line-height: 1.2;
  }

  .sidebar-header p {
    display: none;
  }

  .sidebar-menu .text {
    display: none;
  }

  .sidebar-menu a {
    justify-content: center;
    padding: 14px 10px;
  }

  .sidebar-menu .icon {
    margin-right: 0;
    font-size: 24px;
  }

  .sidebar-footer {
    font-size: 11px;
    padding: 15px 10px;
    overflow-wrap: break-word;
    text-align: center;
  }

  /* Main container ajustado */
  .main-container {
    margin-left: 80px;
    width: calc(100% - 80px);
    padding: 30px;
  }

  /* Cards adaptadas */
  .card {
    padding: 25px;
  }

  /* Tablas con scroll si es necesario */
  table {
    font-size: 14px;
  }

  th, td {
    padding: 10px;
  }
}

/* Desktop Large (1024px - 1439px) */
@media (min-width: 1024px) and (max-width: 1439px) {
  .sidebar {
    width: 260px;
  }

  .main-container {
    margin-left: 260px;
    width: calc(100% - 260px);
    padding: 35px;
  }

  /* Ocultar indicador de scroll en desktop */
  .table-wrap::after,
  .table-container::after {
    display: none;
  }
}

/* Desktop Extra Large (1440px+) */
@media (min-width: 1440px) {
  .main-container {
    padding: 50px;
    max-width: 1600px;
    margin-left: 280px;
  }

  .card {
    padding: 35px;
  }

  .card-header h2 {
    font-size: 26px;
  }

  /* Ocultar indicador de scroll en desktop extra large */
  .table-wrap::after,
  .table-container::after {
    display: none;
  }
}

/* Print styles */
@media print {
  .sidebar,
  .hamburger-btn,
  .sidebar-overlay,
  .btn,
  button {
    display: none !important;
  }

  .main-container {
    margin-left: 0;
    width: 100%;
    padding: 0;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ddd;
    page-break-inside: avoid;
  }
}
