:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --text: #1f2328;
    --muted: #6a737d;
    --primary: #2563eb;
    --primary-weak: #e6efff;
    --primary-strong: #dc2626;
    --border: #e5e7eb;
    --accent: #111827;
    --chip: #eef2ff;
    --chip-text: #3730a3;
}

* {
    box-sizing: border-box
}

html, body {
    height: 100%
}

body {
    margin: 0;
    font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
    color: var(--text);
    background: var(--bg);
    min-height: 100%;
    display: flex;
    flex-direction: column;
    padding-top: 112px;
}

.navbar {
    flex: 0 0 auto;
}

.orders-content {
    flex: 1 0 auto;
}

.site-footer {
    flex: 0 0 auto;
    background: #0b1220;
    color: #cbd5e1;
    border-top: 1px solid #0f172a;
    position: static;
}

/* 頂部導覽列（桌面置頂時） */
.navbar {
    position: fixed; /* 原本 sticky 改為 fixed */
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000; /* 提高層級，避免被內容或黑幕誤蓋 */
    background: var(--accent);
    color: #fff;
    border-bottom: 1px solid #0b1220;
}

.navbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
}

.brand {
    font-weight: 700;
    letter-spacing: .5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 180px;
    max-width: 360px;
    flex: 0 0 auto;
    margin-right: 8px;
}

/* 主選單四個按鈕：維持原樣（桌面置頂） */
.nav {
    display: flex;
    gap: 8px;
    margin-left: 12px;
    width: 100%;
}

.nav button {
    appearance: none;
    border: 1px solid transparent;
    background: transparent;
    color: #cbd5e1;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
}

.nav button:hover {
    background: #0f172a;
    color: #fff
}

.nav button.active {
    background: var(--primary);
    color: #fff;
    border-color: transparent;
}

.nav button[data-tab="logout"] {
    margin-left: auto;
    border: 1px solid #fca5a5;
    color: #fecaca;
    background: rgba(220, 38, 38, 0.08);
    font-weight: 700;
    letter-spacing: .5px;
}

.nav button[data-tab="logout"]:hover {
    background: rgba(220, 38, 38, 0.18);
    color: #fff;
    border-color: #f87171;
    box-shadow: 0 0 0 3px rgba(248, 113, 113, .2);
}

/* 子選單區 */
.subbar {
    border-top: 1px solid #0b1220;
    background: #0b1220;
}

.subbar .tools {
    max-width: 1200px;
    margin: 0 auto;
    padding: 8px 14px;
    display: block;
}

.subbar-content[hidden] {
    display: none !important
}

/* 顯示狀態列（第1排） */
.tools-grid {
    display: grid;
    grid-template-columns:1fr;
    row-gap: 8px;
}

.tools-grid .group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.subbar .group[aria-label="顯示狀態"] {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    margin: 0;
    white-space: nowrap;
}

.subbar .group[aria-label="顯示狀態"] .label,
.subbar .group[aria-label="顯示狀態"] .chips {
    display: inline-flex;
    align-items: center;
}

.subbar .group[aria-label="顯示狀態"] .chips {
    gap: 6px;
    flex-wrap: nowrap;
}

.subbar .group[aria-label="顯示狀態"] .chip {
    padding: 4px 8px;
}

/* 搜尋/依照列（第2排） */
.toolbar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px 0 14px;
    flex-wrap: wrap;
}

