/* ===== 响应式（媒体查询） =====
   位置沿用原 index.css 的顺序：在 index-modals.css 之后、index-workspace.css 之前。
   design-system.css / workspace.css 仍在更后面加载，不要把它挪到最后。 */
/* ========== 响应式 ========== */

/* Large tablet / small desktop */
@media (max-width: 1300px) {
    .left-panel {
        width: 380px;
    }
    .history-sidebar {
        width: 220px;
    }
    .result-content {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 14px;
        padding: 14px;
    }
}

/* Tablet: 历史侧边栏收起 */
@media (max-width: 1060px) {
    .history-sidebar {
        display: none;
    }
    .left-panel {
        width: 400px;
    }
}

/* Narrow / 移动端 ChatGPT 风格上下布局 */
@media (max-width: 768px) {
    .header-inner {
        padding: 10px 16px;
    }

    .logo-text {
        font-size: 14px;
    }

    .logo-icon {
        width: 28px;
        height: 28px;
        font-size: 14px;
        border-radius: 10px;
    }

    .main-container {
        flex-direction: column;
        padding: 0;
        gap: 0;
        height: calc(100vh - 44px);
        overflow: hidden;
    }

    .history-sidebar {
        display: none;
    }

    .left-panel {
        display: none;
    }

    /* 右侧结果区域占满剩余空间 */
    .right-panel {
        flex: 1;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    .result-card {
        min-height: 0;
        height: 100%;
        border-radius: 0;
        border: none;
        box-shadow: none;
        background: var(--bg);
    }

    .result-card-header {
        padding: 10px 16px;
        font-size: 13px;
        background: var(--card-bg);
        border-bottom: 1.5px solid var(--border-light);
    }

    .result-content {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 12px;
        padding-bottom: 68px;
        justify-items: stretch;
        justify-content: stretch;
    }

    .result-content.single-image,
    .result-content.images-1 {
        display: block;      /* 移动端恢复文档流：全宽、高度自然，需要时可滚动 */
        height: auto;
        max-width: 100%;
        margin: 0 auto;
    }

    .result-content.single-image .image-block,
    .result-content.images-1 .image-block {
        width: 100%;
        height: auto;
        min-height: 160px;
    }

    .result-content.single-image .image-preview-button img,
    .result-content.images-1 .image-preview-button img {
        width: 100%;
        height: auto;
        max-height: none;
    }

    /* 移动端一律单列，放弃桌面端的按张数排布 */
    .result-content.images-2,
    .result-content.images-3,
    .result-content.images-4 {
        grid-template-columns: 1fr;
        max-width: 100%;
    }

    .result-content.images-3 .image-block:first-child {
        grid-column: auto;
        width: 100%;
    }

    .result-empty {
        padding: 40px 20px 68px;
    }

    .result-empty-icon {
        width: 48px;
        height: 48px;
        font-size: 22px;
    }

    .result-empty-title {
        font-size: 14px;
    }

    .result-empty-desc {
        font-size: 12px;
    }

    .image-block {
        border-radius: var(--radius-sm);
        aspect-ratio: auto;
        width: 100%;
        background: var(--bg);
    }

    .image-block img {
        display: block;
        width: 100%;
        height: auto;
        object-fit: contain;
    }

    /* 移动端 overlay 始终可见（无法 hover） */
    .image-overlay {
        opacity: 1;
        padding: 8px 12px;
    }

    .image-index {
        font-size: 11px;
    }

    .image-actions {
        gap: 4px;
    }

    .image-action-btn {
        font-size: 11px;
        padding: 4px 12px;
    }

    /* 生成中：移动端使用单列自然高度，底部为输入栏预留空间 */
    .result-card {
        --result-header-height: 58px;
    }

    .result-loading {
        justify-content: flex-start;
        padding: 20px 16px 92px;
    }

    .generation-shell {
        justify-content: flex-start;
        gap: 14px;
        margin: 0 auto;
    }

    .generation-head {
        grid-template-columns: 38px minmax(0, 1fr) auto;
        gap: 10px;
    }

    .generation-mark {
        width: 38px;
        height: 38px;
        border-radius: 11px;
    }

    .generation-title {
        font-size: 14px;
    }

    .generation-meta,
    .generation-elapsed {
        font-size: 11.5px;
    }

    .skeleton-grid,
    .skeleton-grid.cols-1,
    .skeleton-grid.cols-2,
    .skeleton-grid.cols-3,
    .skeleton-grid.cols-4 {
        grid-template-columns: 1fr;
        gap: 10px;
        max-width: 100%;
    }

    .skeleton-grid.cols-3 .skeleton-tile:first-child {
        grid-column: auto;
        width: 100%;
    }

    .skeleton-tile {
        border-radius: 17px;
    }

    .tile-symbol {
        width: 52px;
        height: 52px;
        border-radius: 16px;
    }

    .generation-footer {
        justify-content: center;
    }

    .generation-note {
        display: none;
    }

    /* ===== 移动端顶部: 历史记录按钮 ===== */
    .mobile-history-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border: 1.5px solid var(--border-light);
        border-radius: var(--radius-btn);
        background: var(--bg);
        color: var(--text);
        cursor: pointer;
        position: relative;
        transition: var(--transition);
        font-family: inherit;
    }

    .mobile-history-btn:hover {
        border-color: var(--primary);
        background: var(--primary-light);
    }

    .mobile-history-btn:active {
        transform: scale(0.95);
    }

    .mobile-history-badge {
        position: absolute;
        top: -4px;
        right: -4px;
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
        background: var(--primary);
        color: #fff;
        border-radius: var(--radius-btn);
        font-size: 9px;
        font-weight: 700;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1;
    }

    /* ===== 移动端底部操作栏 ===== */
    .mobile-bottom-bar {
        display: block;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        background: var(--card-bg);
        border-top: 2px solid var(--border-light);
        box-shadow: 0 -2px 12px rgba(61, 52, 40, 0.08);
    }

    .mobile-toolbar {
        padding: 8px 12px 4px;
        border-bottom: 1px solid var(--border-light);
        animation: slideDown 0.2s ease;
    }

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

    .mobile-toolbar-row {
        display: flex;
        gap: 6px;
        align-items: center;
        margin-bottom: 6px;
    }

    .mobile-select {
        flex: 1;
        padding: 7px 10px;
        border: 1.5px solid var(--border);
        border-radius: var(--radius-btn);
        font-size: 12px;
        font-family: inherit;
        font-weight: 500;
        color: var(--text);
        background: var(--bg);
        cursor: pointer;
        appearance: none;
        -webkit-appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%239f927d' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 10px center;
        padding-right: 24px;
    }

    .mobile-select:focus {
        outline: none;
        border-color: var(--focus);
    }

    .mobile-ref-btn {
        display: flex;
        align-items: center;
        gap: 4px;
        padding: 6px 12px;
        border: 1.5px dashed var(--border);
        border-radius: var(--radius-btn);
        background: var(--bg);
        color: var(--text-secondary);
        font-size: 11px;
        font-family: inherit;
        cursor: pointer;
        transition: var(--transition);
        white-space: nowrap;
    }

    .mobile-ref-btn:active {
        border-color: var(--primary);
        color: var(--primary);
        background: var(--primary-light);
    }

    .mobile-ref-previews {
        display: flex;
        gap: 4px;
        overflow-x: auto;
        flex: 1;
    }

    .mobile-ref-previews .mini-ref {
        width: 28px;
        height: 28px;
        border-radius: 4px;
        overflow: hidden;
        border: 1px solid var(--border-light);
        flex-shrink: 0;
        position: relative;
    }

    .mobile-ref-previews .mini-ref img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .mobile-ref-previews .mini-ref .mini-ref-remove {
        position: absolute;
        top: -2px;
        right: -2px;
        width: 14px;
        height: 14px;
        background: rgba(114, 93, 66, 0.7);
        color: #fff;
        border: none;
        border-radius: 50%;
        font-size: 9px;
        line-height: 14px;
        text-align: center;
        cursor: pointer;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-input-row {
        display: flex;
        align-items: flex-end;
        gap: 8px;
        padding: 8px 12px 12px;
    }

    .mobile-tool-toggle {
        flex-shrink: 0;
        width: 36px;
        height: 36px;
        border: 1.5px solid var(--border);
        border-radius: var(--radius-btn);
        background: var(--bg);
        color: var(--text-secondary);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: var(--transition);
        font-family: inherit;
    }

    .mobile-tool-toggle:active {
        background: var(--primary-light);
        color: var(--primary);
        border-color: var(--primary);
    }

    .mobile-tool-toggle.active {
        background: var(--primary-light);
        color: var(--primary);
        border-color: var(--primary);
    }

    .mobile-prompt-input {
        flex: 1;
        padding: 9px 14px;
        border: 1.5px solid var(--border);
        border-radius: var(--radius-btn);
        font-size: 14px;
        font-family: inherit;
        font-weight: 500;
        color: var(--text);
        background: var(--bg);
        resize: none;
        max-height: 100px;
        line-height: 1.5;
        overflow-y: auto;
        transition: var(--transition);
    }

    .mobile-prompt-input::placeholder {
        color: var(--text-muted);
        font-weight: 400;
    }

    .mobile-prompt-input:focus {
        outline: none;
        border-color: var(--focus);
        background: #fff;
        box-shadow: 0 0 0 3px rgba(255, 204, 0, 0.12);
    }

    .mobile-send-btn {
        flex-shrink: 0;
        width: 40px;
        height: 40px;
        border: none;
        border-radius: 50%;
        background: var(--primary);
        color: #fff;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 3px 0 0 var(--primary-3d);
        transition: var(--transition);
        font-family: inherit;
    }

    .mobile-send-btn:active {
        box-shadow: 0 1px 0 0 var(--primary-3d);
        transform: translateY(2px);
    }

    .mobile-send-btn:disabled {
        background: #a8e4df;
        box-shadow: 0 2px 0 0 #8ab8b5;
        transform: none;
    }

    /* ===== 移动端历史记录抽屉 ===== */
    .mobile-history-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(61, 52, 40, 0.35);
        backdrop-filter: blur(4px);
        z-index: 200;
    }

    .mobile-history-overlay.show {
        display: block;
    }

    .mobile-history-drawer {
        display: none;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 201;
        background: var(--card-bg);
        border-radius: var(--radius-card) var(--radius-card) 0 0;
        max-height: 70vh;
        box-shadow: 0 -8px 30px rgba(61, 52, 40, 0.15);
        animation: drawerUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        flex-direction: column;
    }

    .mobile-history-drawer.show {
        display: flex;
    }

    @keyframes drawerUp {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }

    .mobile-drawer-header {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 14px 16px 10px;
        border-bottom: 1.5px solid var(--border-light);
        flex-shrink: 0;
        font-size: 14px;
        font-weight: 700;
        color: var(--text-heading);
    }

    .mobile-drawer-count {
        font-size: 11px;
        font-weight: 600;
        color: var(--text-muted);
    }

    .mobile-drawer-close {
        margin-left: auto;
        width: 28px;
        height: 28px;
        border: none;
        background: var(--bg);
        border-radius: 50%;
        font-size: 18px;
        cursor: pointer;
        color: var(--text-secondary);
        display: flex;
        align-items: center;
        justify-content: center;
        font-family: inherit;
        transition: var(--transition);
    }

    .mobile-drawer-close:active {
        background: var(--danger-bg);
        color: var(--danger);
    }

    .mobile-drawer-body {
        flex: 1;
        overflow-y: auto;
        padding: 8px 12px 20px;
        display: flex;
        flex-direction: column;
        gap: 4px;
        -webkit-overflow-scrolling: touch;
    }

    .mobile-drawer-body .history-item {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 12px;
        background: var(--bg);
        border: 1.5px solid var(--border-light);
        border-radius: var(--radius-sm);
        cursor: pointer;
        transition: var(--transition);
        flex-shrink: 0;
    }

    .mobile-drawer-body .history-item:active {
        border-color: var(--primary);
        background: var(--primary-light);
    }

    .mobile-drawer-body .history-info {
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }

    .mobile-drawer-body .history-prompt {
        font-size: 13px;
        font-weight: 600;
        color: var(--text-heading);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-bottom: 2px;
    }

    .mobile-drawer-body .history-meta {
        font-size: 11px;
        font-weight: 500;
        color: var(--text-muted);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-drawer-body .history-empty {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: var(--text-muted);
        gap: 4px;
        padding: 30px 8px;
        text-align: center;
    }

    .mobile-drawer-body .history-empty-icon {
        font-size: 28px;
        opacity: 0.6;
    }

    .mobile-drawer-body .history-empty-text {
        font-size: 12px;
        font-weight: 500;
        color: var(--text-secondary);
    }

    .mobile-drawer-body .history-skeleton {
        display: flex;
        align-items: center;
        padding: 10px 12px;
        background: var(--bg);
        border: 1.5px solid var(--border-light);
        border-radius: var(--radius-sm);
        flex-shrink: 0;
    }

    .mobile-drawer-body .history-skeleton .skeleton-info {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 6px;
    }

    .mobile-drawer-body .history-skeleton .skeleton-line {
        height: 12px;
        background: linear-gradient(90deg, var(--border-light) 25%, #e8e2d0 50%, var(--border-light) 75%);
        background-size: 200% 100%;
        animation: skeletonShimmer 1.6s ease-in-out infinite;
        border-radius: 4px;
    }

    .mobile-drawer-body .history-skeleton .skeleton-line.short {
        width: 50%;
    }

    /* 弹窗移动端适配 */
    .modal-dialog {
        max-width: 100%;
        margin: 0 8px;
        max-height: 90vh;
    }
    .modal-body {
        padding: 14px;
    }
    .modal-header {
        padding: 12px 16px;
    }
    .modal-prompt {
        font-size: 13px;
        padding: 10px 12px;
    }

    /* toast */
    .toast {
        padding: 10px 14px;
        font-size: 13px;
    }
}

/* Mobile: 小屏设备微调 */
@media (max-width: 640px) {
    .mobile-input-row {
        padding: 6px 10px 10px;
        gap: 6px;
    }

    .mobile-send-btn {
        width: 36px;
        height: 36px;
    }

    .mobile-tool-toggle {
        width: 34px;
        height: 34px;
    }

    .mobile-prompt-input {
        font-size: 14px;
        padding: 8px 12px;
    }

    .mobile-toolbar {
        padding: 6px 10px 2px;
    }

    .mobile-select {
        font-size: 11px;
        padding: 6px 8px;
        padding-right: 22px;
    }

    .mobile-history-drawer {
        max-height: 75vh;
    }
}

/* Small mobile */
@media (max-width: 400px) {
    .mobile-input-row {
        padding: 5px 8px 8px;
    }

    .mobile-history-drawer {
        max-height: 80vh;
    }

    .result-content {
        gap: 8px;
        padding: 8px;
    }
}

