/**
 * 後台響應式 - 遊戲輪播設定頁面
 *
 * 由 admin-responsive.css 依原行序拆出；載入順序見 src/lib/assets.ts 的
 * ADMIN_STYLES，順序即 cascade 順序，不可調換。
 */

/* ==================================================================================== */
/*  遊戲輪播設定頁面 - 響應式設計                                                         */
/*  Game Carousel Settings - Responsive Design                                           */
/* ==================================================================================== */

/* ===== 中等 PC 螢幕 (max-width: 85rem / 1360px) ===== */
@media (max-width: 85rem) {
    #carouselTableContainer {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #carouselTable {
        min-width: 850px;
    }

    /* 預覽圖稍微縮小 */
    .carousel-table-preview {
        width: 180px;
        height: 56px;
    }
}

/* ===== 平板尺寸 (max-width: 64rem / 1024px) ===== */
@media (max-width: 64rem) {
    /* 表格預覽圖進一步縮小 */
    .carousel-table-preview {
        width: 150px;
        height: 46px;
    }

    /* hover 放大倍率調整 */
    .carousel-table-preview:hover .carousel-table-img {
        transform: scale(3);
    }

    /* 隱藏副標題欄位節省空間 */
    #carouselTable th:nth-child(5),
    #carouselTable td:nth-child(5) {
        display: none;
    }
}

