/* ==========================================
   MOBILE STYLES (max-width: 767px)
   Diseño de App Nativa con Bottom Navigation
   ========================================== */

@media (max-width: 767px) {
  /* Layout principal - app nativa */
  body {
    padding-bottom: 60px; /* Espacio para bottom nav */
  }

  /* Header simplificado - solo título y fecha */
  .header-content {
    padding: 12px 16px;
    gap: 8px;
    flex-direction: column;
    align-items: center;
    background: linear-gradient(135deg, var(--primary-color) 0%, #0056b3 100%);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  }

  .header-left {
    width: 100%;
    justify-content: center;
    order: 1;
  }

  .title {
    font-size: 16px;
    font-weight: 600;
    color: white;
    text-align: center;
  }

  /* Ocultar elementos que van a bottom nav */
  .view-tabs,
  .header-actions,
  .last-update {
    display: none !important;
  }

  /* Bottom Navigation Bar */
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: white;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  }

  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-secondary);
    text-decoration: none;
    flex: 1;
    max-width: 80px;
  }

  .bottom-nav-item .material-icons {
    font-size: 24px;
    margin-bottom: 2px;
  }

  .bottom-nav-item span {
    font-size: 11px;
    font-weight: 500;
  }

  .bottom-nav-item.active {
    color: var(--primary-color);
  }

  .bottom-nav-item:active {
    transform: scale(0.95);
  }

  /* Layout */
  .sidebar {
    display: none !important;
  }

  .main-content {
    display: block !important;
    width: 100%;
    padding-bottom: 80px; /* Espacio extra para bottom nav */
  }

  .vista-container {
    width: 100% !important;
  }

  .grid-wrapper {
    padding: 0;
  }

  /* Swipe indicator - visual feedback */
  .swipe-indicator {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    background: rgba(0, 123, 255, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    z-index: 999;
  }

  .swipe-indicator.left {
    left: 20px;
  }

  .swipe-indicator.right {
    right: 20px;
  }

  .swipe-indicator.show {
    opacity: 1;
  }

  /* Touch feedback en celdas */
  .cell:active {
    background-color: rgba(0, 123, 255, 0.05);
  }

  /* Drag and Drop - Feedback visual en móvil */
  .cell.dragging {
    opacity: 0.4;
    transform: scale(0.95);
    transition: all 0.2s;
    box-shadow: 0 8px 16px rgba(0,0,0,0.3);
  }

  .cell.drop-target {
    background: rgba(0, 123, 255, 0.15) !important;
    border: 2px dashed var(--primary-color) !important;
    animation: pulse 0.6s ease-in-out infinite;
  }

  @keyframes pulse {
    0%, 100% { 
      transform: scale(1);
      opacity: 1;
    }
    50% { 
      transform: scale(1.02);
      opacity: 0.9;
    }
  }

  /* Calendario - Vista móvil vertical */
  .calendar-grid {
    grid-template-columns: 60px 1fr;
    gap: 0;
    touch-action: pan-y; /* Permitir scroll vertical, swipe horizontal */
    user-select: none; /* Evitar selección de texto durante drag */
    -webkit-user-select: none;
  }

  .cell {
    min-height: 60px;
    padding: 8px;
    user-select: none; /* Evitar selección durante drag */
    -webkit-user-select: none;
    -webkit-touch-callout: none; /* Evitar menú contextual iOS */
  }

  .day-header {
    grid-column: 1 / -1;
    font-size: 13px;
    padding: 10px 4px;
    font-weight: 600;
    background: var(--primary-color);
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 2px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .day-header.today {
    background: var(--success-color);
    box-shadow: inset 0 -3px 0 rgba(0,0,0,0.2);
  }

  .time {
    font-size: 11px;
    font-weight: 500;
  }

  .busy {
    border-left: 3px solid var(--primary-color);
  }

  .busy strong {
    font-size: 13px;
  }

  .busy span {
    font-size: 11px;
  }

  /* Modal - adaptable al contenido en mobile */
  .modal {
    padding: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    align-items: flex-end; /* Alinear al fondo */
  }

  .modal-content {
    padding: 20px 16px;
    max-width: 100%;
    margin: 0;
    border-radius: 16px 16px 0 0;
    position: relative;
    width: 100%;
    height: auto;
    max-height: 100vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
    box-sizing: border-box;
  }

  /* Formularios de agendamiento - altura completa */
  .modal-content:has(form),
  .modal-content:has(.cita-form) {
    height: 100vh;
  }

  @keyframes slideUp {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }

  .modal h3 {
    font-size: 18px;
    margin-bottom: 16px;
  }

  /* Formularios - optimizados para móvil */
  .form-group label {
    font-size: 13px;
    font-weight: 600;
  }

  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 16px; /* Evita zoom en iOS */
    padding: 12px;
    border-radius: 8px;
  }

  /* Slots View - vertical en móviles */
  .slots-view {
    padding: 12px;
  }

  .slots-grid-columnas {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-x: visible;
    padding: 12px 0;
  }

  .dia-slots-columna {
    min-width: 100%;
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  }

  .dia-slots-header {
    padding: 12px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .dia-nombre-corto {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
  }

  .btn-copiar-horarios {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
  }

  .btn-copiar-horarios .material-icons {
    font-size: 20px;
    color: white;
  }

  .btn-copiar-horarios:active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    transform: scale(0.95);
  }

  .btn-copiar-horarios:active .material-icons {
    color: white;
  }

  .btn-copiar-horarios.copiado {
    background: #4caf50;
    border-color: #4caf50;
  }

  .btn-copiar-horarios.copiado .material-icons {
    color: white;
  }

  .dia-slots-separator {
    height: 1px;
    background: var(--border-color);
    margin: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  }

  .slots-list-vertical {
    padding: 12px;
    display: flex !important;
    flex-direction: column;
    gap: 8px;
  }

  .slot-btn-columna {
    padding: 16px;
    font-size: 15px;
    border-radius: 8px;
    display: block !important;
    font-weight: 500;
    transition: all 0.2s;
  }

  .slot-btn-columna:active {
    transform: scale(0.98);
  }

  .dia-slots-header {
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--primary-color) 0%, #0056b3 100%);
  }

  .dia-nombre-corto {
    font-size: 14px;
    font-weight: 600;
    color: white;
  }

  .slots-list-vertical {
    gap: 8px;
    padding: 12px;
  }

  /* Botones - estilo app nativa */
  .btn-primary,
  .btn-secondary {
    padding: 12px 20px;
    font-size: 15px;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s;
  }

  .btn-primary:active,
  .btn-secondary:active {
    transform: scale(0.98);
  }

  /* Botones del formulario - horizontal en móvil */
  .modal-actions {
    flex-direction: row !important;
    gap: 8px !important;
  }

  .modal-actions .btn,
  .modal-actions button.btn {
    flex: 1 !important;
    min-width: 0 !important;
    width: auto !important;
  }

  /* Stats - ocultos en mobile (van al sidebar que está oculto) */
  .stats-section {
    display: none;
  }

  /* Safe area para dispositivos con notch */
  @supports (padding-bottom: env(safe-area-inset-bottom)) {
    body {
      padding-bottom: calc(60px + env(safe-area-inset-bottom));
    }

    .mobile-bottom-nav {
      padding-bottom: env(safe-area-inset-bottom);
      height: calc(60px + env(safe-area-inset-bottom));
    }
  }
}

