:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --primary-light: #e8f0fe;
    --danger: #d93025;
    --danger-dark: #a50e0e;
    --success: #188038;
    --warning: #f9ab00;
    --bg: #f1f3f4;
    --surface: #ffffff;
    --surface-hover: #f5f5f5;
    --text: #202124;
    --text-secondary: #5f6368;
    --border: #dadce0;
    --sidebar-bg: #ffffff;
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.12);
    --transition: all 0.2s ease;
}

/* Dark theme detection */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1a1a2e;
        --surface: #16213e;
        --surface-hover: #1a1a3e;
        --text: #e8eaed;
        --text-secondary: #9aa0a6;
        --border: #3c4043;
        --sidebar-bg: #0f3460;
        --primary-light: #1a3a6e;
        --shadow: 0 1px 3px rgba(0,0,0,0.3);
        --shadow-lg: 0 4px 24px rgba(0,0,0,0.4);
    }
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html { font-size: 14px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Auth Pages ===== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a73e8, #0d47a1);
    padding: 20px;
}

.auth-container { width: 100%; max-width: 400px; }

.auth-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 40px 32px;
    box-shadow: var(--shadow-lg);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-header i {
    font-size: 48px;
    color: var(--primary);
    margin-bottom: 12px;
}

.auth-header h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 4px;
}

.auth-header p {
    color: var(--text-secondary);
}

.auth-form { margin-bottom: 24px; }

.auth-footer {
    text-align: center;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 14px;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.input-group {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
}

.input-group:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.input-group i {
    padding: 0 12px;
    color: var(--text-secondary);
    font-size: 16px;
    min-width: 40px;
    text-align: center;
}

.input-group input,
.input-group select {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text);
    outline: none;
    min-width: 0;
}

.input-group select {
    cursor: pointer;
    padding-right: 32px;
    appearance: auto;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    transition: var(--transition);
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover {
    background: var(--surface-hover);
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 1px 3px rgba(26, 115, 232, 0.4);
}

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-dark);
}

.btn-icon {
    padding: 8px;
    min-width: 36px;
    justify-content: center;
}

.btn-block {
    display: flex;
    width: 100%;
    justify-content: center;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ===== Install Page ===== */
.install-page {
    background: linear-gradient(135deg, #1a73e8, #0d47a1);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.install-container {
    max-width: 520px;
    width: 100%;
}

.install-header {
    text-align: center;
    color: white;
    margin-bottom: 32px;
}

.install-header h1 { font-size: 28px; margin-top: 8px; }

.install-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 32px;
    box-shadow: var(--shadow-lg);
}

.install-card h2 { margin-bottom: 16px; }

.install-card ul {
    margin: 16px 0;
    padding-left: 20px;
}

.install-card ul li { margin-bottom: 4px; }

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-error {
    background: #fce8e6;
    color: var(--danger);
    border: 1px solid #f5c6cb;
}

.alert-success {
    background: #e6f4ea;
    color: var(--success);
    border: 1px solid #c3e6cb;
}

/* ===== App Layout ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text) !important;
    text-decoration: none !important;
}

.logo i { color: var(--primary); font-size: 28px; }

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text);
    cursor: pointer;
    padding: 4px 8px;
    margin-right: 4px;
}

@media (min-width: 769px) {
    .sidebar-toggle { display: none; }
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text);
    cursor: pointer;
    padding: 4px;
}

.sidebar-nav {
    flex: 1;
    padding: 8px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none !important;
    transition: var(--transition);
    margin-bottom: 2px;
}

.nav-item:hover { background: var(--surface-hover); }

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 500;
}

.nav-item i { width: 20px; text-align: center; font-size: 16px; }

.nav-section-label {
    padding: 16px 16px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.storage-info { margin-bottom: 12px; }

.storage-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 4px;
}

.storage-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s ease;
    min-width: 2px;
}

.storage-text { text-align: center; }
.storage-text small { color: var(--text-secondary); font-size: 11px; }

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.user-details { flex: 1; min-width: 0; }

.user-name {
    font-size: 13px;
    font-weight: 500;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-btn {
    color: var(--text-secondary);
    padding: 4px;
    font-size: 16px;
    transition: var(--transition);
}

.logout-btn:hover { color: var(--danger); }

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ===== Topbar ===== */
.topbar {
    height: var(--topbar-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left { display: flex; align-items: center; gap: 16px; flex: 1; min-width: 0; }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    overflow: hidden;
}

.breadcrumb a {
    color: var(--text-secondary);
    white-space: nowrap;
}

.breadcrumb a:last-child,
.breadcrumb span:last-child {
    color: var(--text);
    font-weight: 500;
}

.breadcrumb-sep { color: var(--text-secondary); font-size: 10px; }

.search-box {
    display: flex;
    align-items: center;
    background: var(--bg);
    border-radius: 24px;
    padding: 0 16px;
    border: 1px solid transparent;
    transition: var(--transition);
    min-width: 240px;
}

.search-box:focus-within {
    border-color: var(--primary);
    background: var(--surface);
}

.search-box i { color: var(--text-secondary); font-size: 16px; }

.search-box input {
    border: none;
    background: transparent;
    padding: 8px 12px;
    font-size: 14px;
    color: var(--text);
    outline: none;
    width: 100%;
}

/* ===== Content Wrapper ===== */
.content-wrapper {
    flex: 1;
    padding: 16px 24px;
    overflow-y: auto;
}

/* ===== Toolbar ===== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 8px;
    flex-wrap: wrap;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== Selection Toolbar ===== */
.selection-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--primary);
    color: white;
    border-radius: var(--radius);
    gap: 8px;
}

