/* ==========================================
   Web OS - 系统核心与全局 UI 主题引擎
   包含动态色彩与严格的 Z-Index 字典
   ========================================== */

/* 定义浅色主题变量 (默认) 与 Z-Index 字典 */
:root, :root[data-theme="light"] {
   /* 1. 色彩变量 */
   --sys-bg-color: #f3f4f6;
   --window-bg: rgba(255, 255, 255, 0.85);
   --window-border: rgba(0, 0, 0, 0.1);
   --text-primary: #1f2937;
   --text-secondary: #4b5563;
   --taskbar-bg: rgba(255, 255, 255, 0.7);
   --backdrop-blur: blur(10px);
   --primary-color: #3b82f6;
   --wallpaper: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
   --icon-hover-bg: rgba(255, 255, 255, 0.4);
   --hover-bg: rgba(0, 0, 0, 0.05);
   --bg-main: #ffffff;
   --bg-toolbar: #f8f9fa;
   --border-color: #e5e7eb;

   /* 2. 【核心新增】：全局 Z-Index 字典 (秩序基石) */
   --z-desktop-icons: 10;
   --z-window-layer: 50;       /* 窗口承载层 */
   /* 注: 具体窗口的层级由 WindowManager 从 100 开始递增分配 */
   --z-taskbar: 5000;          /* 任务栏永远盖住普通窗口 */
   --z-start-menu: 5100;       /* 开始菜单/日历面板在任务栏之上 */
   --z-context-menu: 6000;     /* 右键菜单具有极高优先级 */
   --z-system-dialog: 9000;    /* 阻断式的系统对话框/模态框 */
   --z-system-toast: 10000;    /* 屏幕边缘的轻提示必须处于绝对最顶层！ */
   color-scheme: light; /* 声明系统色彩空间 */
}

/* 监听动态切换的深色模式 */
:root[data-theme="dark"] {
    --sys-bg-color: #111827;
    --window-bg: rgba(31, 41, 55, 0.85);
    --window-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --taskbar-bg: rgba(17, 24, 39, 0.7);
    --wallpaper: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    --icon-hover-bg: rgba(255, 255, 255, 0.15);
    --hover-bg: rgba(255, 255, 255, 0.1);
    --bg-main: #1f2937;
    --bg-toolbar: #111827;
    --border-color: #374151;
    color-scheme: dark; /* 强制浏览器原生组件（如滚动条、下拉框）黑化！ */
}

/* =========================================
   全局基础重置与主桌面布局
========================================= */
* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }
body { color: var(--text-primary); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overflow: hidden; height: 100vh; width: 100vw; }

main.desktop-container { position: relative; width: 100vw; height: calc(100vh - 48px); background: var(--wallpaper); background-size: cover; background-position: center; overflow: hidden; }

/* 窗口承载层 */
.window-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: var(--z-window-layer); }

