/* ── 管理平台殼層（工項 FE-06）──────────────────────────────────────────
   側欄＋頂欄，由 js/shell/adminShell.js 插入。
   每一條選擇器都掛在 .admin-shell 底下：css/tidc-overrides.css 有大量 !important，
   落在 .topbar / .brand-mark / .avatar 這類通用 class 上會被它蓋掉（frontend/CLAUDE.md）。
   顏色一律取自 tokens.css；demo 的 #1a1a2e／#4f8ef7／#a8b2d8 對應見工項清單 §1.2。 */

.admin-shell {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
        "sidebar topbar"
        "sidebar content";
    height: 100vh;
    background: var(--paper);
}

/* ── 側欄 ── */
.admin-shell .admin-shell-sidebar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
    background: var(--ink-900);
    color: var(--ink-300);
}

.admin-shell .admin-shell-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.admin-shell .admin-shell-logo {
    flex: none;
    width: 36px;
    height: 36px;
    padding: 3px;
    border-radius: var(--radius);
    background: var(--white);
    object-fit: contain;
}
.admin-shell .admin-shell-brand-name {
    margin: 0;
    color: var(--white);
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: .02em;
}
.admin-shell .admin-shell-brand-kicker {
    margin: 2px 0 0;
    color: var(--ink-400);
    font-size: 11px;
    letter-spacing: .08em;
}

.admin-shell .admin-shell-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 12px;
}

/* 單一連結與群組開關共用同一個外觀；button 要把瀏覽器預設樣式歸零 */
.admin-shell .admin-shell-link {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink-300);
    font: inherit;
    font-size: 14px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}
.admin-shell .admin-shell-link svg {
    flex: none;
    width: 18px;
    height: 18px;
}
.admin-shell .admin-shell-link:hover {
    background: rgba(255, 255, 255, .08);
    color: var(--white);
}
.admin-shell .admin-shell-link:focus-visible,
.admin-shell .admin-shell-logout:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: -2px;
}
.admin-shell .admin-shell-link[aria-current="page"] {
    background: var(--accent);
    color: var(--white);
    font-weight: 600;
}

/* 群組內有目前頁面時，群組標題本身變白但不上底色（demo 行為） */
.admin-shell .admin-shell-group.is-active > .admin-shell-group-toggle {
    color: var(--white);
    font-weight: 600;
}
.admin-shell .admin-shell-group-toggle span {
    flex: 1;
}
.admin-shell .admin-shell-link .admin-shell-chevron {
    width: 14px;
    height: 14px;
    transition: transform .15s ease;
}
.admin-shell .admin-shell-group-toggle[aria-expanded="true"] .admin-shell-chevron {
    transform: rotate(180deg);
}

.admin-shell .admin-shell-subnav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 2px 0 0 16px;
}
/* [hidden] 的預設 display:none 會被上面的 display:flex 蓋過，需顯式規則（同 layout.css 的 .icon-btn[hidden]） */
.admin-shell .admin-shell-subnav[hidden] {
    display: none;
}
.admin-shell .admin-shell-subnav .admin-shell-link {
    padding: 8px 12px;
}
.admin-shell .admin-shell-subnav .admin-shell-link svg {
    width: 16px;
    height: 16px;
}

.admin-shell .admin-shell-footer {
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, .08);
}
.admin-shell .admin-shell-user {
    margin-bottom: 10px;
    padding: 0 8px;
}
.admin-shell .admin-shell-user-name,
.admin-shell .admin-shell-user-role {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.admin-shell .admin-shell-user-name {
    margin: 0;
    color: var(--white);
    font-size: 14px;
    font-weight: 600;
}
.admin-shell .admin-shell-user-role {
    margin: 2px 0 0;
    color: var(--ink-300);
    font-size: 12px;
}
.admin-shell .admin-shell-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink-300);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}
.admin-shell .admin-shell-logout[hidden] {
    display: none;
}
.admin-shell .admin-shell-logout svg {
    width: 15px;
    height: 15px;
}
.admin-shell .admin-shell-logout:hover {
    background: rgba(255, 255, 255, .08);
    color: var(--white);
}
.admin-shell .admin-shell-version {
    margin: 12px 0 0;
    padding: 0 8px;
    color: var(--ink-500);
    font-size: 12px;
}

/* ── 頂欄 ──
   深底與側欄連成一體，也和地圖修正頁現行頂欄同色 —— FE-07 把它的工具列搬進
   [data-shell-actions] 時，那些為深底設計的按鈕不必重新配色。 */
