/* ── The frame (spec 113) ─────────────────────────────────────────────────
   What every page sits in: the 88px rail (#sidebar), the top bar (.header),
   the Apps screen (#home) and, at 820px and under, the dock in the rail's
   place. Loaded last, after the page stylesheets. Every colour is a variable
   from tokens.css; app.js builds the markup (Navigation, _renderShell). */

.frame-ic {
    width: 20px;
    height: 20px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.frame-lbl {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.frame-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* A part of a shared page that belongs to another app (spec 113 §2). Set by
   the frame only, never by applyTabPermissions' inline display. */
.frame-off { display: none !important; }

/* ── Rail ─────────────────────────────────────────────── */
/* The old frame's rules are still in setup.css (`.sidebar { display: block
   !important }`, `.main-content`'s 260px and 60px) and pages.css (the drawer,
   the 52px header and `.main-content { margin-left: 0 !important }` under
   768px). Those files go with their pages' slices, so the frame overrides
   them here: !important only where theirs is, and every margin, size and
   transform they set, reset. */
.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 88px;
    height: auto;
    transform: none;
    box-shadow: none;
    z-index: 150;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px 8px;
    background: var(--panel);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

.sidebar .nav-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
/* Only the current app's group shows. */
.sidebar .nav-section[data-app]:not(.is-current) { display: none; }
.sidebar .nav-section[data-app] { padding-top: 10px; }
/* All apps sits at the foot of the rail. */
.sidebar .rail-foot { order: 99; margin-top: auto; padding-top: 10px; }

.sidebar .nav-section-title {
    width: 100%;
    padding: 0 2px 6px;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 9.5px;
    line-height: 1.3;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    overflow-wrap: anywhere;
}

.sidebar .nav-item {
    position: relative;
    width: 72px;
    min-height: 58px;
    padding: 8px 4px;
    border: 0;
    border-radius: var(--r-md);
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-text);
    font-size: 10.5px;
    font-weight: 500;
    line-height: 1.2;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}
.sidebar .nav-item:hover { background: var(--panel-raised); color: var(--text); }
.sidebar .nav-item.active { background: var(--panel-raised); color: var(--text); }
.sidebar .nav-item.active::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 14px;
    bottom: 14px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--accent);
}
.sidebar .nav-item.active .nav-icon { color: var(--accent); }

.nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex: none;
}
.nav-icon svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar .rail-mark {
    order: -1;
    min-height: 0;
    width: 48px;
    height: 48px;
    margin-bottom: 6px;
    border-radius: 15px;
    background: var(--primary);
    color: var(--on-primary);
    box-shadow: 0 0 28px var(--glow);
}
.sidebar .rail-mark:hover,
.sidebar .rail-mark.active { background: var(--primary); color: var(--on-primary); }
.sidebar .rail-mark.active::before { content: none; }
.sidebar .rail-mark .nav-icon { color: var(--on-primary); }
.sidebar .rail-mark.active .nav-icon { color: var(--on-primary); }

/* ── Top bar ──────────────────────────────────────────── */
.header {
    position: fixed;
    top: 0;
    left: 88px;
    right: 0;
    height: auto;
    min-height: 68px;
    z-index: 120;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 24px;
    background: var(--ground-glass);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}

.frame-where {
    min-width: 0;
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.frame-outlet {
    font-family: var(--font-mono);
    font-size: 10.5px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.app-title {
    font-family: var(--font-head);
    font-size: 19px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: none;
}
.frame-date {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    color: var(--text-muted);
    padding: 0 6px;
    white-space: nowrap;
}

.frame-ib {
    width: 44px;
    height: 44px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s var(--ease-out);
}
.frame-ib:hover { border-color: var(--accent); }
.frame-ib:active { transform: scale(0.94); }

/* Search: apps and pages (records are issue #306). */
.cmd {
    position: relative;
    flex: 1 1 260px;
    max-width: 560px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 0 8px 0 14px;
    margin: 0;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text-muted);
    font-weight: 400;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.cmd:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--glow); }
.cmd input {
    flex: 1;
    min-width: 0;
    height: 42px;
    padding: 0;
    border: 0;
    border-radius: 0;
    outline: 0;
    box-shadow: none;
    background: transparent;
    color: var(--text);
    font-size: 14px;
}
.cmd input:focus { box-shadow: none; }
.cmd input::-webkit-search-cancel-button { display: none; }
.cmd-kbd {
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 4px 7px;
    border-radius: 7px;
    border: 1px solid var(--line-strong);
    color: var(--text-muted);
    white-space: nowrap;
}
.cmd-list {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    z-index: 400;
    max-height: min(60vh, 420px);
    overflow-y: auto;
    padding: 6px;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: var(--shadow-pop);
}
.cmd-list[hidden] { display: none; }
.cmd-item {
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border: 0;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text);
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}
.cmd-item:hover,
.cmd-item.is-hi { background: var(--panel-raised); }
.cmd-item .nav-icon { color: var(--accent); }
.cmd-item-app { margin-left: auto; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.cmd-empty { padding: 12px 10px; font-size: 13px; color: var(--text-muted); }

.frame-search-btn { display: none; }

/* The account button and its menu. */
.frame-account { position: relative; }
.frame-account-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 400;
    min-width: 240px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: var(--shadow-pop);
}
.frame-account-menu[hidden] { display: none; }
.frame-account-menu .username { font-size: 13px; color: var(--text-muted); }
.logout-btn {
    min-height: 44px;
    padding: 0 16px;
    border-radius: var(--r-sm);
    border: 1px solid var(--line-strong);
    background: transparent;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s;
}
.logout-btn:hover { border-color: var(--attention); color: var(--attention); }

