/* 主要样式文件 - 用户界面 - 性能优化版 */

/* 性能优化：减少重绘和回流 */
* {
    box-sizing: border-box;
}

/* 自定义动画 - 使用GPU加速 */
@keyframes slideInUp {
    from {
        transform: translateY3d(20px, 0, 0);
        opacity: 0;
    }
    to {
        transform: translateY3d(0, 0, 0);
        opacity: 1;
    }
}

/* 预加载关键资源 */
.critical-resource {
    display: none;
}

/* 延迟加载非关键内容 */
.lazy-load {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lazy-load.loaded {
    opacity: 1;
}

/* 容器查询优化 */
.responsive-container {
    container-type: inline-size;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* 基础样式 */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
}

/* 快速问题按钮悬停效果 */
.quick-question {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.quick-question::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.quick-question:hover::before {
    left: 100%;
}

/* 文本输入框增强 */
textarea:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* AI回复区域样式 */
.prose {
    color: #374151;
}

.prose h1, .prose h2, .prose h3 {
    color: #111827;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

.prose h1 {
    font-size: 1.875em;
    font-weight: 700;
}

.prose h2 {
    font-size: 1.5em;
    font-weight: 600;
}

.prose h3 {
    font-size: 1.25em;
    font-weight: 600;
}

.prose ul, .prose ol {
    margin: 1em 0;
    padding-left: 1.5em;
}

.prose li {
    margin: 0.5em 0;
}

.prose p {
    margin: 1em 0;
}

.prose strong {
    color: #111827;
    font-weight: 600;
}

.prose code {
    background-color: #f3f4f6;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
    color: #ef4444;
}

.prose pre {
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 1rem;
    overflow-x: auto;
    margin: 1em 0;
}

/* 评分按钮样式 */
.rating-btn {
    transition: all 0.2s ease;
}

.rating-btn:hover {
    transform: scale(1.1);
}

.rating-btn.active {
    color: #fbbf24;
}

/* Toast 通知样式 */
.toast {
    animation: slideInUp 0.3s ease-out;
}

.toast-success {
    background-color: #10b981;
    color: white;
}

.toast-error {
    background-color: #ef4444;
    color: white;
}

.toast-info {
    background-color: #3b82f6;
    color: white;
}

.toast-warning {
    background-color: #f59e0b;
    color: white;
}

/* 加载动画增强 */
.animate-spin {
    animation: spin 1s linear infinite;
}

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

/* 响应式优化 - 增强版 */
@media (max-width: 768px) {
    /* 性能优化：减少重排 */
    .quick-question {
        padding: 1rem;
        will-change: transform;
        backface-visibility: hidden;
    }

    .quick-question i {
        font-size: 1.5rem;
    }

    .quick-question div {
        font-size: 0.9rem;
    }

    .quick-question div:last-child {
        font-size: 0.8rem;
    }

    /* 移动端导航优化 */
    .max-w-6xl {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* 移动端文本区域优化 */
    textarea {
        font-size: 16px; /* 防止iOS缩放 */
        resize: vertical;
        min-height: 120px;
    }

    /* 移动端按钮优化 */
    button {
        min-height: 44px; /* 触摸友好的最小高度 */
        touch-action: manipulation; /* 减少点击延迟 */
        -webkit-tap-highlight-color: transparent;
    }

    .grid-cols-1.md\\:grid-cols-2 {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    /* 移动端性能优化 */
    body {
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }

    /* 减少移动端动画 */
    .quick-question {
        transition: transform 0.2s ease;
    }

    .quick-question:hover {
        transform: scale(1.02);
    }
}

/* 超小屏幕优化 - 增强版 */
@media (max-width: 480px) {
    body {
        font-size: 14px;
        line-height: 1.5;
    }

    .text-3xl {
        font-size: 1.5rem;
    }

    .text-lg {
        font-size: 1rem;
    }

    .px-6 {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .py-8 {
        padding-top: 2rem;
        padding-bottom: 2rem;
    }

    /* 触摸优化 */
    .quick-question {
        min-height: 120px;
        padding: 0.75rem;
    }

    /* 移动端卡片间距 */
    .space-y-4 > * + * {
        margin-top: 1rem;
    }

    /* 超小屏幕性能优化 */
    .prose {
        font-size: 0.9rem;
    }

    .prose h1, .prose h2, .prose h3 {
        font-size: 1.1em;
        margin-top: 1em;
        margin-bottom: 0.5em;
    }

    /* 减少动画 */
    .animate-spin {
        animation-duration: 0.8s;
    }

    /* 优化滚动性能 */
    * {
        -webkit-overflow-scrolling: touch;
    }
}

/* 横屏模式优化 */
@media (max-width: 768px) and (orientation: landscape) {
    .py-8 {
        padding-top: 1rem;
        padding-bottom: 1rem;
    }

    .mb-8 {
        margin-bottom: 1rem;
    }
}

/* 平滑滚动 */
html {
    scroll-behavior: smooth;
}

/* 选择文本样式 */
::selection {
    background-color: #dbeafe;
    color: #1e40af;
}

/* 焦点样式 */
button:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* 卡片悬停效果 */
.hover-lift {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

/* 渐变背景动画 */
@keyframes gradient {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.animated-gradient {
    background: linear-gradient(-45deg, #667eea, #764ba2, #f093fb, #f5576c);
    background-size: 400% 400%;
    animation: gradient 15s ease infinite;
}

/* 复制成功提示 */
.copy-success {
    position: relative;
}

.copy-success::after {
    content: '已复制!';
    position: absolute;
    top: -30px;
    right: 0;
    background-color: #10b981;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    animation: copyPopup 2s ease;
}

@keyframes copyPopup {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }
    20% {
        opacity: 1;
        transform: translateY(0);
    }
    80% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* 导出按钮状态 */
.export-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    /* 移除悬停效果，避免移动端点击延迟 */
    .quick-question:hover {
        transform: none;
    }

    .quick-question:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }

    button:hover {
        transform: none;
    }

    button:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }

    /* 增加触摸目标大小 */
    .rating-btn {
        padding: 0.5rem;
        margin: 0 0.25rem;
    }

    #copyResponse, #exportResponse {
        padding: 0.5rem;
        margin-left: 0.5rem;
    }
}

/* iOS Safari 特殊优化 */
@supports (-webkit-touch-callout: none) {
    /* 防止iOS缩放 */
    input, textarea, select {
        font-size: 16px;
    }

    /* 修复iOS滚动问题 */
    body {
        -webkit-overflow-scrolling: touch;
        position: relative;
        height: 100%;
    }

    /* 修复iOS固定定位问题 */
    nav {
        position: -webkit-sticky;
        position: sticky;
    }
}

/* Android Chrome 优化 */
@media screen and (-webkit-min-device-pixel-ratio: 0) and (min-resolution: .001dpcm) {
    .quick-question {
        will-change: transform;
    }

    .animate-spin {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
    .prose {
        color: #e5e7eb;
    }

    .prose h1, .prose h2, .prose h3 {
        color: #f9fafb;
    }

    .prose strong {
        color: #f9fafb;
    }

    .prose code {
        background-color: #374151;
        color: #fbbf24;
    }

    .prose pre {
        background-color: #1f2937;
        border-color: #374151;
    }

    /* 深色模式下的按钮优化 */
    .quick-question {
        filter: brightness(0.9);
    }

    .quick-question:active {
        filter: brightness(0.8);
    }
}

/* 现代化性能优化 */
/* CSS容器查询支持 */
@supports (container-type: inline-size) {
    .responsive-container {
        container-type: inline-size;
    }

    @container (max-width: 300px) {
        .quick-question {
            padding: 0.5rem;
            font-size: 0.8rem;
        }
    }
}

/* 网络状态优化 */
@media (prefers-reduced-data: reduce) {
    .quick-question::before {
        display: none; /* 移除动画减少数据使用 */
    }

    .animated-gradient {
        animation: none;
        background: linear-gradient(-45deg, #667eea, #764ba2);
    }
}

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

    .quick-question:hover {
        transform: none !important;
    }
}

/* 性能监控优化 */
.performance-optimized {
    contain: layout style paint;
    content-visibility: auto;
    contain-intrinsic-size: 0 500px;
}

/* 图片懒加载优化 */
img[data-src] {
    opacity: 0;
    transition: opacity 0.3s;
}

img[data-src].loaded {
    opacity: 1;
}

/* 现代CSS变量优化 */
:root {
    --primary-color: #6366f1;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --error-color: #ef4444;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

/* 快速问题网格布局 */
.quick-questions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    width: 100%;
}

/* 快速按钮样式优化 */
.quick-questions-grid .quick-question {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 44px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    position: relative;
    overflow: hidden;
}

.quick-questions-grid .quick-question i {
    font-size: 0.875rem;
    flex-shrink: 0;
}

.quick-questions-grid .quick-question:hover {
    transform: translateY(-1px);
    border-color: rgba(255, 255, 255, 0.2);
}

.quick-questions-grid .quick-question:active {
    transform: translateY(0);
}

/* 响应式设计 */
@media (max-width: 640px) {
    .quick-questions-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 0.5rem;
    }

    .quick-questions-grid .quick-question {
        min-height: 40px;
        font-size: 0.8rem;
        padding: 0.5rem 0.75rem;
    }
}

@media (max-width: 480px) {
    .quick-questions-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .quick-questions-grid .quick-question {
        min-height: 38px;
        font-size: 0.75rem;
        padding: 0.5rem;
    }
}

@media (min-width: 1200px) {
    .quick-questions-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 1rem;
    }

    .quick-questions-grid .quick-question {
        min-height: 48px;
        font-size: 0.9rem;
        padding: 0.75rem 1rem;
    }
}

/* 深色模式变量 */
@media (prefers-color-scheme: dark) {
    :root {
        --text-primary: #f9fafb;
        --text-secondary: #d1d5db;
        --bg-primary: #111827;
        --bg-secondary: #1f2937;
        --border-color: #374151;
    }
}