:host {
    --fv-bg: var(--bg-white, #ffffff);
    --fv-bg-hover: var(--bg-hover, #f5f5f5);
    --fv-bg-active: var(--primary-light, #e0f2fe);
    --fv-text: var(--text-main, #1a1a1a);
    --fv-text-secondary: var(--text-secondary, #666);
    --fv-border: var(--border, #e0e0e0);
    --fv-primary: var(--primary, #2563eb);
    --fv-danger: #dc2626;
    --fv-success: #16a34a;
    --fv-warning: #d97706;
    --fv-row-height: 52px;
    --fv-toolbar-height: 56px;
    --fv-radius: 10px;
    --fv-icon-size: 24px;
    --fv-transition: 200ms ease;
    --fv-safe-top: 0px;
    --fv-safe-bottom: 0px;
    --fv-safe-left: 0px;
    --fv-safe-right: 0px;
    --fv-skeleton-start: #e0e0e0;
    --fv-skeleton-mid: #f0f0f0;
    --fv-overlay-bg: rgba(0, 0, 0, 0.9);
    --fv-overlay-btn-bg: rgba(255, 255, 255, 0.15);
    --fv-overlay-btn-hover: rgba(255, 255, 255, 0.25);
    --fv-overlay-text: #ffffff;
    --fv-font: inherit;
}

:host([context="editor"]) {
    --fv-row-height: 48px;
    --fv-toolbar-height: 50px;
}

.fv-root {
    display: flex;
    flex-direction: column;
    height: 100%;
    font-family: var(--fv-font);
    color: var(--fv-text);
    background: var(--fv-bg);
    position: relative;
    overflow: hidden;
}

.fv-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    height: var(--fv-toolbar-height);
    padding: 0 12px;
    border-bottom: 1px solid var(--fv-border);
    background: var(--fv-bg);
    flex-shrink: 0;
}

.fv-toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 36px;
    min-height: 36px;
    padding: 6px 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--fv-text);
    cursor: pointer;
    font-size: 14px;
    transition: background var(--fv-transition);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.fv-toolbar-btn:hover {
    background: var(--fv-bg-hover);
}

.fv-toolbar-btn .fv-btn-label {
    font-size: 13px;
}

.fv-breadcrumb {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.fv-breadcrumb-item {
    cursor: pointer;
    color: var(--fv-primary);
    white-space: nowrap;
}

.fv-breadcrumb-item:hover {
    text-decoration: underline;
}

.fv-breadcrumb-sep {
    color: var(--fv-text-secondary);
    user-select: none;
}

.fv-breadcrumb-current {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--fv-text);
}

.fv-search-box {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--fv-bg-hover);
    border: 1px solid var(--fv-border);
    border-radius: 8px;
    padding: 4px 8px;
    min-width: 160px;
}

.fv-search-box input {
    border: none;
    background: transparent;
    outline: none;
    font-size: 13px;
    color: var(--fv-text);
    width: 100%;
    min-height: 28px;
}

.fv-search-box input::placeholder {
    color: var(--fv-text-secondary);
}

.fv-body {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.fv-browser {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.fv-browser::-webkit-scrollbar {
    width: 6px;
}

.fv-browser::-webkit-scrollbar-thumb {
    background: var(--fv-border);
    border-radius: 3px;
}

.fv-list {
    position: relative;
    min-height: 100%;
}

.fv-file-row {
    display: grid;
    grid-template-columns: 32px 1fr auto auto;
    gap: 8px;
    align-items: center;
    padding: 6px 16px;
    min-height: var(--fv-row-height);
    cursor: pointer;
    border-bottom: 1px solid var(--fv-border);
    transition: background var(--fv-transition);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.fv-file-row:hover {
    background: var(--fv-bg-hover);
}

.fv-file-row.fv-selected {
    background: var(--fv-bg-active);
}

.fv-row-icon {
    font-size: 18px;
    text-align: center;
}

.fv-row-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
}

.fv-row-size {
    color: var(--fv-text-secondary);
    font-size: 12px;
    white-space: nowrap;
    min-width: 60px;
    text-align: right;
}

.fv-row-date {
    color: var(--fv-text-secondary);
    font-size: 12px;
    white-space: nowrap;
    min-width: 80px;
    text-align: right;
}

.fv-sort-controls {
    display: flex;
    gap: 4px;
    align-items: center;
}

.fv-sort-btn {
    background: none;
    border: 1px solid var(--fv-border);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    color: var(--fv-text-secondary);
    cursor: pointer;
    transition: all var(--fv-transition);
    touch-action: manipulation;
}

.fv-sort-btn.fv-active {
    background: var(--fv-primary);
    color: #fff;
    border-color: var(--fv-primary);
}

.fv-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 8px;
    color: var(--fv-text-secondary);
    padding: 32px;
    text-align: center;
}

.fv-empty-icon {
    font-size: 48px;
    opacity: 0.4;
}

.fv-overlay {
    position: fixed;
    inset: 0;
    z-index: 2147483647;
    background: var(--fv-overlay-bg);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.fv-overlay.fv-open {
    display: flex;
}

.fv-overlay-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

.fv-overlay-btn {
    position: fixed;
    z-index: 10;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 12px;
    background: var(--fv-overlay-btn-bg);
    color: var(--fv-overlay-text);
    font-size: 20px;
    cursor: pointer;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: background var(--fv-transition), opacity var(--fv-transition);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.fv-overlay-btn:hover {
    background: var(--fv-overlay-btn-hover);
}

.fv-overlay-btn.fv-top-left {
    top: calc(16px + var(--fv-safe-top, 0px));
    left: calc(16px + var(--fv-safe-left, 0px));
}

.fv-overlay-btn.fv-top-right {
    top: calc(16px + var(--fv-safe-top, 0px));
    right: calc(16px + var(--fv-safe-right, 0px));
}

.fv-overlay-btn.fv-bottom-right {
    bottom: calc(16px + var(--fv-safe-bottom, 0px));
    right: calc(16px + var(--fv-safe-right, 0px));
}

.fv-overlay-btn.fv-bottom-left {
    bottom: calc(16px + var(--fv-safe-bottom, 0px));
    left: calc(16px + var(--fv-safe-left, 0px));
}

.fv-overlay-btn.fv-side-right {
    top: 50%;
    right: calc(16px + var(--fv-safe-right, 0px));
    transform: translateY(-50%);
}

.fv-overlay-btn.fv-side-left {
    top: 50%;
    left: calc(16px + var(--fv-safe-left, 0px));
    transform: translateY(-50%);
}

.fv-overlay-btn {
    transition: opacity 0.5s ease;
}
.fv-overlay.fv-btn-dimmed .fv-overlay-btn {
    opacity: 0.4;
}
.fv-overlay.fv-auto-hide.fv-controls-hidden .fv-overlay-btn,
.fv-overlay.fv-auto-hide.fv-controls-hidden .fv-page-indicator {
    opacity: 0;
    pointer-events: none;
}

.fv-canvas-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#fvPdfCanvas, #fvImage, #fvVideo, #fvAudio {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

#fvPdfFrame {
    width: 100%;
    height: 100%;
    border: none;
}

.fv-page-indicator {
    position: fixed;
    bottom: calc(80px + var(--fv-safe-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 11;
    backdrop-filter: blur(4px);
    user-select: none;
    transition: opacity var(--fv-transition);
}

.fv-page-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    touch-action: manipulation;
}

.fv-page-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.fv-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px;
}

.fv-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--fv-border);
    border-top-color: var(--fv-primary);
    border-radius: 50%;
    animation: fv-spin 0.8s linear infinite;
}

@keyframes fv-spin {
    to { transform: rotate(360deg); }
}

.fv-loading-text {
    color: var(--fv-text-secondary);
    font-size: 14px;
}

.fv-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px;
    text-align: center;
}

.fv-error-icon {
    font-size: 40px;
}

.fv-error-message {
    color: var(--fv-danger);
    font-size: 14px;
}

.fv-error-retry {
    padding: 8px 20px;
    border: none;
    border-radius: 8px;
    background: var(--fv-primary);
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    touch-action: manipulation;
}

.fv-skeleton {
    padding: 8px;
}

.fv-skeleton-row {
    height: 44px;
    margin-bottom: 6px;
    border-radius: var(--fv-radius);
    background: linear-gradient(
        90deg,
        var(--fv-skeleton-start) 25%,
        var(--fv-skeleton-mid) 50%,
        var(--fv-skeleton-start) 75%
    );
    background-size: 200% 100%;
    animation: fv-shimmer 1.5s ease-in-out infinite;
}

.fv-skeleton-row:nth-child(2) { animation-delay: 0.1s; }
.fv-skeleton-row:nth-child(3) { animation-delay: 0.2s; }
.fv-skeleton-row:nth-child(4) { animation-delay: 0.3s; }
.fv-skeleton-row:nth-child(5) { animation-delay: 0.4s; }
.fv-skeleton-row:nth-child(6) { animation-delay: 0.5s; }

@keyframes fv-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.fv-hud {
    position: fixed;
    bottom: 8px;
    right: 8px;
    z-index: 2147483646;
    background: rgba(0, 0, 0, 0.85);
    color: #0f0;
    font-family: monospace;
    font-size: 11px;
    padding: 8px 12px;
    border-radius: 8px;
    min-width: 200px;
    pointer-events: auto;
}

.fv-hud-header {
    font-weight: bold;
    color: #fff;
    margin-bottom: 4px;
    border-bottom: 1px solid #333;
    padding-bottom: 4px;
}

.fv-hud-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    line-height: 1.6;
}

.fv-hud-row button {
    background: #333;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 2px 8px;
    cursor: pointer;
    font-size: 10px;
}

@media (max-width: 1023px) {
    .fv-toolbar { gap: 4px; }
    .fv-toolbar-btn .fv-btn-label { display: none; }
    .fv-search-box { min-width: 120px; }
}

@media (max-width: 599px) {
    .fv-file-row { min-height: 56px; padding: 8px 12px; }
    .fv-row-date { display: none; }
    .fv-toolbar { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
    .fv-toolbar::-webkit-scrollbar { display: none; }
    .fv-sort-controls { display: none; }
    .fv-breadcrumb { font-size: 13px; }
    .fv-overlay-btn { min-width: 48px; min-height: 48px; }
}

@media (max-width: 380px) {
    .fv-row-size { display: none; }
    .fv-file-row { grid-template-columns: 32px 1fr; }
    .fv-overlay-btn { min-width: 44px; min-height: 44px; font-size: 16px; }
}

@media (orientation: landscape) and (max-height: 500px) {
    .fv-toolbar { height: 44px; }
    .fv-file-row { min-height: 44px; }
}

@media (prefers-color-scheme: dark) {
    :host {
        --fv-bg: #1a1a2e;
        --fv-bg-hover: #25253e;
        --fv-bg-active: #1e3a5f;
        --fv-text: #e0e0e0;
        --fv-text-secondary: #999;
        --fv-border: #333;
        --fv-skeleton-start: #2a2a2a;
        --fv-skeleton-mid: #3a3a3a;
    }
}

[data-theme="dark"] {
    --fv-bg: #1a1a2e;
    --fv-bg-hover: #25253e;
    --fv-bg-active: #1e3a5f;
    --fv-text: #e0e0e0;
    --fv-text-secondary: #999;
    --fv-border: #333;
    --fv-skeleton-start: #2a2a2a;
    --fv-skeleton-mid: #3a3a3a;
}

@media (prefers-contrast: high) {
    :host {
        --fv-border: currentColor;
        --fv-text: #000;
        --fv-bg: #fff;
    }
    .fv-file-row { border-width: 2px; }
}

.fv-dragover {
    outline: 3px dashed var(--fv-primary);
    outline-offset: -3px;
    background: var(--fv-bg-active);
}

.fv-view-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
    padding: 6px;
    border: 1px solid var(--fv-border);
    border-radius: 8px;
    background: transparent;
    color: var(--fv-text);
    cursor: pointer;
    font-size: 16px;
    transition: background var(--fv-transition);
    touch-action: manipulation;
}

.fv-view-toggle:hover {
    background: var(--fv-bg-hover);
}

.fv-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
    padding: 8px;
    contain: strict;
}

.fv-grid-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 8px;
    border: 1px solid var(--fv-border);
    border-radius: var(--fv-radius);
    cursor: pointer;
    transition: background var(--fv-transition), border-color var(--fv-transition);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
}

