/*
 * v2 app shell: fixed sidebar on desktop, slide-in drawer plus bottom bar on mobile.
 * Built mobile-first — the sidebar is off-canvas until the `md` breakpoint.
 */

.v2-shell {
    display: flex;
    min-height: 100dvh;
    background-color: var(--v2-bg);
}

/* ---------- Sidebar ---------- */

.v2-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: var(--v2-z-drawer);
    display: flex;
    flex-direction: column;
    width: min(86vw, var(--v2-sidebar-w));
    background: var(--v2-surface-1);
    border-right: 1px solid var(--v2-border);
    transform: translateX(-100%);
    transition: transform var(--v2-dur-base) var(--v2-ease-out);
    overscroll-behavior: contain;
}

.v2-sidebar.is-open {
    transform: translateX(0);
    box-shadow: var(--v2-shadow-lg);
}

.v2-sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: calc(var(--v2-z-drawer) - 1);
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--v2-dur-base) var(--v2-ease);
}

.v2-sidebar-scrim.is-open {
    opacity: 1;
    pointer-events: auto;
}

.v2-sidebar-head {
    display: flex;
    align-items: center;
    gap: var(--v2-space-3);
    flex: none;
    height: var(--v2-topbar-h);
    padding: 0 var(--v2-space-4);
    border-bottom: 1px solid var(--v2-border-subtle);
}

.v2-brand {
    display: flex;
    align-items: center;
    gap: var(--v2-space-2);
    min-width: 0;
    font-weight: var(--v2-weight-bold);
    font-size: var(--v2-text-md);
    letter-spacing: -0.02em;
    color: var(--v2-text);
}

.v2-brand:link,
.v2-brand:visited,
.v2-brand:hover {
    color: var(--v2-text);
    text-decoration: none;
}

.v2-brand img {
    width: 26px;
    height: 26px;
    border-radius: var(--v2-radius-sm);
}

.v2-brand-mark {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    flex: none;
    border-radius: var(--v2-radius-sm);
    background: linear-gradient(135deg, var(--v2-accent), var(--v2-cyan));
    color: #fff;
}

.v2-sidebar-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: var(--v2-space-4) var(--v2-space-3) var(--v2-space-6);
}

.v2-sidebar-foot {
    flex: none;
    padding: var(--v2-space-3);
    border-top: 1px solid var(--v2-border-subtle);
}

/* Guild / context switcher at the top of the sidebar */
.v2-context-card {
    display: flex;
    align-items: center;
    gap: var(--v2-space-3);
    width: 100%;
    padding: var(--v2-space-2) var(--v2-space-3);
    margin-bottom: var(--v2-space-4);
    border: 1px solid var(--v2-border);
    border-radius: var(--v2-radius-md);
    background: var(--v2-surface-2);
    text-align: left;
    transition: border-color var(--v2-dur-fast) var(--v2-ease),
        background var(--v2-dur-fast) var(--v2-ease);
}

.v2-context-card:hover {
    border-color: var(--v2-border-strong);
    background: var(--v2-surface-3);
    text-decoration: none;
}

.v2-context-avatar {
    width: 30px;
    height: 30px;
    flex: none;
    border-radius: var(--v2-radius-sm);
    object-fit: cover;
    background: var(--v2-surface-4);
}

.v2-context-text {
    min-width: 0;
    flex: 1;
}