.admin-shell .admin-shell-topbar {
    grid-area: topbar;
    position: relative;
    z-index: var(--z-topbar);
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: 56px;
    padding: 10px 28px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    background: var(--ink-900);
}
.admin-shell .admin-shell-sidebar-toggle {
    flex: none;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    margin-left: -8px;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink-300);
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}
.admin-shell .admin-shell-sidebar-toggle svg {
    width: 18px;
    height: 18px;
}
.admin-shell .admin-shell-sidebar-toggle:hover {
    background: rgba(255, 255, 255, .08);
    color: var(--white);
}
.admin-shell .admin-shell-sidebar-toggle:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: -2px;
}
.admin-shell .admin-shell-crumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: var(--ink-400);
    font-size: 13px;
}
.admin-shell .admin-shell-crumb-sep {
    color: var(--ink-500);
}
.admin-shell .admin-shell-crumb-here {
    color: var(--white);
    font-weight: 600;
}
.admin-shell .admin-shell-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

/* ── 側欄收合（FE-07）──
   整條側欄隱藏、頂欄與內容區吃滿寬度。1366／1440 的筆電上，地圖修正頁的車格表收合後才回到接殼層前的寬度。 */
.admin-shell.is-sidebar-collapsed {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
        "topbar"
        "content";
}
.admin-shell.is-sidebar-collapsed .admin-shell-sidebar {
    display: none;
}

/* ── 內容區 ── */
.admin-shell .admin-shell-content {
    grid-area: content;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    padding: 28px 32px;
}

/* 管理頁以 <main> 當內容區時，layout.css 那條裸 main 規則（地圖修正頁的 46% 6px 1fr 兩欄 grid）
   會把頁面內容擠進左側 46%。地圖修正頁的內容區是 div#app，裡面的 <main> 仍需要那個 grid，
   所以只蓋掉 main.admin-shell-content 本身 */
.admin-shell main.admin-shell-content {
    display: block;
}

/* 滿版內容區：頁面自己管版面與捲動（地圖修正頁），不要殼層的留白與捲軸 */
.admin-shell .admin-shell-content.is-flush {
    padding: 0;
    overflow: hidden;
}
/* 地圖修正頁的 #app 在 layout.css 是 height: 100vh 的整頁容器；進了殼層的 grid 之後
   高度要交給 grid 列決定，否則會比可視區多出頂欄的高度。要用 id 選擇器才壓得過 #app 自己的規則（FE-07）。 */
.admin-shell #app {
    height: auto;
}

/* 頁面標記要搬進頂欄的元素：殼層掛載前先藏起來，免得 JS 執行前在內容區頂端閃一下（FE-07） */
.admin-shell:not([data-shell-mounted]) [data-shell-actions-source],
.admin-shell:not([data-shell-mounted]) [data-shell-crumb-source] {
    display: none;
}

/* 各頁共用的標題區（demo 每頁開頭的 h1 ＋ 說明） */
.admin-shell .admin-shell-page-head {
    margin-bottom: 24px;
}
.admin-shell .admin-shell-page-head h1 {
    margin: 0;
    color: var(--ink-900);
    font-size: 24px;
    font-weight: 700;
}
.admin-shell .admin-shell-page-head p {
    margin: 4px 0 0;
    color: var(--ink-500);
    font-size: 14px;
}

/* 管理平台以桌機為主；窄螢幕只保證不破版：側欄疊到上方，整頁改回一般捲動 */
@media (max-width: 768px) {
    .admin-shell {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto minmax(0, 1fr);
        grid-template-areas:
            "sidebar"
            "topbar"
            "content";
        height: auto;
        min-height: 100vh;
    }
    .admin-shell .admin-shell-sidebar {
        overflow-y: visible;
    }
    /* 窄螢幕的疊放版面有三列；收合後少了側欄那列，要跟著改成兩列 */
    .admin-shell.is-sidebar-collapsed {
        grid-template-rows: auto minmax(0, 1fr);
    }
    .admin-shell .admin-shell-topbar,
    .admin-shell .admin-shell-content {
        padding-left: 16px;
        padding-right: 16px;
    }
    .admin-shell .admin-shell-content {
        overflow: visible;
    }
}

/* ── 地區下拉（issue #246）：位置照 PM demo 放在選單與使用者資訊之間，只有跨地區帳號才出現 ── */
.admin-shell .admin-shell-field {
    padding: 0 16px 16px;
}
.admin-shell .admin-shell-field[hidden] {
    display: none;
}
.admin-shell .admin-shell-field-label {
    display: block;
    margin-bottom: 4px;
    color: var(--ink-300);
    font-size: 12px;
}
.admin-shell .admin-shell-field-select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--white);
    border-radius: var(--radius);
    background: var(--white);
    color: var(--ink-900);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}
.admin-shell .admin-shell-field-select:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}
.admin-shell .admin-shell-field-select:disabled {
    cursor: progress;
    opacity: .7;
}