/* ===== 中等手機尺寸 (max-width: 48rem / 768px) - 卡片佈局 ===== */
@media (max-width: 48rem) {

    /* ---- 品牌頁籤 ---- */
    #page-game-carousels .brand-tabs {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    #page-game-carousels .brand-tabs::-webkit-scrollbar {
        display: none;
    }

    #page-game-carousels .brand-tab {
        flex-shrink: 0;
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
        gap: 0.375rem;
    }

    #page-game-carousels .brand-tab-name {
        display: inline;
    }

    /* ---- 環境頁籤 ---- */
    #page-game-carousels .env-tabs {
        width: 100%;
        flex-wrap: nowrap;
    }

    #page-game-carousels .env-tab {
        flex: 1;
        min-width: auto;
        padding: 0.5rem 0.375rem;
        font-size: 0.6875rem;
        gap: 0.25rem;
    }

    #page-game-carousels .env-tab span {
        display: inline;
    }

    #page-game-carousels .env-tab i {
        font-size: 0.75rem;
    }

    /* ---- 工具列 ---- */
    #page-game-carousels .toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.625rem;
    }

    #page-game-carousels .toolbar-left {
        width: 100%;
    }

    #page-game-carousels .toolbar-left .search-box {
        flex: 1;
    }

    #page-game-carousels .toolbar-left .search-box input {
        width: 100%;
    }

    #page-game-carousels .toolbar-right {
        width: 100%;
        display: flex;
        gap: 0.5rem;
    }

    #page-game-carousels .toolbar-right .btn {
        flex: 1;
        justify-content: center;
        padding: 0.625rem 0.75rem;
        font-size: 0.8125rem;
    }

    #page-game-carousels .toolbar-right .btn span {
        display: inline;
    }

    /* ---- 表格容器 - 移除橫向滾動 ---- */
    #carouselTableContainer {
        overflow-x: visible;
        border: none;
        background: transparent;
        box-shadow: none;
    }

    .light-theme #carouselTableContainer {
        background: transparent;
        border: none;
        box-shadow: none;
    }

    /* ---- 表格 → 卡片佈局轉換 ---- */
    #carouselTable {
        min-width: unset;
        display: block;
        width: 100%;
        border: none;
        background: transparent;
    }

    #carouselTable thead {
        display: none;
    }

    #carouselTable tbody {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        width: 100%;
    }

    /* ---- 卡片樣式 ---- */
    /*
     * CSS Grid 佈局結構：
     * Row 1: [預覽圖 - 全寬跨兩列]
     * Row 2: [標題]              [狀態]
     * Row 3: [遊戲代碼 - 全寬跨兩列]
     * Row 4: [ID]                [連結類型]
     * Row 5: [操作按鈕 - 全寬跨兩列]
     *
     * Grid: 2 columns = [1fr] [auto]
     */
    #carouselTable tbody tr {
        display: grid !important;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto auto auto auto;
        position: relative;
        background: var(--admin-bg-elevated, #1a1a2e);
        border: 1px solid rgba(212, 165, 32, 0.12);
        border-radius: 0.75rem;
        overflow: hidden;
        transition: border-color var(--motion-fast) var(--ease-out-quart), box-shadow var(--motion-fast) var(--ease-out-quart);
    }

    #carouselTable tbody tr:hover {
        border-color: rgba(212, 165, 32, 0.25);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    }

    .light-theme #carouselTable tbody tr {
        background: #fff;
        border-color: rgba(184, 134, 11, 0.12);
    }

    .light-theme #carouselTable tbody tr:hover {
        border-color: rgba(184, 134, 11, 0.25);
        box-shadow: 0 4px 16px rgba(184, 134, 11, 0.08);
    }

    /* 所有 td 重置 */
    #carouselTable tbody tr td {
        display: flex !important;
        align-items: center;
        border-bottom: none;
        padding: 0;
        width: auto !important;
        min-width: unset !important;
    }

    /* --- Row 1: 預覽圖 - 全寬 --- */
    #carouselTable tbody tr td:nth-child(1) {
        grid-column: 1 / -1;
        grid-row: 1;
        padding: 0;
    }

    #carouselTable tbody tr td:nth-child(1) .carousel-table-preview {
        width: 100%;
        height: auto;
        aspect-ratio: 800 / 247;
        border-radius: 0;
        overflow: hidden;
    }

    #carouselTable tbody tr td:nth-child(1) .carousel-table-img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 0;
        transition: none;
    }

    /* 手機版禁用 hover 放大（改用 tap 全螢幕預覽） */
    #carouselTable tbody tr td:nth-child(1) .carousel-table-preview:hover .carousel-table-img {
        transform: none;
        box-shadow: none;
        z-index: auto;
    }

    #carouselTable tbody tr td:nth-child(1) .carousel-table-placeholder {
        width: 100%;
        height: 100%;
        border-radius: 0;
        font-size: 1.5rem;
    }

    /* --- Row 2 Col 1: 標題 --- */
    #carouselTable tbody tr td:nth-child(4) {
        grid-column: 1;
        grid-row: 2;
        padding: 0.75rem 0.875rem 0.125rem;
    }

    #carouselTable tbody tr td:nth-child(4) .carousel-card-title {
        font-size: 1rem;
        font-weight: 600;
        color: var(--text-primary, #e0e0e0);
        line-height: 1.3;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .light-theme #carouselTable tbody tr td:nth-child(4) .carousel-card-title {
        color: #1a1a2e;
    }

    /* --- Row 2 Col 2: 狀態 --- */
    #carouselTable tbody tr td:nth-child(8) {
        grid-column: 2;
        grid-row: 2;
        padding: 0.75rem 0.875rem 0.125rem 0;
        justify-content: flex-end;
    }

    /* --- Row 3: 遊戲代碼 (全寬) --- */
    #carouselTable tbody tr td:nth-child(3) {
        grid-column: 1 / -1;
        grid-row: 3;
        padding: 0.25rem 0.875rem 0;
    }

    #carouselTable tbody tr td:nth-child(3)::before {
        content: attr(data-label) ": ";
        font-size: 0.6875rem;
        color: #888;
        margin-right: 0.25rem;
        flex-shrink: 0;
    }

    #carouselTable tbody tr td:nth-child(3) code {
        font-size: 0.8125rem;
        background: rgba(212, 165, 32, 0.1);
        padding: 0.125rem 0.375rem;
        border-radius: 0.25rem;
        color: var(--admin-primary, #d4a520);
    }

    /* --- Row 4 Col 1: ID --- */
    #carouselTable tbody tr td:nth-child(2) {
        grid-column: 1;
        grid-row: 4;
        padding: 0.375rem 0.875rem 0;
        font-size: 0.75rem;
        color: #888;
    }

    #carouselTable tbody tr td:nth-child(2)::before {
        content: "ID: ";
        font-size: 0.6875rem;
        color: #888;
    }

    /* --- Row 4 Col 2: 連結類型 --- */
    #carouselTable tbody tr td:nth-child(6) {
        grid-column: 2;
        grid-row: 4;
        padding: 0.375rem 0.875rem 0;
        justify-content: flex-end;
    }

    #carouselTable tbody tr td:nth-child(6)::before {
        content: attr(data-label) ": ";
        font-size: 0.6875rem;
        color: #888;
        margin-right: 0.25rem;
        flex-shrink: 0;
    }

    /* --- 副標題 (td:nth-child(5)) - 手機版隱藏 --- */
    #carouselTable tbody tr td:nth-child(5) {
        display: none !important;
    }

    /* --- 排序 (td:nth-child(7)) - 手機版隱藏，資訊太多不必全顯示 --- */
    #carouselTable tbody tr td:nth-child(7) {
        display: none !important;
    }

    /* --- Row 5: 操作按鈕 (全寬) --- */
    #carouselTable tbody tr td:nth-child(9) {
        grid-column: 1 / -1;
        grid-row: 5;
        padding: 0.5rem 0.875rem 0.75rem;
        border-top: 1px solid rgba(212, 165, 32, 0.08);
        margin-top: 0.375rem;
    }

    .light-theme #carouselTable tbody tr td:nth-child(9) {
        border-top-color: rgba(184, 134, 11, 0.08);
    }

    #carouselTable tbody tr td:nth-child(9) .action-buttons {
        display: flex;
        gap: 0.5rem;
        width: 100%;
    }

    #carouselTable tbody tr td:nth-child(9) .action-buttons .btn {
        flex: 1;
        justify-content: center;
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
        border-radius: 0.5rem;
        gap: 0.375rem;
        min-height: 2.5rem;
    }

    /* 顯示操作按鈕文字 */
    #carouselTable .action-btn-text {
        display: inline;
    }

    /* ---- Carousel Modal 手機版優化 ---- */
    #carouselModal .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    #carouselModal .modal-body {
        padding: 0.875rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* 圖片預覽區堆疊 */
    #carouselModal .carousel-preview-container {
        flex-direction: column;
        gap: 0.75rem;
    }

    #carouselModal .carousel-preview-item {
        min-width: 100%;
    }

    #carouselModal .carousel-image-preview {
        height: 100px;
    }

    /* Modal 表單欄位 */
    #carouselModal .form-row {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    /* 圖片 URL 輸入框 */
    #carouselModal .input-with-button {
        flex-direction: column;
        gap: 0.375rem;
    }

    #carouselModal .input-with-button .btn {
        width: 100%;
        justify-content: center;
    }

    /* Modal Footer 按鈕 */
    #carouselModal .modal-footer {
        padding: 0.75rem 0.875rem;
        position: sticky;
        bottom: 0;
        background: var(--admin-bg-elevated, #1a1a2e);
        border-top: 1px solid rgba(212, 165, 32, 0.1);
    }

    #carouselModal .modal-footer .btn {
        flex: 1;
        min-height: 2.75rem;
        font-size: 0.875rem;
    }

    .light-theme #carouselModal .modal-footer {
        background: #fff;
        border-top-color: rgba(184, 134, 11, 0.1);
    }
}

