/*
   The shell: everything around the page content.
   Phone and tablet layout first (top bar, status strip, bottom bar, overlay menu);
   the desktop layout (menu left, content, status right) starts at 1200px.
   Reads css/tokens.css. Markup: Pages/Shared/_Layout.cshtml and the shell view components.
*/

/* ---------- Page frame ---------- */

.bj-body {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    /* Room for the fixed bottom bar on phones (players only). */
    padding-bottom: 0;
}

.bj-body--player {
    padding-bottom: calc(var(--bj-bottombar-height) + env(safe-area-inset-bottom, 0px));
}

.bj-skip {
    position: absolute;
    left: var(--bj-space-2);
    top: -100px;
    z-index: 1100;
    padding: var(--bj-space-2) var(--bj-space-4);
    background: var(--bj-accent);
    color: var(--bj-on-accent);
    font-weight: 600;
    border-radius: var(--bj-radius-sm);
}

.bj-skip:focus {
    top: var(--bj-space-2);
    color: var(--bj-on-accent);
}

.bj-frame {
    flex: 1 0 auto;
    width: 100%;
    max-width: 1480px;
    margin: 0 auto;
    padding: 0 var(--bj-space-3) var(--bj-space-5);
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "status" "main" "menu";
}

.bj-main {
    grid-area: main;
    min-width: 0;
    padding-top: var(--bj-space-3);
}

.bj-main:focus {
    outline: none;
}

/* ---------- Top bar ---------- */

.bj-topbar {
    position: sticky;
    top: 0;
    z-index: 1021;
    background: var(--bj-surface);
    border-bottom: 1px solid var(--bj-border);
}

.bj-topbar-inner {
    max-width: 1480px;
    margin: 0 auto;
    height: var(--bj-topbar-height);
    padding: 0 var(--bj-space-3);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--bj-space-3);
}

.bj-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--bj-space-2);
    min-height: var(--bj-target);
    color: var(--bj-text);
    font-weight: 700;
    font-size: var(--bj-text-lg);
    letter-spacing: 0.01em;
}

.bj-brand:hover {
    color: var(--bj-text);
    text-decoration: none;
}

.bj-brand-mark {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: var(--bj-radius-sm);
    background: var(--bj-accent);
    color: var(--bj-on-accent);
    font-size: 1.375rem;
}

.bj-brand-area {
    padding: 2px var(--bj-space-2);
    border-radius: var(--bj-radius-pill);
    background: var(--bj-accent-soft);
    color: var(--bj-accent);
    font-size: var(--bj-text-xs);
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* Header shortcuts are desktop-only; on phones the same destinations are in the bottom bar and the menu. */
.bj-tools {
    display: none;
    align-items: center;
    gap: var(--bj-space-1);
}

.bj-tool {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: var(--bj-target);
    height: var(--bj-target);
    border-radius: var(--bj-radius-sm);
    color: var(--bj-text-muted);
    font-size: 1.5rem;
}

.bj-tool:hover {
    background: var(--bj-surface-raised);
    color: var(--bj-text);
    text-decoration: none;
}

.bj-tool .bj-badge {
    position: absolute;
    top: 2px;
    right: 0;
}

.bj-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--bj-border-control);
}

.bj-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: var(--bj-radius-pill);
    background: var(--bj-accent);
    color: var(--bj-on-accent);
    font-size: var(--bj-text-xs);
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.bj-icon-button {
    display: inline-grid;
    place-items: center;
    width: var(--bj-target);
    height: var(--bj-target);
    border: 0;
    border-radius: var(--bj-radius-sm);
    background: transparent;
    color: var(--bj-text-muted);
    font-size: 1.5rem;
}

.bj-icon-button:hover {
    background: var(--bj-surface-raised);
    color: var(--bj-text);
}

/* ---------- Live ticker ---------- */

.bj-ticker {
    background: var(--bj-surface-sunken);
    border-bottom: 1px solid var(--bj-border);
    color: var(--bj-text-muted);
    font-size: var(--bj-text-sm);
}

.bj-ticker-inner {
    max-width: 1480px;
    margin: 0 auto;
    padding: var(--bj-space-2) var(--bj-space-3);
    display: flex;
    align-items: baseline;
    gap: var(--bj-space-2);
}

.bj-ticker-icon {
    color: var(--bj-accent);
    flex: none;
    position: relative;
    top: 2px;
}

.bj-ticker-text {
    min-width: 0;
    overflow-wrap: anywhere;
}

/* ---------- Cookie notice: in the page flow, so it never covers content or the bottom bar ---------- */

