/* ── МОДАЛЬНЫЕ ОКНА ── */
#ui-modal-overlay, #lock-overlay, #editor-overlay {
    display: flex;
    position: fixed;
    inset: 0;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.75);
    z-index: 200;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease, visibility 0s linear 0.28s;
}

#ui-modal-overlay.open, #lock-overlay.open, #editor-overlay.open {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.28s ease;
}

#ui-modal-box, #lock-box {
    background: var(--window);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 20px;
    width: 320px;
    max-width: 90vw;
    transform: translateY(6px) scale(0.98);
    transition: transform 0.28s ease;
}

#ui-modal-overlay.open > #ui-modal-box,
#lock-overlay.open > #lock-box,
#editor-overlay.open > #editor-box {
    transform: translateY(0) scale(1);
}

#ui-modal-title, #lock-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 12px;
}

#ui-modal-input, #lock-input {
    width: 100%;
    padding: 8px;
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: var(--r);
    font-size: 12px;
    color: var(--text);
    margin-bottom: 12px;
}

.ui-modal-btns {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.ui-modal-btns button, #lock-box button {
    padding: 6px 14px;
    border-radius: var(--r);
    font-size: 12px;
}

.btn-sub { background: var(--tab); color: var(--dim); }
.btn-act { background: var(--accent); color: var(--bg); }
.btn-act.danger { background: var(--accent); color: var(--bg); }

#lock-close {
    position: absolute;
    top: 8px;
    right: 10px;
    cursor: pointer;
}

#editor-box {
    width: 860px;
    max-width: 96vw;
    height: 82vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--r);
}

#editor-head {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--tab);
    border-bottom: 1px solid var(--line);
}

#editor-ta {
    flex: 1;
    padding: 12px;
    font-family: monospace;
    font-size: 12px;
    background: var(--bg);
    color: var(--text);
    border: none;
    resize: none;
}

/* ── КОНТЕКСТНОЕ МЕНЮ ── */
.ctx {
    display: block;
    position: fixed;
    min-width: 160px;
    padding: 4px 0;
    background: var(--tab);
    border: 1px solid var(--line);
    border-radius: calc(var(--r) + 2px);
    z-index: 100;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
}

.ctx.open {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.ctx div { padding: 6px 12px; font-size: 12px; cursor: pointer; color: var(--dim); }
.ctx div:hover { background: var(--field); color: var(--text); }
.ctx hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }
.ctx .ctx-tile-section { padding: 7px 10px; cursor: default; color: var(--dim); font-size: 11px; }
.ctx .ctx-tile-section:hover { background: transparent; color: var(--dim); }
.ctx-tile-buttons { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; margin: 0; }
.ctx .ctx-tile-buttons { padding: 0; background: transparent; cursor: default; }
.ctx-tile-buttons button { grid-column: span 2; display: flex; align-items: center; justify-content: center; min-width: 0; aspect-ratio: 1; height: auto; padding: 3px; border: 0; border-radius: 4px; background: var(--field); color: var(--dim); cursor: pointer; }
.ctx-tile-buttons button:nth-child(5) { grid-column: 2 / span 2; }
.ctx-tile-buttons button:hover { background: var(--tab); color: var(--text); }
.ctx-tile-buttons button[aria-pressed="true"] { background: rgba(255,62,62,.12); color: var(--accent); box-shadow: inset 0 0 0 1px rgba(255,62,62,.45); }
#ctx { min-width: 0; width: 140px; }
#ctx > div:not(.ctx-tile-section) { text-align: left; text-transform: lowercase; padding: 6px 10px; }
#ctx [aria-disabled="true"], #ctx [aria-disabled="true"]:hover { opacity: .38; cursor: default; background: transparent; color: var(--dim); }
#ctx .ctx-tile-section { padding: 6px 10px; }
#ctx .ctx-tile-buttons { width: 116px; margin: 0 auto; }
.ctx-tile-buttons button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-preset-icon { display: grid; grid-template: repeat(2, 7px) / repeat(2, 7px); gap: 2px; pointer-events: none; }
.tile-preset-icon > span { border-radius: 1px; }
.tile-preset-icon > .filled { background: currentColor; }
.styler-tile-size { display: flex; flex-direction: column; gap: 4px; color: var(--dim); font-size: 11px; }
.styler-tile-size .ctx-tile-buttons { margin-top: 0; }
.bundle-pocket { position: fixed; z-index: 260; width: min(340px, calc(100vw - 20px)); max-height: min(360px, calc(100dvh - 20px)); overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--window); box-shadow: 0 18px 50px #000a; color: var(--text); }
.bundle-pocket[hidden] { display: none; }
.bundle-pocket-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; padding: 0 8px 0 12px; border-bottom: 1px solid var(--line); background: var(--tab); font-size: 12px; }
.bundle-pocket-head > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bundle-pocket-head > div { display: flex; gap: 4px; }
.bundle-pocket-head button { width: 28px; height: 28px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; }
.bundle-pocket-head button:hover { border-color: var(--line); background: var(--field); }
.bundle-pocket-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 6px; max-height: 310px; overflow: auto; padding: 10px; font-size: 11px; color: var(--dim); }
.bundle-pocket-grid.dragover { outline: 1px dashed var(--accent); outline-offset: -3px; }
.bundle-pocket-entry { min-width: 0; padding: 9px 7px; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: var(--field); color: var(--text); text-overflow: ellipsis; white-space: nowrap; cursor: grab; }
.bundle-pocket-entry:hover { border-color: var(--accent); }

