:root {
    --bg: #f6f8fc;
    --surface: #ffffff;
    --surface-2: #f0f4f9;
    --surface-hover: #e8eef7;
    --border: #e1e6ef;
    --text: #1f2328;
    --text-muted: #5f6368;
    --primary: #1a73e8;
    --primary-hover: #1557b0;
    --primary-soft: rgba(26, 115, 232, 0.12);
    --accent: #0f9d58;
    --accent-soft: rgba(15, 157, 88, 0.12);
    --danger: #d93025;
    --danger-soft: rgba(217, 48, 37, 0.12);
    --warn: #e37400;
    --warn-soft: rgba(227, 116, 0, 0.14);
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.10);
    --shadow-lg: 0 18px 48px rgba(16, 24, 40, 0.18);
    --radius: 12px;
    --radius-sm: 8px;
}

html[data-theme="dark"] {
    --bg: #0f1218;
    --surface: #171c24;
    --surface-2: #1f2631;
    --surface-hover: #283140;
    --border: #2b3545;
    --text: #eef2f7;
    --text-muted: #9aa4b2;
    --primary: #4c9aff;
    --primary-hover: #74b2ff;
    --primary-soft: rgba(76, 154, 255, 0.16);
    --accent: #2ecc71;
    --accent-soft: rgba(46, 204, 113, 0.15);
    --danger: #ff6b6b;
    --danger-soft: rgba(255, 107, 107, 0.16);
    --warn: #f59f00;
    --warn-soft: rgba(245, 159, 0, 0.16);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.40);
    --shadow-lg: 0 22px 54px rgba(0, 0, 0, 0.55);
}

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

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 0.84rem; }

.boot-screen {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.spinner {
    width: 34px;
    height: 34px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Buttons & Inputs */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--surface-2);
    color: var(--text);
    transition: background 0.15s, border-color 0.15s, transform 0.08s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-hover); }
.btn-outline { background: transparent; border-color: var(--border); }
.btn-outline:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 11px; font-size: 0.82rem; }
.btn-icon { padding: 7px; border-radius: 8px; min-width: 34px; min-height: 34px; }
.btn-full { width: 100%; }

.input, .select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.field-label {
    display: block;
    font-size: 0.84rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.stack-form { display: flex; flex-direction: column; gap: 14px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.alert-error {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid rgba(217, 48, 37, 0.25);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
}

.alert-info {
    background: var(--primary-soft);
    color: var(--primary);
    border: 1px solid rgba(26, 115, 232, 0.25);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
}

/* Auth & Setup Cards */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}

.auth-card {
    width: 100%;
    max-width: 440px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    box-shadow: var(--shadow-md);
}
.auth-card.setup-card { max-width: 580px; }

.brand-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand-logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #1a73e8, #0f9d58);
    color: #fff;
    font-weight: 800;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    letter-spacing: -0.5px;
    flex-shrink: 0;
}
.brand-title { font-weight: 700; font-size: 1.08rem; }

.diag-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 0.82rem;
}
.diag-item { display: flex; justify-content: space-between; gap: 8px; }
.badge-ok { color: var(--accent); font-weight: 700; }
.badge-bad { color: var(--danger); font-weight: 700; }

/* Main Drive Shell */
.drive-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--bg);
    border-right: 1px solid var(--border);
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.new-menu-wrap { position: relative; }
.btn-new {
    width: 100%;
    justify-content: flex-start;
    padding: 12px 16px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    font-size: 0.95rem;
}
.btn-new:hover { background: var(--surface-hover); }

.dropdown-menu {
    position: absolute;
    left: 0;
    top: calc(100% + 6px);
    min-width: 220px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    padding: 6px;
    z-index: 60;
}
.dropdown-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border: none;
    background: transparent;
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.88rem;
    text-align: left;
}
.dropdown-item:hover { background: var(--surface-2); }
.dropdown-item.danger { color: var(--danger); }

.nav-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 14px;
    border: none;
    background: transparent;
    color: var(--text);
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.92rem;
    font-weight: 500;
    text-align: left;
    transition: background 0.14s;
}
.nav-item:hover { background: var(--surface-hover); }
.nav-item.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}

.storage-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    font-size: 0.82rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.progress-track {
    width: 100%;
    height: 7px;
    border-radius: 999px;
    background: var(--surface-2);
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 999px;
    transition: width 0.25s;
}
.lossless-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 4px 8px;
    border-radius: 999px;
    width: fit-content;
}

/* Main Content Area */
.main-col {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
}

.mobile-menu-btn { display: none; }

.search-wrap {
    flex: 1;
    max-width: 560px;
    position: relative;
    display: flex;
    align-items: center;
}
.search-wrap svg {
    position: absolute;
    left: 13px;
    color: var(--text-muted);
    pointer-events: none;
}
.search-input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.92rem;
    outline: none;
}
.search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.workspace {
    flex: 1;
    padding: 18px 22px 100px;
    background: var(--surface);
    border-top-left-radius: 16px;
    min-height: calc(100vh - 64px);
}

.subbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.breadcrumbs {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 1.05rem;
    font-weight: 600;
}
.crumb-btn {
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 8px;
    cursor: pointer;
}
.crumb-btn:hover { background: var(--surface-2); }
.crumb-sep { color: var(--text-muted); }

.subbar-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}
.subbar-controls .select { width: auto; padding: 7px 10px; font-size: 0.85rem; }

.section-heading {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin: 18px 0 10px;
}