.v2-context-name {
    font-size: var(--v2-text-sm);
    font-weight: var(--v2-weight-semibold);
    color: var(--v2-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.v2-context-sub {
    font-size: var(--v2-text-xs);
    color: var(--v2-text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Nav ---------- */

.v2-nav-section + .v2-nav-section {
    margin-top: var(--v2-space-5);
}

.v2-nav-title {
    padding: 0 var(--v2-space-3);
    margin-bottom: var(--v2-space-2);
    font-size: var(--v2-text-xs);
    font-weight: var(--v2-weight-semibold);
    letter-spacing: var(--v2-tracking-caps);
    text-transform: uppercase;
    color: var(--v2-text-dim);
}

.v2-nav-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.v2-nav-list li + li {
    margin-top: 0;
}

.v2-nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--v2-space-3);
    padding: var(--v2-space-2) var(--v2-space-3);
    border-radius: var(--v2-radius-sm);
    font-size: var(--v2-text-sm);
    font-weight: var(--v2-weight-medium);
    color: var(--v2-text-muted);
    transition: background var(--v2-dur-fast) var(--v2-ease),
        color var(--v2-dur-fast) var(--v2-ease);
}

.v2-nav-link:link,
.v2-nav-link:visited {
    color: var(--v2-text-muted);
    text-decoration: none;
}

.v2-nav-link:hover,
.v2-nav-link:hover:visited {
    background: var(--v2-surface-3);
    color: var(--v2-text);
    text-decoration: none;
}

.v2-nav-link.is-active,
.v2-nav-link.is-active:visited {
    background: var(--v2-accent-soft);
    color: var(--v2-text);
}

.v2-nav-link.is-active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 3px;
    height: 18px;
    border-radius: 0 var(--v2-radius-full) var(--v2-radius-full) 0;
    background: var(--v2-accent);
    transform: translateY(-50%);
}

.v2-nav-link .ico {
    flex: none;
    color: var(--v2-text-dim);
    transition: color var(--v2-dur-fast) var(--v2-ease);
}

.v2-nav-link:hover .ico,
.v2-nav-link.is-active .ico {
    color: var(--v2-accent-strong);
}

.v2-nav-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.v2-nav-badge {
    flex: none;
    padding: 1px 6px;
    border-radius: var(--v2-radius-full);
    background: var(--v2-accent);
    color: var(--v2-accent-contrast);
    font-size: 0.6875rem;
    font-weight: var(--v2-weight-semibold);
    line-height: 1.5;
}

.v2-nav-lock {
    flex: none;
    color: var(--v2-warning);
}

/* Collapsible sub-nav */
.v2-nav-group > summary {
    display: flex;
    align-items: center;
    gap: var(--v2-space-3);
    padding: var(--v2-space-2) var(--v2-space-3);
    border-radius: var(--v2-radius-sm);
    font-size: var(--v2-text-sm);
    font-weight: var(--v2-weight-medium);
    color: var(--v2-text-muted);
    cursor: pointer;
    list-style: none;
}

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

.v2-nav-group > summary:hover {
    background: var(--v2-surface-3);
    color: var(--v2-text);
}

.v2-nav-group > summary .v2-nav-caret {
    margin-left: auto;
    color: var(--v2-text-dim);
    transition: transform var(--v2-dur-fast) var(--v2-ease);
}

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

.v2-nav-sublist {
    margin: 2px 0 var(--v2-space-2);
    padding-left: var(--v2-space-6);
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.v2-nav-sublist .v2-nav-link {
    font-size: var(--v2-text-sm);
    padding-top: 6px;
    padding-bottom: 6px;
}

/* ---------- Main column ---------- */

.v2-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    padding-bottom: calc(var(--v2-bottombar-h) + env(safe-area-inset-bottom, 0px));
}

.v2-topbar {
    position: sticky;
    top: 0;
    z-index: var(--v2-z-sticky);
    display: flex;
    align-items: center;
    gap: var(--v2-space-3);
    height: var(--v2-topbar-h);
    padding: 0 var(--v2-space-4);
    background: var(--v2-surface-1);
    border-bottom: 1px solid var(--v2-border);
}

.v2-topbar-title {
    flex: 1;
    min-width: 0;
    font-size: var(--v2-text-md);
    font-weight: var(--v2-weight-semibold);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.v2-topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--v2-space-2);
}

.v2-icon-btn {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex: none;
    border: 1px solid transparent;
    border-radius: var(--v2-radius-sm);
    color: var(--v2-text-muted);
    transition: background var(--v2-dur-fast) var(--v2-ease),
        color var(--v2-dur-fast) var(--v2-ease),
        border-color var(--v2-dur-fast) var(--v2-ease);
}

.v2-icon-btn:hover {
    background: var(--v2-surface-3);
    border-color: var(--v2-border);
    color: var(--v2-text);
}

.v2-content {
    flex: 1;
    width: 100%;
    max-width: var(--v2-content-max);
    margin: 0 auto;
    padding: var(--v2-space-5) var(--v2-space-4);
}

.v2-content.is-narrow {
    max-width: var(--v2-content-narrow);
}

.v2-content.is-wide {
    max-width: none;
}

/* Workspace pages (calendar, split lists, maps, …): consume leftover viewport
   height instead of leaving a footer gap under the main widget. Opt in with
   `is-fill` on `.v2-main`. */
html:has(.v2-main.is-fill) {
    height: 100dvh;
    overflow: hidden;
}