/* ── СКРОЛЛБАР ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #333; border-radius: var(--r); }
* { scrollbar-width: thin; scrollbar-color: #333 var(--bg); }

/* ── ПРОСТОРНЫЙ DESKTOP-РЕЖИМ ──
   Увеличивает каркас интерфейса, а не масштабирует весь DOM. */
@media (min-width: 900px) {
    #scaled-app {
        height: calc(100dvh - 48px);
    }

    #tabs {
        padding: 10px 12px 0;
        gap: 4px;
    }

    .tab {
        gap: 8px;
        padding: 9px 18px;
        font-size: 15px;
    }

    #tab-add {
        padding: 6px 12px;
        font-size: 22px;
    }

    #navbar {
        height: 48px;
    }

    #nav-left,
    #sidebar {
        width: 220px;
        min-width: 220px;
    }



    #nav-left {
        box-sizing: border-box;
        flex: 0 0 220px;
        gap: 6px;
        padding: 0 10px;
    }
    #nav-left .nav-btn { flex: 1; min-width: 0; height: 42px; }

    .nav-btn {
        height: 34px;
        min-width: 36px;
        padding: 0 8px;
        font-size: 17px;
    }

    #path-bar {
        height: 34px;
        margin: 0 12px;
        padding: 0 14px;
        font-size: 15px;
    }

    #nav-right {
        box-sizing: border-box;
        width: 220px;
        min-width: 220px;
        flex: 0 0 220px;
        padding: 0 12px;
    }

    #search-box {
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        height: 34px;
        padding: 0 12px;
        font-size: 14px;
    }

    .win-row {
        height: 34px;
        padding-right: 10px;
        font-size: 14px;
    }

    .win-chevron {
        width: 22px;
        height: 22px;
        min-width: 22px;
        margin-right: 6px;
    }

    .win-arrow {
        width: 11px !important;
        height: 11px !important;
        max-width: 11px;
        max-height: 11px;
    }

    .win-icon {
        margin-right: 8px;
        font-size: 18px;
    }

    .win-sub {
        padding-left: 22px;
    }

    /* Профиль остаётся на своём месте над нижней полосой. */
    #profile {
        position: fixed;
        left: 0;
        bottom: 48px;
        width: 220px;
        max-height: calc(100dvh - 150px);
        padding: 12px;
        border-bottom: 0;
    }

    /* Высоту дерева задаёт JS по верхней границе профиля. */
    #tree-wrap {
        flex: 0 0 auto;
        overflow-y: auto;
        padding: 16px 8px 8px 10px;
    }

    #auth-compact-row {
        gap: 10px;
        height: 60px;
    }

    #avatar {
        width: 56px;
        height: 56px;
        min-width: 56px;
        min-height: 56px;
    }

    #login-fields {
        gap: 6px;
    }

    #login-fields input {
        height: 27px;
        padding: 3px 8px;
        font-size: 13px;
    }

    #p-name {
        font-size: 14px;
    }

    #quota-txt,
    .chk-text {
        font-size: 12px;
    }

    .custom-remember {
        gap: 7px;
        margin: 8px 0 7px;
    }

    .custom-chk-box {
        width: 17px;
        height: 17px;
    }

    #auth-btns {
        gap: 6px;
    }

    .auth-btn {
        height: 32px;
        min-height: 32px;
        font-size: 13px;
    }

    #user-controls {
        gap: 6px;
        margin-top: 8px;
    }

    .profile-actions-column {
        gap: 6px;
    }


    .auth-exit-btn {
        width: 72px;
        min-width: 72px;
        max-width: 72px;
        height: 30px;
        min-height: 30px;
        font-size: 12px;
        margin-top: 0;
    }

    #footer-links {
        height: 48px;
    }

    #scale-bar {
        left: 220px;
        bottom: 48px;
        height: 48px;
        gap: 10px;
        padding: 0 14px;
        font-size: 13px;
    }

    .scale-btn,
    .scale-value {
        height: 32px;
    }

    .scale-btn {
        width: 32px;
        min-width: 32px;
        font-size: 20px;
    }

    #scale-readout {
        width: 52px;
        min-width: 52px;
        flex: 0 0 52px;
    }

    .space-mode-toggle {
        width: 78px;
        min-width: 78px;
        flex: 0 0 78px;
    }

    .scale-value {
        height: 32px;
        font-size: 13px;
    }

    #action-bar {
        right: 14px;
        gap: 6px;
        padding: 7px;
    }

    .act-btn {
        width: 40px;
        height: 38px;
        min-width: 40px;
        min-height: 38px;
        font-size: 19px;
    }
}

