/* Drawing file library. Portrait-first; outdoor mode is white-on-black large type. */

#fileLibrary[hidden] {
    display: none !important;
}

#fileLibrary {
    position: fixed;
    inset: 0;
    z-index: 9200;
    display: flex;
    flex-direction: column;
    background: #12161c;
    color: #f4f1ea;
    font-size: 16px;
}

/* Same home body-hide exceptions as avatar-home.css (#205 overlays). */
html[data-avatar-home="1"] body > *:not(#avatarHome):not(#fileLibrary):not(#securityLock):not(#akiAskStage):not(#akiAskBackdrop):not(#avatarChatStage):not(#avatarChatBackdrop) {
    display: none !important;
}

.file-lib__bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.file-lib__title {
    flex: 1;
    margin: 0;
    font-size: 18px;
    font-weight: 800;
}

.file-lib__tabs {
    display: flex;
    gap: 6px;
    padding: 8px 10px 0;
    overflow-x: auto;
}

.file-lib__tabs button,
.file-lib__bar button,
.file-lib__tools button,
.file-lib__menu button,
.file-lib__fab-menu button {
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 999px;
    background: rgba(12, 16, 22, 0.55);
    color: #f7f4ee;
    font-weight: 700;
}

.file-lib__tabs button[aria-selected="true"] {
    background: #ffe14a;
    color: #111;
    border-color: #111;
}

.file-lib__tools {
    display: flex;
    gap: 8px;
    padding: 8px 10px;
}

.file-lib__tools input[type="search"] {
    flex: 1;
    min-height: 44px;
    border-radius: 12px;
    border: 2px solid #111;
    padding: 0 12px;
    font-size: 16px;
}

.file-lib__list {
    flex: 1;
    overflow: auto;
    padding: 0 8px 88px;
}

.file-lib__row {
    display: grid;
    grid-template-columns: 48px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 10px 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.file-lib__row--share {
    background: rgba(255, 196, 72, 0.08);
}

.file-lib__row--share[data-share-status="failed"] {
    background: rgba(255, 96, 96, 0.12);
}

.file-lib__share-act {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    min-width: 64px;
}

.file-lib__retry {
    min-height: 36px;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: #2a313a;
    color: #fff;
    font-weight: 700;
}

.file-lib__share-del {
    min-height: 36px;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 120, 120, 0.55);
    background: transparent;
    color: #ffb4b4;
    font-weight: 700;
}

.file-lib__share-mark {
    font-size: 12px;
    font-weight: 700;
    color: #f0c674;
}

.file-lib__load-error {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 16px 12px;
}

.file-lib__load-error p {
    margin: 0;
    color: #ffb4b4;
    font-weight: 700;
}

.file-lib__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 8px;
}

.file-lib__grid .file-lib__row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 12px;
    padding: 10px;
}

.file-lib__thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 8px;
    background: #2a313a;
    display: grid;
    place-items: center;
    font-size: 11px;
    font-weight: 800;
}

.file-lib__meta {
    min-width: 0;
}