/* ── Page area ────────────────────────────────────────── */
.main-content {
    margin-left: 88px;
    margin-top: 0;
    padding: 96px 28px 40px;
    min-height: 100dvh;
    min-width: 0;
}

/* A page's content rises in when it is opened. */
.content-section.active { animation: frame-rise 0.45s var(--ease-out); }
@keyframes frame-rise {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: none; }
}

/* ── Apps screen (#home) ──────────────────────────────── */
.apps-wrap {
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 26px;
}

.apps-hero {
    overflow: hidden;
    padding: 28px;
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
}
.apps-hero-text {
    flex: 1 1 320px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.apps-hero-text h1 {
    font-family: var(--font-head);
    font-size: clamp(32px, 4vw, 52px);
    font-weight: 600;
    line-height: 1.02;
    letter-spacing: -0.03em;
    color: var(--text);
}
.apps-hero-text p { color: var(--text-muted); max-width: 440px; }

.apps-legend {
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr) auto;
    gap: 10px 12px;
    align-items: center;
    font-size: 13.5px;
    max-width: 300px;
}
.apps-sw { width: 12px; height: 12px; border-radius: 4px; }
.apps-sw.is-core { background: var(--accent-2); }
.apps-sw.is-app { background: var(--accent); }
.apps-sw.is-conn { background: var(--attention); }
.apps-count {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

/* The layered stack: Core at the bottom, the apps in use, the connectors in
   use on top; one lit square for each. It turns slowly and opens under a
   mouse. */
.apps-stk {
    flex: 1 1 280px;
    min-height: 300px;
    position: relative;
    display: grid;
    place-items: center;
    perspective: 1400px;
}
.apps-stack {
    width: 180px;
    height: 180px;
    margin-top: 64px;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(60deg) rotateZ(45deg);
    animation: apps-turn 24s linear infinite;
}
@keyframes apps-turn {
    from { transform: rotateX(60deg) rotateZ(45deg); }
    to   { transform: rotateX(60deg) rotateZ(405deg); }
}
.apps-plate {
    position: absolute;
    inset: 0;
    border-radius: 18px;
    border: 1px solid var(--line-strong);
    background: var(--panel-raised);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 16px;
    align-content: center;
    transition: transform 0.8s var(--ease-out);
}
.apps-plate.is-core { transform: translateZ(0); }
.apps-plate.is-app { transform: translateZ(56px); }
.apps-plate.is-conn { transform: translateZ(112px); }
.apps-nd { aspect-ratio: 1; border-radius: 7px; }
.apps-plate.is-core .apps-nd { background: var(--accent-2); }
.apps-plate.is-app .apps-nd { background: var(--accent); box-shadow: 0 0 14px var(--glow); }
.apps-plate.is-conn .apps-nd { background: var(--attention); }

.apps-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.apps-head h2 {
    font-family: var(--font-head);
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
}

.apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(230px, 100%), 1fr));
    gap: 16px;
}

/* A tile: .tile-card keeps the home tiles' name, so code listening for a home
   tile still finds one; its look is all here, over setup.css's older one. */
.apps-grid .tile-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 10px;
    min-height: 150px;
    padding: 18px;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    text-align: left;
    font: inherit;
    cursor: pointer;
    box-shadow: none;
    transition: transform 0.4s var(--ease-out), box-shadow 0.4s, border-color 0.4s;
}
.apps-grid .tile-card:active { transform: scale(0.98); }
.app-tile-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.app-tile-ic {
    width: 46px;
    height: 46px;
    flex: none;
    border-radius: var(--r-md);
    display: grid;
    place-items: center;
    background: var(--panel-raised);
    border: 1px solid var(--line);
    color: var(--accent);
}
.app-tile-ic svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.tile-card.is-core .app-tile-ic { color: var(--accent-2); }
.tile-card.is-connector .app-tile-ic { color: var(--attention); }
.app-tile-tag {
    font-family: var(--font-mono);
    font-size: 10.5px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 7px;
    border: 1px solid var(--line-strong);
    color: var(--text-muted);
}
.app-tile-name {
    font-family: var(--font-head);
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.02em;
}
.app-tile-desc { font-size: 13px; color: var(--text-muted); }

