/* Stash page composition — vt99 design system.
   Page CSS arranges shared ui-* components and vt99 blocks only;
   colors, radii, typography and states come from --vt-* tokens.
   Layout: full-screen page with a single management sidebar pinned to the
   left edge and spanning header-to-footer (no floating panel). The rail
   toggle rides the sidebar's right edge (screen edge when collapsed); the
   rest of the page is reserved for future content. */

/* --- page container: full screen width, no padding around the sidebar ---
   The sidebar must run header-to-footer, so the site-wide footer offset
   is removed on this page only. */

.ui-stash-page {
    width: 100%;
    padding: 0;
    flex-grow: 1;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.ui-stash-page + .ui-site-footer.vt-footer {
    margin-top: 0;
}

/* --- app grid --- */

.vt-stash {
    --vt-stash-sidebar-w: clamp(240px, 25%, 340px);
    position: relative;
    flex: 1 0 auto;
    display: grid;
    grid-template-columns: var(--vt-stash-sidebar-w) minmax(0, 1fr);
    align-items: stretch;
}

.vt-stash[data-sidebar-open="false"] {
    grid-template-columns: minmax(0, 1fr);
}

.vt-stash[data-sidebar-open="false"] .vt-stash-sidebar {
    display: none;
}

/* --- mobile-only top toggle (compact pill, not a full-width bar) --- */

.vt-stash-topbar {
    grid-column: 1 / -1;
    justify-self: start;
    align-self: start;
    width: auto;
    display: none;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    margin: 12px 16px;
    padding: 4px 12px;
    font: inherit;
    text-align: left;
    color: var(--vt-text);
    background: var(--vt-panel);
    border: 1px solid var(--vt-line);
    border-radius: var(--vt-r-md);
    cursor: pointer;
}

.vt-stash-topbar:focus-visible {
    outline: 2px solid var(--vt-blue-2);
    outline-offset: 2px;
}

.vt-stash-topbar-icon {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
    flex: none;
}

.vt-stash-topbar-icon i {
    width: 18px;
    height: 2px;
    background: var(--vt-text-2);
    border-radius: 2px;
}

.vt-stash-topbar-copy {
    display: grid;
    line-height: 1.3;
}

.vt-stash-topbar-copy small {
    font-family: var(--vt-mono);
    font-size: 0.62rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--vt-text-3);
}

.vt-stash-topbar-copy strong {
    font-family: var(--vt-disp);
    font-size: 0.85rem;
}

/* --- edge rail: the single sidebar toggle.
      Open (desktop): rides the sidebar's right edge, fixed to the middle of
      the VIEWPORT (not the document — long workspaces must not push it away).
      Collapsed: docks to the screen's left edge as a small reopen tab. --- */

.vt-stash-rail {
    position: fixed;
    left: var(--vt-stash-sidebar-w);
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 56px;
    padding: 0;
    background: var(--vt-bg);
    color: var(--vt-text-3);
    border: none;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
}

.vt-stash-rail:hover {
    color: var(--vt-blue-2);
}

.vt-stash-rail:focus-visible {
    outline: 2px solid var(--vt-blue-2);
    outline-offset: 2px;
}

.vt-stash[data-sidebar-open="false"] .vt-stash-rail {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 701;
    background: var(--vt-bg);
}

/* Open: caret points left (collapse). Collapsed: caret points right (reopen). */
.vt-stash-rail .vt-stash-rail-open { display: inline-flex; }
.vt-stash-rail .vt-stash-rail-closed { display: none; }
.vt-stash[data-sidebar-open="false"] .vt-stash-rail .vt-stash-rail-open { display: none; }
.vt-stash[data-sidebar-open="false"] .vt-stash-rail .vt-stash-rail-closed { display: inline-flex; }

/* --- sidebar: full-height column pinned to the left page edge --- */

