/* 响应式设计 */

/* 平板设备 */
@media (max-width: 768px) {
    .app {
        height: 100vh;
        /* iOS Safari 视口修复 */
        height: calc(var(--vh, 1vh) * 100);
        min-height: -webkit-fill-available;
        max-width: 100%;
        border-radius: 0;
        box-shadow: none;
    }

    .app-header {
        padding: 1.2rem 1rem;
    }

    .app-header h1 {
        font-size: 1.4rem;
    }

    .device-info {
        font-size: 0.8rem;
        flex-direction: row;
        gap: 1rem;
    }

    .connection-status {
        font-size: 0.75rem;
    }

    .message {
        max-width: 85%;
    }

    .message-content {
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
    }

    .message-list {
        padding: 1.5rem 1rem;
        gap: 1.25rem;
    }

    .input-container {
        padding: 8px 12px;
        min-height: 56px;
        /* iOS 平板特殊处理 */
        padding-bottom: calc(8px + var(--safe-area-inset-bottom));
        position: -webkit-sticky;
        position: sticky;
    }

    .upload-area {
        padding: 1.5rem 1rem;
    }

    .input-wrapper {
        gap: 8px;
    }

    .file-button {
        width: 42px;
        height: 42px;
        font-size: 18px;
    }

    .input-field-container {
        min-height: 42px;
    }

    .input-field-container textarea {
        font-size: 16px;
        padding: 11px 13px;
    }
}

/* 手机设备 */
@media (max-width: 480px) {
    .app-header {
        padding: 1rem 0.75rem;
    }

    .app-header h1 {
        font-size: 1.3rem;
        margin-bottom: 0.3rem;
    }

    .device-info {
        font-size: 0.75rem;
        flex-direction: column;
        gap: 0.4rem;
    }

    .connection-status {
        font-size: 0.7rem;
        padding: 0.15rem 0.4rem;
    }

    .message-list {
        padding: 1rem 0.75rem;
        gap: 0.8rem;
    }

    .message {
        max-width: 92%;
    }

    .message-content {
        padding: 0.75rem 0.875rem;
        font-size: 0.95rem;
        border-radius: 20px;
    }

    /* 手机设备上的文本消息优化 */
    .message-content .text-message:not(.markdown-rendered) {
        padding: 0;
        margin: 0;
        font-weight: 400;
        letter-spacing: 0.01em;
    }

    .message-content .text-message.markdown-rendered {
        padding: 0.3rem 24px 0.3rem 0;
        font-weight: 400;
        letter-spacing: 0.01em;
    }

    .message-meta {
        font-size: 0.65rem;
        margin-bottom: 0.3rem;
    }

    .message-time {
        font-size: 0.6rem;
        padding: 0.15rem 0.4rem;
    }

    .input-container {
        padding: 8px 12px;
        min-height: 56px;
        /* iOS 手机特殊处理 */
        padding-bottom: calc(8px + var(--safe-area-inset-bottom));
        position: -webkit-sticky;
        position: sticky;
    }

    .input-wrapper {
        gap: 8px;
    }

    .file-button {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .input-field-container {
        min-height: 40px;
    }

    .input-field-container textarea {
        font-size: 16px;
        padding: 10px 12px;
    }

    .send-button {
        width: 34px;
        height: 34px;
    }

    .send-icon {
        width: 17px;
        height: 17px;
    }
    
    .file-upload {
        margin-bottom: 0.75rem;
    }
    
    .upload-area {
        padding: 0.75rem;
    }
    
    .upload-prompt {
        gap: 0.25rem;
    }
    
    .upload-icon {
        font-size: 1.2rem;
    }
    
    .file-info {
        gap: 0.5rem;
    }
    
    .file-icon {
        font-size: 1.2rem;
    }
    
    .download-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.75rem;
    }
    
    .app-footer {
        padding: 0.5rem;
    }
    
    .refresh-button {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
}

/* 超小屏幕 */
@media (max-width: 320px) {
    .app-header h1 {
        font-size: 1.1rem;
    }
    
    .message-content {
        padding: 0.625rem 0.75rem;
        font-size: 0.9rem;
    }

    /* 超小屏幕的文本消息优化 */
    .message-content .text-message:not(.markdown-rendered) {
        padding: 0;
        margin: 0;
        font-weight: 400;
        letter-spacing: 0.01em;
    }

    .message-content .text-message.markdown-rendered {
        padding: 0.25rem 20px 0.25rem 0;
        font-weight: 400;
        letter-spacing: 0.01em;
    }
    
    .file-name {
        font-size: 0.85rem;
    }
    
    .file-size {
        font-size: 0.75rem;
    }
    
    .input-field-container textarea {
        font-size: 15px;
        padding: 8px 10px;
    }

    .file-button {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    .send-button {
        width: 30px;
        height: 30px;
    }

    .send-icon {
        width: 15px;
        height: 15px;
    }
}

/* 横屏适配 */
@media (max-height: 500px) and (orientation: landscape) {
    .app-header {
        padding: 0.5rem;
    }
    
    .app-header h1 {
        font-size: 1.1rem;
        margin-bottom: 0.2rem;
    }
    
    .device-info {
        font-size: 0.7rem;
    }
    
    .message-list {
        padding: 0.5rem;
    }
    
    .input-container {
        padding: 0.5rem;
    }
    
    .app-footer {
        padding: 0.4rem;
    }
}

/* iOS Safari 专用修复 */
@supports (-webkit-touch-callout: none) {
    .app {
        height: -webkit-fill-available;
        min-height: -webkit-fill-available;
    }

    .input-container {
        /* 强制硬件加速，确保在iOS上正确渲染 */
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
        /* 确保在虚拟键盘弹出时保持可见 */
        position: -webkit-sticky;
        position: sticky;
        bottom: 0;
        /* iOS 特殊的z-index处理 */
        z-index: 9999;
    }
}

/* iOS 设备特定修复 */
@media screen and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait) {
    .app {
        height: calc(var(--vh, 1vh) * 100);
        min-height: calc(var(--vh, 1vh) * 100);
    }

    .input-container {
        /* 确保输入框在iOS上始终可见 */
        position: fixed;
        bottom: var(--safe-area-inset-bottom, 0);
        left: 0;
        right: 0;
        width: 100%;
        max-width: 800px;
        margin: 0 auto;
    }

    .message-list {
        /* 为固定的输入框留出空间 */
        padding-bottom: calc(72px + var(--safe-area-inset-bottom, 0));
    }
}

/* iPhone X 及以上设备的安全区域适配 */
@media screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3),
       screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2),
       screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3),
       screen and (device-width: 390px) and (device-height: 844px) and (-webkit-device-pixel-ratio: 3),
       screen and (device-width: 428px) and (device-height: 926px) and (-webkit-device-pixel-ratio: 3) {
    .input-container {
        padding-bottom: calc(8px + 34px); /* 34px 是 iPhone X 系列的底部安全区域 */
    }
}