.bj-cookie {
    display: flex;
    align-items: center;
    gap: var(--bj-space-2);
    min-height: 48px;
    padding: 6px var(--bj-space-3);
    background: var(--bj-surface-raised);
    border-bottom: 1px solid var(--bj-border);
    color: var(--bj-text);
    font-size: var(--bj-text-sm);
    line-height: var(--bj-leading-tight);
}

.bj-cookie[hidden] {
    display: none;
}

.bj-cookie-icon {
    flex: none;
    font-size: 1.25rem;
    color: var(--bj-text-muted);
}

.bj-cookie-text {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
}

.bj-cookie a {
    text-decoration: underline;
    white-space: nowrap;
}

.bj-cookie .btn {
    flex: none;
    min-width: var(--bj-target);
    min-height: 36px;
    padding-inline: var(--bj-space-3);
}

/* ---------- Status: compact strip on phones, full card on desktop ---------- */

.bj-status {
    grid-area: status;
    position: sticky;
    top: var(--bj-topbar-height);
    z-index: 1020;
    margin: 0 calc(var(--bj-space-3) * -1);
    background: var(--bj-surface);
    border-bottom: 1px solid var(--bj-border);
}

.bj-strip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--bj-space-2);
    width: 100%;
    min-height: var(--bj-target);
    padding: var(--bj-space-1) var(--bj-space-3);
    border: 0;
    background: transparent;
    color: var(--bj-text);
    font-size: var(--bj-text-sm);
    text-align: left;
}

.bj-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    white-space: nowrap;
}

.bj-chip > i {
    font-size: 1.125rem;
    color: var(--bj-text-muted);
}

.bj-chip-value {
    font-weight: 600;
}

.bj-chip--money .bj-chip-value,
.bj-chip--money > i {
    color: var(--bj-money);
}

.bj-chip--timer .bj-chip-value {
    color: var(--bj-text-muted);
}

/* Narrow phones and large numbers: tighten the strip so four values still fit. */
@media (max-width: 419.98px) {
    .bj-strip {
        gap: 6px;
        padding-inline: var(--bj-space-2);
        font-size: 0.8125rem;
    }

    .bj-chip {
        gap: 3px;
    }

    .bj-chip > i {
        font-size: 1rem;
    }

    .bj-strip .bj-meterbox--mini {
        width: 22px;
    }
}

.bj-strip-caret {
    flex: none;
    color: var(--bj-text-muted);
    transition: transform var(--bj-motion);
}

.bj-strip[aria-expanded="true"] .bj-strip-caret {
    transform: rotate(180deg);
}

