:root {
    color-scheme: light;
    --bg: #f8fafd;
    --panel: #ffffff;
    --panel-muted: #f1f5fb;
    --line: #dde5f0;
    --line-strong: #cad5e5;
    --text: #1f2937;
    --muted: #64748b;
    --accent: #6366f1;
    --accent-strong: #4f46e5;
    --danger: #c53929;
    --success: #188038;
    --radius: 18px;
    --shadow: 0 8px 24px rgba(34, 55, 88, 0.06);
    --wrap: 1440px;
}

html.dark {
    color-scheme: dark;
    --bg: #0f1723;
    --panel: #16202f;
    --panel-muted: #1d2a3b;
    --line: #2a3950;
    --line-strong: #36506f;
    --text: #eff5ff;
    --muted: #97a6ba;
    --accent: #a5b4fc;
    --accent-strong: #c7d2fe;
    --danger: #f28b82;
    --success: #81c995;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.24);
}

@media (prefers-color-scheme: dark) {
    html:not(.light) {
        color-scheme: dark;
    }
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Ubuntu, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.4;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
progress {
    font: inherit;
}

button {
    appearance: none;
}

.wrap {
    width: min(var(--wrap), calc(100vw - 2rem));
    margin: 0 auto;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--panel) 94%, transparent);
    backdrop-filter: blur(10px);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0;
}

.brand-lockup {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.04em;
}

.brand-mark {
    display: block;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.brand-note {
    color: var(--muted);
    font-size: 0.82rem;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    min-height: 2.2rem;
    padding: 0.45rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--panel-muted);
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
}

.app-shell,
.login-shell {
    padding: 1rem 0 2rem;
}

.drive-layout {
    display: grid;
    gap: 1rem;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
}

.listing-header h2,
.login-card h1,
.dialog-header h2 {
    margin: 0.2rem 0 0;
    font-size: clamp(1.15rem, 1.9vw, 1.6rem);
    line-height: 1.1;
    letter-spacing: -0.04em;
}

.eyebrow {
    margin: 0;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.72rem;
    font-weight: 700;
}

.panel-note,
.hero-copy,
.listing-note,
.item-meta,
.status-line {
    color: var(--muted);
}

.nav-list {
    display: grid;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.nav-item {
    display: grid;
    gap: 0.15rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel-muted);
    padding: 0.75rem 0.85rem;
}

.nav-item-active {
    border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
    background: color-mix(in srgb, var(--accent) 8%, var(--panel));
}

.drop-target {
    transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.drop-target.drag-active {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, var(--panel));
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent);
}

.nav-item-title {
    font-size: 0.86rem;
    font-weight: 600;
}

.nav-item-meta {
    color: var(--muted);
    font-size: 0.8rem;
    word-break: break-word;
}

.sidebar-current {
    margin-top: 0.65rem;
    font-size: 0.95rem;
    font-weight: 600;
}

.stack-form,
.login-form label,
.dialog-card label {
    display: grid;
    gap: 0.45rem;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="file"] {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    color: var(--text);
    padding: 0.72rem 0.85rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

input::placeholder {
    color: var(--muted);
    opacity: 1;
}

input[type="file"] {
    color: var(--text);
}

input[type="file"]::file-selector-button {
    margin-right: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel-muted);
    color: var(--text);
    padding: 0.45rem 0.7rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

input[type="file"]::-webkit-file-upload-button {
    margin-right: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel-muted);
    color: var(--text);
    padding: 0.45rem 0.7rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
}

.toolbar-shell {
    padding: 0.85rem 1rem;
}

.toolbar-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.toolbar-left {
    min-width: 0;
}

.crumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.crumbs a {
    display: inline-flex;
    align-items: center;
    min-height: 2rem;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    background: var(--panel-muted);
    border: 1px solid var(--line);
    font-size: 0.86rem;
    font-weight: 600;
}

.toolbar-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    margin-top: 0.45rem;
    color: var(--muted);
    font-size: 0.84rem;
}

.toolbar-search {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: min(30rem, 100%);
}

.toolbar-search input[type="search"] {
    flex: 1;
    min-width: 12rem;
    background: var(--panel-muted);
}

.actions-shell {
    padding: 0.85rem 1rem 1rem;
}

.actions-tabs {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin-bottom: 0.85rem;
    flex-wrap: wrap;
}

.action-tab {
    display: inline-flex;
    align-items: center;
    min-height: 2rem;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel-muted);
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 600;
}

.action-tab-active {
    background: color-mix(in srgb, var(--accent) 8%, var(--panel));
    color: var(--accent);
    border-color: color-mix(in srgb, var(--accent) 30%, var(--line));
}

.actions-grid {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 0.75rem;
}

.action-card {
    align-content: start;
    padding: 0.85rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel-muted);
}

.action-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--muted);
}

.compact-note {
    font-size: 0.82rem;
    margin: 0;
}