/* =========================================
   任务栏引擎 (Taskbar)
========================================= */
.taskbar-container { height: 48px; width: 100%; background: var(--taskbar-bg); backdrop-filter: var(--backdrop-blur); -webkit-backdrop-filter: var(--backdrop-blur); border-top: 1px solid var(--window-border); display: flex; align-items: center; padding: 0 10px; position: relative; z-index: var(--z-taskbar); }
.start-button { width: 36px; height: 36px; background: var(--primary-color); color: white; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-weight: bold; cursor: pointer; box-shadow: 0 2px 5px rgba(59, 130, 246, 0.4); transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1); }
.start-button:hover { filter: brightness(1.1); } .start-button:active { transform: scale(0.92); } .start-button.is-active { background: #1d4ed8; box-shadow: inset 0 2px 6px rgba(0,0,0,0.3); }
.taskbar-apps { display: flex; flex-direction: row; align-items: center; margin-left: 15px; flex: 1; justify-content: flex-start; }
.taskbar-item { width: 38px; height: 38px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1); position: relative; overflow: hidden; animation: taskbarPop 0.3s forwards; }
.taskbar-item:hover { background: rgba(255, 255, 255, 0.2); } .taskbar-item:active { transform: scale(0.85); } .taskbar-item:last-child { margin-right: 0; }
.taskbar-item svg { width: 22px; height: 22px; pointer-events: none; transition: all 0.2s ease; opacity: 0.6; filter: grayscale(100%); }
.taskbar-item::after { content: ''; position: absolute; bottom: 0; left: 25%; width: 50%; height: 3px; background-color: var(--text-secondary); border-radius: 3px 3px 0 0; transition: all 0.2s; }
.taskbar-item.is-active { background: var(--icon-hover-bg); } .taskbar-item.is-active svg { opacity: 1; filter: none; } .taskbar-item.is-active::after { background-color: var(--primary-color); box-shadow: 0 -1px 4px rgba(59, 130, 246, 0.5); }
.taskbar-item.is-minimized svg { opacity: 0.4; filter: grayscale(100%); } .taskbar-item.is-minimized::after { width: 4px; height: 4px; bottom: 3px; left: calc(50% - 2px); border-radius: 50%; background-color: var(--text-secondary); box-shadow: none; }
.taskbar-item.is-closing { animation: taskbarHide 0.25s cubic-bezier(0.2, 0.8, 0.2, 1) forwards !important; pointer-events: none; }
.taskbar-item.is-context-open { background: rgba(255, 255, 255, 0.25); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2); } .taskbar-item.is-context-open svg { opacity: 1 !important; filter: none !important; }
.system-tray { margin-left: auto; padding-left: 15px; border-left: 1px solid var(--window-border); display: flex; align-items: center;}
#sys-time-btn:hover { background: var(--hover-bg); }
@keyframes taskbarPop { 0% { opacity: 0; transform: translateY(15px) scale(0.8); } 100% { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes taskbarHide { 0% { opacity: 1; transform: translateY(0) scale(1); width: 38px; margin-right: 8px; } 100% { opacity: 0; transform: translateY(15px) scale(0.5); width: 0; margin-right: 0; padding: 0; border: none; } }

/* =========================================
   开始菜单 (Start Menu)
========================================= */
.start-menu { position: absolute; bottom: 58px; left: 10px; width: 320px; height: 480px; background: var(--window-bg); backdrop-filter: var(--backdrop-blur); -webkit-backdrop-filter: var(--backdrop-blur); border: 1px solid var(--window-border); border-radius: 12px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); display: flex; flex-direction: row; overflow: hidden; z-index: var(--z-start-menu); transform: translateY(20px); opacity: 0; pointer-events: none; transition: all 0.25s cubic-bezier(0.2, 0.8, 0.2, 1); }
.start-menu.is-open { transform: translateY(0); opacity: 1; pointer-events: auto; }
.start-menu-sidebar { width: 48px; background: var(--hover-bg); border-right: 1px solid var(--window-border); display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 15px 0; flex-shrink: 0; }
.start-menu-sidebar .user-profile, .start-menu-sidebar .power-btn { font-size: 20px; cursor: pointer; transition: transform 0.1s; color: var(--text-primary); }
.start-menu-sidebar .power-btn:hover { color: #ef4444; } .start-menu-sidebar .user-profile:active, .start-menu-sidebar .power-btn:active { transform: scale(0.9); }
.start-menu-content { display: flex; flex-direction: column; padding: 15px; gap: 15px; overflow-y: auto; flex: 1; box-sizing: border-box; }
.app-group h3 { margin: 0 0 10px 0; font-size: 13px; color: var(--text-secondary); border-bottom: 1px solid var(--window-border); padding-bottom: 5px; }
.app-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.start-menu-item { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 10px 5px; border-radius: 6px; cursor: pointer; transition: background 0.1s; }
.start-menu-item:hover { background: var(--icon-hover-bg); } .start-menu-item svg { width: 32px; height: 32px; margin-bottom: 5px; pointer-events: none; }
.start-menu-item span { font-size: 12px; color: var(--text-primary); pointer-events: none; word-break: break-all; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.2; }

/* =========================================
   日历面板 (Calendar)
========================================= */
.calendar-popup { position: absolute; bottom: 58px; right: 10px; width: 320px; background: var(--window-bg); backdrop-filter: var(--backdrop-blur); border: 1px solid var(--window-border); border-radius: 12px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); padding: 20px; z-index: var(--z-start-menu); transform: translateY(20px); opacity: 0; pointer-events: none; transition: all 0.25s cubic-bezier(0.2, 0.8, 0.2, 1); }
.calendar-popup.is-open { transform: translateY(0); opacity: 1; pointer-events: auto; }
.calendar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; color: var(--text-primary); font-weight: 600; font-size: 15px; }
.calendar-header button { background: transparent; border: none; color: var(--text-primary); width: 30px; height: 30px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.1s; }
.calendar-header button:hover { background: var(--hover-bg); } .calendar-header button svg { width: 16px; height: 16px; pointer-events: none; }
.calendar-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; font-weight: 500; }
.calendar-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar-day { aspect-ratio: 1/1; display: flex; align-items: center; justify-content: center; font-size: 13px; border-radius: 50%; cursor: default; color: var(--text-primary); transition: background 0.1s; }
.calendar-day:hover:not(.today) { background: var(--icon-hover-bg); } .calendar-day.other-month { color: var(--text-secondary); opacity: 0.4; } .calendar-day.today { background: var(--primary-color); color: white; font-weight: bold; box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4); }