.bj-status-card {
    display: none;
    max-height: calc(100dvh - var(--bj-topbar-height) - var(--bj-target) - var(--bj-bottombar-height) - env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    border-top: 1px solid var(--bj-border);
    padding: var(--bj-space-2) var(--bj-space-3) var(--bj-space-3);
}

.bj-status.is-open .bj-status-card {
    display: block;
}

.bj-stats-list {
    margin: 0;
}

.bj-stat {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 2px var(--bj-space-3);
    padding: var(--bj-space-2) 0;
    border-bottom: 1px solid var(--bj-border);
    font-size: var(--bj-text-sm);
}

.bj-stat:last-child {
    border-bottom: 0;
}

.bj-stat dt {
    display: flex;
    align-items: center;
    gap: var(--bj-space-2);
    font-weight: 400;
    color: var(--bj-text-muted);
}

.bj-stat dt > i {
    font-size: 1.125rem;
}

.bj-stat dd {
    margin: 0 0 0 auto;
    text-align: right;
    min-width: 0;
}

.bj-stat-value {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.bj-stat--meter > dd {
    flex: 1 0 100%;
    margin: 0;
    text-align: left;
}

/* ---------- Menu: overlay panel on phones (Bootstrap offcanvas), sidebar on desktop ---------- */

.bj-menu {
    grid-area: menu;
    --bs-offcanvas-width: min(88vw, 340px);
}

.bj-menu .offcanvas-header {
    justify-content: space-between;
    padding: var(--bj-space-2) var(--bj-space-2) var(--bj-space-2) var(--bj-space-4);
    border-bottom: 1px solid var(--bj-border);
}

.bj-menu-title {
    font-size: var(--bj-text-lg);
    margin: 0;
}

.bj-menu .offcanvas-body {
    padding: var(--bj-space-3);
}

.bj-nav {
    width: 100%;
}

.bj-nav-heading {
    margin: var(--bj-space-4) 0 var(--bj-space-1);
    padding: 0 var(--bj-space-3);
    color: var(--bj-text-subtle);
    font-size: var(--bj-text-xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.bj-nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.bj-nav-link {
    display: flex;
    align-items: center;
    gap: var(--bj-space-3);
    min-height: var(--bj-target);
    padding: var(--bj-space-2) var(--bj-space-3);
    border-radius: var(--bj-radius-sm);
    color: var(--bj-text);
    font-size: var(--bj-text-sm);
    line-height: var(--bj-leading-tight);
    cursor: pointer;
}

/* The log-out entry is a form with a button (a POST), drawn like the links. */
.bj-nav-form {
    margin: 0;
}

.bj-nav-button {
    width: 100%;
    border: 0;
    background: none;
    text-align: start;
    font-family: inherit;
}

.bj-nav-link > i {
    flex: none;
    font-size: 1.25rem;
    color: var(--bj-text-muted);
}

.bj-nav-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
}

.bj-nav-link:hover {
    background: var(--bj-surface-raised);
    color: var(--bj-text);
    text-decoration: none;
}

.bj-nav-link[aria-current="page"] {
    background: var(--bj-accent-soft);
    color: var(--bj-accent);
    font-weight: 600;
}

.bj-nav-link[aria-current="page"] > i {
    color: var(--bj-accent);
}

.bj-nav-link--back {
    color: var(--bj-text-muted);
}

/* Collapsible groups (shop, own gang, dragrace) are native <details>. */
.bj-nav-group > summary {
    list-style: none;
}

.bj-nav-group > summary::-webkit-details-marker {
    display: none;
}

.bj-nav-caret {
    font-size: 1rem !important;
    transition: transform var(--bj-motion);
}

.bj-nav-group[open] > summary .bj-nav-caret {
    transform: rotate(180deg);
}

.bj-nav-sublist {
    margin: 0 0 var(--bj-space-1) var(--bj-space-5);
    padding-left: var(--bj-space-2);
    border-left: 1px solid var(--bj-border);
}

.bj-search {
    display: flex;
    gap: var(--bj-space-2);
}

.bj-search .form-control {
    min-height: var(--bj-target);
    min-width: 0;
}

.bj-search-button {
    flex: none;
    width: var(--bj-target);
    min-height: var(--bj-target);
    padding: 0;
    font-size: 1.25rem;
}

/* ---------- Bottom bar (phones) ---------- */

.bj-bottombar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1030;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    height: calc(var(--bj-bottombar-height) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bj-surface);
    border-top: 1px solid var(--bj-border);
}

.bj-bar-link {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    padding: 0 2px;
    border: 0;
    background: transparent;
    color: var(--bj-text-muted);
    /* Five labels must fit side by side down to 320px ("Meddelanden" is the longest). */
    font-size: clamp(0.625rem, 2.9vw, 0.75rem);
    line-height: 1.2;
}

.bj-bar-link > i {
    font-size: 1.5rem;
}

.bj-bar-text {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bj-bar-link:hover {
    color: var(--bj-text);
    text-decoration: none;
}

.bj-bar-link[aria-current="page"] {
    color: var(--bj-accent);
    font-weight: 600;
}

.bj-bar-link[aria-current="page"]::before {
    content: "";
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--bj-accent);
}

.bj-bar-link .bj-badge {
    position: absolute;
    top: 6px;
    left: calc(50% + 6px);
}

/* ---------- Signed-out side block ---------- */

.bj-anon {
    grid-area: menu;
    padding-top: var(--bj-space-4);
}

.bj-topbar .btn {
    display: inline-flex;
    align-items: center;
    gap: var(--bj-space-2);
    min-height: 40px;
}

.bj-stats {
    list-style: none;
    margin: 0;
    padding: var(--bj-space-3);
    border: 1px solid var(--bj-border);
    border-radius: var(--bj-radius);
    background: var(--bj-surface);
    color: var(--bj-text-muted);
    font-size: var(--bj-text-sm);
}

.bj-stats strong {
    color: var(--bj-text);
}

/* ---------- Flash message ---------- */

.bj-flash {
    display: flex;
    align-items: flex-start;
    gap: var(--bj-space-3);
    margin: 0 0 var(--bj-space-4);
    padding: var(--bj-space-3) var(--bj-space-2) var(--bj-space-3) var(--bj-space-3);
    border: 1px solid var(--bj-border);
    border-left-width: 4px;
    border-radius: var(--bj-radius-sm);
    background: var(--bj-surface-raised);
    color: var(--bj-text);
}

.bj-flash-icon {
    flex: none;
    font-size: 1.375rem;
    line-height: 1.5rem;
    color: var(--bj-text-muted);
}

.bj-flash-body {
    flex: 1 1 auto;
    min-width: 0;
    line-height: 1.5rem;
    overflow-wrap: anywhere;
}

.bj-flash-close {
    flex: none;
    display: inline-grid;
    place-items: center;
    width: var(--bj-target);
    height: var(--bj-target);
    margin: -10px 0;
    border: 0;
    border-radius: var(--bj-radius-sm);
    background: transparent;
    color: var(--bj-text-muted);
    font-size: 1.25rem;
}

.bj-flash-close:hover {
    background: rgb(255 255 255 / 0.08);
    color: var(--bj-text);
}

.bj-flash--success { border-left-color: var(--bj-success); }
.bj-flash--success .bj-flash-icon { color: var(--bj-success); }
.bj-flash--error { border-left-color: var(--bj-danger); }
.bj-flash--error .bj-flash-icon { color: var(--bj-danger); }
.bj-flash--warning { border-left-color: var(--bj-warning); }
.bj-flash--warning .bj-flash-icon { color: var(--bj-warning); }
.bj-flash--info { border-left-color: var(--bj-info); }
.bj-flash--info .bj-flash-icon { color: var(--bj-info); }

/* ---------- Footer ---------- */

.bj-footer {
    flex: none;
    border-top: 1px solid var(--bj-border);
    background: var(--bj-surface-sunken);
    color: var(--bj-text-subtle);
    font-size: var(--bj-text-sm);
}

.bj-footer-inner {
    max-width: 1480px;
    margin: 0 auto;
    padding: var(--bj-space-3);
}

.bj-footer-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0 var(--bj-space-4);
}

.bj-footer-links a {
    display: inline-flex;
    align-items: center;
    min-height: var(--bj-target);
    color: var(--bj-text-muted);
}

.bj-footer-links a:hover {
    color: var(--bj-text);
}

/* The copyright line and, beside it (below it on a narrow screen), the coffee link. */
.bj-footer-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0 var(--bj-space-4);
}