/* iOS 虚拟键盘弹出时的样式调整 */
body.keyboard-open .app {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
}

body.keyboard-open .input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    z-index: 10000;
    /* 确保在虚拟键盘上方 */
    transform: translateY(0);
}

body.keyboard-open .message-list {
    /* 为固定输入框预留更多空间 */
    padding-bottom: 80px;
}

/* 高分辨率屏幕 */
@media (min-width: 1200px) {
    .app {
        max-width: 900px;
    }

    .message {
        max-width: 60%;
    }

    .app-header h1 {
        font-size: 1.6rem;
    }

    .message-content {
        font-size: 1.05rem;
        padding: 1rem 1.25rem;
    }

    /* 高分辨率屏幕的文本消息优化 */
    .message-content .text-message:not(.markdown-rendered) {
        padding: 0;
        margin: 0;
        font-weight: 400;
        letter-spacing: 0.01em;
    }

    .message-content .text-message.markdown-rendered {
        padding: 0.375rem 28px 0.375rem 0;
        font-weight: 400;
        letter-spacing: 0.01em;
    }
}

/* 打印样式 */
@media print {
    .app-header,
    .input-container,
    .app-footer {
        display: none;
    }
    
    .app {
        height: auto;
        box-shadow: none;
    }
    
    .message-list {
        padding: 0;
    }
    
    .message-content {
        border: 1px solid #ddd;
        background-color: white !important;
        color: black !important;
    }
}
