* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #f3f6fb;
    color: #182033;
    font-family: system-ui, sans-serif;
}

.layout {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    align-items: start;
    min-height: 100vh;
}

.layout.sidebar-collapsed {
    grid-template-columns: 68px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    min-width: 0;
    padding: 24px 12px;
    background: #17233a;
    color: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-toggle {
    position: absolute;
    top: 24px;
    left: 12px;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-start;
    width: 44px;
    height: 44px;
    padding: 0;
    margin: 0;
    border: 1px solid #ffffff29;
    border-radius: 10px;
    background: #22304a;
    color: #e6edfa;
    font: inherit;
    font-size: 20px;
    cursor: pointer;
}

.sidebar-toggle:hover {
    background: #2b3b5a;
}

.sidebar-toggle:focus-visible,
.file:focus-visible,
.load-more:focus-visible,
#tree summary:focus-visible {
    outline: 2px solid #a9cdff;
    outline-offset: -2px;
}

.sidebar-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.sidebar-body[hidden] {
    display: none;
}

.sidebar-logo {
    display: block;
    flex-shrink: 0;
    width: 180px;
    max-width: calc(100% - 52px);
    height: auto;
    margin: 0 0 8px 52px;
}

.project-selector {
    position: relative;
    flex-shrink: 0;
    width: 180px;
    max-width: calc(100% - 52px);
    margin: 4px 0 24px 52px;
    padding-bottom: 12px;
}

.project-selector::before {
    content: "";
    position: absolute;
    z-index: 1;
    top: 20px;
    right: 10px;
    width: 7px;
    height: 7px;
    border-right: 2px solid #a9c9f7;
    border-bottom: 2px solid #a9c9f7;
    transform: rotate(45deg);
    pointer-events: none;
}

.project-selector::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 52px;
    height: 2px;
    border-radius: 999px;
    transform: translateX(-50%);
    background: linear-gradient(90deg, transparent, #79a7ff, transparent);
}

.project-selector--fixed::before {
    display: none;
}

.project-label {
    display: block;
    padding: 13px 0;
    color: #f0f6ff;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.5;
    text-align: center;
    overflow-wrap: anywhere;
}

#project-select {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    min-height: 50px;
    padding: 13px 24px;
    border: 1px solid #4a658b;
    border-radius: 14px;
    background: linear-gradient(135deg, #304969, #23344f);
    color: #f0f6ff;
    color-scheme: dark;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.5;
    text-align: center;
    text-align-last: center;
    text-overflow: ellipsis;
    box-shadow: 0 6px 16px #08122433, inset 0 1px 0 #ffffff12;
    cursor: pointer;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

#project-select:hover:not(:disabled) {
    border-color: #8db9f5;
    box-shadow: 0 8px 20px #0812244d, inset 0 1px 0 #ffffff1a;
}

#project-select:focus-visible {
    outline: 2px solid #a9cdff;
    outline-offset: 3px;
    border-color: #a9cdff;
}

#project-select option {
    background: #22304a;
    color: #f0f6ff;
    text-align: center;
    text-align-last: center;
}

#project-select:disabled {
    cursor: wait;
    opacity: 0.65;
}

/* 可自訂的原生選單；不支援的瀏覽器繼續使用上面的原生樣式。 */
@supports (appearance: base-select) {
    #project-select,
    #project-select::picker(select) {
        appearance: base-select;
    }

    .project-selector::before {
        display: none;
    }

    #project-select {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    /* 箭頭不占文字的排版寬度，左右留白維持相同。 */
    #project-select::picker-icon {
        content: "";
        position: absolute;
        top: 50%;
        right: 10px;
        width: 7px;
        height: 7px;
        margin: 0;
        border-right: 2px solid #a9c9f7;
        border-bottom: 2px solid #a9c9f7;
        transform: translateY(-70%) rotate(45deg);
    }

    #project-select:open::picker-icon {
        transform: translateY(-30%) rotate(225deg);
    }

    #project-select::picker(select) {
        box-sizing: border-box;
        width: 180px;
        max-width: calc(100vw - 24px);
        max-height: 320px;
        max-height: min(320px, 60dvh);
        margin-top: 6px;
        padding: 6px;
        border: 1px solid #4a658b;
        border-radius: 12px;
        background: #1c2b44;
        color: #f0f6ff;
        font: inherit;
        box-shadow: 0 12px 28px #08122466;
        overflow-y: auto;
        scrollbar-width: thin;
    }

    #project-select option {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 44px;
        padding: 10px 18px;
        border-radius: 8px;
        background: transparent;
        white-space: normal;
        overflow-wrap: anywhere;
        line-height: 1.5;
    }

    #project-select option:checked {
        background: #354d70;
    }

    #project-select option:hover,
    #project-select option:focus-visible {
        background: #405d85;
    }

    /* 勾選標記獨立靠右，避免只有目前選項的文字偏移。 */
    #project-select option::checkmark {
        position: absolute;
        top: 50%;
        right: 5px;
        margin: 0;
        color: #a9cdff;
        transform: translateY(-50%);
    }
}