.vt-stash-sidebar {
    grid-column: 1;
    display: grid;
    gap: 20px;
    align-content: start;
    min-width: 0;
    padding: 20px 16px 32px;
    background: var(--vt-bg);
    border-right: 1px solid var(--vt-line);
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Mobile-only head: just the drawer close button, right-aligned. */
.vt-stash-side-head {
    display: none;
    align-items: center;
    justify-content: flex-end;
}

.vt-stash-side-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    color: var(--vt-text-2);
    border: 1px solid var(--vt-line);
    border-radius: var(--vt-r-md);
    cursor: pointer;
}

.vt-stash-side-close:hover {
    color: var(--vt-text);
}

.vt-stash-side-title {
    margin: 0 0 10px;
    font-family: var(--vt-mono);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--vt-text-3);
}

.vt-stash-side-group {
    display: block;
}

.vt-stash-side-empty {
    margin: 0;
    color: var(--vt-text-2);
    font-size: 0.9rem;
}

/* --- sidebar: add platform block --- */

.vt-stash-add {
    border: 1px solid var(--vt-line);
    border-radius: var(--vt-r-md);
    background: var(--vt-panel);
}

.vt-stash-add > summary {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 8px 12px;
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--vt-text);
    cursor: pointer;
    list-style: none;
}

.vt-stash-add > summary::-webkit-details-marker { display: none; }

.vt-stash-add > summary:hover {
    color: var(--vt-blue-2);
}

.vt-stash-add > summary:focus-visible {
    outline: 2px solid var(--vt-blue-2);
    outline-offset: -2px;
    border-radius: var(--vt-r-md);
}

.vt-stash-add-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex: none;
    color: var(--vt-blue-2);
    background: var(--vt-panel-2);
    border: 1px solid var(--vt-line);
    border-radius: 8px;
}

.vt-stash-add-form {
    display: grid;
    gap: 12px;
    padding: 4px 12px 12px;
    border-top: 1px solid var(--vt-line-soft);
}

.vt-stash-add-form .ui-button {
    width: 100%;
}

.vt-stash-add-devices {
    display: grid;
    gap: 8px;
    margin: 8px 0 0;
    padding: 0;
    border: none;
}

.vt-stash-add-choices {
    display: flex;
    gap: 8px;
}

.vt-stash-choice {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
}

.vt-stash-choice input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.vt-stash-choice-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 56px;
    padding: 8px 4px;
    font-size: 0.72rem;
    font-weight: 600;
    text-align: center;
    color: var(--vt-text-2);
    background: var(--vt-panel-2);
    border: 1px solid var(--vt-line);
    border-radius: var(--vt-r-md);
    cursor: pointer;
}

.vt-stash-choice-box:hover {
    color: var(--vt-text);
    border-color: var(--vt-line);
}

.vt-stash-choice input:checked + .vt-stash-choice-box {
    color: var(--vt-blue-2);
    border-color: var(--vt-blue);
    background: var(--vt-panel);
}

.vt-stash-choice input:focus-visible + .vt-stash-choice-box {
    outline: 2px solid var(--vt-blue-2);
    outline-offset: 2px;
}

/* --- sidebar: platform nav (icon + name + label, characters inside) --- */

.vt-stash-nav-platform {
    border: 1px solid var(--vt-line);
    border-radius: var(--vt-r-md);
    background: var(--vt-panel);
}

.vt-stash-nav-platform + .vt-stash-nav-platform {
    margin-top: 8px;
}

.vt-stash-nav-platform > summary {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 8px 12px;
    /* right room for the share + kebab menu buttons (absolute overlays in the wrap) */
    padding-inline-end: 90px;
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--vt-text);
    cursor: pointer;
    list-style: none;
}

.vt-stash-nav-platform > summary::-webkit-details-marker { display: none; }

.vt-stash-nav-platform > summary:hover {
    color: var(--vt-blue-2);
}

