/* ============================================
   Markdown笔记应用 - 响应式样式
   ============================================ */

/* ============================================
   平板设备 (768px - 1024px)
   ============================================ */
@media screen and (max-width: 1024px) {
    :root {
        --sidebar-width: 240px;
    }
    
    .preview-section {
        width: 40%;
        min-width: 250px;
    }
    
    .editor-toolbar {
        padding: var(--spacing-xs) var(--spacing-sm);
    }
    
    .tool-btn {
        width: 28px;
        height: 28px;
    }
    
    .toolbar-divider {
        margin: 0 4px;
    }
}

/* ============================================
   小平板设备 (768px 以下)
   ============================================ */
@media screen and (max-width: 768px) {
    :root {
        --header-height: 48px;
    }
    
    /* 头部调整 */
    .app-header {
        padding: 0 var(--spacing-md);
    }
    
    .app-title span {
        display: none;
    }
    
    .view-modes {
        transform: scale(0.9);
    }
    
    /* 侧边栏默认隐藏 */
    .sidebar {
        position: fixed;
        left: 0;
        top: var(--header-height);
        bottom: 0;
        z-index: 90;
        transform: translateX(-100%);
        width: 280px;
        box-shadow: var(--shadow-lg);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar.collapsed {
        transform: translateX(-100%);
    }
    
    /* 遮罩层 */
    .sidebar-overlay {
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 80;
        opacity: 0;
        visibility: hidden;
        transition: all var(--transition-base);
    }
    
    .sidebar-overlay.show {
        opacity: 1;
        visibility: visible;
    }
    
    /* 编辑器全宽 */
    .editor-section {
        width: 100%;
    }
    
    /* 预览区默认隐藏 */
    .preview-section {
        position: fixed;
        right: 0;
        top: var(--header-height);
        bottom: 0;
        width: 100%;
        max-width: 100%;
        z-index: 85;
        transform: translateX(100%);
        border-left: none;
    }
    
    .preview-section.open {
        transform: translateX(0);
    }
    
    /* 工具栏简化 */
    .editor-toolbar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    
    .editor-toolbar::-webkit-scrollbar {
        display: none;
    }
    
    /* 状态栏简化 */
    .editor-status span:not(#saveStatus) {
        display: none;
    }
    
    /* 设置面板全屏 */
    .settings-content,
    .search-content,
    .shortcuts-content {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
}

/* ============================================
   移动设备 (480px 以下)
   ============================================ */
@media screen and (max-width: 480px) {
    :root {
        --header-height: 44px;
        --toolbar-height: 40px;
        --status-height: 24px;
        --line-numbers-width: 40px;
    }
    
    /* 头部进一步简化 */
    .app-header {
        padding: 0 var(--spacing-sm);
    }
    
    .icon-btn {
        width: 32px;
        height: 32px;
    }
    
    .icon-btn svg {
        width: 20px;
        height: 20px;
    }
    
    /* 工具栏分组 */
    .toolbar-group {
        display: none;
    }
    
    .toolbar-group:first-child,
    .toolbar-group:last-child {
        display: flex;
    }
    
    /* 编辑器内边距调整 */
    .editor {
        padding: var(--spacing-sm);
        font-size: var(--font-size-md);
    }
    
    .line-numbers {
        padding: var(--spacing-sm) var(--spacing-xs);
        font-size: var(--font-size-xs);
    }
    
    /* 预览区字体调整 */
    .preview-content {
        padding: var(--spacing-md);
        font-size: var(--font-size-md);
    }
    
    .preview-content h1 {
        font-size: 1.75em;
    }
    
    .preview-content h2 {
        font-size: 1.4em;
    }
    
    .preview-content h3 {
        font-size: 1.2em;
    }
    
    /* 侧边栏全屏 */
    .sidebar {
        width: 100%;
    }
    
    /* 底部标签栏 */
    .mobile-tabs {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 56px;
        background-color: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        z-index: 100;
    }
    
    .mobile-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        border: none;
        background: transparent;
        color: var(--text-secondary);
        font-size: 11px;
        cursor: pointer;
        transition: all var(--transition-fast);
    }
    
    .mobile-tab.active {
        color: var(--accent-color);
    }
    
    .mobile-tab svg {
        width: 24px;
        height: 24px;
    }
    
    /* 调整主内容区底部间距 */
    .app-main {
        padding-bottom: 56px;
    }
    
    /* 浮动操作按钮 */
    .fab {
        position: fixed;
        right: 16px;
        bottom: 72px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background-color: var(--accent-color);
        color: white;
        border: none;
        box-shadow: var(--shadow-lg);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 90;
        transition: transform var(--transition-fast);
    }
    
    .fab:active {
        transform: scale(0.95);
    }
    
    .fab svg {
        width: 24px;
        height: 24px;
    }
    
    /* 笔记列表项调整 */
    .note-item {
        padding: var(--spacing-md);
    }
    
    .note-actions {
        opacity: 1;
    }
    
    /* 设置项调整 */
    .setting-item {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-sm);
    }
    
    .setting-item > *:last-child {
        align-self: stretch;
    }
    
    .setting-item select,
    .setting-item input[type="range"] {
        width: 100%;
    }
}