.button-row,
.inline-form,
.actions-cell,
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.inline-form,
.actions-cell {
    flex-wrap: nowrap;
}

.checkbox-row {
    color: var(--muted);
}

.primary-button,
.ghost-button,
.danger-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.35rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    padding: 0.58rem 0.95rem;
    cursor: pointer;
    font-weight: 700;
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.primary-button:hover,
.ghost-button:hover,
.danger-button:hover {
    transform: translateY(-1px);
}

.primary-button {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.primary-button:hover {
    background: var(--accent-strong);
}

.ghost-button {
    background: transparent;
    color: var(--text);
}

.ghost-button:hover {
    border-color: var(--line-strong);
    background: color-mix(in srgb, var(--panel-muted) 75%, transparent);
}

.danger-button {
    border-color: color-mix(in srgb, var(--danger) 40%, var(--line));
    color: var(--danger);
    background: transparent;
}

.danger-button:hover {
    background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.small {
    min-height: 1.95rem;
    padding: 0.36rem 0.68rem;
    font-size: 0.8rem;
}

.actions-cell {
    white-space: nowrap;
}

.actions-cell .ghost-button,
.actions-cell .danger-button,
.actions-cell .inline-form {
    flex: 0 0 auto;
}

.actions-cell .ghost-button,
.actions-cell .danger-button {
    min-width: 6rem;
}

.actions-cell .inline-form {
    margin: 0;
}

.listing-panel {
    overflow: hidden;
    padding: 0;
}

.listing-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.45rem 1rem 0.9rem;
    border-bottom: 1px solid var(--line);
}

.listing-note {
    margin: 0;
    font-size: 0.84rem;
}

.listing-table {
    width: 100%;
    border-collapse: collapse;
}

.listing-table th,
.listing-table td {
    padding: 0.8rem 1rem;
    border-top: 1px solid var(--line);
    vertical-align: middle;
}

.listing-table thead th {
    border-top: 0;
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    background: color-mix(in srgb, var(--panel-muted) 70%, transparent);
}

.listing-table tbody tr:hover {
    background: color-mix(in srgb, var(--panel-muted) 42%, transparent);
}

.item-row-draggable {
    cursor: grab;
}

.item-row-draggable.is-dragging {
    opacity: 0.45;
}

.name-cell {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.item-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 10px;
    border: 1px solid var(--line);
    font-size: 0.76rem;
    font-weight: 800;
    background: var(--panel-muted);
}

.item-icon-folder {
    color: var(--accent);
}

.item-icon-file {
    color: var(--muted);
}

.item-link {
    font-weight: 600;
    font-size: 0.92rem;
}

.item-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 3.9rem;
    padding: 0.28rem 0.52rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--panel-muted);
    font-size: 0.72rem;
    font-weight: 700;
}

.badge-folder {
    color: var(--accent);
}

.badge-file {
    color: var(--muted);
}

.item-meta {
    margin-top: 0.18rem;
    font-size: 0.74rem;
}

.empty-state {
    padding: 2.5rem 1rem;
    text-align: center;
    color: var(--muted);
}

.flash {
    margin-bottom: 1rem;
    border-radius: 14px;
    border: 1px solid var(--line);
    padding: 0.8rem 0.95rem;
    background: var(--panel);
}

.flash-success {
    border-color: color-mix(in srgb, var(--success) 45%, var(--line));
}

.flash-error {
    border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
}

.upload-panel.is-drop-target {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, var(--panel));
}

progress {
    width: 100%;
    margin-top: 0.6rem;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
}

.login-card {
    width: min(30rem, 100%);
}

.login-form {
    display: grid;
    gap: 0.95rem;
}

.rename-dialog {
    border: 0;
    padding: 0;
    background: transparent;
}

.rename-dialog::backdrop {
    background: rgba(8, 15, 28, 0.5);
}

.dialog-card {
    width: min(28rem, calc(100vw - 2rem));
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 1rem;
}

.dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.7rem;
    margin-top: 1rem;
}

