/* ============================================
   COLE - Escritorio Educativo tipo OS
   ============================================ */

/* --- Layout principal del escritorio --- */
.cole-desktop {
    position: relative;
    width: 100vw;
    height: 100vh;
    background: var(--cole-bg-desktop);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.cole-desktop-wallpaper {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    opacity: 0.08;
}

[data-theme="dark"] .cole-desktop-wallpaper {
    background: linear-gradient(135deg, #1a1c2e 0%, #2d1b69 100%);
    opacity: 0.3;
}

/* --- Área de iconos del escritorio --- */
.cole-desktop-area {
    flex: 1;
    position: relative;
    z-index: var(--cole-z-desktop);
    padding: var(--cole-space-lg);
    padding-bottom: calc(var(--cole-taskbar-height) + var(--cole-space-lg));
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, 100px);
    grid-template-rows: repeat(auto-fill, 110px);
    gap: var(--cole-space-md);
    align-content: start;
}

/* --- Icono del escritorio --- */
.cole-desktop-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--cole-space-xs);
    padding: var(--cole-space-sm);
    border-radius: var(--cole-radius-md);
    cursor: pointer;
    transition: background var(--cole-transition-fast);
    user-select: none;
    text-decoration: none;
    color: var(--cole-text-primary);
    width: 100px;
    height: 100px;
    justify-content: center;
}

.cole-desktop-icon:hover {
    background: rgba(79, 70, 229, 0.08);
    text-decoration: none;
    color: var(--cole-text-primary);
}

.cole-desktop-icon:active {
    background: rgba(79, 70, 229, 0.15);
}

.cole-desktop-icon.active {
    background: rgba(79, 70, 229, 0.12);
}

.cole-desktop-icon__graphic {
    width: var(--cole-icon-size);
    height: var(--cole-icon-size);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--cole-radius-lg);
    font-size: 28px;
    transition: transform var(--cole-transition-fast);
    position: relative;
}

.cole-desktop-icon:hover .cole-desktop-icon__graphic {
    transform: scale(1.08);
}

