/*
 * SPACE — Mobile Responsive Styles
 * Cubre desde tablet (768px) hasta móvil pequeño (360px)
 * Estrategia: iOS/Android-like shell en móvil, escritorio macOS en desktop
 */

/* ═══════════════════════════════════════════════════
   VARIABLES MOBILE
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root {
    --menu-height: 44px;       /* Más alto en móvil para tap targets */
    --dock-height: 80px;
    --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* ═══════════════════════════════════════════════════
   BASE — Evitar zoom en inputs, scroll suave
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  * {
    -webkit-tap-highlight-color: transparent;
  }

  input, select, textarea {
    font-size: 16px !important; /* Evita zoom automático en iOS */
  }

  html, body {
    overscroll-behavior: none;  /* Evita pull-to-refresh accidental */
    touch-action: manipulation;
  }
}

/* ═══════════════════════════════════════════════════
   MENU BAR — Mobile
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .menu-bar {
    height: var(--menu-height, 44px);
    padding: 0 12px;
    gap: 6px;
  }

  .menu-bar .apple-menu {
    font-size: 17px;
    padding: 4px 8px;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Ocultar items de menú en móvil — se muestran via toggle */
  .menu-items {
    display: none;
  }

  .menu-bar.mobile-open .menu-items {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: var(--menu-height, 44px);
    left: 0;
    right: 0;
    background: rgba(28, 28, 30, 0.96);
    backdrop-filter: blur(32px) saturate(200%);
    -webkit-backdrop-filter: blur(32px) saturate(200%);
    border-bottom: 1px solid rgba(255,255,255,0.12);
    z-index: 10060;
    padding: 8px 0;
  }

  .menu-bar.mobile-open .menu-item {
    padding: 14px 20px;
    font-size: 15px;
    border-radius: 0;
    min-height: 48px;   /* Tap target mínimo */
    display: flex;
    align-items: center;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.05);
  }

  .menu-bar.mobile-open .menu-item:active {
    background: rgba(255,255,255,0.12);
  }

  /* Botón hamburguesa */
  .menu-mobile-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.15s;
  }

  .menu-mobile-toggle:active {
    background: rgba(255,255,255,0.15);
  }

  .menu-app-name {
    font-size: 13px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .menu-clock {
    font-size: 12px;
    min-width: 80px;
    text-align: right;
  }

  .menu-status-icons {
    gap: 4px;
  }

  /* Ocultar íconos de status menos importantes */
  .status-icon:nth-child(n+3) {
    display: none;
  }
}

@media (max-width: 390px) {
  .menu-app-name { display: none; }
  .status-icon:nth-child(n+2) { display: none; }
}

/* ═══════════════════════════════════════════════════
   DESKTOP / FONDO — Mobile
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  #desktop {
    /* El escritorio ocupa todo entre menu y dock */
    top: var(--menu-height, 44px);
    bottom: var(--dock-height, 80px);
  }
}

/* ═══════════════════════════════════════════════════
   ICONOS DE ESCRITORIO — Mobile
   Los iconos se reorganizan en columna derecha compacta
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .desktop-icons {
    left: 0;
    right: 0;
    top: calc(var(--menu-height, 44px) + 8px);
    bottom: calc(var(--dock-height, 80px) + 8px);
  }

  .desktop-icon {
    width: 64px;
    padding: 6px 4px;
    border-radius: 12px;
    /* Tap target mínimo 48x48 según HIG */
    min-height: 48px;
    -webkit-tap-highlight-color: transparent;
  }

  .desktop-icon:active {
    background: rgba(255,255,255,0.25);
    transform: scale(0.92);
  }

  .desktop-icon-symbol {
    font-size: 32px;
  }

  .desktop-icon-svg {
    width: 44px;
    height: 44px;
  }

  .desktop-icon-svg svg {
    border-radius: 20%;
  }

  .desktop-icon-label {
    font-size: 10px;
    font-weight: 600;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8), 0 0 8px rgba(0,0,0,0.5);
    line-height: 1.2;
    max-width: 60px;
    word-break: break-word;
    text-align: center;
  }
}

@media (max-width: 390px) {
  .desktop-icon {
    width: 56px;
    padding: 4px 2px;
  }

  .desktop-icon-symbol { font-size: 28px; }
  .desktop-icon-svg    { width: 38px; height: 38px; }
  .desktop-icon-label  { font-size: 9px; }
}

/* ═══════════════════════════════════════════════════
   VENTANAS — Mobile (full-screen sheet style)
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .window {
    /* Full-width, entre menu y dock */
    position: fixed !important;
    left: 6px !important;
    right: 6px !important;
    top: calc(var(--menu-height, 44px) + 6px) !important;
    bottom: calc(var(--dock-height, 80px) + 6px) !important;
    width: calc(100vw - 12px) !important;
    height: calc(100vh - var(--menu-height, 44px) - var(--dock-height, 80px) - 12px) !important;
    min-width: unset !important;
    max-width: unset !important;
    border-radius: 14px;
    resize: none;
    /* Animación de entrada tipo sheet */
    transform-origin: bottom center;
  }

  .window.window-opening {
    animation: mobileWindowOpen 0.3s cubic-bezier(0.32, 0.72, 0, 1) forwards;
  }

  @keyframes mobileWindowOpen {
    from { opacity: 0.6; transform: translateY(40px) scale(0.97); }
    to   { opacity: 1;   transform: translateY(0) scale(1); }
  }

  /* Titlebar más alto y touch-friendly */
  .window-titlebar {
    height: 48px;
    min-height: 48px;
    padding: 0 12px;
    touch-action: none; /* Permite drag en móvil */
    -webkit-touch-callout: none;
    user-select: none;
  }

  /* Traffic lights más grandes */
  .traffic-lights {
    gap: 10px;
  }

  .traffic-light {
    width: 14px;
    height: 14px;
  }

  /* Área de drag visible — barra de grip iOS-style */
  .window-titlebar::after {
    content: '';
    display: block;
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    pointer-events: none;
  }

  .window-title {
    font-size: 14px;
    font-weight: 600;
  }

  .window-fullscreen-btn {
    font-size: 16px;
    padding: 0 10px;
    min-width: 36px;
    min-height: 36px;
  }

  /* Contenido con scroll touch */
  .window-content {
    -webkit-overflow-scrolling: touch;
    overflow: auto;
  }
}

