/* Base variables and settings */
:root {
    --sidebar-width: 250px;
    --toolbar-height: 50px;
    --breadcrumb-height: 40px;
    --preview-panel-width: 400px;
}

/* Base styles */
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    overflow: hidden;
}

.explorer {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
    background: #f8f9fa;
}

.sidebar {
    background: #f0f0f0;
    border-right: 1px solid #dee2e6;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
}

.main-content {
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0; /* Prevent content overflow */
}

/* Toolbar styles with responsive adjustments */
.toolbar {
    height: var(--toolbar-height);
    padding: 0.5rem 1rem;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    background: white;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.toolbar .btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.toolbar button span {
    display: inline;
}

/* Files container responsive grid */
.files-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    padding: 1rem;
}

.files-container.list-view {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* File items with touch-friendly sizing */
.file-item {
    padding: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transition: background-color 0.2s;
    min-height: 100px;
    justify-content: center;
}

.file-item:hover {
    background-color: #f8f9fa;
}

.file-item.selected {
    background-color: #e3f2fd;
}

.file-item-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.file-item-name {
    font-size: 0.875rem;
    word-break: break-word;
}


/* Preview panel responsive adjustments */
.preview-panel {
    width: var(--preview-panel-width);
    border-left: 1px solid #dee2e6;
    background: white;
    display: none;
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    box-shadow: -2px 0 5px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.preview-header {
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
}

.preview-title {
    flex: 1;
    min-width: 0;
    margin-right: 1rem;
}

.preview-title h6 {
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.preview-content {
    padding: 1rem;
    height: calc(100% - 60px);
    overflow: auto;
    position: relative;
}

.preview-image-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.preview-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.preview-text {
    width: 100%;
    height: 100%;
    white-space: pre-wrap;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.5;
    overflow-x: auto;
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 4px;
    margin: 0;
}

.preview-code {
    width: 100%;
    height: 100%;
    overflow: auto;
    background: #ffffff;
    border-radius: 4px;
}

.preview-code pre {
    margin: 0;
    padding: 1rem;
}

.preview-code code {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.5;
}

.preview-pdf {
    width: 100%;
    height: 100%;
    border: none;
}

.preview-video,
.preview-audio {
    width: 100%;
    max-height: 100%;
    margin: 0 auto;
    display: block;
}

.preview-unsupported {
    text-align: center;
    padding: 2rem;
    color: #6c757d;
}

.preview-unsupported i {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.preview-unsupported p {
    margin-bottom: 1rem;
}

.zoom-controls {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.9);
    padding: 0.5rem;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.context-menu {
    position: fixed;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    padding: 0.5rem 0;
    z-index: 1000;
    display: none;
}

.context-menu-item {
    padding: 0.5rem 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.context-menu-item:hover {
    background-color: #f8f9fa;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

/* Responsive breakpoints */
@media (max-width: 1200px) {
    :root {
        --preview-panel-width: 350px;
    }
}

@media (max-width: 992px) {
    .toolbar button span {
        display: none;
    }

    .toolbar .btn-group {
        margin-right: 0.25rem;
    }

    :root {
        --preview-panel-width: 300px;
    }
}

@media (max-width: 768px) {
    .explorer {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 1001;
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: block;
    }

    .preview-panel {
        width: 100%;
    }

    .files-container {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    .toolbar {
        padding: 0.5rem;
        justify-content: center;
    }

    .toolbar .btn-group {
        flex: 0 0 auto;
    }
}

@media (max-width: 576px) {
    .files-container {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .file-item {
        padding: 0.5rem;
        min-height: 80px;
    }

    .breadcrumb-container {
        padding: 0.5rem;
    }

    .toolbar {
        height: auto;
        flex-wrap: wrap;
        gap: 0.25rem;
    }
}

/* Touch device optimizations */
@media (hover: none) {
    .file-item {
        -webkit-tap-highlight-color: transparent;
    }

    .file-item:active {
        background-color: #e3f2fd;
    }
}

/* Keep existing utility classes */
[data-feather] {
    width: 18px;
    height: 18px;
    stroke-width: 2;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

/* ---------------------------------------------------------------- */
/* Login gate                                                        */
/* ---------------------------------------------------------------- */
.login-overlay {
    position: fixed;
    inset: 0;
    background: #f1f3f5;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    padding: 1rem;
}

.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 340px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

.login-icon {
    font-size: 2rem;
    color: #0d6efd;
    margin-bottom: 0.5rem;
}

.login-card h4 {
    margin-bottom: 0.25rem;
}

.login-card p {
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.login-card .form-control {
    text-align: center;
    letter-spacing: 0.35em;
    font-size: 1.25rem;
}

.login-error {
    color: #dc3545;
    font-size: 0.875rem;
    min-height: 1.25rem;
    margin-top: 0.75rem;
}

/* ---------------------------------------------------------------- */
/* Thumbnails in the file grid                                       */
/* ---------------------------------------------------------------- */
.file-item {
    position: relative;
}

.file-item-thumb {
    width: 100%;
    height: 96px;
    object-fit: cover;
    border-radius: 6px;
    background: #eef1f4;
    display: block;
    margin-bottom: 0.5rem;
}

.file-item-badge {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-item-badge [data-feather] {
    width: 14px;
    height: 14px;
}

.file-item-meta {
    font-size: 0.7rem;
    color: #6c757d;
    margin-top: 0.15rem;
}

/* Grid view shows a cover image; list view keeps a compact icon row. */
.files-container.list-view .file-item {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    gap: 0.75rem;
    min-height: 0;
    padding: 0.5rem 0.75rem;
}

.files-container.list-view .file-item-thumb {
    width: 40px;
    height: 40px;
    margin-bottom: 0;
    flex: 0 0 auto;
}

.files-container.list-view .file-item-icon {
    margin-bottom: 0;
    font-size: 1.25rem;
    flex: 0 0 auto;
}

.files-container.list-view .file-item-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.files-container.list-view .file-item-meta {
    margin-top: 0;
    flex: 0 0 auto;
}

.empty-folder {
    grid-column: 1 / -1;
    text-align: center;
    color: #6c757d;
    padding: 3rem 1rem;
}

/* ---------------------------------------------------------------- */
/* Upload progress                                                   */
/* ---------------------------------------------------------------- */
.upload-progress {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    width: min(90vw, 420px);
    background: #fff;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
    z-index: 2200;
}

.upload-progress-label {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}