/* ===== 小型手機尺寸 (max-width: 30rem / 480px) ===== */
@media (max-width: 30rem) {
    /* 品牌頁籤 - 只顯示圖標 */
    #page-game-carousels .brand-tab-name {
        display: none;
    }

    #page-game-carousels .brand-tab {
        padding: 0.5rem;
    }

    #page-game-carousels .brand-tab-icon,
    #page-game-carousels .brand-tab-letter {
        width: 28px;
        height: 28px;
    }

    /* 環境頁籤 - 更緊湊 */
    #page-game-carousels .env-tab {
        padding: 0.4375rem 0.25rem;
        font-size: 0.625rem;
        gap: 0.1875rem;
    }

    #page-game-carousels .env-tab i {
        font-size: 0.6875rem;
    }

    /* 工具列按鈕 */
    #page-game-carousels .toolbar-right .btn {
        padding: 0.5rem 0.5rem;
        font-size: 0.75rem;
    }

    /* 卡片間距縮小 */
    #carouselTable tbody {
        gap: 0.5rem;
    }

    /* 卡片內邊距縮小 */
    #carouselTable tbody tr td:nth-child(4) {
        padding: 0.625rem 0.625rem 0.125rem;
    }

    #carouselTable tbody tr td:nth-child(8) {
        padding: 0.625rem 0.625rem 0.125rem 0;
    }

    #carouselTable tbody tr td:nth-child(3) {
        padding: 0.1875rem 0.625rem 0;
    }

    #carouselTable tbody tr td:nth-child(2) {
        padding: 0.25rem 0.625rem 0;
    }

    #carouselTable tbody tr td:nth-child(6) {
        padding: 0.25rem 0.625rem 0;
    }

    #carouselTable tbody tr td:nth-child(9) {
        padding: 0.5rem 0.625rem 0.625rem;
    }

    /* 標題字體縮小 */
    #carouselTable tbody tr td:nth-child(4) .carousel-card-title {
        font-size: 0.9375rem;
    }

    /* 操作按鈕 */
    #carouselTable tbody tr td:nth-child(9) .action-buttons .btn {
        padding: 0.4375rem 0.5rem;
        font-size: 0.75rem;
        min-height: 2.25rem;
    }

    /* 小螢幕: ID + 連結類型改為上下排列 */
    #carouselTable tbody tr {
        grid-template-rows: auto auto auto auto auto auto;
    }

    #carouselTable tbody tr td:nth-child(2) {
        grid-column: 1 / -1;
        grid-row: 4;
    }

    #carouselTable tbody tr td:nth-child(6) {
        grid-column: 1 / -1;
        grid-row: 5;
        justify-content: flex-start;
        padding-left: 0.625rem;
    }

    #carouselTable tbody tr td:nth-child(9) {
        grid-row: 6;
    }

    /* Modal - 小手機進一步優化 */
    #carouselModal .modal-body {
        padding: 0.625rem;
    }

    #carouselModal .carousel-image-preview {
        height: 80px;
    }

    #carouselModal .form-group label {
        font-size: 0.8125rem;
    }

    #carouselModal .form-input {
        font-size: 0.875rem;
        padding: 0.5rem 0.625rem;
    }
}
