/* =====================================================
   DESKTOP.CSS
   Sistema de escritorio para ≥ 1200px
   Ventanas flotantes con drag, resize y taskbar
   ===================================================== */

/* ─────────────────────────────────────────────────────
   Solo activo en modo escritorio
   ───────────────────────────────────────────────────── */
@media (min-width: 1200px) {

  /* ── Fondo del escritorio ── */
  #desktopBackground {
    position: fixed;
    inset: 0;
    z-index: 0;
    background:
      radial-gradient(ellipse at 20% 30%, rgba(102, 126, 234, 0.18) 0%, transparent 55%),
      radial-gradient(ellipse at 80% 70%, rgba(118, 75, 162, 0.15) 0%, transparent 55%),
      linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    /* Grilla sutil tipo blueprint */
    background-image:
      radial-gradient(ellipse at 20% 30%, rgba(102, 126, 234, 0.18) 0%, transparent 55%),
      radial-gradient(ellipse at 80% 70%, rgba(118, 75, 162, 0.15) 0%, transparent 55%),
      linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px),
      linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    background-size: 100% 100%, 100% 100%, 40px 40px, 40px 40px, 100% 100%;
  }

  [data-theme="light"] #desktopBackground {
    background:
      radial-gradient(ellipse at 20% 30%, rgba(102, 126, 234, 0.1) 0%, transparent 55%),
      radial-gradient(ellipse at 80% 70%, rgba(118, 75, 162, 0.08) 0%, transparent 55%),
      linear-gradient(rgba(0,0,0,0.04) 1px, transparent 1px),
      linear-gradient(90deg, rgba(0,0,0,0.04) 1px, transparent 1px),
      linear-gradient(135deg, #e2e8f0 0%, #f1f5f9 50%, #e2e8f0 100%);
    background-size: 100% 100%, 100% 100%, 40px 40px, 40px 40px, 100% 100%;
  }

  /* ── Body en modo escritorio: sin padding, overflow hidden ── */
  body {
    padding: 0 !important;
    overflow: hidden;
    background: transparent !important;
  }

  /* Ocultar el layout normal — las ventanas reemplazan todo */
  .app-layout {
    display: none !important;
  }

  /* ── Contenedor de las ventanas flotantes ── */
  #desktopWindowsLayer {
    position: fixed;
    inset: 0;
    bottom: 40px; /* espacio para taskbar */
    z-index: 50;
    pointer-events: none; /* las ventanas manejan sus propios eventos */
  }

  /* =================================================
     VENTANA BASE
     ================================================= */
  .desktop-window {
    position: fixed;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
    box-shadow:
      0 24px 64px rgba(0, 0, 0, 0.45),
      0 4px 16px rgba(0, 0, 0, 0.3),
      inset 0 1px 0 rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.1);
    pointer-events: all;
    transition: box-shadow 0.2s ease;
    min-width: 280px;
    min-height: 200px;
    /* El fondo lo pone el contenido interno (.container) */
    background: var(--bg-container);
  }

  .desktop-window:focus-within,
  .desktop-window.focused {
    box-shadow:
      0 32px 80px rgba(0, 0, 0, 0.55),
      0 8px 24px rgba(102, 126, 234, 0.2),
      inset 0 1px 0 rgba(255,255,255,0.12);
    border-color: rgba(102, 126, 234, 0.35);
  }

  /* =================================================
     BARRA DE TÍTULO
     ================================================= */
  .win-titlebar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    height: 36px;
    min-height: 36px;
    background: var(--bg-header);
    color: rgba(255,255,255,0.92);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: grab;
    user-select: none;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
  }

  .win-titlebar:active { cursor: grabbing; }

  .win-title-icon { font-size: 1rem; }

  .win-title-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: 0.3px;
  }

  /* ── Controles de ventana ── */
  .win-controls {
    display: flex;
    gap: 6px;
    align-items: center;
  }

  .win-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    font-weight: 700;
    flex-shrink: 0;
  }

  .win-minimize {
    background: rgba(255, 189, 46, 0.85);
    color: #7a4800;
  }

  .win-minimize:hover {
    background: #ffbd2e;
    transform: scale(1.1);
  }

  /* ── Contenido scrollable de la ventana ── */
  .win-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
  }

  /* El .container dentro de cada ventana pierde su propio shadow/radius */
  .desktop-window .container {
    max-width: none !important;
    margin: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    width: 100% !important;
    min-height: 100%;
    overflow: visible;
  }

  /* =================================================
     HANDLES DE RESIZE (8 direcciones)
     ================================================= */
  .win-resize-handle {
    position: absolute;
    z-index: 10;
    user-select: none;
  }

  /* Lados */
  .win-resize-n  { top: 0;    left: 6px;  right: 6px;  height: 5px; cursor: n-resize;  }
  .win-resize-s  { bottom: 0; left: 6px;  right: 6px;  height: 5px; cursor: s-resize;  }
  .win-resize-e  { right: 0;  top: 6px;   bottom: 6px; width: 5px;  cursor: e-resize;  }
  .win-resize-w  { left: 0;   top: 6px;   bottom: 6px; width: 5px;  cursor: w-resize;  }

  /* Esquinas */
  .win-resize-ne { top: 0;    right: 0;   width: 12px; height: 12px; cursor: ne-resize; }
  .win-resize-se { bottom: 0; right: 0;   width: 12px; height: 12px; cursor: se-resize; }
  .win-resize-sw { bottom: 0; left: 0;    width: 12px; height: 12px; cursor: sw-resize; }
  .win-resize-nw { top: 0;    left: 0;    width: 12px; height: 12px; cursor: nw-resize; }

  /* Indicador visual en esquina SE */
  .win-resize-se::after {
    content: '';
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 8px;
    height: 8px;
    border-right: 2px solid rgba(255,255,255,0.25);
    border-bottom: 2px solid rgba(255,255,255,0.25);
    border-radius: 0 0 2px 0;
  }

  /* =================================================
     TASKBAR
     ================================================= */
  #desktopTaskbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 -4px 24px rgba(0,0,0,0.4);
  }

  [data-theme="light"] #desktopTaskbar {
    background: rgba(255,255,255,0.88);
    border-top-color: rgba(0,0,0,0.1);
    box-shadow: 0 -2px 12px rgba(0,0,0,0.1);
  }

  .taskbar-left {
    display: flex;
    align-items: center;
    flex-shrink: 0;
  }

  .taskbar-app-name {
    font-size: 0.78rem;
    font-weight: 700;
    color: rgba(255,255,255,0.6);
    letter-spacing: 0.5px;
    padding-right: 12px;
    border-right: 1px solid rgba(255,255,255,0.12);
  }

  [data-theme="light"] .taskbar-app-name { color: rgba(0,0,0,0.45); }

  .taskbar-windows {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .taskbar-windows::-webkit-scrollbar { display: none; }

  .taskbar-win-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.07);
    color: rgba(255,255,255,0.75);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    height: 28px;
  }

  [data-theme="light"] .taskbar-win-btn {
    background: rgba(0,0,0,0.05);
    border-color: rgba(0,0,0,0.1);
    color: rgba(0,0,0,0.65);
  }

  .taskbar-win-btn:hover {
    background: rgba(255,255,255,0.14);
    border-color: rgba(255,255,255,0.2);
    color: #fff;
  }

  .taskbar-win-btn.active {
    background: rgba(102, 126, 234, 0.25);
    border-color: rgba(102, 126, 234, 0.5);
    color: #a5b4fc;
  }

  .taskbar-win-btn.minimized {
    opacity: 0.5;
    border-style: dashed;
  }

  .taskbar-right {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding-left: 8px;
    border-left: 1px solid rgba(255,255,255,0.12);
  }

  [data-theme="light"] .taskbar-right {
    border-left-color: rgba(0,0,0,0.1);
  }

  #desktopResetLayout {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.55);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
  }

  #desktopResetLayout:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
  }

  [data-theme="light"] #desktopResetLayout {
    border-color: rgba(0,0,0,0.15);
    color: rgba(0,0,0,0.45);
  }

  /* =================================================
     VENTANA: PANEL PRINCIPAL (Biblia)
     ================================================= */
  #desktopWinMain {
    /* El contenido interno ya tiene su propio scroll */
  }

  #desktopWinMain .win-body {
    /* El .container maneja su propio overflow */
    overflow: hidden;
  }

  /* Resetear height fijo del app-layout dentro de la ventana */
  #desktopWinMain .container {
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  /* =================================================
     VENTANA: IA PANEL
     ================================================= */
  #desktopWinIA .ia-panel-wrapper {
    position: static !important;
    transform: none !important;
    width: 100% !important;
    height: 100% !important;
    flex: 1;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
  }

  #desktopWinIA .ia-panel-wrapper.ia-open {
    top: auto !important;
  }

  #desktopWinIA .ia-trigger-bar {
    display: none !important;
  }

  #desktopWinIA .ia-panel {
    flex: 1;
    border-radius: 0;
    border-top: none;
    overflow: hidden;
  }

  /* =================================================
     SCROLLBARS personalizados dentro de ventanas
     ================================================= */
  .desktop-window .win-body::-webkit-scrollbar,
  .desktop-window .content::-webkit-scrollbar {
    width: 5px;
  }

  .desktop-window .win-body::-webkit-scrollbar-track { background: transparent; }

  .desktop-window .win-body::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
  }

  .desktop-window .win-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.25);
  }

  /* =================================================
     ANIMACIÓN DE APERTURA
     ================================================= */
  @keyframes win-appear {
    from {
      opacity: 0;
      transform: scale(0.96) translateY(8px);
    }
    to {
      opacity: 1;
      transform: scale(1) translateY(0);
    }
  }

  .desktop-window {
    animation: win-appear 0.2s ease forwards;
  }

} /* fin @media ≥1200px */

/* ── Adaptar ventanas a contenedores normales en móvil/tablet ── */
@media (max-width: 1199px) {
  #desktopBackground,
  #desktopTaskbar,
  #desktopWindowsLayer {
    display: none !important;
  }

  /* En lugar de ocultar las ventanas, les quitamos su formato para que se vean como antes */
  .desktop-window {
    position: static !important;
    display: block !important;
    width: 100% !important;
    height: auto !important;
    box-shadow: none !important;
    border: none !important;
    background: transparent !important;
    z-index: auto !important;
    transform: none !important;
    min-height: auto !important;
    min-width: auto !important;
  }

  /* Ocultamos la barra superior de "arrastrar" y los bordes para redimensionar */
  .win-titlebar,
  .win-resize-handle {
    display: none !important;
  }

  /* El body de la ventana pasa a ser un contenedor invisible para no afectar tu diseño móvil */
  .win-body {
    display: contents !important;
  }
}