.selection-toolbar-left {
    font-weight: 500;
    font-size: 14px;
}

.selection-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.selection-toolbar .btn {
    background: rgba(255,255,255,0.15);
    color: white;
    border-color: rgba(255,255,255,0.3);
}

.selection-toolbar .btn:hover {
    background: rgba(255,255,255,0.25);
}

.selection-toolbar .btn-danger {
    background: var(--danger);
    border-color: var(--danger);
}

.selection-toolbar .btn-danger:hover {
    background: var(--danger-dark);
}

/* ===== Upload Progress ===== */
.upload-progress {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.upload-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.upload-progress-header button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 18px;
}

.upload-progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.upload-progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

.upload-progress-files {
    max-height: 120px;
    overflow-y: auto;
    font-size: 12px;
    color: var(--text-secondary);
}

.upload-progress-files div { padding: 2px 0; }

/* ===== File Grid ===== */
.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

.file-grid.list-view {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.file-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
    cursor: pointer;
    position: relative;
}

.file-item:hover {
    box-shadow: var(--shadow);
    border-color: var(--primary);
}

.file-item.selected {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.file-item.selected .file-thumb {
    background: var(--primary-light);
}

.list-view .file-item.selected {
    background: var(--primary-light);
    border-color: var(--primary);
}

.file-thumb {
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    font-size: 48px;
    color: var(--text-secondary);
    overflow: hidden;
}

.file-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.folder-thumb { font-size: 56px; }

.file-info {
    padding: 10px 12px;
}

.file-name {
    display: block;
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.file-meta {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.file-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: none;
    gap: 4px;
}

.file-item:hover .file-actions { display: flex; }

.file-actions button {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: rgba(255,255,255,0.9);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: var(--transition);
    backdrop-filter: blur(4px);
}

.file-actions button:hover {
    background: var(--surface);
    color: var(--text);
}

/* List view */
.list-view .file-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
}

.list-view .file-thumb {
    width: 40px;
    height: 40px;
    font-size: 20px;
    border-radius: var(--radius);
    flex-shrink: 0;
}

.list-view .file-info {
    flex: 1;
    padding: 0;
    min-width: 0;
}

.list-view .file-actions {
    position: static;
    display: flex;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 80px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 20px;
    color: var(--text);
    margin-bottom: 8px;
}

.empty-state p { margin-bottom: 24px; }

/* ===== Sidebar Overlay ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 99;
}

/* ===== Modals ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-sm { max-width: 400px; }
.modal-lg { max-width: 640px; }
.modal-full {
    max-width: 90vw;
    width: 90vw;
    height: 85vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-header button {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

.modal-header button:hover { color: var(--text); }

.modal-body {
    padding: 24px;
}

.modal-body.preview-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

/* ===== Preview ===== */
.preview-body {
    text-align: center;
}

.preview-loading {
    padding: 60px;
    color: var(--text-secondary);
    font-size: 18px;
}

.preview-image img {
    max-width: 100%;
    max-height: 60vh;
    border-radius: var(--radius);
}

.preview-text {
    text-align: left;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    max-height: 55vh;
    overflow-y: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.preview-audio audio {
    width: 100%;
    margin: 20px 0;
}

.preview-video video {
    max-width: 100%;
    max-height: 55vh;
    border-radius: var(--radius);
}

.preview-pdf embed {
    width: 100%;
    height: 55vh;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.preview-unsupported {
    padding: 40px;
    color: var(--text-secondary);
}

.preview-unsupported i { margin-bottom: 16px; }

.preview-info {
    text-align: left;
    margin-top: 16px;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius);
    font-size: 13px;
}

.preview-info p { margin-bottom: 4px; }
.preview-info p:last-child { margin-bottom: 0; }

/* ===== Shared Users ===== */
.shared-users-list {
    margin-top: 16px;
}

.shared-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: var(--radius);
    margin-bottom: 4px;
}

.shared-user button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

.shared-user button:hover { color: var(--danger); }

/* ===== Folder Tree ===== */
.folder-tree {
    max-height: 300px;
    overflow-y: auto;
}

.folder-tree-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: var(--radius);
    transition: var(--transition);
}

