:root {
    color-scheme: light;
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #111827;
    --muted: #667085;
    --line: #e4e7ec;
    --primary: #635bff;
    --primary-dark: #4f46e5;
    --primary-soft: #eeecff;
    --success: #079455;
    --danger: #b42318;
    --danger-soft: #fff1f0;
    --shadow: 0 20px 55px rgba(16, 24, 40, .09);
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b1020;
    --surface: #111827;
    --surface-soft: #182132;
    --text: #f7f8fb;
    --muted: #9aa4b2;
    --line: #263244;
    --primary: #817aff;
    --primary-dark: #6d63ff;
    --primary-soft: #29264c;
    --success: #32d583;
    --danger: #fda29b;
    --danger-soft: #3a2024;
    --shadow: 0 24px 70px rgba(0, 0, 0, .28);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background .2s ease, color .2s ease;
}
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.container { width: min(1180px, calc(100% - 40px)); margin-inline: auto; }
.brand-mark {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 14px;
    background: var(--primary-soft);
}
.brand-mark svg { width: 23px; fill: var(--primary); }
.brand-mark-large { width: 72px; height: 72px; border-radius: 22px; background: rgba(255,255,255,.14); }
.brand-mark-large svg { width: 36px; fill: white; }
.eyebrow { margin: 0 0 8px; color: var(--primary); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
.muted { color: var(--muted); }
.button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 0 17px;
    text-decoration: none;
    font-weight: 750;
    cursor: pointer;
    transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.button:hover { transform: translateY(-1px); }
.button-primary { color: white; background: var(--primary); box-shadow: 0 9px 20px rgba(99, 91, 255, .22); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { background: var(--surface); border-color: var(--line); color: var(--text); }
.button-small { min-height: 38px; padding-inline: 13px; font-size: 13px; }
.button-large { min-height: 54px; width: 100%; font-size: 15px; }
.icon-button {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}
/* Login */
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(360px, .92fr) minmax(460px, 1.08fr); }
.auth-visual {
    position: relative;
    overflow: hidden;
    padding: clamp(42px, 7vw, 92px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: white;
    background: linear-gradient(145deg, #17134e 0%, #5145cd 50%, #766cff 100%);
}
.auth-visual::before, .auth-visual::after { content: ""; position: absolute; border-radius: 999px; border: 1px solid rgba(255,255,255,.18); }
.auth-visual::before { width: 480px; height: 480px; right: -210px; top: -160px; }
.auth-visual::after { width: 620px; height: 620px; left: -370px; bottom: -390px; }
.visual-kicker { margin: 28px 0 10px; font-size: 13px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; opacity: .78; }
.auth-visual h1 { margin: 0; font-size: clamp(42px, 5.4vw, 72px); line-height: 1.02; letter-spacing: -.055em; }
.auth-visual > p:not(.visual-kicker) { max-width: 560px; margin: 24px 0; font-size: 17px; line-height: 1.7; color: rgba(255,255,255,.78); }
.security-points { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.security-points span { padding: 10px 13px; border: 1px solid rgba(255,255,255,.2); border-radius: 999px; background: rgba(255,255,255,.08); font-size: 12px; font-weight: 700; }
.auth-panel { position: relative; display: grid; place-items: center; padding: 40px; background: var(--surface); }
.auth-card { width: min(100%, 440px); }
.auth-card h2 { margin: 0; font-size: clamp(32px, 4vw, 46px); letter-spacing: -.04em; }
.auth-card > .muted { line-height: 1.65; margin: 12px 0 30px; }
.mobile-brand { display: none; }
.theme-button-auth { position: absolute; top: 25px; right: 25px; width: auto; padding-inline: 12px; gap: 6px; font-size: 12px; }
.theme-moon { display: none; }
:root[data-theme="dark"] .theme-sun { display: none; }
:root[data-theme="dark"] .theme-moon { display: inline; }
.login-form { display: grid; gap: 11px; }
.login-form label { font-size: 14px; font-weight: 750; }
.password-field { position: relative; }
.password-field input, .search-box input, select {
    width: 100%;
    height: 50px;
    border: 1px solid var(--line);
    border-radius: 12px;
    outline: none;
    color: var(--text);
    background: var(--surface);
    transition: border-color .16s ease, box-shadow .16s ease;
}
.password-field input { padding: 0 75px 0 15px; }
.password-field input:focus, .search-box input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99, 91, 255, .12); }
.password-toggle { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; color: var(--primary); font-weight: 750; cursor: pointer; padding: 9px; }
.alert { margin: 0 0 20px; padding: 13px 14px; border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent); border-radius: 12px; color: var(--danger); background: var(--danger-soft); font-size: 14px; line-height: 1.5; }
.auth-note { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 20px; color: var(--muted); font-size: 12px; }
.auth-note span { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 15%, transparent); }
/* Dashboard */
.topbar { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(16px); }
.topbar-inner { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand > div:last-child { display: grid; gap: 3px; }
.brand strong { font-size: 15px; }
.brand span { color: var(--muted); font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.secure-status { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 700; margin-right: 5px; }
.secure-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 14%, transparent); }
.dashboard { padding-block: 54px 35px; }
.hero { display: flex; align-items: end; justify-content: space-between; gap: 25px; margin-bottom: 28px; }
.hero h1 { margin: 0; font-size: clamp(34px, 5vw, 56px); letter-spacing: -.05em; line-height: 1.02; }
.hero p:last-child { color: var(--muted); margin: 14px 0 0; font-size: 15px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { min-width: 0; display: flex; align-items: center; gap: 13px; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 8px 22px rgba(16,24,40,.035); }
.stat-icon { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 12px; color: var(--primary); background: var(--primary-soft); font-size: 12px; font-weight: 900; }
.stat-card div { min-width: 0; display: grid; gap: 4px; }
.stat-card small { color: var(--muted); font-size: 11px; }
.stat-card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 18px; }
.library-panel { padding: 18px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.library-toolbar { display: grid; grid-template-columns: minmax(250px, 1fr) 180px 175px auto; gap: 10px; }
.search-box { position: relative; }
.search-box span { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 21px; }
.search-box input { padding: 0 14px 0 43px; }
select { padding: 0 36px 0 13px; cursor: pointer; }
.view-switch { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.view-switch button { min-width: 43px; border: 0; background: var(--surface); color: var(--muted); cursor: pointer; }
.view-switch button + button { border-left: 1px solid var(--line); }
.view-switch button.active { color: var(--primary); background: var(--primary-soft); }
.library-summary { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 19px 2px 13px; color: var(--muted); font-size: 12px; }
.library-summary strong { color: var(--text); font-size: 13px; }
.library-summary code, .empty-state code { color: var(--primary); background: var(--primary-soft); padding: 3px 6px; border-radius: 6px; }
.file-list { display: grid; gap: 9px; }
.file-item { display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface-soft); transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease; }
.file-item:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--primary) 35%, var(--line)); box-shadow: 0 9px 25px rgba(16,24,40,.06); }
.file-type { width: 52px; height: 58px; display: grid; place-items: center; position: relative; border-radius: 11px; background: #eceef2; color: #475467; }
.file-type::after { content: ""; position: absolute; right: 0; top: 0; border-style: solid; border-width: 0 0 12px 12px; border-color: transparent transparent rgba(255,255,255,.55) transparent; }
.file-type span { font-size: 10px; font-weight: 900; letter-spacing: .04em; }
.type-archive { background: #fff4e5; color: #b54708; }
.type-document { background: #eaf2ff; color: #175cd3; }
.type-image { background: #ecfdf3; color: #067647; }
.type-video { background: #f4ebff; color: #6941c6; }
.type-audio { background: #fff1f3; color: #c01048; }
.type-app { background: #e8f7f8; color: #087b87; }
.type-code { background: #eef4ff; color: #3538cd; }
.file-main { min-width: 0; }
.file-heading { display: flex; align-items: center; gap: 8px; min-width: 0; }
.file-heading h2 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 0; font-size: 14px; }
.type-badge { flex: 0 0 auto; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: var(--surface); font-size: 9px; font-weight: 800; }
.folder-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.file-meta-row { display: flex; flex-wrap: wrap; gap: 6px 17px; margin-top: 8px; color: var(--muted); font-size: 11px; }
.file-meta-row span { position: relative; }
.file-meta-row span + span::before { content: ""; width: 3px; height: 3px; position: absolute; left: -10px; top: 50%; border-radius: 50%; background: #98a2b3; }
.file-actions { display: flex; align-items: center; gap: 8px; }
.download-button { min-height: 40px; font-size: 12px; padding-inline: 14px; }
.copy-button { width: 40px; height: 40px; }
.file-list.grid-view { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.file-list.grid-view .file-item { min-width: 0; grid-template-columns: 1fr; align-items: start; padding: 18px; }
.file-list.grid-view .file-type { width: 50px; height: 56px; }
.file-list.grid-view .file-actions { width: 100%; margin-top: 5px; }
.file-list.grid-view .download-button { flex: 1; }
.file-list.grid-view .file-meta-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.file-list.grid-view .file-meta-row span + span::before { display: none; }
.empty-state, .no-results { padding: 70px 20px; text-align: center; }
.empty-icon { width: 64px; height: 64px; display: grid; place-items: center; margin: 0 auto 18px; border-radius: 19px; color: var(--primary); background: var(--primary-soft); font-size: 30px; }
.empty-state h2, .no-results h2 { margin: 0; font-size: 22px; }
.empty-state p, .no-results p { max-width: 560px; margin: 10px auto 0; color: var(--muted); line-height: 1.65; }
.footer { display: flex; justify-content: space-between; gap: 20px; margin-top: 20px; color: var(--muted); font-size: 11px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; max-width: calc(100% - 44px); padding: 13px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); opacity: 0; transform: translateY(15px); pointer-events: none; transition: .2s ease; font-size: 13px; font-weight: 700; }
.toast.show { opacity: 1; transform: translateY(0); }
[hidden] { display: none !important; }
@media (max-width: 980px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-visual { display: none; }
    .auth-panel { min-height: 100vh; align-content: center; }
    .mobile-brand { display: flex; align-items: center; gap: 11px; width: min(100%, 440px); position: absolute; top: 24px; left: 50%; transform: translateX(-50%); }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .library-toolbar { grid-template-columns: 1fr 1fr; }
    .search-box { grid-column: 1 / -1; }
    .view-switch { justify-self: end; }
    .file-list.grid-view { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
    .container { width: min(100% - 24px, 1180px); }
    .topbar-inner { min-height: 66px; }
    .brand span, .secure-status, .topbar-actions form { display: none; }
    .dashboard { padding-top: 34px; }
    .hero { align-items: start; flex-direction: column; }
    .hero h1 { font-size: 38px; }
    .refresh-button { width: 100%; }
    .stats-grid { gap: 9px; }
    .stat-card { padding: 14px; }
    .stat-icon { width: 37px; height: 37px; }
    .stat-card strong { font-size: 15px; }
    .library-panel { padding: 12px; border-radius: 16px; }
    .library-toolbar { grid-template-columns: 1fr; }
    .search-box { grid-column: auto; }
    .view-switch { justify-self: stretch; }
    .view-switch button { flex: 1; height: 44px; }
    .library-summary { align-items: start; flex-direction: column; gap: 5px; }
    .file-item { grid-template-columns: auto minmax(0, 1fr); }
    .file-actions { grid-column: 1 / -1; }
    .file-actions .download-button { flex: 1; }
    .file-list.grid-view { grid-template-columns: 1fr; }
    .file-list.grid-view .file-item { grid-template-columns: 1fr; }
    .footer { flex-direction: column; gap: 6px; }
    .auth-panel { padding: 25px 20px; }
    .mobile-brand { width: calc(100% - 40px); }
    .theme-button-auth { top: 25px; right: 20px; }
}
@media (max-width: 420px) {
    .stats-grid { grid-template-columns: 1fr; }
    .file-meta-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
    .file-meta-row span + span::before { display: none; }
}


/* Mobile-first refinements */
html, body { max-width: 100%; overflow-x: hidden; }
body { min-height: 100dvh; }
.button, .icon-button, .view-switch button { touch-action: manipulation; }
.file-heading h2 { overflow-wrap: anywhere; }
.signout-icon { display: none; }

@media (max-width: 680px) {
    body { padding-bottom: env(safe-area-inset-bottom); }
    .container { width: calc(100% - 20px); }
    .topbar { padding-top: env(safe-area-inset-top); }
    .topbar-inner { min-height: 62px; gap: 8px; }
    .brand { min-width: 0; gap: 9px; }
    .brand-mark { width: 39px; height: 39px; border-radius: 12px; }
    .brand > div:last-child { min-width: 0; }
    .brand strong { display: block; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
    .topbar-actions { gap: 6px; }
    .topbar-actions form { display: block; }
    .topbar-actions .icon-button { width: 40px; height: 40px; }
    .signout-button { width: 40px; min-height: 40px; padding: 0; border-radius: 11px; }
    .signout-icon { display: inline; font-size: 19px; line-height: 1; transform: rotate(180deg); }
    .signout-text { display: none; }

    .dashboard { padding-top: 25px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
    .hero { gap: 17px; margin-bottom: 20px; }
    .hero h1 { font-size: clamp(29px, 9vw, 36px); line-height: 1.05; }
    .hero p:last-child { margin-top: 10px; font-size: 13px; line-height: 1.55; }
    .refresh-button { min-height: 46px; }

    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
    .stat-card { min-height: 78px; gap: 10px; padding: 12px; border-radius: 14px; }
    .stat-icon { width: 36px; height: 36px; border-radius: 10px; }
    .stat-card small { font-size: 10px; }
    .stat-card strong { font-size: 14px; }

    .library-panel { margin-inline: -2px; padding: 10px; border-radius: 16px; }
    .library-toolbar { gap: 8px; }
    .password-field input, .search-box input, select { height: 48px; font-size: 16px; }
    .library-toolbar select { min-width: 0; }
    .view-switch { display: none; }
    .library-summary { padding: 14px 2px 10px; font-size: 11px; }
    .library-summary span { line-height: 1.45; }

    .file-list, .file-list.grid-view { grid-template-columns: 1fr; gap: 9px; }
    .file-item, .file-list.grid-view .file-item {
        grid-template-columns: 46px minmax(0, 1fr);
        gap: 11px;
        align-items: start;
        padding: 12px;
        border-radius: 14px;
    }
    .file-type, .file-list.grid-view .file-type { width: 46px; height: 51px; border-radius: 10px; }
    .file-heading { align-items: flex-start; }
    .file-heading h2 {
        white-space: normal;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        line-height: 1.35;
        font-size: 14px;
    }
    .type-badge { margin-top: 1px; }
    .folder-path { margin-top: 4px; }
    .file-meta-row, .file-list.grid-view .file-meta-row {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 5px 8px;
        margin-top: 7px;
        font-size: 10px;
    }
    .file-meta-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .file-meta-row span + span::before { display: none; }
    .file-actions, .file-list.grid-view .file-actions {
        grid-column: 1 / -1;
        width: 100%;
        gap: 8px;
        margin-top: 1px;
    }
    .copy-button { width: 48px; height: 48px; flex: 0 0 48px; }
    .download-button { min-height: 48px; flex: 1; font-size: 13px; }

    .footer { padding-inline: 2px; line-height: 1.5; }
    .toast { left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); max-width: none; text-align: center; }

    .auth-panel { min-height: 100dvh; padding: calc(86px + env(safe-area-inset-top)) 18px calc(30px + env(safe-area-inset-bottom)); }
    .auth-card h2 { font-size: 34px; }
    .auth-card > .muted { margin-bottom: 24px; }
    .mobile-brand { top: calc(18px + env(safe-area-inset-top)); width: calc(100% - 36px); }
    .theme-button-auth { top: calc(18px + env(safe-area-inset-top)); right: 18px; }
    .button-large { min-height: 52px; }
}

@media (max-width: 380px) {
    .container { width: calc(100% - 16px); }
    .brand strong { max-width: 35vw; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-card { display: grid; justify-items: start; min-height: 95px; }
    .library-panel { padding: 8px; }
    .file-item, .file-list.grid-view .file-item { padding: 10px; }
}
