/* ============================================
   HTML+CSS+JS 综合教程 - 主样式文件
   ============================================ */

/* CSS变量定义 */
:root {
    --primary-color: #4a90e2;
    --primary-hover: #357abd;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-dark: #343a40;
    --bg-darker: #212529;
    
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-light: #ffffff;
    
    --border-color: #dee2e6;
    --border-radius: 8px;
    --box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --box-shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
    
    --sidebar-width: 280px;
    --toolbar-height: 60px;
    --transition-speed: 0.3s;
}

/* 暗色主题 */
[data-theme="dark"] {
    --bg-primary: #1e1e1e;
    --bg-secondary: #2d2d2d;
    --bg-dark: #343a40;
    --bg-darker: #212529;
    
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    
    --border-color: #404040;
    --box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* 全局重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    overflow-x: hidden;
}

/* ============================================
   应用容器布局
   ============================================ */

.app-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* ============================================
   侧边栏样式
   ============================================ */

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(135deg, var(--bg-darker) 0%, var(--bg-dark) 100%);
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 1000;
    transition: transform var(--transition-speed) ease;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h1 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-light);
}

.sidebar-toggle {
    display: none;
    flex-direction: column;
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
}

.sidebar-toggle span {
    width: 20px;
    height: 2px;
    background: var(--text-light);
    margin: 2px 0;
    transition: all 0.3s ease;
}

/* 用户信息区域 */
.user-info {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
}

.user-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.user-name {
    font-weight: 500;
    font-size: 0.95rem;
}

.user-progress {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
}

/* 导航菜单 */
.nav-menu {
    flex: 1;
    list-style: none;
    padding: 10px 0;
    overflow-y: auto;
}

.nav-item {
    margin: 2px 10px;
}

.nav-item a {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.nav-item a:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-light);
}

.nav-item.active a {
    background: var(--primary-color);
    color: var(--text-light);
    font-weight: 500;
}

/* 侧边栏底部 */
.sidebar-footer {
    padding: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    gap: 10px;
}

.sidebar-footer .btn {
    flex: 1;
    font-size: 0.85rem;
}

/* ============================================
   主内容区域
   ============================================ */

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--transition-speed) ease;
}

/* 工具栏 */
.toolbar {
    height: var(--toolbar-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.mobile-menu-toggle {
    display: none;
    flex-direction: column;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    margin-right: 15px;
}

.mobile-menu-toggle span {
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    margin: 2px 0;
    transition: all 0.3s ease;
}

.toolbar-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
}

.toolbar-actions {
    display: flex;
    gap: 10px;
}

/* 内容包装器 */
.content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ============================================
   课程内容区域
   ============================================ */

.lesson-content {
    padding: 30px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    max-height: 40vh;
    overflow-y: auto;
}

.lesson-content h2 {
    font-size: 1.8rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.lesson-content h3 {
    font-size: 1.4rem;
    margin: 25px 0 15px;
    color: var(--text-primary);
}

.lesson-content p {
    margin-bottom: 15px;
    line-height: 1.8;
}

.lesson-content code {
    background: var(--bg-dark);
    color: var(--text-light);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.lesson-content pre {
    background: var(--bg-dark);
    color: var(--text-light);
    padding: 15px;
    border-radius: var(--border-radius);
    overflow-x: auto;
    margin: 15px 0;
}

.lesson-content pre code {
    background: none;
    padding: 0;
}

.lesson-content ul, .lesson-content ol {
    margin: 15px 0;
    padding-left: 30px;
}

.lesson-content li {
    margin-bottom: 8px;
}

.content-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* ============================================
   编辑器和预览容器
   ============================================ */

.editor-preview-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.editor-panel, .preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.preview-panel {
    border-right: none;
}

/* 面板头部 */
.panel-header {
    height: 50px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
}

.panel-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.panel-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.tab-btn {
    background: none;
    border: none;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
}

.tab-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--primary-color);
    color: var(--text-light);
}

/* 编辑器包装器 */
.editor-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.code-editor {
    width: 100%;
    height: 100%;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    border: none;
    resize: none;
    outline: none;
}

.CodeMirror {
    height: 100% !important;
    font-size: 14px;
    font-family: 'Courier New', monospace;
}

/* 预览包装器 */
.preview-wrapper {
    flex: 1;
    position: relative;
    background: var(--bg-secondary);
}

#previewFrame {
    width: 100%;
    height: 100%;
    border: none;
    background: var(--bg-primary);
}