@media (max-width: 1080px) {
    .drive-layout {
        grid-template-columns: 1fr;
    }

    .toolbar-main,
    .listing-header {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-search {
        min-width: 0;
        width: 100%;
    }

    .actions-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 780px) {
    .topbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .top-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .toolbar-search,
    .actions-cell,
    .inline-form,
    .dialog-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .listing-table,
    .listing-table thead,
    .listing-table tbody,
    .listing-table tr,
    .listing-table th,
    .listing-table td {
        display: block;
        width: 100%;
    }

    .listing-table thead {
        display: none;
    }

    .listing-table tbody tr {
        padding: 0.8rem 0;
        border-top: 1px solid var(--line);
    }

    .listing-table td {
        border: 0;
        padding: 0.35rem 1rem;
    }
}

/* --- UI polish (move dialog, drag feedback, icon glyphs) --- */
select {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border-radius: 12px;
    border: 1px solid var(--line-strong);
    background: var(--panel);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

select:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.move-select {
    max-width: 100%;
}

.drop-target.drag-active {
    outline: 2px dashed var(--accent);
    outline-offset: -4px;
}

.item-icon {
    overflow: hidden;
}

.item-icon-folder {
    background: color-mix(in srgb, var(--accent) 13%, var(--panel-muted));
    border-color: color-mix(in srgb, var(--accent) 26%, var(--line));
}

.item-row:hover {
    background: color-mix(in srgb, var(--accent) 5%, var(--panel));
}

/* ============================================================
   Modern layout overhaul — app bar, path bar, menus, listing
   ============================================================ */
body {
    background:
        radial-gradient(1100px 560px at 100% -8%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 60%),
        radial-gradient(900px 520px at -8% 2%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 55%),
        var(--bg);
    background-attachment: fixed;
}

.appbar {
    position: sticky;
    top: 0;
    z-index: 30;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--panel) 80%, transparent);
    backdrop-filter: saturate(1.4) blur(14px);
}

.appbar-inner {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 1rem;
    padding: 0.7rem 0;
}

.appbar-search {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 34rem;
    justify-self: center;
}

.appbar-search .search-ic {
    position: absolute;
    left: 0.9rem;
    color: var(--muted);
    pointer-events: none;
}

.appbar-search input[type="search"] {
    width: 100%;
    height: 2.6rem;
    padding: 0 2.4rem 0 2.6rem;
    border-radius: 999px;
    background: var(--panel-muted);
}

.appbar-search input[type="search"]:focus {
    background: var(--panel);
}

.search-clear {
    position: absolute;
    right: 0.55rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 999px;
    color: var(--muted);
    font-size: 1.15rem;
    line-height: 1;
}

.search-clear:hover {
    background: var(--panel);
    color: var(--text);
}

/* Path bar */
.pathbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.path {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.1rem;
    min-width: 0;
    font-size: 0.95rem;
}

.path-seg {
    padding: 0.35rem 0.6rem;
    border-radius: 9px;
    font-weight: 600;
    color: var(--muted);
    transition: background 0.15s ease, color 0.15s ease;
}

.path-seg:last-child {
    color: var(--text);
}

.path-seg:hover {
    background: var(--panel-muted);
    color: var(--text);
}

.path-sep {
    color: var(--muted);
    opacity: 0.45;
}

.pathbar-actions {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

/* <details>-based disclosure menus (New folder / Upload / row kebab) */
.menu {
    position: relative;
}

.menu > summary,
.rowmenu > summary {
    list-style: none;
    cursor: pointer;
    gap: 0.4rem;
}

.menu > summary::-webkit-details-marker,
.rowmenu > summary::-webkit-details-marker {
    display: none;
}

.menu > summary::marker,
.rowmenu > summary::marker {
    content: "";
}

.menu-panel {
    position: absolute;
    z-index: 40;
    top: calc(100% + 0.5rem);
    right: 0;
    min-width: 17.5rem;
    padding: 0.9rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 18px 44px rgba(20, 30, 60, 0.16);
    animation: menupop 0.14s ease;
}

@keyframes menupop {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: none; }
}

/* Row kebab menu */
.rowmenu {
    position: relative;
    display: inline-flex;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.15rem;
    height: 2.15rem;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-button:hover,
.rowmenu[open] > .icon-button {
    background: var(--panel-muted);
    color: var(--text);
    border-color: var(--line);
}

.rowmenu-panel {
    min-width: 12rem;
    padding: 0.4rem;
}

.menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.7rem;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
}

.menu-item:hover {
    background: var(--panel-muted);
}

.menu-item-danger {
    color: var(--danger);
}

.menu-item-danger:hover {
    background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.rowmenu-panel form {
    margin: 0;
}

/* Listing refinements */
.table-scroll {
    overflow-x: auto;
}

.col-actions {
    width: 3rem;
}

.col-num {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.col-muted {
    color: var(--muted);
    white-space: nowrap;
}

.actions-cell {
    text-align: right;
}

/* Empty state */
.empty-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 4rem;
    height: 4rem;
    margin-bottom: 0.5rem;
    border-radius: 18px;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, var(--panel-muted));
    border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line));
}

/* Login brand lockup */
.login-brand {
    font-size: 1.45rem;
    margin-bottom: 0.6rem;
}

.login-brand .brand-mark {
    width: 34px;
    height: 34px;
}

/* Softer, larger listing card */
.listing-panel {
    border-radius: 20px;
}

@media (max-width: 720px) {
    .appbar-inner {
        grid-template-columns: auto auto;
        row-gap: 0.6rem;
    }
    .appbar-search {
        grid-column: 1 / -1;
        order: 3;
        max-width: none;
    }
    .col-hide {
        display: none;
    }
}