.vt-stash-nav-platform > summary:focus-visible {
    outline: 2px solid var(--vt-blue-2);
    outline-offset: -2px;
    border-radius: var(--vt-r-md);
}

.vt-stash-platform-icon {
    display: inline-flex;
    flex: none;
    color: var(--vt-blue-2);
}

.vt-stash-nav-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
}

.vt-stash-nav-type {
    margin-left: 8px;
    color: var(--vt-text-3);
    font-weight: 400;
    font-size: 0.78rem;
    white-space: nowrap;
}

.vt-stash-count {
    flex: none;
    font-family: var(--vt-mono);
    font-size: 0.72rem;
    color: var(--vt-text-2);
    padding: 2px 8px;
    border: 1px solid var(--vt-line-soft);
    border-radius: 999px;
}

.vt-stash-caret {
    display: inline-flex;
    flex: none;
    color: var(--vt-text-3);
}

.vt-stash-caret svg {
    transition: transform 0.2s ease-out;
}

details[open] > summary .vt-stash-caret svg {
    transform: rotate(180deg);
}

/* --- sidebar: characters (nav rows with kebab menu, see stash-workspace.css) --- */

.vt-stash-nav-characters {
    list-style: none;
    margin: 0;
    padding: 10px 12px 12px;
    display: grid;
    gap: 12px;
    border-top: 1px solid var(--vt-line-soft);
}

.vt-stash-character-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--vt-text);
    overflow-wrap: anywhere;
}

/* compact square icon-only action (trash / check), canonical ui-button colors */
.vt-stash-icon-btn {
    width: 40px;
    min-width: 40px;
    padding: 0;
}

.vt-stash-remove {
    display: flex;
}

/* --- sidebar: platform actions moved into dropdown menu --- */

/* --- sidebar: separator + reserved module links (square buttons) --- */

.vt-stash-sep {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.vt-stash-sep::before,
.vt-stash-sep::after {
    content: "";
    flex: 1 1 0;
    height: 1px;
    background: var(--vt-line);
}

.vt-stash-sep-label {
    font-family: var(--vt-mono);
    font-size: 0.62rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--vt-text-3);
    text-align: center;
    white-space: nowrap;
}

.vt-stash-links {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.vt-stash-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    aspect-ratio: 1;
    width: 100%;
    padding: 10px;
    font: inherit;
    color: var(--vt-text-2);
    background: var(--vt-panel);
    border: 1px dashed var(--vt-line);
    border-radius: var(--vt-r-md);
    cursor: not-allowed;
}

.vt-stash-link-icon {
    display: inline-flex;
    color: var(--vt-text-3);
}

.vt-stash-link-name {
    font-weight: 600;
    font-size: 0.82rem;
    text-align: center;
    color: var(--vt-text-2);
}

.vt-stash-link-soon {
    font-family: var(--vt-mono);
    font-size: 0.62rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--vt-text-3);
}

/* --- shared helpers --- */

/* platform menu: separator + full-width action buttons */
.vt-stash-menu-sep {
    height: 1px;
    background: var(--vt-line-soft);
    margin: 4px 0;
}

.vt-stash-menu-action {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
}

/* On the narrowest sidebar budgets the action label may not fit one line;
   the shared ui-button keeps its nowrap, the popover lets it wrap. */
.vt-stash-menu .vt-stash-menu-action span {
    white-space: normal;
    text-align: left;
}

/* share menu (D7): second kebab-style toggle left of the management menu,
   same interaction pattern — stash.js opens one [data-stash-menu] at a time */
.vt-stash-menu-wrap--share {
    right: 47px;
}

