/* ── Variables ── */

:root {
    --grad-dark:       linear-gradient(to bottom, #40464d, #22262b, #373d44);
    --grad-dark-alt:   linear-gradient(to bottom, #4d5560, #2d3238, #434b55);

    --grad-light:      linear-gradient(to bottom, #66707c, #4c545e, #606a76);
    --grad-light-alt:  linear-gradient(to bottom, #718297, #505862, #69798d);

    --grad-header:     linear-gradient(to bottom, #48505a, #17191c, #323841);

    --grad-folder:     linear-gradient(to bottom, #47607a, #2a2f35, #39485d);
    --grad-folder-alt: linear-gradient(to bottom, #607c9c, #3c434c, #506784);

    --grad-hover:      linear-gradient(to bottom, #5b7dab, #365074, #50709d);

    --grad-page:       linear-gradient(to bottom, #7391e2, #3b61c0, #24387b);

    --border-dark:     4px solid #111;
    --border-cell:     1px solid black;

    --radius-panel:    12px 12px 4px 4px;
    --radius-header:   12px 12px 0 0;
}
/* ── Reset ── */

*, *::before, *::after {
    box-sizing: border-box;
    scrollbar-width: none;
    font-family: monospace;
}

input {
    appearance: none;
}

.hidden {
    display: none !important;
}

/* ── Root ── */

html, body {
    height: 100%;
    margin: 0;
}

html {
    background-image: var(--grad-page);
    scroll-behavior: smooth;
}

body {
    height: 100vh;
    padding: 0 8px 8px;
    background-image: var(--grad-page);
    background-attachment: fixed;
    width: 100%;
    color: #eee;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    user-select: none;
}

/* ── Header ── */

header {
    height: 48px;
    border-radius: 0 0 12px 12px;
    display: grid;
    grid-template-columns: 196px minmax(0, 1fr);
    position: sticky;
    top: 0;
    z-index: 10;
    overflow: visible;
    margin-left: 8px;
    margin-right: 8px;
    box-shadow: 0 0 8px black;

}

header div.left {
    background-image: var(--grad-dark);
    border-radius: 0 0 0 12px;
    border: var(--border-dark);
    border-top: none;
    border-right: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: inset 0 0 8px black;
}

header div.left img {
    width: 128px;
}

header div.right {
    background-image: var(--grad-header);
    border-radius: 0 0 12px 0;
    border: var(--border-dark);
    border-top: none;
    border-left: none;
    display: flex;
    align-items: center;
    justify-content: space-between;  /* merged from second def */
}

header div.right div.option {
    background-image: var(--grad-header);
    padding: 4px 10px;
    height: 100%;
    cursor: pointer;
    white-space: nowrap;
    font-size: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

header div.right div.option:hover:not(.disabled) {
    filter: brightness(1.1);
    transition: filter 100ms;
}

header div.right div.option:active {
    background-image: var(--grad-hover);
}

/* ── Main layout ── */

main {
    display: grid;
    grid-template-columns: minmax(0, 20%) minmax(0, 1fr);
    gap: 8px;
    overflow: hidden;
    height: 100%;
    padding: 8px;
}

/* shared panel shell */
main div.left,
main div.right {
    border-radius: var(--radius-panel);
    display: grid;
    grid-template-rows: 48px minmax(0, 1fr);
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    box-shadow: 0 0 8px black;

}

/* left panel: shrink to content height, don't stretch full main height */
main div.left {
    align-self: start;
    grid-template-rows: 48px auto;
}

/* panel header bar */
main div div.header {
    background-image: var(--grad-header);
    border-radius: var(--radius-header);
    border: var(--border-dark);
    border-bottom: none;
    display: flex;
    align-items: center;
    min-width: 0;
    overflow: hidden;
}

main div div.header p {
    margin: 0 0 0 8px;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* panel content area */
main div div.content {
    border: var(--border-dark);
    border-top: none;
    border-radius: 0 0 4px 4px;
    background-color: #333333dc;
    min-width: 0;
    overflow: hidden;
    box-shadow: inset 0 0 8px black;

}

/* ── Left panel — directory list ── */

div.directorylist {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    overflow: hidden;
}

div.directorylist div.directory {
    background-image: var(--grad-dark);
    display: flex;
    align-items: center;
    border: var(--border-cell);
    padding: 4px 8px;
    cursor: pointer;
    min-width: 0;
    min-height: 48px;
    overflow: hidden;
    box-shadow: 0 0 6px black;

}

div.directorylist div.directory p {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    font-size: 1.25em;
}

div.directorylist div.directory:hover {
    filter: brightness(0.9);
    transition: filter 100ms;
}

div.directorylist div.directory:active {
    filter: brightness(0.76);
}

div.directorylist div.directory.active {
    background-image: var(--grad-hover);
}

/* ── Right panel — header tabs ── */

main div.right div.header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 0 8px;
    gap: 8px;
}

main div.right div.header div.headerleft {
    display: flex;
    align-items: center;
    gap: 0;
    overflow-x: auto;
    min-width: 0;
}

main div.right div.header div.headerright {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

main div.right div.header div.headerright input {
    margin-right: 8px;
    padding: 2px 6px;
    border-radius: 6px;
    border: 1px solid #111;
    background-image: var(--grad-light);
    color: #eee;
}

main div.right div.header div.headerright input:focus {
    background-image: var(--grad-light-alt);
    outline: none;
}

div.pathtab {
    background-image: var(--grad-dark-alt);
    padding: 4px 10px;
    cursor: pointer;
    white-space: nowrap;
    font-size: 1em;
    flex-shrink: 0;
    border: 1px solid #111;
    line-height: 1.6;
}

div.pathtab + div.pathtab        { border-left: none; }
div.pathtab:first-child          { border-radius: 6px 0 0 6px; }
div.pathtab:last-child           { border-radius: 0 6px 6px 0; }
div.pathtab:only-child           { border-radius: 6px; }

div.pathtab:hover:not(.disabled) {
    filter: brightness(1.2);
    transition: filter 100ms;
}

div.pathtab.active {
    background-image: var(--grad-hover);
}

div.pathtab.disabled {
    opacity: 0.35;
    cursor: default;
}

div.pathtab.back {
    margin-right: 8px;
    border-radius: 6px;
    border: 1px solid #111;
}

div.pathtab.back + div.pathtab {
    border-left: 1px solid #111;
    border-radius: 6px 0 0 6px;
}

/* ── Right panel — item list ── */

main div.right div.content {
    display: flex;
    overflow-y: scroll;
}

table.itemlist {
    font-family: monospace;
    flex: 1;
    align-self: start;
    min-width: 0;
}

table.itemlist tr {
    text-align: center;
    display: grid;
    grid-template-columns: 4fr 1fr 1fr 1fr 1fr;
    margin: 8px;
    cursor: pointer;
    box-shadow: 0 0 6px black;

}

table.itemlist td {
    background-image: var(--grad-dark);
    padding: 12px;
    border: var(--border-cell);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

table.itemlist td:nth-child(even)       { background-image: var(--grad-dark-alt); }
table.itemlist tr.folder td             { background-image: var(--grad-folder); }
table.itemlist tr.folder td:nth-child(even) { background-image: var(--grad-folder-alt); }

table.itemlist tr:hover td,
table.itemlist tr.folder:hover td       { background-image: var(--grad-hover); transition: background-image 100ms; }

table.itemlist tr:active td,
table.itemlist tr.folder:active td      { filter: brightness(0.9); }

table.itemlist td.name {
    text-align: left;
}

table.itemlist td a {
    font-weight: 100;
    color: #6690ea;
}

/* ── Right panel — preview ── */

.preview-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    padding: 16px;
    overflow: auto;
}

.preview-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

.preview-container video {
    width: 100%;
    max-width: 960px;
    max-height: 100%;
}

.preview-container audio {
    width: 100%;
    max-width: 960px;
}

iframe {
    width: 100%;
    height: 100%;
    border: none;
    overflow: hidden;
}

.preview-container pre {
    width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

.user-dropdown {
    z-index: 999;
}

    /* ── User widget ──────────────────────────────────────── */
        .user-widget {
            position: relative;
            display: flex;
            align-items: center;
            gap: 8px;
            cursor: pointer;
            user-select: none;
            padding: 4px 8px;
            border-radius: 4px;
            transition: filter 0.1s;
        }

        .user-widget:hover { filter: brightness(1.15); }

        .user-widget .avatar {
            width: 28px;
            height: 28px;
            border-radius: 50%;
            object-fit: cover;
            border: 1px solid #111;
            flex-shrink: 0;
            background-image: var(--grad-light);
        }

        .user-widget .avatar.placeholder {
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 12px;
            font-weight: 700;
            background-image: var(--grad-light);
            color: #eee;
            text-transform: uppercase;
            border-radius: 50%;
            width: 28px;
            height: 28px;
        }

        .user-widget .display-name {
            font-size: 13px;
            color: #eee;
            white-space: nowrap;
        }

        .user-widget .chevron {
            font-size: 9px;
            color: #aaa;
            transition: transform 0.15s;
        }

        .user-widget.open .chevron { transform: rotate(180deg); }

        /* Dropdown — uses gradient theme */
        .user-dropdown {
            display: none;
            position: absolute;
            top: calc(100% + 4px);
            right: 0;
            min-width: 170px;
            background-image: var(--grad-header);
            border: 1px solid #111;
            border-radius: 4px;
            overflow: hidden;
            z-index: 200;
            box-shadow: 0 6px 20px rgba(0,0,0,0.6);
        }

        .user-widget.open .user-dropdown { display: block; }

        .user-dropdown .dd-header {
            padding: 10px 14px 8px;
            border-bottom: 1px solid #222;
            background-image: var(--grad-dark);
        }

        .user-dropdown .dd-uid {
            font-size: 10px;
            font-family: monospace;
            color: #888;
            letter-spacing: 0.05em;
        }

        .user-dropdown .dd-name {
            font-size: 13px;
            font-weight: 600;
            color: #eee;
            margin-top: 2px;
        }

        .user-dropdown .dd-item {
            display: block;
            width: 100%;
            text-align: left;
            padding: 9px 14px;
            background: none;
            border: none;
            color: #eee;
            font-size: 13px;
            font-family: monospace;
            cursor: pointer;
            text-decoration: none;
            transition: filter 0.1s;
        }

        .user-dropdown .dd-item:hover { filter: brightness(1.3); }
        .user-dropdown .dd-item.danger { color: #ff7070; }

        .header-right-user {
            display: flex;
            align-items: center;
            height: 100%;
            padding: 0 8px;
            flex-shrink: 0;
            border-left: 2px solid #111;
            overflow: visible;
        }

        /* ── Upload button ────────────────────────────────────── */
        .header-upload {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 0 12px;
            height: 100%;
        }

        .header-upload input[type="file"] { display: none; }

        .btn-upload {
            display: flex;
            align-items: center;
            gap: 6px;
            padding: 0 14px;
            height: 32px;
            background-image: var(--grad-dark-alt);
            border: 1px solid #111;
            border-radius: 6px;
            color: #eee;
            font-family: monospace;
            font-size: 13px;
            cursor: pointer;
            white-space: nowrap;
            transition: filter 0.1s;
            box-shadow: 0 0 4px black;
        }

        .btn-upload:hover  { filter: brightness(1.25); }
        .btn-upload:active { filter: brightness(0.9); }

        .upload-progress {
            font-size: 11px;
            font-family: monospace;
            color: #aaa;
            white-space: nowrap;
        }

        /* ── Owner badge ──────────────────────────────────────── */
        .owner-badge {
            display: inline-block;
            font-size: 11px;
            font-family: monospace;
            color: #aac4ff;
            background: rgba(100, 140, 220, 0.15);
            border: 1px solid rgba(100, 140, 220, 0.3);
            border-radius: 3px;
            padding: 1px 6px;
        }

        .owner-badge.unix {
            color: #555;
            background: none;
            border-color: transparent;
        }

        /* ── Action buttons ───────────────────────────────────── */
        .action-cell {
            display: flex;
            align-items: center;
            gap: 6px;
            justify-content: flex-end;
        }

        .btn-icon {
            background: none;
            border: 1px solid transparent;
            border-radius: 3px;
            color: #aaa;
            font-size: 13px;
            font-family: monospace;
            cursor: pointer;
            padding: 2px 7px;
            transition: border-color 0.12s, color 0.12s, background 0.12s;
            white-space: nowrap;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
        }

        .btn-icon:hover {
            color: #eee;
            border-color: #444;
            background: rgba(255,255,255,0.06);
        }

        .btn-icon.danger:hover {
            color: #ff7070;
            border-color: rgba(255, 80, 80, 0.5);
            background: rgba(255, 80, 80, 0.08);
        }

        /* ── Delete modal — gradient theme ────────────────────── */
        .confirm-overlay {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.6);
            z-index: 300;
            align-items: center;
            justify-content: center;
        }

        .confirm-overlay.active { display: flex; }

        .confirm-box {
            width: 100%;
            max-width: 320px;
            border-radius: var(--radius-panel);
            box-shadow: 0 0 32px rgba(0,0,0,0.8);
            overflow: hidden;
        }

        .confirm-box-header {
            background-image: var(--grad-header);
            border-radius: var(--radius-header);
            border: var(--border-dark);
            border-bottom: none;
            height: 40px;
            display: flex;
            align-items: center;
            padding: 0 14px;
            font-size: 13px;
            font-weight: 700;
            color: #eee;
        }

        .confirm-box-body {
            background-color: #333333dc;
            border: var(--border-dark);
            border-top: none;
            border-radius: 0 0 4px 4px;
            padding: 16px 16px 18px;
            display: flex;
            flex-direction: column;
            gap: 14px;
            box-shadow: inset 0 0 8px black;
        }

        .confirm-box-body p {
            font-size: 13px;
            color: #eee;
            line-height: 1.5;
            margin: 0;
        }

        .confirm-box-body p strong {
            color: #ff7070;
            font-weight: 700;
        }

        .confirm-actions {
            display: flex;
            gap: 8px;
            justify-content: flex-end;
        }

        .btn-modal {
            padding: 6px 16px;
            border-radius: 4px;
            border: 1px solid #111;
            font-family: monospace;
            font-size: 12px;
            font-weight: 600;
            cursor: pointer;
            transition: filter 0.1s;
        }

        .btn-modal.cancel {
            background-image: var(--grad-dark-alt);
            color: #eee;
        }

        .btn-modal.cancel:hover { filter: brightness(1.2); }

        .btn-modal.delete {
            background-image: linear-gradient(to bottom, #8b2020, #5a1010, #7a1c1c);
            color: #ffaaaa;
        }

        .btn-modal.delete:hover { filter: brightness(1.25); }

        /* ── Directory visibility label ───────────────────────── */
        div.directorylist div.directory {
            flex-direction: column;
            align-items: flex-start;
            gap: 2px;
        }

        div.directorylist div.directory .dir-label {
            font-size: 1.1em;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            min-width: 0;
            width: 100%;
        }

        div.directorylist div.directory .dir-vis {
            font-size: 0.75em;
            color: #778;
            letter-spacing: 0.04em;
        }

        div.directorylist div.directory.active .dir-vis { color: #aac; }