/* Равные боковые колонки удерживают ползунок на оси экрана. */
#scale-bar { left: 0; display: grid; grid-template-columns: 272px minmax(0, 1fr) 272px; column-gap: 10px; box-sizing: border-box; }
.scale-left, .scale-right, .scale-center { display: flex; align-items: center; gap: 8px; min-width: 0; }
.scale-left { justify-content: flex-end; }
.scale-right { justify-content: flex-end; width: 100%; }
.scale-center { position: static; transform: none; width: 100%; }
.scale-center .scale-btn { flex: 0 0 auto; }
#ui-scale { flex: 1 1 0; width: 0; min-width: 0; margin: 0; }
#scale-readout { width: 52px; min-width: 52px; flex: 0 0 52px; }
#scale-readout .scale-label-value { display: inline; }
#marafet-toggle { width: 78px; min-width: 78px; flex: 0 0 78px; }
#space-mode-toggle { width: 77px; min-width: 77px; flex: 0 0 77px; }
#hidden-files-toggle { transform: translateX(-3px); }
#hidden-files-toggle { flex: 0 0 auto; }
#scale-bar #alphabet-sort { flex: 1 1 37px; width: auto; min-width: 24px; padding: 0 3px; font-size: inherit; }
#marafet-toggle:disabled, #space-mode-toggle:disabled { opacity: .4; cursor: default; color: var(--dim); }
#marafet-toggle:disabled:hover, #space-mode-toggle:disabled:hover { background: var(--field); border-color: var(--line); }
#scale-bar [hidden] { display: none !important; }
.my-folder-compact { display: none; }
#profile { --profile-avatar-side: 52px; --profile-button-height: 30px; --profile-trash-side: 36px; --profile-gap: 4px; --profile-inset: 8px; padding: var(--profile-inset); border-bottom: 1px solid var(--line); }
#auth-compact-row { height: var(--profile-avatar-side); gap: var(--profile-gap); }
#profile #user-controls { margin-top: var(--profile-gap); }
#avatar { width: var(--profile-avatar-side); height: var(--profile-avatar-side); min-width: var(--profile-avatar-side); min-height: var(--profile-avatar-side); border-radius: 10px; }
#quota-wrap { width: 100%; align-self: stretch; }
.profile-actions-column { width: 100%; display: grid; grid-template-columns: var(--profile-avatar-side) minmax(0, 1fr) var(--profile-trash-side); grid-template-rows: repeat(2, var(--profile-button-height)); gap: var(--profile-gap); }
.profile-actions-row { display: contents; }
#profile .auth-exit-btn, #profile #btn-profile-trash { width: 100%; min-width: 0; max-width: none; margin: 0; padding: 0 2px; font: inherit; font-size: 10px; font-weight: 400; line-height: 1; white-space: nowrap; color: var(--dim); background: var(--field); border: 1px solid var(--line); border-radius: var(--r); transform: none; opacity: 1; }
#profile .auth-exit-btn { height: var(--profile-button-height); min-height: var(--profile-button-height); }
#btn-public-page { grid-column: 1; grid-row: 1; }
#btn-my-folder { grid-column: 2; grid-row: 1; }
#profile #btn-logout { grid-column: 1; grid-row: 2; border-color: rgba(255,62,62,.45); }
#profile #btn-profile-trash { grid-column: 3; grid-row: 1 / span 2; height: calc(var(--profile-button-height) * 2 + var(--profile-gap)); min-height: calc(var(--profile-button-height) * 2 + var(--profile-gap)); align-self: stretch; border-color: rgba(255,62,62,.45); cursor: not-allowed; }
#profile .auth-exit-btn:hover { background: rgba(255,255,255,.04); color: var(--dim); }
#profile .auth-exit-btn:focus-visible { outline: 1px solid var(--dim); outline-offset: 2px; }
#btn-profile-trash svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
@media (min-width: 900px) {
    #profile { --profile-avatar-side: 64px; --profile-button-height: 30px; --profile-trash-side: 40px; --profile-gap: 6px; --profile-inset: 12px; }
    #profile .auth-exit-btn, #profile #btn-profile-trash { font-size: 13px; }
}

