/* The open vault's frame: an icon rail, the main column (title, search, the tiles), and a drawer for the detail.

   Three sizes, decided by width, not by device:
     wide     rail | main | drawer, side by side; opening the drawer narrows the main column
     medium   rail | main, the drawer floats over the right edge
     narrow   main above, the rail as a bar along the bottom, the drawer a full screen over everything
*/

.pv-app {
    display: grid;
    grid-template-columns: var(--rail-width) minmax(0, 1fr) auto;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    background: var(--bg-app);
    color: var(--text-primary);
}

.pv-app[hidden] {
    display: none;
}

/* --- The rail ------------------------------------------------------------------------------------------------ */

.pv-rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4) 0;
    border-right: 1px solid var(--border-subtle);
    background: var(--bg-sidebar);
}

.pv-rail__group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
}

/* Account and lock sit at the bottom, apart from the four places you go. */
.pv-rail__group--end {
    margin-top: auto;
}

.pv-rail__brand {
    width: 32px;
    height: 32px;
    margin-bottom: var(--space-3);
    border-radius: 9px;
    background: var(--accent-subtle);
    color: var(--accent-text);
}

.pv-rail__brand .pv-icon {
    width: 18px;
    height: 18px;
}

.pv-rail__item {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    text-decoration: none;
    cursor: pointer;
    transition: background var(--motion-hover), color var(--motion-hover);
}

.pv-rail__item:hover {
    background: var(--surface-2);
    color: var(--text-primary);
}

.pv-rail__item.is-active {
    background: var(--accent-subtle);
    color: var(--accent-text);
}

/* The selected mark of the spec: a bar 2 px wide and 16 px tall, on the rail's own edge. */
.pv-rail__item.is-active::before {
    content: "";
    position: absolute;
    left: -10px;
    width: 2px;
    height: 16px;
    border-radius: 2px;
    background: var(--accent-fill);
}

.pv-rail__label {
    display: none;
}

/* --- The main column ----------------------------------------------------------------------------------------- */

.pv-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.pv-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-5) var(--space-6) var(--space-3);
}

.pv-topbar__heading {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    min-width: 0;
}

.pv-topbar__heading .pv-iconbutton {
    align-self: center;
}

.pv-topbar__title {
    margin: 0;
    overflow: hidden;
    color: var(--text-primary);
    font-size: var(--type-title);
    font-weight: 650;
    letter-spacing: -0.02em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pv-topbar__count {
    color: var(--text-tertiary);
    font-size: var(--type-caption);
    white-space: nowrap;
}

.pv-search {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 0 1 380px;
    height: 40px;
    padding: 0 var(--space-3);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    background: var(--surface-1);
    color: var(--text-tertiary);
}

.pv-search:focus-within {
    border-color: var(--focus-ring);
    box-shadow: 0 0 0 3px var(--focus-glow);
}

.pv-search input {
    flex: 1;
    min-width: 0;
    height: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    font-size: 14px;
}

/* O anel de foco desta caixa é o do contentor (`.pv-search:focus-within`, arredondado). Sem esta regra, o contorno
   genérico de `base.css` (`.pv-page :is(button, a, input, ...):focus-visible`, especificidade 0,3,0) ganha ao
   `outline: 0` de cima (0,1,1) e desenha um segundo retângulo dentro do primeiro. */
.pv-page .pv-search input:focus-visible {
    outline: 0;
}

.pv-search input::placeholder {
    color: var(--text-tertiary);
}

.pv-search kbd {
    padding: 1px 6px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-chip);
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    font-size: 11px;
}

/* How old the copy is: the first thing to know about it. */
.pv-notice {
    margin: 0;
    padding: 0 var(--space-6) var(--space-3);
    color: var(--text-tertiary);
    font-size: var(--type-caption);
    line-height: 1.4;
}

.pv-notice:empty {
    display: none;
}