#tree {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

#tree::-webkit-scrollbar {
    width: 6px;
}

#tree::-webkit-scrollbar-track {
    background: transparent;
}

#tree::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 999px;
}

#tree::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.42);
}

.file {
    width: 100%;
    border: 0;
    border-radius: 8px;
    padding: 8px 10px;
    text-align: left;
    cursor: pointer;
    background: transparent;
    color: #dce5f6;
    overflow-wrap: anywhere;
}

.file:hover,
.file.active {
    background: #2b3b5a;
}

details {
    margin: 5px 0 5px 10px;
}

summary {
    cursor: pointer;
    padding: 7px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.folder-contents {
    min-width: 0;
}

.load-more {
    width: calc(100% - 10px);
    margin: 6px 0 6px 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.08);
    color: #cbd8ed;
}

.load-more:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.14);
}

.load-more:disabled {
    cursor: wait;
    opacity: 0.65;
}

.tree-error {
    padding: 8px 10px;
    color: #ffb4ab;
    font-size: 13px;
}

.content {
    min-width: 0;
    padding: 28px;
    display: grid;
    align-content: start;
    gap: 24px;
}

.card {
    min-width: 0;
    background: #fff;
    border-radius: 16px;
    padding: 22px;
    box-shadow: 0 5px 22px #ccd3e055;
}

header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 16px;
    align-items: baseline;
}

header > * {
    min-width: 0;
    overflow-wrap: anywhere;
}

h1 {
    font-size: 21px;
    margin: 0;
}

small {
    color: #687189;
}

.message {
    min-height: 22px;
    color: #b42318;
    overflow-wrap: anywhere;
}

.chart-wrap {
    position: relative;
    height: 390px;
    min-width: 0;
}

.empty {
    padding: 8px;
    color: #9eabc1;
}

@media (max-width: 760px) {
    .layout,
    .layout.sidebar-collapsed {
        grid-template-columns: minmax(0, 1fr);
    }

    .sidebar {
        position: fixed;
        left: 0;
        z-index: 10;
        width: min(300px, calc(100% - 24px));
        height: 100vh;
        height: 100dvh;
        padding: 12px;
        box-shadow: 3px 0 12px #17233a22;
        transition: width 0.18s ease;
    }

    .sidebar-collapsed .sidebar {
        width: 0;
        height: 0;
        padding: 0;
        overflow: visible;
        box-shadow: none;
    }

    .sidebar-toggle {
        top: 12px;
    }

    .sidebar-logo {
        width: 180px;
        max-height: 64px;
        object-fit: contain;
    }

    .project-selector {
        margin-bottom: 12px;
    }

    #project-select {
        font-size: 16px;
    }

    .file,
    .load-more,
    #tree summary {
        min-height: 44px;
        padding-block: 12px;
    }

    .content {
        grid-column: 1;
        padding: 68px 14px 14px;
        gap: 16px;
    }

    .card {
        padding: 16px;
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    h1 {
        font-size: 18px;
    }

    .chart-wrap {
        height: 300px;
        height: clamp(220px, 45dvh, 320px);
    }
}

@media (prefers-reduced-motion: reduce) {
    #project-select,
    .sidebar {
        transition: none;
    }
}