#path-bar, #search-box { background: #242424; }
#navbar > #btn-refresh { flex: 0 0 34px; min-width: 34px; margin-right: 4px; transform: none; }
@media (max-width: 899px) {
    #navbar { display: grid; grid-template-columns: minmax(96px, .8fr) 30px minmax(0, 1fr); grid-template-rows: 36px 30px; gap: 0 4px; height: auto; padding: 0 6px; box-sizing: border-box; }
    #nav-left { grid-column: 1; grid-row: 1; width: 100%; min-width: 0; padding: 0; gap: 2px; box-sizing: border-box; }
    #nav-left .nav-btn { flex: 1; min-width: 0; height: 30px; padding: 0 4px; }
    #navbar > #btn-refresh { grid-column: 2; grid-row: 1; width: 30px; min-width: 0; height: 30px; margin: 0; padding: 0; }
    #nav-right { grid-column: 3; grid-row: 1; width: 100%; min-width: 0; padding: 0; margin: 0; box-sizing: border-box; }
    #search-box { width: 100%; max-width: 100%; min-width: 0; padding: 0 6px; box-sizing: border-box; }
    #path-bar { grid-column: 1 / -1; grid-row: 2; width: auto; min-width: 0; margin: 0; height: 26px; padding: 0 6px; }
    #scale-bar { height: 72px; grid-template-columns: 52px minmax(0, 1fr); grid-template-rows: 26px 26px; gap: 6px 4px; padding: 6px; align-items: center; }
    .scale-left { grid-column: 1; grid-row: 1; }
    .scale-right { grid-column: 2; grid-row: 1; gap: 4px; }
    .scale-center { grid-column: 1 / -1; grid-row: 2; gap: 8px; }
    #marafet-toggle { width: 68px; min-width: 68px; flex-basis: 68px; }
    #space-mode-toggle { width: 67px; min-width: 67px; flex-basis: 67px; }
    #hidden-files-toggle { transform: translateX(-3px); }
    #profile { bottom: 110px; }
    #main { padding-bottom: 124px; }
    .my-folder-wide { display: none; }
    .my-folder-compact { display: inline; }
}
@media (max-width: 360px) {
    #profile { --profile-avatar-side: 46px; --profile-trash-side: 32px; }
}
@media (max-width: 360px) {
    #profile .auth-exit-btn { font-size: 9px; }
}

/* Перекрываем базовые размеры .player-window для компактного окна метрик. */
#system-stats-window.system-stats-window {
    width: 190px !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    left: auto;
    top: auto;
    right: 18px;
    bottom: 86px;
    transform: none !important;
    resize: none !important;
    background: rgba(18, 18, 18, 0.52) !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28) !important;
}