@media (max-width: 390px) {
  .window {
    left: 0 !important;
    right: 0 !important;
    top: var(--menu-height, 44px) !important;
    bottom: var(--dock-height, 80px) !important;
    width: 100vw !important;
    height: calc(100vh - var(--menu-height, 44px) - var(--dock-height, 80px)) !important;
    border-radius: 0;
  }
}

/* ═══════════════════════════════════════════════════
   SPOTLIGHT / BÚSQUEDA — Mobile
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .spotlight {
    padding-top: 8vh;
    align-items: flex-start;
  }

  .spotlight-panel {
    width: calc(100vw - 16px);
    max-width: none;
    margin: 0 8px;
    border-radius: 14px;
  }

  .spotlight-input {
    font-size: 17px;
    padding: 14px 16px 14px 44px;
  }
}

/* ═══════════════════════════════════════════════════
   APP LAUNCHER / LAUNCHPAD — Mobile
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .launcher-overlay {
    padding: 60px 12px 100px;
  }

  .launcher-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px 8px;
  }

  .launcher-item {
    padding: 8px 4px;
  }

  .launcher-icon {
    width: 56px;
    height: 56px;
    font-size: 32px;
    border-radius: 14px;
  }

  .launcher-icon-svg {
    width: 56px;
    height: 56px;
    border-radius: 14px;
  }

  .launcher-label {
    font-size: 10px;
    margin-top: 6px;
  }

  .launcher-search {
    width: calc(100% - 32px);
    font-size: 16px;
  }
}

@media (max-width: 390px) {
  .launcher-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px 6px;
  }

  .launcher-icon,
  .launcher-icon-svg {
    width: 52px;
    height: 52px;
  }
}

/* ═══════════════════════════════════════════════════
   LOGIN OVERLAY — Mobile
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .login-overlay {
    padding: 16px;
    align-items: flex-start;
    padding-top: 15vh;
  }

  .login-card {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    padding: 28px 20px;
    border-radius: 18px;
  }

  .login-card input {
    height: 48px;
    font-size: 16px;
    padding: 0 14px;
  }

  .login-card button[type="submit"] {
    height: 48px;
    font-size: 16px;
    border-radius: 12px;
  }
}

/* ═══════════════════════════════════════════════════
   TOASTS / NOTIFICACIONES — Mobile
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .toast-container,
  #toast-container {
    top: calc(var(--menu-height, 44px) + 8px);
    right: 8px;
    left: 8px;
    max-width: none;
  }

  .toast {
    width: 100%;
    font-size: 13px;
    padding: 12px 14px;
    border-radius: 12px;
  }
}

/* ═══════════════════════════════════════════════════
   NOTIFICATION CENTER — Mobile
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .notification-panel,
  #notification-panel {
    width: 100vw !important;
    right: 0 !important;
    border-radius: 0 0 0 16px;
  }
}

/* ═══════════════════════════════════════════════════
   DIALOGS / MODALS — Mobile
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .dialog-overlay,
  .confirm-overlay {
    padding: 16px;
    align-items: flex-end;  /* Sheet desde abajo en móvil */
  }

  .dialog-card,
  .confirm-card {
    width: 100%;
    border-radius: 18px 18px 12px 12px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 20px;
  }

  .dialog-actions,
  .confirm-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }

  .dialog-actions button,
  .confirm-actions button {
    width: 100%;
    height: 48px;
    font-size: 16px;
    border-radius: 12px;
  }
}

/* ═══════════════════════════════════════════════════
   CONTEXT MENU — Mobile (no aparece en táctil)
   ═══════════════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {
  /* En dispositivos táctiles puros, el context menu se activa por long-press */
  .context-menu {
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  }

  .context-menu-item {
    padding: 14px 18px;
    font-size: 15px;
    min-height: 48px;
  }
}

/* ═══════════════════════════════════════════════════
   PWA / STANDALONE — cuando se instala como app
   ═══════════════════════════════════════════════════ */
@media (display-mode: standalone) {
  :root {
    --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
  }

  .dock {
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .menu-bar {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(var(--menu-height, 44px) + env(safe-area-inset-top, 0px));
  }
}

/* ═══════════════════════════════════════════════════
   TOUCH — Mejorar arrastre de ventanas en móvil
   ═══════════════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {
  /* Deshabilitar hover states que no tienen sentido en táctil */
  .dock-item:hover .dock-icon {
    transform: none;
    width: auto;
    height: auto;
    margin-bottom: 0;
  }

  /* Cursor por defecto en todo (no hay cursor en táctil) */
  .desktop-icon,
  .dock-item,
  .window-titlebar {
    cursor: default;
  }

  /* Touch action en titlebar para arrastre */
  .window-titlebar {
    touch-action: none;
  }
}