html:has(.v2-main.is-fill) body,
html:has(.v2-main.is-fill) .v2-shell {
    height: 100%;
    max-height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

.v2-main.is-fill {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    overflow: hidden;
}

.v2-main.is-fill > .v2-content {
    flex: 1 1 0;
    height: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-top: var(--v2-space-4);
    padding-bottom: var(--v2-space-4);
}

.v2-main.is-fill > .v2-content > * {
    flex-shrink: 0;
}

.v2-main.is-fill > .v2-content > .v2-page-head {
    margin-bottom: var(--v2-space-4);
}

.v2-main.is-fill > .v2-content > .guild-cal-stretch,
.v2-main.is-fill > .v2-content > .ld-loot-panes,
.v2-main.is-fill > .v2-content > .cd-panel-requests,
.v2-main.is-fill > .v2-content > #cdPanelMyRequests,
.v2-main.is-fill > .v2-content > .map-detail-hub,
.v2-main.is-fill > .v2-content > .builder-layout,
.v2-main.is-fill > .v2-content > .members-list-card,
.v2-main.is-fill > .v2-content > .event-detail-tabs,
.v2-main.is-fill > .v2-content > .ms-lb-table-card {
    flex: 1 1 0;
    min-height: 0;
}

@media (max-width: 700px) {
    html:has(.v2-main.is-fill),
    html:has(.v2-main.is-fill) body,
    html:has(.v2-main.is-fill) .v2-shell {
        height: auto;
        max-height: none;
        overflow: auto;
    }

    .v2-main.is-fill {
        height: auto;
        max-height: none;
        overflow: visible;
    }

    .v2-main.is-fill > .v2-content {
        height: auto;
        flex: none;
        display: block;
        overflow: visible;
        padding-bottom: var(--v2-space-6);
    }

    .v2-main.is-fill > .v2-content > .guild-cal-stretch,
    .v2-main.is-fill > .v2-content > .ld-loot-panes,
    .v2-main.is-fill > .v2-content > .cd-panel-requests,
    .v2-main.is-fill > .v2-content > #cdPanelMyRequests,
    .v2-main.is-fill > .v2-content > .map-detail-hub,
    .v2-main.is-fill > .v2-content > .builder-layout,
    .v2-main.is-fill > .v2-content > .members-list-card,
    .v2-main.is-fill > .v2-content > .event-detail-tabs,
    .v2-main.is-fill > .v2-content > .ms-lb-table-card {
        flex: none;
        min-height: 0;
    }
}

/* ---------- Page header ---------- */

.v2-page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--v2-space-4);
    margin-bottom: var(--v2-space-6);
}

.v2-page-head-text {
    flex: 1;
    min-width: min(100%, 260px);
}

.v2-page-title {
    display: flex;
    align-items: center;
    gap: var(--v2-space-3);
    font-size: var(--v2-text-2xl);
    font-weight: var(--v2-weight-bold);
    letter-spacing: -0.025em;
}

.v2-page-title .ico {
    color: var(--v2-accent-strong);
}

.v2-page-lead {
    margin: var(--v2-space-2) 0 0;
    max-width: 68ch;
    color: var(--v2-text-muted);
    font-size: var(--v2-text-base);
}

.v2-page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--v2-space-2);
}

/* ---------- Sections & grids ---------- */

.v2-section + .v2-section {
    margin-top: var(--v2-space-10);
}

.v2-section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--v2-space-3);
    margin-bottom: var(--v2-space-4);
}

.v2-section-title {
    font-size: var(--v2-text-lg);
    font-weight: var(--v2-weight-semibold);
}

.v2-section-sub {
    color: var(--v2-text-muted);
    font-size: var(--v2-text-sm);
}

.v2-grid {
    display: grid;
    gap: var(--v2-space-4);
}

.v2-grid.cols-2,
.v2-grid.cols-3,
.v2-grid.cols-4 {
    grid-template-columns: 1fr;
}

.v2-stack {
    display: flex;
    flex-direction: column;
    gap: var(--v2-space-4);
}

.v2-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--v2-space-3);
}

.v2-row.is-between {
    justify-content: space-between;
}

.v2-spacer {
    flex: 1;
}

/* ---------- Mobile bottom bar ---------- */

.v2-bottombar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: var(--v2-z-sticky);
    display: flex;
    align-items: stretch;
    height: calc(var(--v2-bottombar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--v2-surface-1);
    border-top: 1px solid var(--v2-border);
}

.v2-bottombar-item {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    padding: 0 var(--v2-space-1);
    font-size: 0.6875rem;
    font-weight: var(--v2-weight-medium);
    color: var(--v2-text-dim);
    transition: color var(--v2-dur-fast) var(--v2-ease);
}

.v2-bottombar-item:link,
.v2-bottombar-item:visited {
    color: var(--v2-text-dim);
    text-decoration: none;
}

.v2-bottombar-item:hover,
.v2-bottombar-item:hover:visited,
.v2-bottombar-item.is-active,
.v2-bottombar-item.is-active:visited {
    color: var(--v2-accent-strong);
    text-decoration: none;
}

.v2-bottombar-item span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Breakpoints ---------- */

@media (min-width: 768px) {
    .v2-content {
        padding: var(--v2-space-6);
    }

    .v2-grid.cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .v2-grid.cols-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .v2-grid.cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .v2-sidebar {
        position: sticky;
        top: 0;
        height: 100dvh;
        width: var(--v2-sidebar-w);
        transform: none;
        box-shadow: none;
    }

    .v2-sidebar-scrim,
    .v2-bottombar,
    .v2-sidebar-toggle {
        display: none !important;
    }

    .v2-main {
        padding-bottom: 0;
    }

    .v2-topbar {
        padding: 0 var(--v2-space-6);
    }

    .v2-grid.cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .v2-grid.cols-4 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (min-width: 1280px) {
    .v2-content {
        padding-left: var(--v2-space-8);
        padding-right: var(--v2-space-8);
    }
}

/* Body scroll lock while the mobile drawer is open. */
body.v2-drawer-open {
    overflow: hidden;
}