/* =========================================
   全局右键菜单引擎 (Context Menu)
========================================= */
.desktop-context-menu, .start-context-menu { position: absolute; background: var(--window-bg); backdrop-filter: var(--backdrop-blur); -webkit-backdrop-filter: var(--backdrop-blur); border: 1px solid var(--window-border); border-radius: 8px; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); padding: 5px; min-width: 160px; z-index: var(--z-context-menu); display: none; transition: width 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), left 0.2s ease, top 0.2s ease; overflow: hidden; }
.desktop-context-menu.is-active, .start-context-menu.is-active { display: block; }
.context-menu-item, .start-context-menu .ctx-item { position: relative; display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; font-size: 13px; color: var(--text-primary); cursor: pointer; border-radius: 4px; transition: background 0.1s; white-space: nowrap; }
.context-menu-item:hover, .start-context-menu .ctx-item:hover { background: var(--primary-color); color: white; }
.context-menu-item.has-children::after { content: '▶'; font-size: 10px; color: var(--text-secondary); margin-left: 15px; } .context-menu-item.has-children:hover::after { color: white; }
.context-menu-back { color: var(--primary-color); font-weight: bold; font-size: 14px; } .context-menu-back:hover { color: white; }
.context-menu-icon { width: 16px; margin-right: 8px; display: inline-block; text-align: center; font-weight: bold; }
.context-menu-separator { height: 1px; background-color: var(--window-border); margin: 4px 8px; }
.menu-content-wrapper { display: flex; flex-direction: column; width: 100%; }
.animate-forward { animation: menuSlideForward 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; } .animate-backward { animation: menuSlideBackward 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
@keyframes menuSlideForward { 0% { opacity: 0; transform: translateX(15px); } 100% { opacity: 1; transform: translateX(0); } } @keyframes menuSlideBackward { 0% { opacity: 0; transform: translateX(-15px); } 100% { opacity: 1; transform: translateX(0); } }

/* =========================================
   系统级通知 (Toast) & 对话框 (System Dialog)
========================================= */
#system-toast-container { position: fixed; top: 20px; right: 20px; z-index: var(--z-system-toast); display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.system-toast { background: var(--bg-main); border-left: 4px solid var(--primary-color); box-shadow: 0 4px 15px rgba(0,0,0,0.1); padding: 12px 20px; border-radius: 4px; font-size: 13px; color: var(--text-primary); pointer-events: auto; animation: toast-in 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); display: flex; justify-content: space-between; align-items: center; min-width: 250px; }
.system-toast.error { border-left-color: #ef4444; } .system-toast.success { border-left-color: #10b981; }
.system-toast .close-btn { cursor: pointer; color: var(--text-secondary); margin-left: 15px; font-weight: bold; } .system-toast .close-btn:hover { color: var(--text-primary); }
.system-toast.fade-out { animation: toast-out 0.3s forwards; }

.system-dialog-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.4); z-index: var(--z-system-dialog); display: flex; justify-content: center; align-items: center; }
.system-dialog { background: var(--bg-main); border-radius: 8px; width: 350px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); overflow: hidden; animation: dialog-pop 0.2s ease-out; }
.system-dialog-header { padding: 15px 20px; font-weight: bold; border-bottom: 1px solid var(--window-border); background: var(--bg-toolbar); color: var(--text-primary);}
.system-dialog-body { padding: 20px; font-size: 13px; line-height: 1.6; color: var(--text-primary); }
.system-dialog-footer { padding: 15px 20px; display: flex; justify-content: flex-end; gap: 10px; background: var(--bg-toolbar); border-top: 1px solid var(--window-border); }
.system-dialog-footer { padding: 15px 20px; display: flex; justify-content: flex-end; gap: 10px; background: var(--bg-toolbar); border-top: 1px solid var(--window-border); }