.folder-tree-item:hover { background: var(--surface-hover); }

.folder-tree-item.selected {
    background: var(--primary-light);
    color: var(--primary);
}

.folder-tree-item i { color: #f9ab00; }

.folder-tree-item .child {
    padding-left: 32px;
}

.folder-children { display: block; }

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    color: white;
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    transition: opacity 0.3s ease;
    min-width: 200px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }

/* ===== Star ===== */
.fa-star.starred { color: #f9ab00; }
.fa-star:not(.starred) { color: var(--text-secondary); }

/* ===== Text Utilities ===== */
.text-muted { color: var(--text-secondary); font-size: 13px; }

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 100;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,0.2);
    }

    .sidebar.open ~ .sidebar-overlay {
        display: block;
    }

    .sidebar-toggle { display: block; }

    .sidebar-close { display: block; }

    .sidebar-header .logo span { display: none; }

    .main-content {
        margin-left: 0;
    }

    .topbar {
        padding: 0 8px;
        height: 52px;
    }

    .content-wrapper {
        padding: 8px;
    }

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

    .toolbar,
    .selection-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-left, .toolbar-right,
    .selection-toolbar-left, .selection-toolbar-right {
        flex-wrap: wrap;
    }

    .selection-toolbar-right {
        justify-content: flex-end;
    }

    .search-box {
        min-width: 0;
        flex: 1;
        max-width: 200px;
    }

    .topbar-right .btn-icon {
        padding: 6px;
        min-width: 32px;
    }

    .topbar-left {
        gap: 8px;
        flex: 1;
        min-width: 0;
    }

    .breadcrumb {
        font-size: 13px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    .file-thumb {
        height: 80px;
        font-size: 36px;
    }

    .folder-thumb { font-size: 40px; }

    .file-actions {
        position: static;
        display: flex;
        padding: 4px 8px 8px;
        gap: 4px;
        flex-wrap: wrap;
    }

    .file-grid.list-view .file-actions {
        padding: 0;
    }

    .file-item {
        position: relative;
    }

    .file-item .file-actions button {
        width: 32px;
        height: 32px;
        font-size: 13px;
    }

    .modal-full {
        max-width: 100vw;
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }

    .admin-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .form-row {
        grid-template-columns: 1fr;
    }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }
