/* Base Styling */
:root {
    --bg-gradient: #0f172a;
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-border: rgba(255, 255, 255, 0.08);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --success: #10b981;
}

body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    background: var(--bg-gradient);
    color: var(--text-main);
    height: 100vh; /* Fixed height to prevent scrolling */
    max-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Global Top Navigation */
.global-header {
    width: 100%;
    height: 40px;
    background: #020617;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    box-sizing: border-box;
    margin-bottom: 15px;
    transition: margin-bottom 0.4s ease;
}

body.sidebar-collapsed .global-header {
    margin-bottom: 0;
}

.brand-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #e2e8f0;
}

/* Typography */
h2 {
    font-weight: 600;
    font-size: 1.5rem;
    margin: 0;
    color: #e2e8f0;
}

h3 {
    margin-top: 0;
    font-size: 0.95rem;
    font-weight: 600;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 5px;
    margin-bottom: 10px;
    color: #cbd5e1;
}

/* Dashboard Grid Layout */
.dashboard-grid {
    grid-template-columns: 1fr 380px;
    overflow: hidden;
    gap: 15px;
    width: 100%;
    max-width: 1600px;
    flex: 1; /* Take remaining space */
    min-height: 0;
    opacity: 0;
    /* Smooth transitions for all layout properties */
    transition: grid-template-columns 0.5s cubic-bezier(0.4, 0, 0.2, 1), 
                gap 0.5s cubic-bezier(0.4, 0, 0.2, 1), 
                padding 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                max-width 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.5s ease;
    padding: 10px 15px;
    box-sizing: border-box;
}

body.sidebar-collapsed .dashboard-grid {
    grid-template-columns: 1fr 0px;
    gap: 0;
    padding: 0;
    max-width: none;
    height: auto;
}

body.sidebar-collapsed .main-pane {
    gap: 0;
    overflow: hidden;
}

body.sidebar-collapsed .viewer-card {
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 10px 0 10px 0; /* Tightened from 30px */
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Ensure title and actions still have horizontal breathing room when card is edge-to-edge */
body.sidebar-collapsed .viewer-card > div:first-child,
body.sidebar-collapsed .viewer-actions {
    padding-left: 20px;
    padding-right: 20px;
}

body.sidebar-collapsed #inlinePreviewContainer {
    border: none;
    border-radius: 0;
    flex: 1; /* Allow container to fill space between title and buttons */
    height: auto;
    min-height: 0;
    padding: 0; /* Remove padding to allow video to take full area */
    background: #020617; /* Dark cinematic background */
}