/* =========================================
   系统对话框 (System Dialog) 全局按钮美化
========================================= */
.system-dialog-footer button {
    padding: 8px 18px; 
    border-radius: 6px; 
    font-size: 13px; 
    font-weight: 500; 
    cursor: pointer; 
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1); 
    background: transparent; 
    border: 1px solid var(--window-border); 
    color: var(--text-primary); 
    outline: none;
}
.system-dialog-footer button:hover { 
    background: var(--hover-bg); 
    border-color: var(--text-secondary); 
}
.system-dialog-footer button:active { 
    transform: scale(0.95); 
}

/* 强调色按钮 (主行动) */
.system-dialog-footer button.btn-primary { 
    background: var(--primary-color); 
    color: #ffffff; 
    border: 1px solid var(--primary-color); 
}
.system-dialog-footer button.btn-primary:hover { 
    filter: brightness(1.1); 
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4); 
    border-color: var(--primary-color); 
}

/* 危险色按钮 (删除/警告) */
.system-dialog-footer button.btn-danger { 
    background: #ef4444; 
    color: #ffffff; 
    border: 1px solid #ef4444; 
}
.system-dialog-footer button.btn-danger:hover { 
    background: #dc2626; 
    border-color: #dc2626; 
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4); 
}
@keyframes toast-in { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } } @keyframes toast-out { to { transform: translateX(100%); opacity: 0; } } @keyframes dialog-pop { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ==========================================
   冲突对话框精细化 (Dialog Conflict)
========================================== */
/* 1. 黄金比例加宽 */
.system-dialog.dialog-conflict { 
    width: 520px; 
    max-width: 95vw; 
}

/* 2. 底部采用流式居中网格布局 */
.system-dialog.dialog-conflict .system-dialog-footer { 
    display: flex;
    flex-wrap: wrap; 
    justify-content: center; /* 核心：整体居中排列 */
    gap: 12px;
    padding: 18px 20px; /* 增加四周的呼吸感 */
}

/* 3. 强制所有按钮等宽，排版极其工整 */
.system-dialog.dialog-conflict .system-dialog-footer button {
    flex: 1 1 calc(25% - 12px); /* 弹性分配：默认一行最多放4个 */
    min-width: 110px; /* 保证中文文字不会被挤压 */
    max-width: 140px; /* 限制最大宽度，防止数量少时被拉得太丑 */
    margin: 0; 
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 0; /* 统一高度 */
}

/* 4. 图标与文字内容区精细化排版 */
.dialog-conflict-content { 
    display: flex; 
    align-items: center; 
    gap: 20px; 
    padding: 10px 10px; 
}

.conflict-icon { 
    font-size: 3em; 
    color: #f59e0b; 
    text-shadow: 0 2px 4px rgba(0,0,0,0.1); 
    flex-shrink: 0; 
}

.conflict-text { 
    line-height: 1.7; 
    color: var(--text-primary); 
    word-break: break-all; 
    font-size: 14px;
}

.conflict-text b.filename { 
    color: var(--primary-color); 
    font-weight: bold; 
    padding: 2px 6px; 
    background-color: var(--hover-bg); 
    border-radius: 4px; 
}
/* =========================================
   全局滚动条美化引擎 (Mac 质感)
========================================= */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { 
    background: rgba(156, 163, 175, 0.4); 
    border-radius: 4px; 
    border: 2px solid transparent; 
    background-clip: padding-box; 
}
::-webkit-scrollbar-thumb:hover { background: rgba(156, 163, 175, 0.8); }


/* =========================================
   系统级文件选择器 (File Picker API)
========================================= */
.system-dialog.file-picker-dialog { width: 550px; max-width: 95vw; height: 480px; display: flex; flex-direction: column; }
.file-picker-toolbar { display: flex; align-items: center; padding: 10px 15px; background: var(--bg-toolbar); border-bottom: 1px solid var(--window-border); gap: 15px; }
.file-picker-toolbar button { padding: 6px 10px; border-radius: 4px; border: 1px solid var(--border-color); background: var(--bg-main); color: var(--text-primary); cursor: pointer; font-size: 13px; font-weight: 500;}
.file-picker-toolbar button:hover { background: var(--hover-bg); }
.fp-path-display { font-size: 13px; color: var(--text-secondary); word-break: break-all; flex: 1; user-select: text; }
.file-picker-body { flex: 1; overflow-y: auto; background: var(--bg-main); padding: 5px; display: flex; flex-direction: column; }
.fp-item { display: flex; align-items: center; padding: 8px 12px; border-radius: 6px; cursor: pointer; transition: background 0.1s; gap: 12px; margin-bottom: 2px;}
.fp-item:hover { background: var(--hover-bg); }
.fp-item.selected { background: var(--primary-color); color: white; }
.fp-icon { font-size: 18px; }
.fp-name { font-size: 14px; user-select: none; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-picker-footer { padding: 15px 20px; display: flex; align-items: center; gap: 12px; background: var(--bg-toolbar); border-top: 1px solid var(--window-border); }
.file-picker-footer input { flex: 1; padding: 10px 12px; border: 1px solid var(--border-color); border-radius: 6px; background: var(--bg-main); color: var(--text-primary); font-size: 13px; outline: none; transition: border 0.2s;}
.file-picker-footer input:focus { border-color: var(--primary-color); box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2); }

/* ==========================================
   移动端 (Mobile) 核心 UI 适配
   ========================================== */
@media screen and (max-width: 768px) {
    body {
        /* 使用 dvh (动态视口) 完美适配手机浏览器自带的地址栏收缩/展开 */
        height: 100dvh !important; 
    }
    
    main.desktop-container {
        /* 减去移动端加高后的任务栏(56px)，严丝合缝 */
        height: calc(100dvh - 56px) !important; 
    }
    /* 1. 全局禁止长按选中文字 (除了应用内部的 iframe) */
    body {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    /* 2. 任务栏高度增加，增大触控热区 */
    #taskbar {
        height: 56px !important;
    }
    /* 【核心修复 3】：让应用列表容器撑满高度，允许横向滚动，防止底部裁切 */
    .taskbar-apps {
        height: 100% !important; /* 必须撑满 56px，防止截断蓝条 */
        overflow-x: auto !important; 
        overflow-y: visible !important;
        display: flex !important;
        align-items: center !important;
        scrollbar-width: none; /* Firefox 隐藏滚动条 */
        -ms-overflow-style: none; /* IE 隐藏滚动条 */
    }
    .taskbar-apps::-webkit-scrollbar {
        display: none; /* Chrome/Safari 隐藏滚动条 */
    }
    .taskbar-item {
        /* 绝对禁止图标在空间不足时被挤压变形 */
        flex-shrink: 0 !important; 
        width: 46px !important;
        height: 46px !important;
        margin: 0 4px !important;
    }

    /* 【核心修复 4】：绝对禁止图标被挤压 */
    .taskbar-item, .start-btn {
        flex-shrink: 0 !important; /* 关键：空间再小也不允许压扁图标 */
        width: 46px !important;
        height: 46px !important;
        margin: 0 4px !important;
    }
    /* 【核心修复 5】：将蓝条稍微上移，确保在任何手机屏幕上都能完整显示 */
    .taskbar-item::after {
        bottom: 6px !important; 
    }
    /* 3. 开始菜单优化：升级为全屏应用抽屉模式 */
    .start-menu {
        width: 100vw !important;
        height: calc(100vh - 56px) !important; /* 填满任务栏上方的整个屏幕 */
        bottom: 56px !important;
        left: 0 !important;
        border-radius: 0 !important;
        border: none !important;
        background: rgba(255, 255, 255, 0.95) !important; /* 降低透明度防花屏 */
        overflow-y: auto; /* 允许内部滚动 */
    }
    
    html[data-theme="dark"] .start-menu {
        background: rgba(17, 24, 39, 0.98) !important;
    }

    /* 开始菜单内的网格图标放大并重新排版 */
    .start-menu-grid {
        grid-template-columns: repeat(auto-fill, minmax(75px, 1fr)) !important;
        gap: 20px 10px !important;
        padding: 20px !important;
    }
    .start-menu-item {
        padding: 10px !important;
    }
    .start-menu-item svg {
        width: 36px !important;
        height: 36px !important;
    }
    .start-menu-item span {
        font-size: 13px !important;
        margin-top: 8px !important;
    }

    /* 4. 右键菜单放大，防止手指误触 */
    .desktop-context-menu {
        min-width: 180px !important;
        padding: 8px 0 !important;
    }
    .context-menu-item {
        padding: 14px 20px !important;
        font-size: 15px !important;
    }
}

