/* ── ЦЕНТРАЛЬНАЯ ЧАСТЬ И СЕТКА ── */
#center-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100%;
    overflow: hidden;
}

#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: auto;
    box-sizing: border-box;
    padding-bottom: 90px;
}

/* ── СЕТКА ПАПОК И ФАЙЛОВ ── */
#grid {
    position: relative;
    flex: 1;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(calc(70px * var(--file-scale)), 1fr));
    grid-auto-flow: dense;
    grid-auto-rows: calc(86px * var(--file-scale));
    gap: calc(8px * var(--file-scale));
    align-content: start;
    transition: background-image .25s ease;
}

#grid.canvas-mode {
    position: relative;
    display: block;
    flex: 0 0 auto;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    padding: 0;
    overflow: visible;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

#main.canvas-host { overflow: hidden; position: relative; padding-bottom: 0; touch-action: none; }
#grid.canvas-bounded { outline: 1px dashed rgba(255,255,255,.24); outline-offset: -1px; }
#grid.canvas-mode:active { cursor: grabbing; }
#grid.canvas-mode .canvas-item {
    position: absolute;
    width: calc(130px * var(--file-scale));
    height: calc(120px * var(--file-scale));
    min-height: 60px;
    box-sizing: border-box;
    overflow: visible;
    transition: box-shadow .15s ease;
    cursor: grab;
    user-select: none;
}
#grid.canvas-mode .canvas-item:active { cursor: grabbing; }
#grid.canvas-mode .canvas-item:hover { box-shadow: 0 8px 24px rgba(0,0,0,.35); }
#grid.canvas-mode .canvas-item.selected { outline: none; background: transparent; }
.canvas-transform-frame { --frame-blue: #5099ff; position: absolute; inset: 0; z-index: 5; border: calc(1px * var(--canvas-control-scale, 1)) solid var(--frame-blue); border-radius: 0; opacity: 0; visibility: hidden; transform: scale(.97); pointer-events: none; transition: opacity .18s ease, transform .18s ease, visibility .18s; }
.canvas-item.selected .canvas-transform-frame { opacity: 1; visibility: visible; transform: scale(1); }
.canvas-transform-handle { position: absolute; z-index: 2; width: calc(18px * var(--canvas-control-scale, 1)); height: calc(18px * var(--canvas-control-scale, 1)); transform: translate(-50%, -50%); touch-action: none; pointer-events: none; }
.canvas-transform-handle::after { content: ""; position: absolute; left: 50%; top: 50%; width: calc(8px * var(--canvas-control-scale, 1)); height: calc(8px * var(--canvas-control-scale, 1)); box-sizing: border-box; border: calc(1px * var(--canvas-control-scale, 1)) solid var(--frame-blue); background: #fff; transform: translate(-50%, -50%); }
.canvas-item.selected .canvas-transform-handle, .canvas-item.selected .canvas-rotate-zone { pointer-events: auto; }
.handle-nw { left: 0; top: 0; cursor: nwse-resize; }
.handle-n { left: 50%; top: 0; cursor: ns-resize; }
.handle-ne { left: 100%; top: 0; cursor: nesw-resize; }
.handle-e { left: 100%; top: 50%; cursor: ew-resize; }
.handle-se { left: 100%; top: 100%; cursor: nwse-resize; }
.handle-s { left: 50%; top: 100%; cursor: ns-resize; }
.handle-sw { left: 0; top: 100%; cursor: nesw-resize; }
.handle-w { left: 0; top: 50%; cursor: ew-resize; }
.canvas-rotate-zone { position: absolute; z-index: 1; touch-action: none; pointer-events: none; cursor: crosshair; }
.rotate-n, .rotate-s { left: 0; right: 0; height: calc(18px * var(--canvas-control-scale, 1)); }
.rotate-n { bottom: calc(100% + 8px * var(--canvas-control-scale, 1)); }
.rotate-s { top: calc(100% + 8px * var(--canvas-control-scale, 1)); }
.rotate-e, .rotate-w { top: 0; bottom: 0; width: calc(18px * var(--canvas-control-scale, 1)); }
.rotate-e { left: calc(100% + 8px * var(--canvas-control-scale, 1)); }
.rotate-w { right: calc(100% + 8px * var(--canvas-control-scale, 1)); }
.rotate-nw, .rotate-ne, .rotate-sw, .rotate-se { width: calc(26px * var(--canvas-control-scale, 1)); height: calc(26px * var(--canvas-control-scale, 1)); }
.rotate-nw, .rotate-ne { bottom: 100%; }
.rotate-sw, .rotate-se { top: 100%; }
.rotate-nw, .rotate-sw { right: 100%; }
.rotate-ne, .rotate-se { left: 100%; }
@media (prefers-reduced-motion: reduce) { .canvas-transform-frame { transition: none; } }
#grid.canvas-mode .canvas-item .name,
#grid.canvas-mode .canvas-item .size { position: absolute; top: 100%; left: 0; width: 100%; margin-top: 4px; opacity: 0; transition: opacity .16s ease; pointer-events: none; text-align: center; }
#grid.canvas-mode .canvas-item .size { margin-top: calc(8px + 2.8em); }
#grid.canvas-mode .canvas-item:hover .name, #grid.canvas-mode .canvas-item.selected .name,
#grid.canvas-mode .canvas-item:hover .size, #grid.canvas-mode .canvas-item.selected .size { opacity: 1; }
#marafet-toggle[aria-pressed="true"] { color: var(--accent); }
#marafet-layers.marafet-layers { left: auto; top: 110px; right: 20px; width: min(270px, calc(100vw - 24px)); height: min(380px, calc(100dvh - 210px)); min-width: 180px; transform: none; background: rgba(24,24,24,.94); }
#marafet-layer-list { flex: 1; overflow: auto; padding: 6px; }
.marafet-layer { display: block; width: 100%; padding: 8px; border: 0; border-radius: 4px; background: transparent; color: var(--text); font: inherit; font-size: 12px; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: grab; }
.marafet-layer:hover { background: #ffffff0d; }
.marafet-layer.selected { background: #ffffff18; box-shadow: inset 2px 0 var(--accent); }
#grid.marafet-mode .item { cursor: grab; }
#grid.marafet-mode .marafet-dragging { opacity: .4; }
#grid.canvas-mode .selection-marquee { z-index: 2147483647; }
#grid.canvas-mode .asset-sticker { overflow: visible; background: transparent !important; border: 0 !important; box-shadow: none; }
#grid.canvas-mode .canvas-item .icon.preview { height: calc(100% - 16px); }
#grid.canvas-mode .asset-sticker .icon.preview { height: calc(100% - 16px); background: transparent; overflow: visible; }
#grid.canvas-mode .asset-sticker .icon.preview img { object-fit: contain; filter: drop-shadow(0 6px 14px rgba(0,0,0,.45)); }
#grid.canvas-mode .canvas-item.folder-large { width: calc(260px * var(--file-scale)); height: calc(240px * var(--file-scale)); }
.item.tile-1-1 { grid-column: span 1; grid-row: span 1; }
.item[class*="tile-"] { height: 100%; min-height: 0; box-sizing: border-box; }
.item.tile-2-1 { grid-column: span 2; grid-row: span 1; }
.item.tile-1-2 { grid-column: span 1; grid-row: span 2; }
.item.tile-2-2 { grid-column: span 2; grid-row: span 2; }
.item.tile-3-1 { grid-column: span 3; grid-row: span 1; }
.item.tile-3-2 { grid-column: span 3; grid-row: span 2; }
.item.tile-1-3 { grid-column: span 1; grid-row: span 3; }
.item.tile-2-3 { grid-column: span 2; grid-row: span 3; }
.item.tile-3-3 { grid-column: span 3; grid-row: span 3; }
.tile-shape-grid:not(.canvas-mode) { grid-auto-flow: row dense; grid-auto-columns: calc(var(--file-card-side) * var(--file-scale)); }
.item.tile-shape-managed[class*="tile-"] { min-height: 0; }
#grid:not(.canvas-mode) > .item.tile-shape-irregular { padding: 0; }
#grid:not(.canvas-mode) > .item.tile-shape-irregular > .tile-shape-content {
    position: absolute;
    left: var(--tile-content-x, 0px);
    top: var(--tile-content-y, 0px);
    width: var(--tile-content-width, 100%);
    height: var(--tile-content-height, 100%);
    box-sizing: border-box;
    min-width: 0;
    min-height: 0;
    padding: calc(6px * var(--file-scale)) 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
#grid:not(.canvas-mode) .tile-shape-content > .icon:not(.preview) {
    width: 100%;
    font-size: min(calc(38px * var(--file-scale)), calc(var(--tile-content-height, 86px) * .45));
}
#grid:not(.canvas-mode) .tile-shape-content > .name { flex-shrink: 0; }
.item.folder-large { grid-column: span 2; grid-row: span 2; min-height: calc(174px * var(--file-scale)); }
.item.folder-stealth { opacity: 0; background: transparent !important; outline: none !important; }
.item.folder-stealth:hover { opacity: .12; cursor: pointer; }

.item {
    position: relative;
    width: 100%;
    height: calc(86px * var(--file-scale));
    min-width: 0;
    min-height: calc(86px * var(--file-scale));
    padding: calc(6px * var(--file-scale)) 2px;
    text-align: center;
    cursor: pointer;
    user-select: none;
    border-radius: var(--r);
    overflow: hidden;
}

.item:hover {
    background: var(--tab);
}

.item.selected {
    background: rgba(255, 62, 62, .18);
    outline: 1px solid var(--accent);
}

.selection-marquee {
    position: absolute;
    z-index: 20;
    border: 1px solid rgba(112, 118, 128, .9);
    background: rgba(42, 45, 51, .62);
    border-radius: 2px;
    pointer-events: none;
}

#grid.marquee-active,
#grid.multi-select-mode {
    user-select: none;
    -webkit-user-select: none;
}

#grid.marquee-active { cursor: crosshair; }
#grid.multi-select-mode { cursor: copy; }
#grid.marquee-active .item { transition: none; }

.item.cut-item {
    opacity: 0.42;
}

.bg-set-button {
    position: absolute;
    left: 50%;
    bottom: 3px;
    z-index: 2;
    transform: translateX(-50%);
    height: 18px;
    min-height: 18px;
    padding: 0 6px;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: rgba(16, 16, 16, .82);
    color: var(--text);
    font-size: 10px;
    line-height: 1;
    white-space: nowrap;
    touch-action: manipulation;
}

.bg-set-button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.item .icon {
    font-size: calc(38px * var(--file-scale));
    line-height: 1;
}

.item .icon.preview {
    position: relative;
    width: 100%;
    height: calc(42px * var(--file-scale));
    margin: 0 auto;
    overflow: hidden;
    border-radius: var(--r);
    background: #0a0a0a;
}
.item .icon.preview.video-preview-pending::after {
    content: "🎬";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #171717, #242424);
    font-size: calc(22px * var(--file-scale));
    pointer-events: none;
}
.item .icon.preview video[data-frame-ready="0"] { opacity: 0; }
.item .icon.preview video[data-frame-ready="1"] { opacity: 1; transition: opacity .12s ease; }
.item.asset-sticker { background: transparent; border-color: transparent; box-shadow: none; }
.item.asset-sticker:hover, .item.asset-sticker.selected { background: transparent; }
.item.asset-sticker .icon.preview { background: transparent; overflow: visible; }
.item.asset-sticker .icon.preview img { object-fit: contain; filter: drop-shadow(0 6px 14px rgba(0,0,0,.45)); }
.item.asset-sticker .name, .item.asset-sticker .size { display: none; }
.item.transparent-art-card,
.item.transparent-art-card:hover,
.item.transparent-art-card.selected { background: transparent; border-color: transparent; box-shadow: none; }
.item.transparent-art-card .icon.preview { background: transparent; overflow: visible; }
.item.transparent-art-card .icon.preview img { object-fit: contain; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .45)); }