.bj-footer-copyright {
    margin: 0;
}

/* Discreet: the footer's own text colour, only a step brighter on hover. */
.bj-footer-coffee {
    display: inline-flex;
    align-items: center;
    gap: var(--bj-space-1);
    min-height: var(--bj-target);
    color: var(--bj-text-subtle);
}

.bj-footer-coffee:hover {
    color: var(--bj-text-muted);
}

/* ---------- Desktop layout ---------- */

@media (min-width: 1200px) {
    .bj-body--player {
        padding-bottom: 0;
    }

    .bj-topbar {
        position: static;
    }

    .bj-topbar-inner {
        padding: 0 var(--bj-space-4);
    }

    .bj-tools {
        display: flex;
    }

    .bj-ticker-inner,
    .bj-footer-inner {
        padding-inline: var(--bj-space-4);
    }

    .bj-cookie {
        padding-inline: max(var(--bj-space-4), calc((100% - 1480px) / 2 + var(--bj-space-5)));
    }

    .bj-frame {
        padding: var(--bj-space-4);
        grid-template-columns: 220px minmax(0, 1fr) 248px;
        grid-template-rows: auto 1fr;
        grid-template-areas:
            "menu main status"
            "menu main .";
        column-gap: var(--bj-space-4);
        row-gap: var(--bj-space-4);
    }

    .bj-main {
        padding-top: 0;
    }

    .bj-menu .offcanvas-header {
        display: none;
    }

    .bj-menu .offcanvas-body {
        padding: 0;
    }

    .bj-nav {
        padding: var(--bj-space-3);
        border: 1px solid var(--bj-border);
        border-radius: var(--bj-radius);
        background: var(--bj-surface);
    }

    .bj-nav-heading:first-of-type {
        margin-top: var(--bj-space-3);
    }

    .bj-nav-link {
        min-height: 40px;
    }

    .bj-bottombar {
        display: none;
    }

    /* The strip is a phone control; on desktop the full card is always shown and stays in view. */
    .bj-status {
        position: sticky;
        top: var(--bj-space-4);
        align-self: start;
        z-index: auto;
        margin: 0;
        border: 1px solid var(--bj-border);
        border-radius: var(--bj-radius);
    }

    .bj-strip {
        display: none;
    }

    .bj-status-card,
    .bj-status.is-open .bj-status-card {
        display: block;
        max-height: none;
        overflow: visible;
        border-top: 0;
        padding: var(--bj-space-1) var(--bj-space-4);
    }

    .bj-stat {
        padding: 6px 0;
    }

}

/* Wider screens get more room around the three columns. */
@media (min-width: 1440px) {
    .bj-topbar-inner,
    .bj-ticker-inner,
    .bj-footer-inner,
    .bj-frame {
        max-width: 1480px;
    }

    .bj-frame {
        padding: var(--bj-space-5);
        grid-template-columns: 240px minmax(0, 1fr) 272px;
        column-gap: var(--bj-space-5);
    }

    .bj-status {
        top: var(--bj-space-5);
    }
}

/* Signed-out pages have no menu or status: one centred column with the stats block under it. */
.bj-body--anon .bj-frame {
    max-width: 960px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: "main" "menu";
}