/* ============================================
   横屏模式
   ============================================ */
@media screen and (max-height: 500px) and (orientation: landscape) {
    :root {
        --header-height: 40px;
        --toolbar-height: 36px;
    }
    
    .app-header {
        padding: 0 var(--spacing-sm);
    }
    
    .sidebar {
        top: var(--header-height);
    }
    
    .preview-section {
        top: var(--header-height);
    }
    
    /* 隐藏底部标签栏 */
    .mobile-tabs {
        display: none;
    }
    
    .app-main {
        padding-bottom: 0;
    }
}

/* ============================================
   大屏幕优化 (1440px 以上)
   ============================================ */
@media screen and (min-width: 1440px) {
    :root {
        --sidebar-width: 320px;
    }
    
    .preview-section {
        width: 35%;
        max-width: 600px;
    }
    
    .editor {
        font-size: 15px;
    }
    
    .preview-content {
        font-size: 16px;
    }
}

/* ============================================
   超宽屏幕 (1920px 以上)
   ============================================ */
@media screen and (min-width: 1920px) {
    :root {
        --sidebar-width: 360px;
    }
    
    .editor-section {
        max-width: 900px;
        margin: 0 auto;
    }
    
    .preview-section {
        max-width: 700px;
    }
}

/* ============================================
   打印样式
   ============================================ */
@media print {
    .app-header,
    .sidebar,
    .editor-section,
    .mobile-tabs,
    .fab {
        display: none !important;
    }
    
    .app-main {
        padding: 0;
    }
    
    .preview-section {
        position: static;
        width: 100% !important;
        transform: none !important;
        border: none !important;
    }
    
    .preview-content {
        padding: 0 !important;
    }
}

/* ============================================
   深色模式媒体查询
   ============================================ */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-primary: #1e1e1e;
        --bg-secondary: #252526;
        --bg-tertiary: #2d2d30;
        --bg-hover: #2a2d2e;
        --bg-active: #37373d;
        
        --text-primary: #cccccc;
        --text-secondary: #9cdcfe;
        --text-tertiary: #858585;
        --text-inverse: #1e1e1e;
        
        --border-color: #3e3e42;
        --border-light: #2d2d30;
        --border-dark: #5a5a5a;
        
        --accent-color: #4ec9b0;
        --accent-hover: #3dbba3;
        --accent-light: #264f78;
    }
}

/* ============================================
   减少动画偏好
   ============================================ */
@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;
        --text-primary: #000000;
        --bg-primary: #ffffff;
    }
    
    [data-theme="dark"] {
        --border-color: #ffffff;
        --text-primary: #ffffff;
        --bg-primary: #000000;
    }
    
    .tool-btn:hover,
    .icon-btn:hover,
    .note-item:hover {
        outline: 2px solid var(--accent-color);
        outline-offset: -2px;
    }
}

/* ============================================
   触摸设备优化
   ============================================ */
@media (pointer: coarse) {
    .tool-btn,
    .icon-btn,
    .note-item,
    .sidebar-tab,
    .toolbar-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .editor {
        font-size: 16px; /* 防止iOS缩放 */
    }
    
    /* 增大触摸目标 */
    .note-actions {
        opacity: 1;
    }
    
    .note-action-btn {
        width: 32px;
        height: 32px;
    }
}

/* ============================================
   悬停设备优化
   ============================================ */
@media (hover: hover) {
    .note-actions {
        opacity: 0;
    }
    
    .note-item:hover .note-actions {
        opacity: 1;
    }
}

/* ============================================
   安全区域适配 (刘海屏)
   ============================================ */
@supports (padding-top: env(safe-area-inset-top)) {
    .app-header {
        padding-top: env(safe-area-inset-top);
        height: calc(var(--header-height) + env(safe-area-inset-top));
    }
    
    .sidebar,
    .preview-section {
        top: calc(var(--header-height) + env(safe-area-inset-top));
    }
    
    .mobile-tabs {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(56px + env(safe-area-inset-bottom));
    }
    
    .fab {
        bottom: calc(72px + env(safe-area-inset-bottom));
    }
}