.cole-desktop-icon__graphic--courses {
    background: linear-gradient(135deg, #4F46E5, #7C3AED);
    color: white;
}

.cole-desktop-icon__graphic--tests {
    background: linear-gradient(135deg, #06B6D4, #3B82F6);
    color: white;
}

.cole-desktop-icon__graphic--store {
    background: linear-gradient(135deg, #F59E0B, #EF4444);
    color: white;
}

.cole-desktop-icon__graphic--ai {
    background: linear-gradient(135deg, #10B981, #06B6D4);
    color: white;
}

.cole-desktop-icon__graphic--chat {
    background: linear-gradient(135deg, #8B5CF6, #EC4899);
    color: white;
}

.cole-desktop-icon__graphic--profile {
    background: linear-gradient(135deg, #6366F1, #8B5CF6);
    color: white;
}

.cole-desktop-icon__graphic--calendar {
    background: linear-gradient(135deg, #EF4444, #F59E0B);
    color: white;
}

.cole-desktop-icon__graphic--notifications {
    background: linear-gradient(135deg, #F59E0B, #F97316);
    color: white;
}

.cole-desktop-icon__graphic--progress {
    background: linear-gradient(135deg, #10B981, #34D399);
    color: white;
}

.cole-desktop-icon__graphic--library {
    background: linear-gradient(135deg, #6366F1, #4F46E5);
    color: white;
}

.cole-desktop-icon__graphic--help {
    background: linear-gradient(135deg, #64748B, #94A3B8);
    color: white;
}

.cole-desktop-icon__graphic--gamification {
    background: linear-gradient(135deg, #F59E0B, #EF4444);
    color: white;
}

.cole-desktop-icon__graphic--settings {
    background: linear-gradient(135deg, #6B7280, #4B5563);
    color: white;
}

.cole-desktop-icon__graphic--classroom {
    background: linear-gradient(135deg, #0EA5E9, #6366F1);
    color: white;
}

.cole-desktop-icon__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--cole-error);
    color: white;
    font-size: 11px;
    font-weight: var(--cole-font-weight-bold);
    border-radius: var(--cole-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.cole-desktop-icon__label {
    font-size: var(--cole-font-size-xs);
    font-weight: var(--cole-font-weight-medium);
    text-align: center;
    color: #FFFFFF;
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

[data-theme="dark"] .cole-desktop-icon__label {
    color: #FFFFFF;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

/* --- Barra de tareas --- */
.cole-taskbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--cole-taskbar-height);
    background: var(--cole-bg-taskbar);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--cole-border);
    box-shadow: var(--cole-shadow-taskbar);
    z-index: var(--cole-z-taskbar);
    display: flex;
    align-items: center;
    padding: 0 var(--cole-space-md);
    gap: var(--cole-space-sm);
}

.cole-taskbar__start {
    display: flex;
    align-items: center;
    gap: var(--cole-space-sm);
}

.cole-taskbar__logo {
    display: flex;
    align-items: center;
    gap: var(--cole-space-sm);
    padding: 6px 14px;
    border-radius: var(--cole-radius-md);
    font-weight: var(--cole-font-weight-bold);
    font-size: var(--cole-font-size-lg);
    color: var(--cole-primary);
    transition: background var(--cole-transition-fast);
    cursor: pointer;
}

.cole-taskbar__logo:hover {
    background: var(--cole-bg-surface-hover);
    text-decoration: none;
    color: var(--cole-primary);
}

.cole-taskbar__logo svg {
    width: 28px;
    height: 28px;
}

.cole-taskbar__divider {
    width: 1px;
    height: 28px;
    background: var(--cole-border);
    margin: 0 var(--cole-space-xs);
}

.cole-taskbar__apps {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: none;
}

.cole-taskbar__apps::-webkit-scrollbar {
    display: none;
}

.cole-taskbar__app {
    display: flex;
    align-items: center;
    gap: var(--cole-space-xs);
    padding: 6px 12px;
    border-radius: var(--cole-radius-sm);
    font-size: var(--cole-font-size-sm);
    color: var(--cole-text-secondary);
    transition: all var(--cole-transition-fast);
    white-space: nowrap;
    text-decoration: none;
    position: relative;
}

.cole-taskbar__app:hover {
    background: var(--cole-bg-surface-hover);
    color: var(--cole-text-primary);
    text-decoration: none;
}

.cole-taskbar__app.active {
    background: var(--cole-bg-surface);
    color: var(--cole-text-primary);
    box-shadow: var(--cole-shadow-sm);
}

.cole-taskbar__app.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 3px;
    background: var(--cole-primary);
    border-radius: var(--cole-radius-full);
}

.cole-taskbar__app-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.cole-taskbar__end {
    display: flex;
    align-items: center;
    gap: var(--cole-space-sm);
}

.cole-taskbar__time {
    font-size: var(--cole-font-size-sm);
    color: var(--cole-text-secondary);
    font-weight: var(--cole-font-weight-medium);
    padding: 4px 8px;
    white-space: nowrap;
}

.cole-taskbar__user-btn {
    display: flex;
    align-items: center;
    gap: var(--cole-space-sm);
    padding: 4px 10px 4px 4px;
    border: none;
    border-radius: var(--cole-radius-full);
    transition: background var(--cole-transition-fast);
    color: var(--cole-text-primary);
    background: var(--cole-bg-taskbar-btn, transparent);
    cursor: pointer;
    font-family: inherit;
}

.cole-taskbar__user-btn:hover {
    background: var(--cole-bg-surface-hover);
}

/* --- Menú de usuario --- */
.cole-user-menu {
    position: fixed;
    bottom: calc(var(--cole-taskbar-height) + var(--cole-space-sm));
    right: var(--cole-space-md);
    width: 280px;
    background: var(--cole-bg-elevated);
    border: 1px solid var(--cole-border);
    border-radius: var(--cole-radius-lg);
    box-shadow: var(--cole-shadow-xl);
    z-index: var(--cole-z-dropdown);
    padding: var(--cole-space-sm);
    animation: cole-scale-in var(--cole-transition-fast);
    display: none;
}

.cole-user-menu.open {
    display: block;
}

.cole-user-menu__header {
    display: flex;
    align-items: center;
    gap: var(--cole-space-md);
    padding: var(--cole-space-md);
    border-bottom: 1px solid var(--cole-border);
    margin-bottom: var(--cole-space-xs);
}

.cole-user-menu__name {
    font-weight: var(--cole-font-weight-semibold);
    font-size: var(--cole-font-size-sm);
}

.cole-user-menu__role {
    font-size: var(--cole-font-size-xs);
    color: var(--cole-text-muted);
}

.cole-user-menu__item {
    display: flex;
    align-items: center;
    gap: var(--cole-space-sm);
    padding: 8px var(--cole-space-md);
    border-radius: var(--cole-radius-sm);
    font-size: var(--cole-font-size-sm);
    color: var(--cole-text-secondary);
    transition: all var(--cole-transition-fast);
    width: 100%;
    text-align: left;
    text-decoration: none;
}

.cole-user-menu__item:hover {
    background: var(--cole-bg-surface-hover);
    color: var(--cole-text-primary);
    text-decoration: none;
}

.cole-user-menu__item--danger {
    color: var(--cole-error);
}

.cole-user-menu__item--danger:hover {
    background: rgba(239, 68, 68, 0.08);
    color: var(--cole-error);
}

.cole-user-menu__separator {
    height: 1px;
    background: var(--cole-border);
    margin: var(--cole-space-xs) 0;
}

/* --- Responsive: Móvil --- */
@media (max-width: 768px) {
    .cole-desktop-area {
        grid-template-columns: repeat(auto-fill, 85px);
        grid-template-rows: repeat(auto-fill, 95px);
        gap: var(--cole-space-sm);
        padding: var(--cole-space-md);
        padding-bottom: calc(var(--cole-taskbar-height) + var(--cole-space-md));
    }

    .cole-desktop-icon {
        width: 85px;
        height: 90px;
    }

    .cole-desktop-icon__graphic {
        width: var(--cole-icon-size-sm);
        height: var(--cole-icon-size-sm);
        font-size: 22px;
    }

    .cole-desktop-icon__label {
        font-size: 11px;
        max-width: 80px;
    }

    .cole-taskbar__app span {
        display: none;
    }

    .cole-taskbar__time {
        display: none;
    }

    .cole-user-menu {
        right: var(--cole-space-sm);
        left: var(--cole-space-sm);
        width: auto;
    }
}

@media (max-width: 480px) {
    .cole-desktop-area {
        grid-template-columns: repeat(4, 1fr);
        gap: var(--cole-space-xs);
        padding: var(--cole-space-sm);
    }

    .cole-desktop-icon {
        width: auto;
        height: auto;
        padding: var(--cole-space-sm) var(--cole-space-xs);
    }

    .cole-taskbar {
        height: 50px;
    }

    .cole-taskbar__logo span {
        display: none;
    }
}

/* ============================================
   PERSONALIZATION: Wallpaper variants
   ============================================ */
.cole-desktop-wallpaper[data-wallpaper="gradient-blue"] { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important; opacity: 1 !important; }
.cole-desktop-wallpaper[data-wallpaper="gradient-purple"] { background: linear-gradient(135deg, #a855f7 0%, #6366f1 100%) !important; opacity: 1 !important; }
.cole-desktop-wallpaper[data-wallpaper="gradient-green"] { background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important; opacity: 1 !important; }
.cole-desktop-wallpaper[data-wallpaper="gradient-sunset"] { background: linear-gradient(135deg, #f97316 0%, #ec4899 100%) !important; opacity: 1 !important; }
.cole-desktop-wallpaper[data-wallpaper="gradient-ocean"] { background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%) !important; opacity: 1 !important; }
.cole-desktop-wallpaper[data-wallpaper="gradient-forest"] { background: linear-gradient(135deg, #059669 0%, #065f46 100%) !important; opacity: 1 !important; }
.cole-desktop-wallpaper[data-wallpaper="gradient-candy"] { background: linear-gradient(135deg, #ec4899 0%, #f59e0b 100%) !important; opacity: 1 !important; }
.cole-desktop-wallpaper[data-wallpaper="gradient-night"] { background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e1b4b 100%) !important; opacity: 1 !important; }
.cole-desktop-wallpaper[data-wallpaper="gradient-warm"] { background: linear-gradient(135deg, #fbbf24 0%, #f97316 50%, #ef4444 100%) !important; opacity: 1 !important; }
.cole-desktop-wallpaper[data-wallpaper="solid-dark"] { background: #1a1a2e !important; opacity: 1 !important; }
.cole-desktop-wallpaper[data-wallpaper="solid-light"] { background: #e5e7eb !important; opacity: 1 !important; }

/* ============================================
   PERSONALIZATION: Palette overrides
   ============================================ */
.cole-desktop[data-palette="blue"] { --cole-primary: #3B82F6; --cole-primary-light: #60A5FA; --cole-primary-dark: #2563EB; }
.cole-desktop[data-palette="green"] { --cole-primary: #10B981; --cole-primary-light: #34D399; --cole-primary-dark: #059669; }
.cole-desktop[data-palette="purple"] { --cole-primary: #8B5CF6; --cole-primary-light: #A78BFA; --cole-primary-dark: #7C3AED; }
.cole-desktop[data-palette="orange"] { --cole-primary: #F59E0B; --cole-primary-light: #FBBF24; --cole-primary-dark: #D97706; }
.cole-desktop[data-palette="red"] { --cole-primary: #EF4444; --cole-primary-light: #FCA5A5; --cole-primary-dark: #DC2626; }
.cole-desktop[data-palette="cyan"] { --cole-primary: #06B6D4; --cole-primary-light: #22D3EE; --cole-primary-dark: #0891B2; }
.cole-desktop[data-palette="pink"] { --cole-primary: #EC4899; --cole-primary-light: #F472B6; --cole-primary-dark: #DB2777; }

/* ============================================
   PERSONALIZATION: Icon sizes
   ============================================ */
.cole-desktop[data-icon-size="small"] .cole-desktop-icon__graphic { width: 48px; height: 48px; }
.cole-desktop[data-icon-size="small"] .cole-desktop-icon__label { font-size: 10px; }
.cole-desktop[data-icon-size="small"] .cole-desktop-icon { width: 80px; height: 85px; }
.cole-desktop[data-icon-size="large"] .cole-desktop-icon__graphic { width: 80px; height: 80px; }
.cole-desktop[data-icon-size="large"] .cole-desktop-icon__label { font-size: 14px; }
.cole-desktop[data-icon-size="large"] .cole-desktop-icon { width: 120px; height: 130px; }

/* ============================================
   PERSONALIZATION: Hide labels
   ============================================ */
.cole-desktop[data-show-labels="false"] .cole-desktop-icon__label { display: none; }

/* ============================================
   PERSONALIZATION: Taskbar top
   ============================================ */
.cole-desktop[data-taskbar="top"] .cole-taskbar {
    top: 0;
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid var(--cole-border);
}
.cole-desktop[data-taskbar="top"] .cole-desktop-area {
    padding-top: calc(var(--cole-taskbar-height) + var(--cole-space-lg));
    padding-bottom: var(--cole-space-lg);
}
.cole-desktop[data-taskbar="top"] .cole-start-menu {
    bottom: auto;
    top: calc(var(--cole-taskbar-height) + var(--cole-space-sm));
}
.cole-desktop[data-taskbar="top"] .cole-user-menu {
    bottom: auto;
    top: calc(var(--cole-taskbar-height) + var(--cole-space-sm));
}

/* --- Embed mode: hide desktop chrome inside iframes --- */
.cole-embed .cole-desktop {
    background: var(--cole-bg-body) !important;
    min-height: auto !important;
    padding-bottom: 0 !important;
}
.cole-embed .cole-desktop-wallpaper {
    display: none !important;
}
.cole-embed .cole-taskbar {
    display: none !important;
}
.cole-embed .cole-page {
    padding-bottom: var(--cole-space-lg) !important;
}
.cole-embed [style*="padding-bottom"] {
    padding-bottom: 12px !important;
}

/* --- Dark mode badge fixes --- */
[data-theme="dark"] .cole-badge[style*="background:rgba(139,92,246"],
[data-theme="dark"] .cole-badge[style*="background:#F3E8FF"],
[data-theme="dark"] [style*="background:rgba(139,92,246"] {
    background: rgba(139,92,246,0.25) !important;
    color: #C4B5FD !important;
}
[data-theme="dark"] .cole-badge[style*="background:rgba(245,158,11"],
[data-theme="dark"] [style*="background:rgba(245,158,11"] {
    background: rgba(245,158,11,0.25) !important;
    color: #FCD34D !important;
}
[data-theme="dark"] .cole-badge[style*="background:rgba(239,68,68"],
[data-theme="dark"] [style*="background:rgba(239,68,68"],
[data-theme="dark"] .cole-badge[style*="background:#FEE2E2"] {
    background: rgba(239,68,68,0.25) !important;
    color: #FCA5A5 !important;
}
[data-theme="dark"] .cole-badge[style*="background:#D1FAE5"],
[data-theme="dark"] [style*="background:#D1FAE5"] {
    background: rgba(16,185,129,0.25) !important;
    color: #6EE7B7 !important;
}
[data-theme="dark"] .cole-badge[style*="background:#DBEAFE"],
[data-theme="dark"] [style*="background:#DBEAFE"] {
    background: rgba(59,130,246,0.25) !important;
    color: #93C5FD !important;
}
[data-theme="dark"] .cole-badge[style*="background:#ECFEFF"],
[data-theme="dark"] [style*="background:#ECFEFF"] {
    background: rgba(6,182,212,0.25) !important;
    color: #67E8F9 !important;
}
[data-theme="dark"] .cole-badge[style*="background:#e5e7eb"],
[data-theme="dark"] [style*="background:#e5e7eb"],
[data-theme="dark"] .action-badge.edited {
    background: rgba(156,163,175,0.25) !important;
    color: #D1D5DB !important;
}
[data-theme="dark"] .cole-message-error,
[data-theme="dark"] .cole-alert-error {
    background: rgba(239,68,68,0.15) !important;
    color: #FCA5A5 !important;
}
[data-theme="dark"] .cole-message-success,
[data-theme="dark"] .cole-alert-success {
    background: rgba(34,197,94,0.15) !important;
    color: #86EFAC !important;
}