/* ==========================================
   EXTRA SMALL MOBILE (max-width: 480px)
   ========================================== */

@media (max-width: 480px) {
  .header-content {
    padding: 8px 12px;
  }

  .title {
    font-size: 13px;
  }

  .last-update {
    font-size: 9px;
  }

  .btn-icon {
    width: 32px;
    height: 32px;
  }

  .btn-nav {
    padding: 5px 10px;
    font-size: 11px;
  }

  .cell {
    min-height: 50px;
    padding: 6px;
  }

  .modal-content {
    padding: 16px;
  }

  .modal h3 {
    font-size: 16px;
  }

  .slots-view {
    padding: 8px;
  }

  .slots-grid-columnas {
    gap: 12px;
    padding: 8px 0;
  }

  .dia-slots-header {
    padding: 10px 12px;
  }

  .dia-nombre-corto {
    font-size: 13px;
  }

  .slots-list-vertical {
    gap: 6px;
    padding: 10px;
  }

  .slot-btn-columna {
    padding: 12px 10px;
    font-size: 13px;
  }

  .btn-primary,
  .btn-secondary {
    padding: 8px 14px;
    font-size: 12px;
  }

  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 13px;
    padding: 8px;
  }

  /* Safe Area Support - iPhone notch, etc */
  .mobile-bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(60px + env(safe-area-inset-bottom));
  }

  body {
    padding-bottom: calc(60px + env(safe-area-inset-bottom));
  }

  .main-content {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }
}

/* ==========================================
   DESKTOP con ventana pequeña - Anular estilos móviles
   Cuando es desktop pero la ventana está minimizada
   ========================================== */

@media (max-width: 767px) {
  /* Si es desktop o tablet (no móvil), mantener grid normal */
  body.device-desktop .calendar-grid,
  body.device-tablet .calendar-grid {
    grid-template-columns: 80px repeat(7, 1fr) !important;
  }

  /* Mostrar sidebar en desktop */
  body.device-desktop .sidebar {
    display: block !important;
  }

  /* No aplicar bottom nav en desktop/tablet */
  body.device-desktop .mobile-bottom-nav,
  body.device-tablet .mobile-bottom-nav {
    display: none !important;
  }

  /* Mostrar tabs normales en desktop/tablet */
  body.device-desktop .view-tabs,
  body.device-tablet .view-tabs {
    display: flex !important;
  }

  /* Reset padding en desktop */
  body.device-desktop,
  body.device-tablet {
    padding-bottom: 0 !important;
  }

  body.device-desktop .main-content,
  body.device-tablet .main-content {
    padding-bottom: 0 !important;
  }
}
