/* =========================================
   响应式布局 - 移动端优先
   ========================================= */

/* =========================================
   PC端布局优化 - 三栏布局
   ========================================= */
@media (min-width: 769px) {
    /* PC端显示pc-only，隐藏mobile-only */
    .pc-only {
        display: block !important;
    }
    
    .mobile-only {
        display: none !important;
    }
    
    .detail-panel.mobile-only {
        display: none !important;
    }
    /* 应用容器优化 */
    .app-container {
        height: 100vh;
        overflow: hidden;
        background: var(--bg-primary);
    }
    
    /* 主内容区域 */
    .main-content {
        flex: inherit;
        display: flex;
        overflow: hidden;
        min-width: 0;
        background: var(--bg-primary);
    }
    
    /* 当没有列表时（朋友圈、个人中心），main-content隐藏 */
    .main-content.no-list {
        display: none;
    }
    
    /* 详情面板 - 充分利用空间 */
    .detail-panel.pc-only {
        flex: 1;
        min-width: 0;
        max-width: none;
        background: var(--bg-primary);
        display: flex !important;
        align-items: stretch;
        justify-content: flex-start;
    }
    
    /* PC端确保列表和详情面板无缝连接 */
    .main-content {
        gap: 0;
        margin: 0;
        padding: 0;
    }
    
    .list-container {
        margin-right: 0;
        border-right: 1px solid var(--border-color);
    }
    
    .detail-panel.pc-only {
        margin-left: 0;
        border-left: 1px solid var(--border-color);
    }
    
    /* 聊天窗口 - 完全填充详情面板 */
    .chat-window {
        width: 100%;
        height: 100%;
        max-width: 100%;
        margin: 0;
        padding: 0;
        background: var(--bg-primary);
        border-radius: 0;
        box-shadow: none;
    }
    
    /* 好友详情 - 完全填充详情面板 */
    .friend-detail {
        width: 100%;
        height: 100%;
        max-width: 100%;
        margin: 0;
        padding: 0;
        background: var(--bg-primary);
    }
    
    /* 朋友圈容器 - 充分利用空间 */
    .moments-container {
        width: 100%;
        height: 100%;
        padding: 0;
        overflow-y: auto;
        background: var(--bg-primary);
        margin: 0;
        max-width: none;
    }
    
    /* 个人中心容器 - 充分利用空间 */
    .profile-container {
        width: 100%;
        height: 100%;
        padding: 0;
        overflow-y: auto;
        background: var(--bg-primary);
        margin: 0;
        max-width: none;
    }
}