/* Folder Grid */
.folders-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}
.folder-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.14s, border-color 0.14s;
    position: relative;
}
.folder-card:hover { background: var(--surface-hover); border-color: var(--primary); }
.folder-main {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}
.folder-name {
    font-weight: 600;
    font-size: 0.92rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Files Grid */
.files-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
    gap: 14px;
}
.file-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.16s, border-color 0.16s, transform 0.12s;
    position: relative;
}
.file-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}
.file-thumb-wrap {
    position: relative;
    aspect-ratio: 16 / 9;
    background: linear-gradient(135deg, #171e2b, #243147);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
}
.file-thumb-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.play-overlay {
    position: absolute;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.58);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    transition: transform 0.15s, background 0.15s;
}
.file-thumb-wrap:hover .play-overlay {
    transform: scale(1.08);
    background: rgba(26, 115, 232, 0.9);
}
.thumb-badges-top {
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
}
.res-badge {
    background: rgba(15, 18, 24, 0.82);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 3px 7px;
    border-radius: 6px;
    letter-spacing: 0.02em;
}
.res-badge.res-hi { background: rgba(26, 115, 232, 0.9); }
.duration-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.78);
    color: #fff;
    font-size: 0.74rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 5px;
}

.file-card-body {
    padding: 11px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.file-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}
.file-name {
    font-weight: 600;
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}
.file-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.79rem;
    color: var(--text-muted);
}
.file-card-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding-top: 4px;
    border-top: 1px solid var(--border);
}

/* List / Table View */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.drive-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.89rem;
}
.drive-table th {
    text-align: left;
    padding: 11px 14px;
    font-size: 0.79rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.drive-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.drive-table tr:last-child td { border-bottom: none; }
.drive-table tbody tr:hover { background: var(--surface-2); }

.row-name-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 600;
}
.mini-thumb {
    width: 44px;
    height: 28px;
    border-radius: 5px;
    object-fit: cover;
    background: #1f2631;
    flex-shrink: 0;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 0.78rem;
    font-weight: 600;
}
.pill-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill-res { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

.empty-state {
    text-align: center;
    padding: 58px 20px;
    border: 2px dashed var(--border);
    border-radius: 16px;
    margin-top: 12px;
}

.upload-hero {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px 20px;
    margin-bottom: 18px;
    border: 2px dashed var(--border);
    border-radius: 14px;
    background: var(--surface-2);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.upload-hero:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
}
.upload-hero-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}
.upload-hero-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Drag & Drop Overlay */
.drop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26, 115, 232, 0.16);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.drop-overlay-box {
    background: var(--surface);
    border: 2px dashed var(--primary);
    border-radius: 20px;
    padding: 34px 48px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

/* Floating Upload Drawer */
.upload-drawer {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: min(410px, calc(100vw - 24px));
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    z-index: 120;
    overflow: hidden;
}
.upload-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 14px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.9rem;
}
.upload-drawer-body {
    max-height: 290px;
    overflow-y: auto;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.upload-item {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.83rem;
}
.upload-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.upload-item-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Modals */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 150;
}
.modal-box {
    width: 100%;
    max-width: 500px;
    max-height: 92vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 22px;
    box-shadow: var(--shadow-lg);
}
.modal-box.modal-wide { max-width: 880px; }
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.modal-head h2 { margin: 0; font-size: 1.12rem; word-break: break-word; }

.preview-video-wrap {
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 14px;
}
.preview-video-wrap video {
    width: 100%;
    max-height: 56vh;
    display: block;
}
.player-fallback {
    padding: 12px 14px;
    background: var(--warn-soft);
    color: var(--warn);
    font-size: 0.86rem;
}

.integrity-box {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
}
.integrity-title { font-weight: 700; font-size: 0.85rem; color: var(--accent); }
.sha-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.79rem;
    word-break: break-all;
    background: var(--surface);
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    display: block;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-top: 10px;
}
.info-cell {
    background: var(--surface-2);
    border-radius: 10px;
    padding: 10px 12px;
}
.info-cell-label { font-size: 0.75rem; color: var(--text-muted); }
.info-cell-val { font-weight: 700; font-size: 0.92rem; margin-top: 2px; }

/* Context Menu */
.context-menu {
    position: fixed;
    min-width: 195px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 220;
}

/* Toasts */
.toast-container {
    position: fixed;
    top: 18px;
    right: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 300;
}
.toast {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    padding: 11px 14px;
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    font-size: 0.88rem;
    max-width: 340px;
}
.toast.toast-ok { border-left-color: var(--accent); }
.toast.toast-err { border-left-color: var(--danger); }

/* Public Share Page */
.share-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}
.share-card {
    width: 100%;
    max-width: 860px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 24px;
    box-shadow: var(--shadow-md);
}
.share-card-narrow { max-width: 440px; }
.share-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.share-file-meta h1 { margin: 16px 0 10px; font-size: 1.35rem; word-break: break-word; }
.meta-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.share-player-wrap {
    margin-top: 18px;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
}
.share-player-wrap video { width: 100%; max-height: 62vh; display: block; }
.share-badge-warn {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--danger-soft);
    color: var(--danger);
    font-weight: 700;
    font-size: 0.8rem;
}

/* Mobile responsiveness */
@media (max-width: 860px) {
    .drive-layout { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 265px;
        z-index: 140;
        transform: translateX(-105%);
        transition: transform 0.2s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .mobile-menu-btn { display: inline-flex; }
    .form-row-2 { grid-template-columns: 1fr; }
}

