:root {
    --fm-bg: #ffffff;
    --fm-sidebar-bg: #f7f8fa;
    --fm-border: #e2e5ea;
    --fm-text: #1a1d23;
    --fm-text-secondary: #5f6570;
    --fm-accent: #4f6ef7;
    --fm-accent-light: #eef1fe;
    --fm-hover-bg: #edf0f5;
    --fm-active-bg: #e8ecf8;
    --fm-shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.18), 0 8px 20px rgba(0, 0, 0, 0.1);
    --fm-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --fm-radius-lg: 14px;
    --fm-radius-md: 10px;
    --fm-radius-sm: 8px;
    --fm-transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);

    --pdf-color: #f04438;
    --pdf-bg: #fef3f2;
    --png-color: #2e8b57;
    --png-bg: #f2faf6;
    --jpg-color: #f0883e;
    --jpg-bg: #fef8f3;
    --board-color: #7c3aed;
    --board-bg: #f9f5fe;
}

#fileManagerOverlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(15, 18, 25, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    align-items: center;
    justify-content: center;
    animation: fmFadeIn 0.2s ease-out;
}

#fileManagerOverlay.visible {
    display: flex;
}

@keyframes fmFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fmSlideUp {
    from { opacity: 0; transform: translateY(30px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

#fileManagerPanel {
    position: relative;
    width: 700px;
    max-width: 94vw;
    height: 520px;
    max-height: 85vh;
    background: var(--fm-bg);
    border-radius: var(--fm-radius-lg);
    box-shadow: var(--fm-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: fmSlideUp 0.28s ease-out;
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: var(--fm-text);
    z-index: 9999;
}

#fileManagerHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 14px 20px;
    border-bottom: 1px solid var(--fm-border);
    flex-shrink: 0;
    background: var(--fm-bg);
}

#fileManagerTitle {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--fm-text);
    margin: 0;
    user-select: none;
}

#fileManagerClose {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--fm-text-secondary);
    font-size: 1.2rem;
    transition: all var(--fm-transition);
    flex-shrink: 0;
    line-height: 1;
}

#fileManagerClose:hover {
    background: var(--fm-hover-bg);
    color: var(--fm-text);
}

#fileManagerClose:active {
    background: #dde1e8;
    transform: scale(0.94);
}

#fileManagerBody {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

#fileManagerSidebar {
    width: 175px;
    flex-shrink: 0;
    background: var(--fm-sidebar-bg);
    border-right: 1px solid var(--fm-border);
    padding: 12px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.fm-sidebar-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: calc(100% - 16px);
    margin: 0 8px;
    padding: 11px 14px;
    border: none;
    border-radius: var(--fm-radius-sm);
    background: transparent;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--fm-text-secondary);
    transition: all var(--fm-transition);
    text-align: left;
    white-space: nowrap;
    letter-spacing: -0.01em;
    position: relative;
}

.fm-sidebar-btn:hover {
    background: var(--fm-hover-bg);
    color: var(--fm-text);
}

.fm-sidebar-btn:active {
    background: #dde1e8;
    transform: scale(0.97);
}

.fm-sidebar-btn.active {
    background: var(--fm-active-bg);
    color: var(--fm-accent);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--fm-accent);
    border-radius: var(--fm-radius-sm);
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}

.fm-sidebar-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
}

#fileManagerContent {
    flex: 1;
    padding: 16px 20px;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--fm-bg);
    position: relative;
    min-width: 0;
}

.fm-content-panel {
    display: none;
    flex-direction: column;
    height: 100%;
    animation: fmContentFade 0.22s ease-out;
}

.fm-content-panel.active {
    display: flex;
}

@keyframes fmContentFade {
    from { opacity: 0; transform: translateX(8px); }
    to { opacity: 1; transform: translateX(0); }
}

#fileSearchContainer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--fm-border);
    flex-shrink: 0;
    margin-bottom: 4px;
}

#fileSearchInput {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--fm-border);
    border-radius: var(--fm-radius-sm);
    font-size: 0.88rem;
    font-family: inherit;
    color: var(--fm-text);
    background: #fafbfc;
    transition: all var(--fm-transition);
    outline: none;
    letter-spacing: -0.01em;
}

#fileSearchInput:focus {
    border-color: var(--fm-accent);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.08);
}

#fileSearchInput::placeholder {
    color: #b0b7c3;
}

#fileSearchBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--fm-radius-sm);
    border: 1.5px solid var(--fm-border);
    background: #fafbfc;
    cursor: pointer;
    color: var(--fm-text-secondary);
    font-size: 1rem;
    transition: all var(--fm-transition);
    flex-shrink: 0;
}

#fileSearchBtn:hover {
    background: var(--fm-hover-bg);
    color: var(--fm-text);
    border-color: #cdd3dc;
}

#fileSearchBtn:active {
    background: #dde1e8;
    transform: scale(0.94);
}

#fileListContainer {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    margin-top: 6px;
    padding: 4px 2px;
    min-height: 120px;
    border-radius: var(--fm-radius-sm);
    background: #fdfdfe;
    position: relative;
}