/* 移动端样式（默认） */
@media (max-width: 768px) {
    /* 强制重置可能的布局问题 */
    html, body {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    .pc-only {
        display: none !important;
    }

    .mobile-only {
        display: block !important;
    }
    
    /* 但detail-panel和mobile-tab-bar的mobile-only需要flex */
    .detail-panel.mobile-only {
        display: flex !important;
    }
    
    .mobile-tab-bar.mobile-only {
        display: flex !important;
    }
    
    /* 移动端确保只显示mobile-only的detail-panel */
    .detail-panel.pc-only {
        display: none !important;
        width: 0 !important;
        min-width: 0 !important;
        max-width: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
    }
    
    /* 移动端确保侧边栏完全隐藏且不占用空间 */
    .sidebar-menu.pc-only {
        display: none !important;
        width: 0 !important;
        min-width: 0 !important;
        max-width: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
    }

    /* 确保app-container占满全宽 */
    .app-container {
        flex-direction: column !important;
        padding-bottom: var(--tab-bar-height);
        background: var(--bg-primary);
        display: flex !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    /* 确保main-content占满全宽且不使用flex布局 */
    .main-content {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: calc(100vh - var(--tab-bar-height));
        position: relative;
        flex: none !important;
        flex-grow: 0 !important;
        flex-shrink: 0 !important;
        flex-basis: auto !important;
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
        float: none !important;
        box-sizing: border-box !important;
    }
    
    /* 移动端当切换到朋友圈或个人中心时，隐藏列表容器 */
    .main-content.no-list .list-container,
    .main-content.no-list chat-list,
    .main-content.no-list contacts-list {
        display: none !important;
        width: 0 !important;
        min-width: 0 !important;
        max-width: 0 !important;
    }
    
    /* 移动端确保朋友圈和个人页面组件占满全宽 */
    moments-page.mobile-only,
    profile-page.mobile-only,
    .main-content .moments-page.mobile-only,
    .main-content .profile-page.mobile-only {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
        margin: 0 !important;
        padding: 0 !important;
        float: none !important;
        flex: none !important;
        flex-grow: 0 !important;
        flex-shrink: 0 !important;
        flex-basis: auto !important;
        position: relative !important;
    }
    
    /* 确保组件内部的容器也占满全宽 */
    .main-content .moments-page.mobile-only > *,
    .main-content .profile-page.mobile-only > * {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box;
    }
    
    /* 确保moments-container和profile-container占满全宽 */
    .moments-container,
    .profile-container,
    .main-content .moments-page.mobile-only .moments-container,
    .main-content .profile-page.mobile-only .profile-container {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        box-sizing: border-box !important;
        display: block !important;
    }

    .list-container {
        width: 100%;
        border-right: none;
        height: 100%;
        background: var(--bg-secondary);
    }

    .detail-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: var(--tab-bar-height);
        z-index: 999;
        border-left: none;
        background: var(--bg-primary);
        animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* 聊天窗口移动端样式 */
    .chat-window {
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .chat-header {
        position: sticky;
        top: 0;
        z-index: 100;
    }

    /* 朋友圈移动端样式 */
    .moments-container {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        padding: 0;
        padding-bottom: 10px;
        box-sizing: border-box;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    /* 确保朋友圈头部显示 */
    .moments-header {
        width: 100%;
        position: relative;
        height: 250px;
        display: block !important;
    }
    
    .moments-cover {
        width: 100% !important;
        height: 100% !important;
        display: block !important;
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
    }
    
    .moments-user-info {
        display: flex !important;
        position: absolute;
        bottom: 20px;
        right: 20px;
        z-index: 10;
    }
    
    .moments-nickname {
        display: block !important;
        color: white;
        font-size: 16px;
        font-weight: 500;
        text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
        margin-bottom: 10px;
    }
    
    .moments-avatar {
        display: block !important;
        width: 70px !important;
        height: 70px !important;
        border-radius: 5px;
        border: 3px solid white;
        object-fit: cover;
        flex-shrink: 0;
    }

    .moment-item {
        padding: 15px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .moment-avatar {
        display: block !important;
        width: 40px !important;
        height: 40px !important;
        border-radius: 5px;
        margin-right: 10px;
        object-fit: cover;
        flex-shrink: 0;
    }

    .moment-images {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 5px !important;
        width: 100%;
    }
    
    /* 发布按钮移动端样式 */
    .publish-btn {
        position: fixed;
        right: 20px;
        bottom: 80px;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background: var(--primary-fill);
        color: white;
        border: none;
        font-size: 20px;
        cursor: pointer;
        box-shadow: 0 4px 12px rgba(79, 172, 254, 0.4);
        display: flex !important;
        align-items: center;
        justify-content: center;
        z-index: 100;
        transition: all 0.3s;
    }
    
    .publish-btn:active {
        transform: scale(0.95);
    }

    /* 个人页面移动端样式 */
    .profile-container {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        padding: 0;
        box-sizing: border-box;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .profile-header {
        width: 100%;
        display: flex !important;
        align-items: center;
        padding: 15px 20px;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color);
        box-sizing: border-box;
    }
    
    .profile-body {
        width: 100%;
        box-sizing: border-box;
    }
    
    .profile-item {
        width: 100%;
        box-sizing: border-box;
        display: flex !important;
        justify-content: space-between;
        align-items: center;
    }
    
    .profile-item img {
        display: block !important;
        width: 50px !important;
        height: 50px !important;
        border-radius: 8px;
        object-fit: cover;
    }

    /* 登录页面移动端 */
    .login-container {
        padding: 30px 20px;
    }

    .login-header h1 {
        font-size: 28px;
    }
}

/* 平板样式 */
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar-menu {
        width: 50px;
        flex-shrink: 0;
        flex-grow: 0;
    }

    .list-container {
        width: 250px;
        flex-shrink: 0;
        flex-grow: 0;
    }
    
    .detail-panel {
        flex: 1;
        min-width: 0;
    }

    .mobile-tab-bar {
        display: none !important;
    }
}

/* PC端样式 */
@media (min-width: 1025px) {
    .sidebar-menu {
        width: var(--sidebar-width);
        flex-shrink: 0;
        flex-grow: 0;
    }

    .list-container {
        width: var(--list-width);
        flex-shrink: 0;
        flex-grow: 0;
    }
    
    .detail-panel {
        flex: 1;
        min-width: 0;
    }

    .mobile-tab-bar {
        display: none !important;
    }
}

/* 大屏幕 */
@media (min-width: 1440px) {
    .sidebar-menu {
        flex-shrink: 0;
        flex-grow: 0;
    }
    
    .list-container {
        width: 350px;
        flex-shrink: 0;
        flex-grow: 0;
    }

    .detail-panel {
        flex: 1;
        min-width: 600px;
    }
}

/* =========================================
   聊天窗口响应式
   ========================================= */

@media (max-width: 768px) {
    .chat-window {
        border-radius: 0;
    }

    .chat-messages {
        padding: 10px;
    }

    .message-bubble {
        max-width: 80%;
    }

    .chat-input-area {
        padding: 8px 12px;
        box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.04);
    }
    
    .input-toolbar {
        padding: 4px 0 2px;
        gap: 6px;
        border-bottom: none;
    }
    
    .toolbar-btn {
        font-size: 18px;
        padding: 4px;
        min-width: 32px;
        min-height: 32px;
    }
    
    .input-box {
        padding: 4px 0 2px;
    }
    
    .input-box textarea {
        min-height: 34px;
        max-height: 90px;
        padding: 7px 10px;
        font-size: 15px;
        border-radius: 6px;
    }
    
    .input-actions {
        padding: 3px 0 6px;
    }
    
    .btn-send {
        padding: 6px 18px;
        font-size: 14px;
        border-radius: 16px;
        min-height: 32px;
    }
}

/* =========================================
   朋友圈响应式
   ========================================= */

@media (max-width: 768px) {
    .moments-header {
        height: 250px;
        width: 100%;
        position: relative;
        display: block !important;
    }

    .moments-cover {
        height: 100%;
        width: 100%;
        display: block !important;
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
    }

    .moments-user-info {
        bottom: 15px;
        right: 15px;
    }

    .moments-avatar {
        width: 60px;
        height: 60px;
    }

    .publish-btn {
        position: fixed;
        bottom: calc(var(--tab-bar-height) + 20px);
        right: 20px;
        z-index: 100;
    }
}

@media (min-width: 769px) {
    .moments-header {
        height: 300px;
    }

    .moments-cover {
        height: 300px;
    }

    .moments-container {
        max-width: 800px;
        margin: 0 auto;
    }
}

/* =========================================
   个人中心响应式
   ========================================= */

@media (max-width: 768px) {
    .profile-header {
        padding: 20px 15px;
    }

    .profile-avatar {
        width: 60px;
        height: 60px;
    }

    .profile-cover {
        height: 150px;
    }
}

@media (min-width: 769px) {
    .profile-container {
        max-width: 600px;
        margin: 0 auto;
    }

    .profile-cover {
        height: 200px;
    }
}

/* =========================================
   图片预览响应式
   ========================================= */

.image-preview {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-preview img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

.image-preview-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 24px;
    color: white;
}

/* =========================================
   触摸优化
   ========================================= */

@media (max-width: 768px) {
    .list-item,
    .menu-item,
    .tab-item,
    button {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    /* 增大触摸目标 */
    .list-item {
        min-height: 64px;
        padding: 14px 16px;
    }

    .tab-item {
        min-height: 50px;
        flex: 1 !important;
        display: flex !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
    }
    
    /* 确保mobile-tab-bar内所有tab-item都显示 */
    .mobile-tab-bar .tab-item {
        display: flex !important;
        flex: 1 !important;
        visibility: visible !important;
        opacity: 1 !important;
        width: auto !important;
        min-width: 0 !important;
    }

    button {
        min-height: 44px;
    }

    /* 禁止长按选择 */
    .list-item,
    .moment-item {
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* 允许消息内容选择 */
    .message-bubble {
        -webkit-user-select: text;
        user-select: text;
    }
    
    /* 优化滚动性能 */
    .list-body,
    .chat-messages {
        will-change: scroll-position;
        transform: translateZ(0);
    }
}

/* =========================================
   横屏适配
   ========================================= */

@media (max-width: 768px) and (orientation: landscape) {
    .login-container {
        padding: 20px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .moments-header {
        height: 150px;
    }

    .chat-messages {
        height: calc(100vh - 150px);
    }
}

/* =========================================
   主题说明
   -----------------------------------------
   此处原有一段 @media (prefers-color-scheme: dark) 覆盖 :root 变量，
   已移除。原因：

   1. 它与 theme.css 的 [data-theme] 机制冲突 —— 本文件在 theme.css 之后加载，
      同优先级选择器下后者胜出，导致系统处于深色模式时，即使用户选择了
      日间模式，页面仍被强制改成深色；
   2. 它只覆盖了 6 个变量，其余变量仍为浅色，于是出现
      "侧边栏深色 + 列表白色 + 气泡浅色" 的错乱配色；
   3. 本应用已有显式的主题切换（写入 <html data-theme>），
      不应再由系统偏好隐式决定配色。

   所有主题变量统一在 css/theme.css 维护。
   ========================================= */

/* =========================================
   动画效果
   ========================================= */

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

@keyframes scaleIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* 页面切换动画 */
.main-content > * {
    animation: fadeIn 0.3s ease-out;
}

/* 列表项进入动画 */
.list-item {
    animation: slideDown 0.2s ease-out backwards;
}

.list-item:nth-child(1) { animation-delay: 0.02s; }
.list-item:nth-child(2) { animation-delay: 0.04s; }
.list-item:nth-child(3) { animation-delay: 0.06s; }
.list-item:nth-child(4) { animation-delay: 0.08s; }
.list-item:nth-child(5) { animation-delay: 0.1s; }

@media (max-width: 768px) {
    .detail-panel {
        animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* =========================================
   可访问性
   ========================================= */

@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) {
    .list-item,
    .menu-item {
        border: 2px solid var(--text-primary);
    }
}

/* 大字体模式 */
@media (min-width: 1025px) {
    html {
        font-size: 16px;
    }

    body {
        font-size: 15px;
    }
}