.vt-stash-share-url {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.vt-stash-share-url-text {
    flex: 1 1 auto;
    min-width: 0;
    font-family: var(--vt-mono);
    font-size: 0.72rem;
    color: var(--vt-text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vt-stash-share-url .vt-stash-icon-btn {
    flex: none;
}

/* brief "copied" feedback on the copy button (no native prompts, rule 3.16) */
.vt-stash-share-url .vt-stash-icon-btn.is-copied {
    color: var(--vt-pip);
    border-color: color-mix(in srgb, var(--vt-pip) 40%, transparent);
}

.vt-stash-share-summary {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.4;
    color: var(--vt-text-2);
}

/* off-screen proxy textarea for the execCommand clipboard fallback */
.vt-stash-copy-proxy {
    position: fixed;
    left: -9999px;
    top: 0;
    opacity: 0;
}

/* action forms stretch inside the menu grid */
.vt-stash-menu > form {
    display: flex;
    min-width: 0;
}

/* platform menu: rename + delete on one row */
.vt-stash-menu-platform-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
    align-items: center;
}

/* character menu: delete-icon + rename-form on one row */
.vt-stash-menu-char-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
    align-items: center;
}

.vt-stash-menu-char-row .vt-stash-menu-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
}

/* spacing between platform blocks */
.vt-stash-nav-item + .vt-stash-nav-item {
    margin-top: 12px;
}

/* --- off-canvas drawer mode (admin-menu mechanics), <=1023px --- */

@media (max-width: 1023px) {
    .vt-stash,
    .vt-stash[data-sidebar-open="false"] {
        grid-template-columns: minmax(0, 1fr);
    }

    .vt-stash[data-sidebar-open="false"] .vt-stash-sidebar {
        display: grid;
    }

    .vt-stash-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 690;
        width: min(330px, 88vw);
        border-right: none;
        border-radius: 0;
        transform: translateX(-102%);
        transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    }

    .vt-stash-sidebar.is-open {
        transform: translateX(0);
    }

    .vt-stash-side-head {
        display: flex;
    }

    .vt-stash-topbar {
        display: flex;
    }

    /* On mobile the reopen tab lives at the screen edge and joins the top bar.
       Icon follows the drawer state: caret-right when closed, left when open. */
    .vt-stash-rail,
    .vt-stash[data-sidebar-open="false"] .vt-stash-rail {
        position: fixed;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        z-index: 701;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 24px;
        height: 56px;
        padding: 0;
        background: var(--vt-bg);
        color: var(--vt-text-3);
        border: none;
        border-radius: 0 8px 8px 0;
        cursor: pointer;
    }

    .vt-stash-rail .vt-stash-rail-open { display: none; }
    .vt-stash-rail .vt-stash-rail-closed { display: inline-flex; }

    .vt-stash-backdrop {
        position: fixed;
        inset: 0;
        z-index: 680;
        width: 100%;
        padding: 0;
        background: rgba(6, 8, 16, 0.6);
        backdrop-filter: blur(3px);
        border: none;
        cursor: pointer;
    }

    body.vt-stash-locked {
        overflow: hidden;
    }

    /* Drawer open: the edge tab rides the drawer's right edge as its close
       control (caret flips left; clicking it or the head X closes). */
    body.vt-stash-locked .vt-stash-rail {
        left: min(330px, 88vw);
        transform: translateY(-50%);
    }

    body.vt-stash-locked .vt-stash-rail .vt-stash-rail-closed { display: none; }
    body.vt-stash-locked .vt-stash-rail .vt-stash-rail-open { display: inline-flex; }
}

/* --- Flat Mode (single media list, <=767px) --- */

@media (max-width: 767px) {
    .vt-stash-sidebar {
        gap: 16px;
        padding: 14px;
    }

    .vt-stash-add-choices {
        flex-wrap: wrap;
    }

    .vt-stash-choice {
        flex: 1 1 40%;
    }

    /* full-size touch targets on mobile */
    .vt-stash-icon-btn {
        width: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    .vt-stash-links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .vt-stash-link {
        aspect-ratio: auto;
        min-height: 96px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .vt-stash-sidebar {
        transition: none;
    }

    .vt-stash-caret svg {
        transition: none;
    }
}