.item .icon.preview img,
.item .icon.preview video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

.item .name {
    font-size: calc(11px * var(--file-scale));
    line-height: 1.15;
    margin-top: 4px;
    color: var(--dim);
    word-break: break-all;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
}

.item .size {
    margin-top: 2px;
    color: var(--dim);
    font-size: calc(9px * var(--file-scale));
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#grid.dragover {
    outline: 2px dashed var(--accent);
    background: var(--field);
}

#grid:not(.canvas-mode) {
    grid-template-columns: repeat(auto-fill, calc(var(--file-card-side) * var(--file-scale)));
    grid-auto-rows: calc(var(--file-card-side) * var(--file-scale));
}

#grid:not(.canvas-mode) .item {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-radius: calc(var(--r) + 2px);
}

#grid:not(.canvas-mode) .item .icon:not(.preview) {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#grid:not(.canvas-mode) .item .name,
#grid:not(.canvas-mode) .item .size {
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    width: 100%;
    margin-top: 0;
    text-align: center;
}

#grid:not(.canvas-mode) .item .name {
    order: 2;
}

#grid:not(.canvas-mode) .item .size {
    order: 1;
    margin-bottom: calc(2px * var(--file-scale));
}

#grid:not(.canvas-mode) .item .icon.preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    border-radius: inherit;
}

#grid:not(.canvas-mode) .item .icon.preview img,
#grid:not(.canvas-mode) .item .icon.preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: none;
}

#grid:not(.canvas-mode) .media-card {
    justify-content: flex-end;
    isolation: isolate;
}

#grid:not(.canvas-mode) .media-card::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: inherit;
    background: linear-gradient(to top, rgba(0, 0, 0, .48), transparent 60%);
    pointer-events: none;
}

#grid:not(.canvas-mode) .media-card .name,
#grid:not(.canvas-mode) .media-card .size {
    color: #f0f0f0;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .65);
}

#grid:not(.canvas-mode) .media-card .name {
    display: -webkit-box;
}

#grid:not(.canvas-mode) .media-card .size {
    display: block;
}

#grid:not(.canvas-mode) .item:hover {
    outline: 1px solid var(--dim);
    outline-offset: 0;
}

#grid:not(.canvas-mode) .item.selected {
    outline: 2px solid var(--accent);
    outline-offset: 0;
}

@media (max-width: 899px) {
    :root {
        --file-card-side: 70px;
    }

    #grid:not(.canvas-mode) {
        padding: 6px;
        gap: calc(5px * var(--file-scale));
    }
}