.pv-scroll {
    flex: 1;
    min-height: 0;
    padding: var(--space-2) var(--space-6) var(--space-8);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

/* --- Sizes --------------------------------------------------------------------------------------------------- */

@media (max-width: 1100px) {
    .pv-app {
        grid-template-columns: var(--rail-width) minmax(0, 1fr);
    }
}

@media (max-width: 720px) {
    .pv-app {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .pv-main {
        grid-row: 1;
    }

    /* The rail becomes a bar along the bottom, clear of the home indicator. */
    .pv-rail {
        grid-row: 2;
        flex-direction: row;
        justify-content: stretch;
        gap: 0;
        padding: var(--space-1) var(--space-2) calc(var(--space-1) + env(safe-area-inset-bottom));
        border-top: 1px solid var(--border-subtle);
        border-right: 0;
    }

    .pv-rail__brand {
        display: none;
    }

    .pv-rail__group {
        flex: 5 1 0;
        flex-direction: row;
        justify-content: space-around;
        min-width: 0;
        gap: 0;
    }

    .pv-rail__group--end {
        flex: 2 1 0;
        min-width: 0;
    }

    .pv-rail__item {
        flex-direction: column;
        gap: 2px;
        flex: 1 1 0;
        width: auto;
        min-width: 0;
        height: 52px;
        padding: 0 2px;
    }

    .pv-rail__item.is-active::before {
        left: 50%;
        top: -5px;
        width: 16px;
        height: 2px;
        transform: translateX(-50%);
    }

    .pv-rail__label {
        display: block;
        font-size: 11px;
        line-height: 1.2;
    }

    .pv-topbar {
        flex-wrap: wrap;
        padding: var(--space-4) var(--space-4) var(--space-2);
    }

    .pv-search {
        flex: 1 1 100%;
        height: 44px;
    }

    .pv-search kbd {
        display: none;
    }

    /* 16px: below it iOS zooms in on focus. */
    .pv-search input {
        font-size: 16px;
    }

    .pv-notice {
        padding: 0 var(--space-4) var(--space-2);
    }

    .pv-scroll {
        padding: var(--space-2) var(--space-4) var(--space-6);
    }
}

/* Em 320 px, sete destinos com rótulo não cabem. Mantém os alvos de ícone e os aria-labels; esconde
   apenas as legendas visuais para que todos os destinos continuem dentro do ecrã. */
@media (max-width: 480px) {
    .pv-rail__label {
        display: none;
    }
}

/* Em ecrãs baixos na horizontal, a rail vertical ultrapassa a altura útil. Reutiliza a barra inferior sem
   aplicar o cabeçalho móvel de pesquisa, que continua legível à largura disponível. */
@media (max-width: 1100px) and (max-height: 480px) and (orientation: landscape) {
    .pv-app {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .pv-main { grid-row: 1; }
    .pv-rail {
        grid-row: 2;
        flex-direction: row;
        justify-content: stretch;
        gap: 0;
        padding: var(--space-1) var(--space-2) calc(var(--space-1) + env(safe-area-inset-bottom));
        border-top: 1px solid var(--border-subtle);
        border-right: 0;
    }
    .pv-rail__brand { display: none; }
    .pv-rail__group {
        flex: 5 1 0;
        flex-direction: row;
        justify-content: space-around;
        min-width: 0;
        gap: 0;
    }
    .pv-rail__group--end { flex: 2 1 0; min-width: 0; }
    .pv-rail__item {
        flex-direction: column;
        gap: 2px;
        flex: 1 1 0;
        width: auto;
        min-width: 0;
        height: 52px;
        padding: 0 2px;
    }
    .pv-rail__item.is-active::before {
        left: 50%;
        top: -5px;
        width: 16px;
        height: 2px;
        transform: translateX(-50%);
    }
}

/* Os rótulos só cabem na barra horizontal quando cada destino tem largura suficiente. Até 480 px ficam ocultos. */
@media (min-width: 481px) and (max-width: 1100px) and (max-height: 480px) and (orientation: landscape) {
    .pv-rail__label { display: block; font-size: 11px; line-height: 1.2; }
}