.file-lib__name {
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-lib__sub {
    font-size: 12px;
    opacity: 0.85;
}

.file-lib__fab {
    position: absolute;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid #111;
    background: #ffe14a;
    color: #111;
    font-size: 28px;
    font-weight: 900;
}

.file-lib__fab-menu,
.file-lib__pop {
    position: absolute;
    right: 16px;
    bottom: calc(80px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #1b2128;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 8px;
    z-index: 2;
}

.file-lib__pop {
    right: 8px;
    bottom: auto;
}

.file-lib__viewer {
    position: absolute;
    inset: 0;
    background: #0c1016;
    display: flex;
    flex-direction: column;
    z-index: 3;
}

.file-lib__viewer[hidden] {
    display: none !important;
}

/* Viewer toolbar stays fixed above the stage; only .file-lib__zoom transforms. */
.file-lib__viewer > .file-lib__bar {
    flex: 0 0 auto;
    position: relative;
    z-index: 2;
    background: #0c1016;
}

/* Viewer buttons (符合螢幕 / 關閉): flat translucent dark grey, no border, font size untouched. */
.file-lib__viewer > .file-lib__bar button {
    position: relative;
    min-height: 44px;
    min-width: 44px;
    padding: 8px 12px;
    border: 0;
    border-radius: 10px;
    background: rgba(99, 99, 102, 0.32);
    color: #f7f4ee;
    -webkit-tap-highlight-color: transparent;
}

.file-lib__viewer > .file-lib__bar button:hover {
    background: rgba(99, 99, 102, 0.46);
}

.file-lib__viewer > .file-lib__bar button:focus-visible {
    outline: 2px solid rgba(10, 132, 255, 0.7);
    outline-offset: 2px;
}

.file-lib__viewer-fit {
    font-variant-numeric: tabular-nums;
}

.file-lib__viewer-fit[hidden] {
    display: none !important;
}

.file-lib__stage {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: contain;
    -webkit-user-select: none;
    user-select: none;
    background: #0b0f14;
}

/* Zoomable content: absolute, sized in content units by JS, transformed from the top-left. */
.file-lib__zoom {
    position: absolute;
    left: 0;
    top: 0;
    transform-origin: 0 0;
    will-change: transform;
}

.file-lib__stage img.file-lib__zoom,
.file-lib__stage svg.file-lib__zoom {
    display: block;
    max-width: none;
    max-height: none;
    pointer-events: none;
    -webkit-user-drag: none;
}

.file-lib__pdf {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    pointer-events: none;
}

.file-lib__pdf canvas {
    display: block;
    background: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

.file-lib__stage--info {
    overflow: auto;
    touch-action: auto;
}

.file-lib__stage--info > p {
    padding: 16px 16px 8px;
    line-height: 1.5;
}

.file-lib__extract {
    padding: 0 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-lib__extract button {
    align-self: flex-start;
    min-height: 44px;
    padding: 8px 14px;
}

.file-lib__extract-result p {
    margin: 0;
    padding: 4px 0;
}

.file-lib__extract-skip {
    font-size: 13px;
    opacity: 0.9;
}

.file-lib__confirm {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(8, 10, 14, 0.72);
}

.file-lib__confirm-card {
    width: min(420px, 100%);
    padding: 16px;
    border-radius: 12px;
    background: #1c2430;
    color: #f4f1ea;
}

.file-lib__confirm-card p {
    margin: 0 0 14px;
    font-size: 18px;
    line-height: 1.45;
}

.file-lib__confirm-actions {
    display: flex;
    gap: 8px;
}

.file-lib__confirm-skip,
.file-lib__confirm-go {
    min-height: 44px;
    padding: 8px 14px;
    font-size: 16px;
}

.file-lib__confirm-skip {
    font-weight: 800;
}

/* Browser PDF viewer fallback (not zoom-managed) fills the stage. */
.file-lib__stage > iframe,
.file-lib__stage > embed {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

.file-lib__layers {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
}

.file-lib__layers label {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.file-lib__progress {
    height: 8px;
    background: #333;
    border-radius: 99px;
    overflow: hidden;
}

.file-lib__progress > span {
    display: block;
    height: 100%;
    background: #ffe14a;
    width: 0;
}

.file-lib__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.file-lib__table th,
.file-lib__table td {
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 6px 8px;
}

html.sunlight-readable #fileLibrary,
body.sunlight-readable #fileLibrary {
    background: #fff !important;
    color: #111 !important;
}

html.sunlight-readable #fileLibrary button,
body.sunlight-readable #fileLibrary button,
html.sunlight-readable #fileLibrary .file-lib__tabs button,
body.sunlight-readable #fileLibrary .file-lib__tabs button {
    background: #fff !important;
    color: #111 !important;
    border: 2px solid #111 !important;
    font-size: 18px !important;
    min-height: 52px !important;
}

html.sunlight-readable #fileLibrary .file-lib__tabs button[aria-selected="true"],
body.sunlight-readable #fileLibrary .file-lib__tabs button[aria-selected="true"],
html.sunlight-readable #fileLibrary .file-lib__fab,
body.sunlight-readable #fileLibrary .file-lib__fab {
    background: #111 !important;
    color: #fff !important;
    -webkit-text-fill-color: #fff !important;
}

html.sunlight-readable #fileLibrary .file-lib__sub,
body.sunlight-readable #fileLibrary .file-lib__sub {
    font-size: 16px !important;
    color: #111 !important;
    opacity: 1;
}

@media (min-width: 720px) {
    .file-lib__grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* Unassigned project/floor reminder — fold cards + ios chips, no white frames. */
.file-lib__unassigned {
    padding: 6px 10px 0;
}

.file-lib__unassigned-toggle {
    width: 100%;
    max-width: none;
    justify-content: flex-start;
    text-align: left;
}

.file-lib__unassigned-panel {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.file-lib__fold {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.file-lib__fold-head {
    width: 100%;
    max-width: none;
    justify-content: flex-start;
}

.file-lib__fold-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 2px 8px;
}

.file-lib__unassigned-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-lib__unassigned-row .file-lib__meta {
    flex: 1;
    min-width: 0;
}

.file-lib__assign {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px 0 4px;
}

.file-lib__assign-select,
.file-lib__assign-input {
    min-height: 44px;
    border: none;
    border-radius: var(--bm-ios-chip-radius, 10px);
    padding: 0 10px;
    background: var(--bm-ios-chip-bg, rgba(60, 60, 67, 0.6));
    color: var(--bm-ios-chip-ink, #F4F6F8);
    font-size: 16px;
}

#fileLibrary .file-lib__unassigned .bm-ios-chip,
#fileLibrary .file-lib__tools .bm-ios-chip {
    border: none;
    background: var(--bm-ios-chip-bg);
    color: var(--bm-ios-chip-ink);
}

html.sunlight-readable #fileLibrary .file-lib__unassigned .bm-ios-chip,
body.sunlight-readable #fileLibrary .file-lib__unassigned .bm-ios-chip,
html.sunlight-readable #fileLibrary .file-lib__tools .bm-ios-chip,
body.sunlight-readable #fileLibrary .file-lib__tools .bm-ios-chip {
    background: var(--bm-ios-chip-sun-bg) !important;
    color: var(--bm-ios-chip-sun-ink) !important;
    -webkit-text-fill-color: var(--bm-ios-chip-sun-ink) !important;
    border: none !important;
}

html.sunlight-readable #fileLibrary .file-lib__assign-select,
body.sunlight-readable #fileLibrary .file-lib__assign-select,
html.sunlight-readable #fileLibrary .file-lib__assign-input,
body.sunlight-readable #fileLibrary .file-lib__assign-input {
    background: var(--bm-ios-chip-sun-bg) !important;
    color: var(--bm-ios-chip-sun-ink) !important;
    border: none !important;
}