.fv-grid-item:hover {
    background: var(--fv-bg-hover);
}

.fv-grid-selected {
    background: var(--fv-bg-active);
    border-color: var(--fv-primary);
}

.fv-grid-icon {
    font-size: 32px;
    margin-bottom: 6px;
}

.fv-grid-name {
    font-size: 12px;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
    color: var(--fv-text);
}

.fv-grid-size {
    font-size: 11px;
    color: var(--fv-text-secondary);
    margin-top: 2px;
}

.fv-keyboard-help {
    background: var(--fv-bg);
    color: var(--fv-text);
    border-radius: 12px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.fv-keyboard-help h3 {
    margin: 0 0 16px;
    font-size: 18px;
}

.fv-keyboard-help table {
    width: 100%;
    border-collapse: collapse;
}

.fv-keyboard-help td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--fv-border);
    font-size: 14px;
}

.fv-keyboard-help kbd {
    display: inline-block;
    padding: 2px 8px;
    border: 1px solid var(--fv-border);
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
    background: var(--fv-bg-hover);
    min-width: 24px;
    text-align: center;
}

.fv-close-help {
    margin-top: 16px;
    padding: 8px 20px;
    border: none;
    border-radius: 8px;
    background: var(--fv-primary);
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    display: block;
    width: 100%;
}

@media (max-width: 599px) {
    .fv-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 6px;
        padding: 6px;
    }
    .fv-grid-icon {
        font-size: 28px;
    }
}

@media (prefers-reduced-motion: reduce) {
    :host {
        --fv-transition: 0ms;
    }
    .fv-skeleton-row {
        animation: none;
        background: var(--fv-border);
    }
    .fv-spinner {
        animation: none;
        border-color: var(--fv-border);
    }
}
