html {
    height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    container-type: inline-size;
}

main {
    min-height: 100dvh;
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas:
        "header"
        "toolbar"
        "content"
        "footer";
}

/* Header: dark background, logo + avatar */

header {
    grid-area: header;
    background-color: hsl(0, 0%, 14%);
    padding: 0.5rem 1.5rem;
}

.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-logo {
    height: 1.75rem;
}

/* Avatar / User Menu */

.avatar-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background-color: hsl(0, 0%, 40%);
    color: white;
    font-weight: 600;
    font-size: 0.85rem;
}

.avatar:hover {
    background-color: hsl(0, 0%, 50%);
}

/* Toolbar: sandwich + breadcrumb */

spc-toolbar {
    grid-area: toolbar;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1.5rem;
    border-bottom: 1px solid hsl(0, 0%, 90%);
}

/* Sandwich / hamburger button */

.sandwich {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 2rem;
    height: 2rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.sandwich span {
    display: block;
    height: 2px;
    width: 1.25rem;
    border-radius: 1px;
    background-color: hsl(0, 0%, 71%);
    transition: background-color 0.2s;
}

.sandwich.is-active {
    background-color: hsl(217, 71%, 53%);
}

.sandwich.is-active span {
    background-color: #fff;
}

.sandwich:not(.is-active):hover span {
    background-color: hsl(0, 0%, 29%);
}

/* Breadcrumb override */

.toolbar .breadcrumb {
    margin-bottom: 0;
    font-size: 0.875rem;
}

.toolbar .breadcrumb ul {
    align-items: center;
}

/* Content area: nav + view */

.content-area {
    grid-area: content;
    display: flex;
    overflow: auto;
}

/* Side navigation */

.side-nav {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 12rem;
    min-width: 12rem;
    padding: 0.5rem;
    border-right: 1px solid hsl(0, 0%, 90%);
    background-color: hsl(0, 0%, 98%);
}

.nav-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
}

.nav-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: hsl(0, 0%, 21%);
    text-decoration: none;
}

.nav-hide {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.2rem;
    color: hsl(0, 0%, 71%);
    border-radius: 4px;
    display: flex;
    align-items: center;
}

.nav-hide:hover {
    background-color: hsl(0, 0%, 90%);
    color: hsl(0, 0%, 21%);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    color: hsl(0, 0%, 29%);
    text-decoration: none;
    border-radius: 4px;
    margin-top: 0.25rem;
}

.nav-item:hover {
    background-color: hsl(0, 0%, 90%);
    color: hsl(217, 71%, 53%);
}

.view {
    flex: 1;
    overflow: hidden; /* Prevent body scroll, let children scroll */
    padding: 0 1.5rem;
    display: flex;
    flex-direction: column;
}

/* Footer: dark background */

footer {
    grid-area: footer;
    background-color: hsl(0, 0%, 14%);
    color: hsl(0, 0%, 71%);
    padding: 0.75rem 1.5rem;
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

footer a {
    color: hsl(0, 0%, 71%);
}

footer a:hover {
    color: white;
}

.footer-legal {
    text-decoration: none;
    font-weight: 700;
}

.landing, .variables-view {
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.variables-view .level {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.variables-view .level .subtitle {
    margin-bottom: 0;
}

/* Table Container for scrolling */
.table-container {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    margin-bottom: 0 !important;
}

.table-container th {
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
}

/* Chart */

.chart-container {
    overflow-x: auto;
    flex-shrink: 0;
}

.spc-chart {
    width: 100%;
    height: auto;
}

.chart-legend {
    display: flex;
    gap: 1.5rem;
    font-size: 0.8rem;
    color: #999;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.chart-legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.legend-line {
    display: inline-block;
    width: 1.5rem;
    height: 2px;
}

.legend-target {
    background: #333;
    border-top: 2px dashed #333;
    height: 0;
}

.legend-spec {
    background: #e74c3c;
    border-top: 2px dashed #e74c3c;
    height: 0;
}

.legend-control {
    background: #f39c12;
    border-top: 2px dashed #f39c12;
    height: 0;
}

.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-oos {
    background: #e74c3c;
}

.legend-inactive {
    background: #a9cce3;
}

.chart-tooltip {
    position: fixed;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    line-height: 1.5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    pointer-events: auto;
    transform: translate(-50%, -100%);
    white-space: nowrap;
    z-index: 10;
}

/* Session expired overlay */

.session-expired-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.session-expired-modal {
    background: white;
    border-radius: 6px;
    padding: 2rem 2.5rem;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.session-expired-message {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
}

/* Small screens */

@container (max-width: 768px) {
    header, .toolbar, footer {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .view {
        padding: 0 1rem;
    }

    .side-nav {
        display: none !important;
    }

    .chart-legend {
        flex-direction: column;
        gap: 0.5rem;
    }

    footer {
        flex-direction: column;
        text-align: center;
        gap: 0.25rem;
    }
}