.main-pane {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: hidden; /* Prevent global scrollbar */
    flex: 1; /* Allow scaling */
    min-height: 0;
    transition: gap 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-pane {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    overflow: hidden;
    transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1), 
                padding 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                flex 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-collapsed .sidebar-pane {
    opacity: 0;
    pointer-events: none;
    padding: 0;
}

/* Cards */
.card {
    background: #1e293b;
    border: 1px solid var(--card-border);
    border-radius: 4px;
    padding: 10px 12px; /* Condensed global padding */
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    min-width: 0;
}

.sidebar-card {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%;
    margin-bottom: 0;
    overflow: hidden;
}

.sidebar-card h3 {
    margin-bottom: 8px;
    flex-shrink: 0;
}

.sidebar-card ul {
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 5px;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.viewer-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 10px 12px 10px 12px; /* Tightened from 30px */
    box-sizing: border-box;
}

/* Form Elements */
input {
    width: 100%;
    background: #0f172a;
    border: 1px solid var(--card-border);
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    margin-bottom: 10px;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 0.85rem;
}

input:focus {
    outline: none;
    border-color: var(--accent);
}

input[type="file"]::file-selector-button {
    background: #334155;
    border: 1px solid var(--card-border);
    color: var(--text-main);
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 10px;
    font-size: 0.8rem;
}

button.primary {
    background: #2563eb;
    color: white;
    border: none;
    padding: 6px 12px;
    font-weight: 500;
    font-size: 0.85rem;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: none;
    width: 100%;
}

button.primary:hover {
    background: #1d4ed8;
}

/* Interactive Sidebar List */
ul {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-x: hidden;
}

li {
    padding: 4px 6px; /* Condensed */
    background: transparent;
    border-radius: 2px;
    margin-bottom: 1px; /* Reduced */
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid transparent;
    cursor: pointer;
    overflow: hidden;
}

li:nth-child(odd) {
    background: rgba(255, 255, 255, 0.02);
}

li:hover {
    background: #334155;
}

li.selected {
    background: rgba(59, 130, 246, 0.2) !important;
    border-color: var(--accent) !important;
}

.file-info {
    display: flex;
    flex-direction: column;
    width: 100%;
    pointer-events: none;
    min-width: 0;
    overflow: hidden;
    gap: 2px;
}

.file-row-content {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-width: 0;
}

.file-thumbnail-container {
    width: 30px; /* Shrinking for density */
    height: 30px;
    flex-shrink: 0;
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid var(--card-border);
}

.file-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.file-thumbnail.loaded {
    opacity: 1;
}

.file-icon-placeholder {
    font-size: 1.1rem;
    opacity: 0.3;
    filter: grayscale(1);
    transition: opacity 0.3s ease;
}

.file-name-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    width: 100%;
    gap: 10px;
}

.file-name {
    font-weight: 500;
    font-size: 0.85rem;
    color: #cbd5e1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
    min-width: 0;
}

.file-size {
    font-size: 0.75rem;
    color: var(--accent);
    white-space: nowrap;
    flex-shrink: 0;
    font-weight: normal;
}

.file-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Dropdown Profile Menu */
.profile-dropdown {
    position: relative;
}

.avatar-btn {
    background: transparent;
    border: none;
    color: #cbd5e1;
    padding: 4px 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    font-family: inherit;
    font-size: 0.85rem;
}

.avatar-btn:hover {
    color: white;
}

.dropdown-menu {
    position: absolute;
    right: 0;
    top: 100%;
    background: #0f172a;
    border: 1px solid var(--card-border);
    border-radius: 4px;
    min-width: 180px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    display: none;
    overflow: hidden;
    z-index: 1000;
}

.dropdown-menu.active {
    display: block;
}

.dropdown-header {
    padding: 10px 15px;
    border-bottom: 1px solid var(--card-border);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.dropdown-item {
    padding: 8px 15px;
    cursor: pointer;
    color: var(--text-main);
    font-size: 0.85rem;
    display: none;
    margin-bottom: 2px;
}

.dropdown-item.safe {
    display: block;
}

.dropdown-item:hover {
    background: #1e293b;
}

/* Inline Viewer Controls */
#inlinePreviewContainer {
    flex-grow: 1;
    min-height: 0; /* Allow shrinking */
    background: #020617;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    border: 1px solid #1e293b;
}

#inlinePreviewContainer img,
#inlinePreviewContainer video {
    display: block;
    margin: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

#inlinePreviewContainer iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

.viewer-actions {
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

a.btn-download {
    background: transparent;
    color: #3b82f6;
    text-decoration: none;
    border: 1px solid #3b82f6;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    display: none;
}

a.btn-download:hover {
    background: rgba(59, 130, 246, 0.1);
}

/* Login Screen Overlay */
#loginScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0f172a;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.login-box {
    background: #1e293b;
    padding: 30px;
    border-radius: 4px;
    border: 1px solid var(--card-border);
    width: 100%;
    max-width: 340px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.login-box h2 {
    margin-bottom: 25px;
    font-size: 1.4rem;
}

.login-options {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 18px;
    justify-content: flex-start;
    width: 100%;
}

.login-options input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-bottom: 0;
    cursor: pointer;
    accent-color: var(--accent);
}