#system-stats-window.system-stats-window.system-stats-expanded {
    width: min(560px, calc(100vw - 24px)) !important;
    max-height: min(760px, calc(100vh - 100px)) !important;
}

@media (max-width: 520px) {
    #system-stats-window.system-stats-window {
        width: 150px !important;
        max-width: calc(100vw - 16px) !important;
        right: 8px;
        bottom: 74px;
    }

    #system-stats-window .player-header {
        flex-basis: 28px;
        min-height: 28px;
        padding: 0 5px 0 7px;
        gap: 4px;
    }

    #system-stats-window .player-title {
        font-size: 10px;
    }

    #system-stats-window .system-stats-actions {
        gap: 4px;
    }

    #system-stats-window .system-stats-toggle,
    #system-stats-window .system-stats-reboot {
        min-width: 42px;
        height: 20px;
        padding: 0 4px;
        font-size: 9px;
    }

    #system-stats-window .system-stats-body {
        padding: 5px 7px 6px;
        font-size: 9px;
    }

    #system-stats-window .system-stat-row {
        line-height: 1.3;
    }
}

/* ── QR GENERATOR MODAL ── */
.qr-overlay {
    position: fixed;
    inset: 0;
    z-index: 240;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: rgba(0, 0, 0, 0.76);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.qr-overlay.open {
    display: flex;
}

#qr-modal-box {
    width: min(780px, calc(100vw - 24px));
    max-height: min(900px, calc(100dvh - 24px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #141416;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.72);
}

.qr-modal-header {
    flex: 0 0 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 12px 0 16px;
    background: #1a1a1d;
    border-bottom: 1px solid var(--line);
    color: var(--text);
    font-size: 13px;
}

.cl-btn {
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid transparent;
    background: transparent;
    color: var(--dim);
    font-size: 17px;
    cursor: pointer;
}

.cl-btn:hover {
    border-color: var(--line);
    color: var(--text);
}

.qr-modal-body {
    min-height: 0;
    display: flex;
    gap: 14px;
    padding: 14px;
    overflow-y: auto;
}

.qr-preview-pane {
    flex: 0 1 340px;
    min-width: 0;
    align-self: flex-start;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 10px;
    background-color: #111;
    background-image: conic-gradient(#1e1e1e 25%, #111 0 50%, #1e1e1e 0 75%, #111 0);
    background-size: 20px 20px;
}

#qr-composite-canvas {
    display: block;
    width: 100%;
    max-width: 340px;
    height: auto;
}

.qr-controls-pane {
    flex: 1 1 300px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.qr-ctrl-row {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
    color: var(--dim);
    font-size: 11px;
}

.qr-ctrl-row[hidden] {
    display: none !important;
}

.qr-ctrl-row input[type="text"] {
    width: 100%;
    min-width: 0;
    padding: 7px 9px;
    font-size: 12px;
}

.qr-ctrl-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.qr-ctrl-grid input[type="color"] {
    width: 100%;
    height: 32px;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: var(--field);
    cursor: pointer;
}

.qr-size-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.qr-size-grid .qr-ctrl-row > span {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.qr-size-grid input[type="range"],
#qr-card-radius {
    width: 100%;
    accent-color: var(--accent);
}

.qr-toggles-row {
    display: flex;
    flex-wrap: wrap;
    gap: 7px 12px;
}

.qr-toggles-row .custom-remember {
    margin: 0;
}

.qr-actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 3px;
}

.qr-actions-row .btn-vpn {
    flex: 1 1 auto;
}

#qr-status-msg {
    min-height: 15px;
    margin-top: 2px;
    color: var(--dim);
    font-size: 11px;
}

@media (max-width: 680px) {
    .qr-overlay {
        padding: 8px;
    }

    #qr-modal-box {
        width: calc(100vw - 16px);
        max-height: calc(100dvh - 16px);
    }

    .qr-modal-body {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }

    .qr-preview-pane {
        flex: 0 0 auto;
        width: min(100%, 300px);
        align-self: center;
    }

    #qr-composite-canvas {
        max-width: 280px;
    }

    .qr-controls-pane {
        flex: 0 0 auto;
        width: 100%;
    }
}