/* Tiles tilt under a mouse, never on touch. */
@media (hover: hover) {
    .apps-grid .tile-card:hover {
        transform: perspective(900px) rotateX(4deg) rotateY(-5deg) translateY(-6px);
        box-shadow: var(--lift);
        border-color: var(--line-strong);
    }
    .apps-stk:hover .apps-plate.is-app { transform: translateZ(84px); }
    .apps-stk:hover .apps-plate.is-conn { transform: translateZ(168px); }
}

/* ── Dock and More (phone) ────────────────────────────── */
.dock { display: none; }

.frame-more {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: var(--scrim);
}
.frame-more[hidden] { display: none; }
.frame-more-sheet {
    width: 100%;
    max-width: 520px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: var(--shadow-pop);
    animation: frame-sheet 0.35s var(--ease-out);
}
@keyframes frame-sheet {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: none; opacity: 1; }
}
.frame-more-sheet .frame-lbl { padding: 4px 10px 8px; }
.frame-more-sheet .logout-btn { margin-top: 10px; }

/* ── Phone: 820px and under ───────────────────────────── */
@media (max-width: 820px) {
    .sidebar { display: none !important; }

    .header {
        left: 0;
        height: auto;
        min-height: 60px;
        gap: 8px;
        padding: 8px 12px 8px 16px;
    }
    .app-title { font-size: 17px; }
    .frame-date { display: none; }
    .frame-search-btn { display: grid; }
    .cmd {
        display: none;
        position: absolute;
        left: 12px;
        right: 12px;
        top: calc(100% + 8px);
        max-width: none;
        box-shadow: var(--shadow-pop);
    }
    .header.is-searching .cmd { display: flex; }
    .cmd-kbd { display: none; }

    .main-content {
        margin-left: 0 !important;
        width: auto !important;
        margin-top: 0;
        padding: 80px 16px 112px;
    }

    .apps-hero { padding: 20px; }
    .apps-stk { min-height: 230px; }
    .apps-stack { width: 140px; height: 140px; margin-top: 50px; }
    .apps-grid { grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr)); gap: 12px; }
    .apps-grid .tile-card { padding: 14px; min-height: 0; }
    .app-tile-desc,
    .app-tile-tag { display: none; }

    .dock {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom));
        z-index: 140;
        height: 68px;
        padding: 0 6px;
        display: flex;
        align-items: center;
        justify-content: space-around;
        gap: 2px;
        border-radius: 24px;
        border: 1px solid var(--line-strong);
        background: var(--panel);
        box-shadow: var(--lift);
    }
    .dock-item {
        flex: 1 1 0;
        min-width: 0;
        min-height: 56px;
        padding: 4px 2px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        border: 0;
        border-radius: 16px;
        background: transparent;
        color: var(--text-muted);
        font-family: var(--font-text);
        font-size: 10.5px;
        font-weight: 500;
        cursor: pointer;
    }
    .dock-item span:last-child {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .dock-item.active { color: var(--text); }
    .dock-item.active .nav-icon { color: var(--accent); }
    .dock-fab {
        flex: none;
        width: 60px;
        height: 60px;
        display: grid;
        place-items: center;
        border: 0;
        border-radius: 20px;
        background: var(--primary);
        color: var(--on-primary);
        transform: translateY(-16px);
        box-shadow: 0 14px 30px -8px var(--glow);
        cursor: pointer;
    }
    .dock-fab .nav-icon { color: var(--on-primary); }

    /* A bar a page keeps stuck to the bottom of the screen (Pepup's audit:
       Save & exit, Finish) would sit behind the dock. It is styled inline, so
       it is matched by that style and lifted above the dock. */
    .main-content [style*="position:sticky"][style*="bottom:0"] {
        bottom: calc(92px + env(safe-area-inset-bottom)) !important;
        z-index: 1;
    }
}

/* More's entries look like the search list's. */
.frame-more-sheet .nav-item {
    width: 100%;
    min-height: 48px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border: 0;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text);
    font-size: 15px;
    text-align: left;
    cursor: pointer;
}
.frame-more-sheet .nav-item:hover,
.frame-more-sheet .nav-item.active { background: var(--panel-raised); }
.frame-more-sheet .nav-item .nav-icon { color: var(--accent); }

/* ── Motion off when asked ────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .content-section.active,
    .apps-stack,
    .frame-more-sheet { animation: none !important; }
    .apps-grid .tile-card:hover,
    .apps-grid .tile-card:active,
    .frame-ib:active { transform: none !important; }
    .apps-stk:hover .apps-plate.is-app { transform: translateZ(56px); }
    .apps-stk:hover .apps-plate.is-conn { transform: translateZ(112px); }
}