.login-options label {
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    z-index: 1000;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: #0f172a;
    border: 1px solid var(--card-border);
    border-radius: 4px;
    width: 90%;
    max-width: 800px;
    padding: 20px;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 10px;
}

.close-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
}

textarea {
    width: 100%;
    background: #020617;
    border: 1px solid var(--card-border);
    color: #10b981;
    font-family: monospace;
    padding: 10px;
    border-radius: 4px;
    min-height: 100px;
    box-sizing: border-box;
    margin-bottom: 15px;
    font-size: 0.85rem;
}

/* User Management */
.user-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1e293b;
    padding: 8px 12px;
    border-radius: 4px;
    margin-bottom: 4px;
    border: 1px solid transparent;
    font-size: 0.85rem;
}

select {
    background: #0f172a;
    color: white;
    border: 1px solid var(--card-border);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
}

/* Auto-hide elements restricted by RBAC */
.right-btn-upload,
.right-btn-sql,
.right-btn-users {
    display: none;
}

/* Viewer Controls Toolbar */
.viewer-controls {
    display: flex;
}

.control-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Modern Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 18px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #334155;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 12px;
    width: 12px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: #3b82f6;
}

input:focus+.slider {
    box-shadow: 0 0 1px #3b82f6;
}

input:checked+.slider:before {
    transform: translateX(16px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Text Preview Scaling */
.text-preview {
    background: #020617;
    color: #10b981;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.85rem;
    padding: 20px;
    width: 100%;
    flex: 1;
    /* Take up all space in flex-column parent */
    margin: 0;
    overflow-y: auto;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    box-sizing: border-box;
    text-align: left;
}

/* Progress Bar UX */
.progress-outer {
    width: 100%;
    margin-bottom: 12px;
}

.progress-inner {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    width: 0%;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}

.status-box {
    margin-top: 10px;
    font-size: 0.75rem;
    color: var(--text-muted);
    min-height: 1em;
}

.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Video Playback Overlay */
.video-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

.video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    pointer-events: none; /* Allow interaction with native controls below */
}

.video-wrapper:hover .video-overlay {
    opacity: 1;
    background: rgba(0, 0, 0, 0.2);
}

.overlay-btn {
    width: 64px;
    height: 64px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    pointer-events: auto; /* Re-enable interaction for the button specifically */
    cursor: pointer;
}

.video-overlay:hover .overlay-btn {
    transform: scale(1.1);
    background: var(--accent);
    border-color: var(--accent);
}

.video-overlay:active .overlay-btn {
    transform: scale(0.95);
}

/* State-based icon visibility */
.video-overlay.playing .overlay-play { display: none; }
.video-overlay:not(.playing) .overlay-pause { display: none; }

/* Dense Layout Utilities */
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    padding-bottom: 4px;
}

.filter-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    width: 100%;
}

.filter-bar input {
    margin-bottom: 0;
    flex: 2;
    padding: 4px 8px;
}

.filter-bar select {
    flex: 1;
    padding: 2px 4px;
    font-size: 0.75rem;
}

/* Upload Tray Footer */
.upload-tray {
    border-top: 1px solid var(--card-border);
    padding-top: 10px;
    margin-top: auto; /* Push to bottom */
}

.upload-tray-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.upload-tray-row input[type="file"] {
    font-size: 0.7rem;
    padding: 2px;
    margin-bottom: 0;
}

.upload-tray-row button {
    padding: 4px 8px;
    font-size: 0.75rem;
    width: auto;
}

/* Nitro-UX: Performance & Perceived Speed */
.nitro-placeholder {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.placeholder-blur {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(20px) brightness(0.5);
    transform: scale(1.1);
    opacity: 0.6;
}

.shimmer-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.05) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 2s infinite linear;
}

@keyframes shimmer {
    0% { background-position: -100% 0; }
    100% { background-position: 100% 0; }
}

.loading-text {
    position: absolute;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-family: monospace;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.video-wrapper {
    width: 100%;
    height: 100%;
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}