.fm-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 160px;
    color: #c5cad4;
    user-select: none;
    pointer-events: none;
    gap: 8px;
}

.fm-empty-state .fm-empty-icon {
    font-size: 2.8rem;
    opacity: 0.6;
}

.fm-empty-state .fm-empty-text {
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: #bcc3ce;
}

.fm-file-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--fm-radius-sm);
    cursor: pointer;
    transition: all var(--fm-transition);
    margin-bottom: 2px;
    font-size: 0.88rem;
}

.fm-file-item:hover {
    background: var(--fm-hover-bg);
}

.fm-file-item.selected {
    background: var(--fm-active-bg);
    color: var(--fm-accent);
    font-weight: 600;
}

.fm-format-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    padding: 6px 2px;
    flex: 1;
    align-content: start;
}

.fm-format-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 22px 16px 18px;
    border-radius: var(--fm-radius-md);
    border: 1.5px solid var(--fm-border);
    background: #fdfdfe;
    cursor: pointer;
    transition: all var(--fm-transition);
    text-align: center;
    position: relative;
    overflow: hidden;
    user-select: none;
    min-height: 110px;
}

.fm-format-card:hover {
    border-color: #c8d0db;
    box-shadow: var(--fm-shadow-sm);
    transform: translateY(-2px);
}

.fm-format-card:active {
    transform: scale(0.96);
    background: #f5f6f9;
    transition: all 0.1s ease;
}

.fm-format-card .fm-format-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.02em;
    flex-shrink: 0;
}

.fm-format-card .fm-format-label {
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: -0.01em;
    color: var(--fm-text);
}

.fm-format-card .fm-format-ext {
    font-size: 0.78rem;
    color: var(--fm-text-secondary);
    letter-spacing: -0.01em;
    font-weight: 500;
}

.fm-format-card.pdf-card .fm-format-icon {
    background: var(--pdf-bg);
    color: var(--pdf-color);
}
.fm-format-card.pdf-card:hover {
    border-color: #f5c6c2;
    background: #fffbfb;
}

.fm-format-card.png-card .fm-format-icon {
    background: var(--png-bg);
    color: var(--png-color);
}
.fm-format-card.png-card:hover {
    border-color: #b8d9c5;
    background: #fafffc;
}

.fm-format-card.jpg-card .fm-format-icon {
    background: var(--jpg-bg);
    color: var(--jpg-color);
}
.fm-format-card.jpg-card:hover {
    border-color: #f5cfb2;
    background: #fffdfa;
}

.fm-format-card.board-card .fm-format-icon {
    background: var(--board-bg);
    color: var(--board-color);
}
.fm-format-card.board-card:hover {
    border-color: #d4c4f5;
    background: #fdfbff;
}

.fm-format-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 16px;
    right: 16px;
    height: 3px;
    border-radius: 0 0 3px 3px;
    opacity: 0;
    transition: opacity var(--fm-transition);
}
.fm-format-card.pdf-card::before { background: var(--pdf-color); }
.fm-format-card.png-card::before { background: var(--png-color); }
.fm-format-card.jpg-card::before { background: var(--jpg-color); }
.fm-format-card.board-card::before { background: var(--board-color); }
.fm-format-card:hover::before { opacity: 0.7; }

#importFileInput {
    display: none;
}

.fm-toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #1a1d23;
    color: #fff;
    padding: 11px 22px;
    border-radius: 30px;
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    z-index: 99999;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.fm-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#fileManagerContent::-webkit-scrollbar,
#fileListContainer::-webkit-scrollbar {
    width: 5px;
}
#fileManagerContent::-webkit-scrollbar-track,
#fileListContainer::-webkit-scrollbar-track {
    background: transparent;
}
#fileManagerContent::-webkit-scrollbar-thumb,
#fileListContainer::-webkit-scrollbar-thumb {
    background: #d5dae3;
    border-radius: 10px;
}
#fileManagerContent::-webkit-scrollbar-thumb:hover,
#fileListContainer::-webkit-scrollbar-thumb:hover {
    background: #bcc3cf;
}

@media (max-width: 600px) {
    #fileManagerPanel {
        width: 96vw;
        height: 90vh;
        max-height: 92vh;
        border-radius: var(--fm-radius-md);
    }
    #fileManagerSidebar {
        width: 130px;
        padding: 8px 0;
    }
    .fm-sidebar-btn {
        font-size: 0.8rem;
        padding: 10px 10px;
        gap: 6px;
        margin: 0 4px;
        width: calc(100% - 8px);
    }
    .fm-format-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .fm-format-card {
        padding: 16px 10px 14px;
        min-height: 90px;
        gap: 5px;
    }
    .fm-format-card .fm-format-icon {
        width: 36px;
        height: 36px;
        font-size: 0.85rem;
    }
    .fm-format-card .fm-format-label {
        font-size: 0.8rem;
    }
    #fileManagerContent {
        padding: 12px 10px;
    }
}

/* Import Selected button */
#importSelectedBtn {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: #4f6ef7;
    color: #fff;
    padding: 8px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 10;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}
#importSelectedBtn:hover {
    background: #3b5de7;
    transform: translateY(-1px);
}