.toolbar-row .group {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 文字靠左對齊（無論置頂或置底） */
.subbar .group[aria-label="顯示狀態"], .toolbar-row .group {
    justify-content: flex-start;
}

.subbar .group[aria-label="顯示狀態"] .label,
.toolbar-row .label {
    min-width: 28px;
    text-align: left;
    font-size: 12px;
}

/* chip 樣式 */
.label {
    color: #9ca3af;
    font-size: 12px;
    margin-right: 4px;
}

.chips {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    background: #1f2937;
    color: #e5e7eb;
    border: 1px solid #374151;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
}

.chip input {
    display: none
}

.chip.active {
    background: var(--chip);
    color: var(--chip-text);
    border-color: #c7d2fe
}

/* 統一 chip 尺寸 */
#statusChips .chip, #sortChips .chip, #searchFieldChips .chip {
    height: 26px;
    padding: 0 8px;
    line-height: 24px;
    border-radius: 999px;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

#statusChips, #sortChips, #searchFieldChips {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

/* 搜索列（緊湊） */
.searchbar {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #111827;
    border: 1px solid #374151;
    border-radius: 999px;
    padding: 3px 8px;
}

.searchbar-compact input[type="text"] {
    height: 16px;
    line-height: 16px;
}

.searchbar input[type="text"] {
    border: none;
    background: transparent;
    outline: none;
    width: 180px;
    font-size: 12.5px;
    color: #e5e7eb;
}

.btn {
    border: 1px solid var(--primary);
    color: #fff;
    background: var(--primary);
    border-radius: 8px;
    padding: 4px 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
}

.btn.secondary {
    background: var(--primary-weak);
    color: #1e40af;
    border-color: #c7d2fe;
}

.btn.danger {
    background: var(--primary-strong);;
    color: #fff;
    border-color: #dc2626;
}

.btn-clear {
    appearance: none;
    background: transparent;
    color: #93c5fd;
    border: 1px solid #334155;
    border-radius: 999px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 11.5px;
    line-height: 16px;
}

.btn-clear:hover {
    background: #0f172a;
    border-color: #475569;
    color: #bfdbfe;
}

.muted {
    color: var(--muted)
}

.site-footer .footer-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 20px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 手機置底：四個按鈕近滿版，登出較小；子選項兩排左對齊且對齊一致 */
@media (max-width: 600px) {

    /* 手機不需要上方 padding */
    body {
        padding-top: 0;
    }

    /* 只改主選單置底與四格滿版，其餘沿用置頂樣式的對齊與內距 */
    /* 導覽列置底 */
    .navbar {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        border-top: 1px solid #0b1220;
        border-bottom: none;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    /* 預留底部高度，避免內容被蓋住（縮小保留空間） */
    .orders-content {
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0));
    }

    /* 內層間距縮小 */
    .navbar-inner {
        max-width: none;
        margin: 0;
        padding: 8px 14px;
    }

    .brand {
        display: none;
    }

    /* 四個按鈕滿版：前三個等分，登出較小；高度縮小 */
    .nav {
        margin-left: 8px;
        gap: 6px;
        justify-content: flex-start;
    }

    .nav button {
        background: #111827;
        border: 1px solid #1f2937;
        color: #cbd5e1;
        border-radius: 8px;
        padding: 6px 10px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;

        /* 滿版等分 */
        flex: 1 1 0;
        min-width: 0;
    }

    .nav button.active {
        background: var(--primary);
        color: #fff;
        border-color: transparent;
    }

    /* 登出較小但不改齊線 */
    .nav button[data-tab="logout"] {
        flex: 0.6 0 0;
        min-width: 72px;
        margin-left: 0;
        border-color: #fca5a5;
        background: rgba(220, 38, 38, 0.12);
        color: #fecaca;
    }

    /* 子選單（subbar）保持左右內距與靠左對齊 */
    .subbar {
        position: relative;
        top: auto;
        border-top: none;
        background: transparent;
    }

    .subbar .tools {
        max-width: 1200px;
        margin: 0 auto;
        padding: 6px 10px;
    }

    /* 工具列：窄時不換行，優先縮內容；若過窄再降級為滿版換行 */
    .toolbar-row {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-wrap: nowrap; /* 先不換行 */
        padding:6px 14px 0 14px;
        overflow:visible;
    }

    .toolbar-row .group {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-wrap: nowrap;
        min-width: 0; /* 允許內部壓縮 */
        flex: 1 1 auto;
    }

    /* chips 不換行，允許橫向捲動；字級稍微縮小 */
    #statusChips, #sortChips, #searchFieldChips {
        display: flex;
        gap: 6px;
        align-items: center;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    #statusChips .chip, #sortChips .chip, #searchFieldChips .chip {
        height: 24px;
        padding: 0 8px;
        line-height: 22px;
        font-size: 11.5px;
        flex: 0 0 auto; /* 保持單列橫捲 */
    }

    /* 搜索列可縮窄，必要時縮小輸入框寬度 */
    .searchbar {
        gap: 6px;
        padding: 3px 8px;
        flex: 0 0 auto;
    }

    .searchbar input[type="text"] {
        width: clamp(96px, 22vw, 160px);
        font-size: 12px;
    }

    .btn-clear {
        flex: 0 0 auto;
        padding: 2px 8px;
        font-size: 11px;
        line-height: 16px;
        white-space: nowrap;
    }

    /* 當螢幕極窄（再退讓）：允許每一排子選項滿版換行 */
    @media (max-width: 360px) {
        .toolbar-row {
            flex-wrap: wrap;
        }

        .toolbar-row .group {
            width: 100%;
            flex: 1 1 100%;
        }

        #statusChips, #sortChips, #searchFieldChips {
            width: 100%;
            overflow-x: visible;
            flex-wrap: wrap;
        }

        .searchbar {
            width: 100%;
        }

        .searchbar input[type="text"] {
            width: 100%;
        }

        .btn-clear {
            width: auto;
        }
    }
}