.preview-loading, .preview-error {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    z-index: 10;
}

.preview-error {
    background: rgba(220, 53, 69, 0.1);
    padding: 20px;
}

.error-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}

.error-message {
    font-weight: 600;
    color: var(--danger-color);
    margin-bottom: 10px;
}

.error-details {
    background: var(--bg-dark);
    color: var(--text-light);
    padding: 15px;
    border-radius: var(--border-radius);
    max-width: 90%;
    max-height: 200px;
    overflow: auto;
    font-size: 0.85rem;
}

/* ============================================
   按钮样式
   ============================================ */

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--box-shadow);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary-color);
    color: var(--text-light);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: var(--text-light);
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-success {
    background: var(--success-color);
    color: var(--text-light);
}

.btn-success:hover {
    background: #218838;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-block {
    width: 100%;
}

/* ============================================
   模态框样式
   ============================================ */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow-lg);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    font-size: 1.3rem;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* 表单样式 */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.form-group input[type="checkbox"] {
    margin-right: 8px;
}

.setting-group {
    margin-bottom: 20px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
}

.register-link {
    text-align: center;
    margin-top: 15px;
    color: var(--text-secondary);
}

.register-link a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.register-link a:hover {
    text-decoration: underline;
}

/* ============================================
   Toast 提示
   ============================================ */

.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--bg-dark);
    color: var(--text-light);
    padding: 12px 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow-lg);
    z-index: 3000;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--danger-color);
}

.toast.warning {
    background: var(--warning-color);
    color: var(--text-primary);
}

.toast.info {
    background: var(--info-color);
}

/* ============================================
   加载动画
   ============================================ */

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   响应式设计
   ============================================ */

/* 平板设备 */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .mobile-menu-toggle {
        display: flex;
    }
    
    .editor-preview-container {
        flex-direction: column;
    }
    
    .editor-panel, .preview-panel {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        min-height: 300px;
    }
}

/* 手机设备 */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 100%;
    }
    
    .toolbar {
        padding: 0 15px;
    }
    
    .toolbar-title {
        font-size: 1rem;
    }
    
    .toolbar-actions .btn {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
    
    .lesson-content {
        padding: 20px 15px;
        max-height: 35vh;
    }
    
    .lesson-content h2 {
        font-size: 1.4rem;
    }
    
    .lesson-content h3 {
        font-size: 1.2rem;
    }
    
    .panel-header {
        padding: 0 10px;
    }
    
    .tab-btn {
        padding: 6px 12px;
        font-size: 0.75rem;
    }
    
    .modal-content {
        margin: 10px;
    }
    
    .toast {
        left: 15px;
        right: 15px;
        bottom: 15px;
    }
}

/* 小屏手机 */
@media (max-width: 480px) {
    html {
        font-size: 14px;
    }
    
    .toolbar {
        height: 50px;
    }
    
    .toolbar-actions {
        gap: 5px;
    }
    
    .btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
    
    .user-info {
        padding: 15px;
    }
    
    .user-avatar {
        width: 35px;
        height: 35px;
    }
}

/* ============================================
   打印样式
   ============================================ */

@media print {
    .sidebar,
    .toolbar,
    .editor-panel,
    .preview-panel {
        display: none;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .lesson-content {
        max-height: none;
        overflow: visible;
    }
}

/* ============================================
   辅助功能
   ============================================ */

/* 焦点可见性 */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* 减少动画 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }
}

/* 深色模式偏好 */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-primary: #1e1e1e;
        --bg-secondary: #2d2d2d;
        --text-primary: #e0e0e0;
        --text-secondary: #a0a0a0;
        --border-color: #404040;
    }
}
