/* Mobile-specific styles */
@media (max-width: 768px) {
    /* Global Layout Adjustments */
    body {
        overscroll-behavior-y: none; /* Prevent pull-to-refresh on some browsers */
        background-color: #f3f4f6; /* Light gray background matching design */
    }
    
    .dark body {
        background-color: #020617;
    }

    /* Mobile Drawer / Bottom Sheet */
    .mobile-drawer-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        z-index: 150;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .mobile-drawer-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-drawer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #ffffff;
        border-top-left-radius: 1.5rem;
        border-top-right-radius: 1.5rem;
        z-index: 151;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
        max-height: 90vh;
        display: flex;
        flex-direction: column;
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.1);
    }

    .dark .mobile-drawer {
        background: #0f172a;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .mobile-drawer.active {
        transform: translateY(0);
    }

    .drawer-handle {
        width: 3rem;
        height: 0.25rem;
        background: #e2e8f0;
        border-radius: 999px;
        margin: 0.75rem auto;
    }

    .dark .drawer-handle {
        background: #334155;
    }

    /* New Mobile Immersive Layout - Matching Design */
    .mobile-immersive-container {
        display: flex;
        flex-direction: column;
        height: calc(100dvh - 4rem); /* Subtract header height */
        padding: 1rem;
        gap: 1rem;
        overflow-y: auto;
        padding-bottom: 6rem; /* Space for fixed bottom action */
    }

    /* 1. Parameter Grid Area */
    .mobile-param-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        background: #ffffff;
        padding: 1rem;
        border-radius: 1rem;
    }

    .dark .mobile-param-grid {
        background: #1e293b;
    }

    .mobile-select-box {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
        position: relative; /* For dropdown positioning */
    }

    /* Mobile Dropdown Styles */
    .mobile-dropdown {
        position: absolute;
        top: 100%;
        left: 0;
        min-width: 100%;
        width: max-content;
        max-width: 85vw;
        z-index: 20;
        margin-top: 0.25rem;
    }

    /* Right align dropdown for the 3rd column to prevent overflow */
    .mobile-select-box:nth-child(3n) .mobile-dropdown {
        left: auto;
        right: 0;
    }

    .mobile-select-label {
        font-size: 0.75rem;
        color: #94a3b8;
        font-weight: 600;
    }

    .mobile-select-trigger {
        display: flex;
        align-items: center;
        justify-content: space-between;
        background: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 0.5rem;
        padding: 0.5rem;
        height: 2.25rem;
        font-size: 0.8rem;
        font-weight: 600;
        color: #334155;
    }

    .dark .mobile-select-trigger {
        background: #0f172a;
        border-color: #334155;
        color: #e2e8f0;
    }

    .mobile-select-trigger span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* 2. Reference Image Area */
    .mobile-ref-container {
        background: #ffffff;
        border-radius: 1rem;
        padding: 1rem;
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .dark .mobile-ref-container {
        background: #1e293b;
    }

    .mobile-ref-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .mobile-ref-title {
        font-size: 0.75rem;
        color: #94a3b8;
        font-weight: 600;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .mobile-ref-history-btn {
        font-size: 0.75rem;
        color: #6366f1;
        background: #eff6ff;
        padding: 0.25rem 0.75rem;
        border-radius: 999px;
        font-weight: 600;
    }

    .dark .mobile-ref-history-btn {
        background: rgba(99, 102, 241, 0.1);
        color: #818cf8;
    }

    .mobile-upload-placeholder {
        border: 2px dashed #cbd5e1;
        border-radius: 1rem;
        height: 5rem;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.25rem;
        color: #64748b;
        cursor: pointer;
    }

    .dark .mobile-upload-placeholder {
        border-color: #334155;
        color: #94a3b8;
    }

    .mobile-upload-icon {
        font-size: 1.5rem;
        color: #94a3b8;
    }

    .mobile-upload-text {
        font-size: 0.75rem;
        font-weight: 600;
    }

    .mobile-upload-subtext {
        font-size: 0.65rem;
        color: #cbd5e1;
    }

    /* Reference Images List (When images uploaded) */
    .mobile-ref-list {
        display: flex;
        gap: 0.5rem;
        overflow-x: auto;
    }
    
    .mobile-ref-item {
        width: 4rem;
        height: 4rem;
        border-radius: 0.5rem;
        overflow: hidden;
        flex-shrink: 0;
        position: relative;
    }

    /* 3. Input Card Area */
    .mobile-input-card {
        background: #ffffff;
        border-radius: 1rem;
        padding: 1rem;
        flex: 1;
        min-height: 200px;
        display: flex;
        flex-direction: column;
        position: relative;
    }

    .dark .mobile-input-card {
        background: #1e293b;
    }

    .mobile-input-tools {
        display: flex;
        gap: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .mobile-tool-btn {
        width: 2rem;
        height: 2rem;
        border-radius: 50%;
        border: 1px dashed #cbd5e1;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #94a3b8;
    }

    .dark .mobile-tool-btn {
        border-color: #334155;
    }

    .mobile-input-textarea {
        flex: 1;
        width: 100%;
        background: transparent;
        border: none;
        resize: none;
        font-size: 0.95rem;
        line-height: 1.6;
        outline: none;
        color: #334155;
    }

    .dark .mobile-input-textarea {
        color: #e2e8f0;
    }

    .mobile-input-textarea::placeholder {
        color: #94a3b8;
    }

    /* 4. Bottom Action Bar (Fixed) */
    .mobile-bottom-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 1rem;
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
        background: rgba(243, 244, 246, 0.9); /* Matches body bg */
        backdrop-filter: blur(10px);
        display: flex;
        gap: 0.75rem;
        z-index: 40;
    }

    .dark .mobile-bottom-bar {
        background: rgba(2, 6, 23, 0.9);
    }

    /* Batch Control Group */
    .mobile-batch-group {
        display: flex;
        background: #ffffff;
        border-radius: 0.75rem;
        overflow: hidden;
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
        height: 3.5rem;
    }

    .dark .mobile-batch-group {
        background: #1e293b;
    }

    .batch-btn {
        width: 2.5rem;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #64748b;
        font-size: 0.875rem;
    }

    .batch-display {
        width: 2.5rem;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        border-left: 1px solid #f1f5f9;
        border-right: 1px solid #f1f5f9;
    }

    .dark .batch-display {
        border-color: #334155;
    }

    .batch-num {
        font-weight: bold;
        font-size: 1.125rem;
        line-height: 1;
        color: #0f172a;
    }

    .dark .batch-num {
        color: #f8fafc;
    }

    .batch-label {
        font-size: 0.55rem;
        color: #94a3b8;
        text-transform: uppercase;
    }

    /* Generate Button */
    .mobile-gen-btn {
        flex: 1;
        height: 3.5rem;
        border-radius: 0.75rem;
        background: linear-gradient(135deg, #a78bfa, #f472b6); /* Purple to Pink gradient */
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        font-weight: 700;
        font-size: 1rem;
        box-shadow: 0 4px 12px rgba(167, 139, 250, 0.3);
        transition: transform 0.1s;
    }

    .mobile-gen-btn:active {
        transform: scale(0.98);
    }

    .mobile-gen-btn:disabled {
        opacity: 0.5;
        box-shadow: none;
        cursor: not-allowed;
    }

    .gen-cost-pill {
        background: rgba(255, 255, 255, 0.2);
        padding: 0.15rem 0.5rem;
        border-radius: 999px;
        font-size: 0.7rem;
        font-weight: 500;
    }

    /* Task Queue Drawer Specifics */
    .mobile-queue-drawer {
        height: 85vh;
    }

    /* Fullscreen Preview Modal */
    .mobile-fullscreen-preview {
        position: fixed;
        inset: 0;
        background: #000;
        z-index: 200;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }

    .mobile-fullscreen-preview.active {
        opacity: 1;
        pointer-events: auto;
    }

    .preview-close-btn {
        position: absolute;
        top: 1rem;
        right: 1rem;
        width: 2.5rem;
        height: 2.5rem;
        background: rgba(255, 255, 255, 0.2);
        backdrop-filter: blur(4px);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
        z-index: 201;
    }

    /* =========================================
       Mobile Dynamic Island (灵动岛) - Invisible Idle
       ========================================= */
    .mobile-dynamic-island {
        position: absolute;
        top: 0.75rem;
        left: 50%;
        transform: translateX(-50%);
        z-index: 100;
        
        /* Idle: 透明无形 */
        background: transparent;
        backdrop-filter: none;
        border: none;
        border-radius: 999px;
        
        height: 2.5rem;
        min-width: auto;
        padding: 0.25rem 0.5rem;
        
        display: flex;
        align-items: center;
        justify-content: center;
        
        box-shadow: none;
        transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        
        cursor: pointer;
        overflow: hidden;
        color: #475569; /* Slate-600 */
    }

    /* 夜间模式 Idle */
    .dark .mobile-dynamic-island {
        background: transparent;
        backdrop-filter: none;
        border: none;
        box-shadow: none;
        color: rgba(255, 255, 255, 0.9);
    }

    /* Processing State (Expanded) - 显形为深色胶囊 */
    .mobile-dynamic-island.processing {
        min-width: 200px;
        padding: 0.25rem;
        
        /* 显形 */
        background: rgba(15, 23, 42, 0.95);
        backdrop-filter: blur(12px);
        border: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: 0 8px 25px rgba(167, 139, 250, 0.25);
        
        color: white;
    }
    
    .dark .mobile-dynamic-island.processing {
        background: rgba(0, 0, 0, 0.8);
        border-color: rgba(167, 139, 250, 0.4);
    }

    /* Notification State (Expanded) */
    .mobile-dynamic-island.notification {
        min-width: 240px;
        padding: 0.35rem;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(12px);
        border: 1px solid rgba(0, 0, 0, 0.05);
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
        color: #1e293b;
    }

    .dark .mobile-dynamic-island.notification {
        background: rgba(15, 23, 42, 0.95);
        border-color: rgba(255, 255, 255, 0.1);
        color: white;
    }

    /* Success Theme */
    .mobile-dynamic-island.success {
        border-color: rgba(34, 197, 94, 0.2);
        box-shadow: 0 8px 30px rgba(34, 197, 94, 0.15);
    }
    .mobile-dynamic-island.success .island-icon {
        color: #22c55e;
    }

    /* Error Theme */
    .mobile-dynamic-island.error {
        border-color: rgba(239, 68, 68, 0.2);
        box-shadow: 0 8px 30px rgba(239, 68, 68, 0.15);
    }
    .mobile-dynamic-island.error .island-icon {
        color: #ef4444;
    }
    .mobile-dynamic-island.error .island-progress-bar {
        display: none;
    }

    /* Notification Content Layout */
    .island-notification-content {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        width: 100%;
        position: relative;
    }

    .island-icon {
        font-size: 1.25rem;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 1.5rem;
        flex-shrink: 0;
        margin-left: 0.25rem;
    }

    .island-message {
        flex: 1;
        font-size: 0.85rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding-right: 0.5rem;
    }

    .island-thumb {
        width: 2rem;
        height: 2rem;
        border-radius: 0.5rem;
        overflow: hidden;
        flex-shrink: 0;
        border: 1px solid rgba(0,0,0,0.1);
    }
    .dark .island-thumb {
        border-color: rgba(255,255,255,0.1);
    }

    /* Progress Bar */
    .island-progress-bar {
        position: absolute;
        bottom: -0.35rem;
        left: 0.5rem;
        right: 0.5rem;
        height: 2px;
        background: currentColor;
        opacity: 0.2;
        border-radius: 99px;
        transform-origin: left;
        animation: island-progress linear forwards;
    }

    @keyframes island-progress {
        from { transform: scaleX(0); }
        to { transform: scaleX(1); }
    }

    /* Inner Layouts */
    .island-idle, .island-processing {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        height: 100%;
        padding: 0 0.5rem;
    }

    .island-section {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        font-size: 0.75rem;
        font-weight: 600;
        white-space: nowrap;
    }

    .island-divider {
        width: 1px;
        height: 12px;
        background: rgba(0, 0, 0, 0.1);
        margin: 0 0.5rem;
    }
    
    .dark .island-divider {
        background: rgba(255, 255, 255, 0.15);
    }
    
    .mobile-dynamic-island.processing .island-divider {
        background: rgba(255, 255, 255, 0.2);
        margin: 0 0.25rem;
    }

    /* Mode Section */
    .mode-section {
        color: #64748b;
    }
    .dark .mode-section {
        color: #94a3b8;
    }
    .mode-section i {
        font-size: 0.8rem;
    }

    /* Balance Section */
    .balance-section {
        color: #334155;
    }
    .dark .balance-section {
        color: white;
    }
    .island-value {
        font-family: "JetBrains Mono", monospace;
        letter-spacing: -0.5px;
    }

    /* Queue Section */
    .queue-section {
        color: #64748b;
        /* width: 1.5rem; Removed fixed width */
        justify-content: center;
    }
    .dark .queue-section {
        color: #94a3b8;
    }

    /* Processing Animation */
    .island-wave {
        display: flex;
        align-items: center;
        gap: 3px;
        height: 16px;
    }

    .island-wave span {
        display: block;
        width: 3px;
        height: 100%;
        background: #a78bfa; /* Purple */
        border-radius: 99px;
        animation: island-wave-anim 1s ease-in-out infinite;
    }

    .island-wave span:nth-child(1) { animation-delay: 0s; }
    .island-wave span:nth-child(2) { animation-delay: 0.1s; }
    .island-wave span:nth-child(3) { animation-delay: 0.2s; }
    .island-wave span:nth-child(4) { animation-delay: 0.3s; }

    @keyframes island-wave-anim {
        0%, 100% { height: 4px; opacity: 0.5; }
        50% { height: 14px; opacity: 1; }
    }

    .island-info {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        font-size: 0.75rem;
    }

    .island-status-text {
        color: white;
        font-weight: 600;
    }

    .island-count {
        color: #94a3b8;
        font-size: 0.7rem;
    }

    /* =========================================
       Downloading State (下载中状态)
       ========================================= */
    .mobile-dynamic-island.downloading {
        min-width: 200px;
        padding: 0.25rem;
        
        /* 蓝色主题显形 */
        background: linear-gradient(135deg, 
            rgba(30, 64, 175, 0.9), 
            rgba(14, 116, 144, 0.85)
        );
        backdrop-filter: blur(12px);
        border: 1px solid rgba(96, 165, 250, 0.4);
        box-shadow: 
            0 8px 25px rgba(59, 130, 246, 0.3),
            inset 0 1px 1px rgba(255, 255, 255, 0.1);
        
        color: white;
    }

    .dark .mobile-dynamic-island.downloading {
        background: linear-gradient(135deg, 
            rgba(30, 58, 138, 0.95), 
            rgba(8, 145, 178, 0.85)
        );
        border-color: rgba(96, 165, 250, 0.5);
        box-shadow: 
            0 8px 30px rgba(59, 130, 246, 0.35),
            inset 0 1px 2px rgba(255, 255, 255, 0.08);
    }

    /* 下载状态内容布局 */
    .island-downloading {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        height: 100%;
        padding: 0 0.5rem;
    }

    /* 下载区域 (左侧) */
    .island-download-section {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        cursor: pointer;
    }

    /* 环形进度条容器 */
    .island-ring-progress {
        position: relative;
        width: 1.5rem;
        height: 1.5rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .island-ring-progress svg {
        position: absolute;
        inset: 0;
        transform: rotate(-90deg);
    }

    /* 背景圆环 */
    .island-ring-progress .ring-bg {
        color: rgba(255, 255, 255, 0.2);
    }

    /* 进度圆环 */
    .island-ring-progress .ring-progress {
        color: #60a5fa;
        transition: stroke-dashoffset 0.35s ease-out;
        filter: drop-shadow(0 0 3px rgba(96, 165, 250, 0.5));
    }

    /* 下载图标 (静态) */
    .island-dl-icon {
        font-size: 0.5rem;
        color: #60a5fa;
        position: relative;
        z-index: 1;
    }

    /* 进度百分比 */
    .island-dl-percent {
        font-size: 0.8rem;
        font-weight: 700;
        color: white;
        font-family: "JetBrains Mono", monospace;
    }

    /* 下载数量 */
    .island-dl-count {
        font-size: 0.65rem;
        color: rgba(255, 255, 255, 0.7);
        font-weight: 500;
    }

    /* 下载状态分隔线 */
    .mobile-dynamic-island.downloading .island-divider {
        background: rgba(255, 255, 255, 0.25);
        margin: 0 0.5rem;
    }

    /* 下载状态队列按钮 */
    .mobile-dynamic-island.downloading .queue-section {
        color: rgba(255, 255, 255, 0.9);
    }

    .mobile-dynamic-island.downloading .queue-section:active {
        opacity: 0.7;
    }

    /* =========================================
       移动端历史记录顶部面板优化（云端存档）
       ========================================= */
    
    /* 顶部面板容器 - 减小内边距和间距 */
    .sticky.top-0.z-\[25\] {
        padding: 0.625rem !important; /* 10px，原16px */
        gap: 0.5rem !important; /* 8px，原16px */
        margin-bottom: 0.75rem !important; /* 12px，原24px */
        border-radius: 0.75rem !important; /* 更小的圆角 */
    }
    
    /* 标题 - 更小字体 */
    .sticky.top-0 h3.font-bold {
        font-size: 0.8rem !important;
    }
    
    /* 搜索框 - 更紧凑 */
    .sticky.top-0 input[placeholder="搜索提示词..."] {
        padding: 0.375rem 0.5rem 0.375rem 2rem !important;
        font-size: 11px !important;
    }
    
    /* 分页器区域 - 更紧凑 */
    .sticky.top-0 .flex.flex-wrap.justify-center {
        gap: 0.375rem !important;
        margin-left: 0 !important;
    }
    
    /* 分页按钮 - 保持可点击尺寸但更紧凑 */
    .sticky.top-0 .flex.items-center.gap-1 button {
        width: 1.375rem !important; /* 22px，保持可点击 */
        height: 1.375rem !important;
        min-width: 1.375rem !important;
        min-height: 1.375rem !important;
    }
    
    /* 分页数字按钮 */
    .sticky.top-0 .flex.items-center.gap-1 button:not(:disabled) {
        font-size: 10px !important;
    }
    
    /* 每页选择器 */
    .sticky.top-0 select {
        font-size: 10px !important;
        padding: 0.125rem !important;
    }
    
    /* 分页文字 */
    .sticky.top-0 .text-\[10px\] {
        font-size: 9px !important;
    }
    
    /* 全选区域 - 更紧凑 */
    .sticky.top-0 .flex.items-center.gap-2.px-3 {
        padding: 0.25rem 0.5rem !important;
        gap: 0.375rem !important;
    }
    
    /* 全选文字 */
    .sticky.top-0 .flex.items-center.gap-2 span.text-xs {
        font-size: 10px !important;
    }
    
    /* 清空按钮 */
    .sticky.top-0 button.text-accent {
        font-size: 10px !important;
        padding: 0.25rem 0 !important;
    }
    
    /* =========================================
       移动端历史记录卡片优化
       ========================================= */
    
    /* 卡片信息区域 - 减小内边距和间距 */
    .grid.grid-cols-2 > div > .p-3 {
        padding: 0.5rem !important;
        gap: 0.25rem !important;
    }
    
    /* 移除 Prompt 区域的最小高度 */
    .grid.grid-cols-2 > div .min-h-\[2\.5em\] {
        min-height: auto !important;
    }
    
    /* Prompt 文本 - 限制为1行 */
    .grid.grid-cols-2 > div .line-clamp-2 {
        -webkit-line-clamp: 1 !important;
        line-clamp: 1 !important;
    }
    
    /* 参数标签区域 - 更紧凑 */
    .grid.grid-cols-2 > div .flex-wrap.gap-1\.5 {
        gap: 0.25rem !important;
    }
    
    /* 参数标签 - 更小的字体和内边距 */
    .grid.grid-cols-2 > div .flex-wrap.gap-1\.5 > span {
        padding: 0.125rem 0.375rem !important;
        font-size: 9px !important;
    }
    
    /* 底部操作栏 - 减小上边距和内边距 */
    .grid.grid-cols-2 > div .pt-2.border-t {
        padding-top: 0.375rem !important;
        margin-top: 0.25rem !important;
    }
    
    /* 操作按钮 - 更紧凑 */
    .grid.grid-cols-2 > div .pt-2.border-t .flex.gap-1 {
        gap: 0 !important;
    }
    
    /* 隐藏移动端的"同款"文字，只保留图标 */
    .grid.grid-cols-2 > div .pt-2.border-t button[title="使用同款配置"] {
        padding: 0.25rem !important;
    }
    
    /* 模型名和时间行 - 更小字体 */
    .grid.grid-cols-2 > div .text-\[10px\] {
        font-size: 9px !important;
    }
}
