/* Cardinal dashboard shell — left sidebar + iframe content area.
   Loaded once on the root index.html. Each module is rendered inside the
   iframe in "embed" mode (its own top-toolbar collapses, shader skipped). */

body.dashboard {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: 100vh;
    height: 100vh;
    overflow: hidden;
    margin: 0;
    /* The shader canvas is z-index:-1 and parented to <body>; isolation
       confines its negative z-index so it sits behind the sidebar and iframe
       instead of escaping the stacking context. */
    isolation: isolate;
}

/* ===== Sidebar ===== */
.sidebar {
    background: var(--glass-bg);
    -webkit-backdrop-filter: var(--glass-blur);
            backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 2;
    transform: translateZ(0);
}

.sidebar-header {
    padding: 22px 22px 18px;
    border-bottom: 1px solid var(--border);
}
.sidebar-header h1 {
    margin: 0;
    font-size: 19px;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--fg);
}
.sidebar-header .sub {
    display: block;
    margin-top: 4px;
    color: var(--fg-mute);
    font-size: 11px;
    font-weight: 300;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-dim) transparent;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.10em;
    color: var(--fg-mute);
    margin: 18px 14px 6px;
    user-select: none;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 13px;
    border-radius: var(--radius-sm);
    color: var(--fg-dim);
    cursor: pointer;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.02em;
    position: relative;
    transition: background 0.14s ease, color 0.14s ease;
    border-left: 2px solid transparent;
    user-select: none;
}
.nav-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--fg);
    text-decoration: none;
}
.nav-item.active {
    background: var(--accent-faint);
    color: var(--accent);
    box-shadow: inset 0 0 16px -8px var(--accent-glow);
}
.nav-item.disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.nav-item.disabled:hover {
    background: transparent;
    color: var(--fg-dim);
}

.nav-icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.nav-icon svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
}
.nav-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Sidebar footer =====
   align-items: flex-start so the lang-toggle pill keeps its inline width.
   Children that need to span the full footer (.auth-widget) opt in via
   `align-self: stretch` or `width: 100%`. */
.sidebar-footer {
    padding: 14px 18px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
}
/* The HTML5 `hidden` attribute is overridden by anything that sets
   `display: flex|grid|inline-flex`, which is the case for both .nav-item
   and .auth-* children below. Restore the expected behavior. */
.sidebar [hidden], .auth-widget [hidden] { display: none !important; }
.sidebar-footer .version {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--fg-mute);
    letter-spacing: 0.06em;
}

/* ===== Auth widget (Steam login state) ===== */
.auth-widget {
    width: 100%;
    min-height: 32px;
    align-self: stretch;
}
.auth-widget .auth-loading {
    color: var(--fg-mute);
    font-size: 11px;
    text-align: center;
    padding: 6px 0;
}
.auth-widget .auth-signin {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--accent-faint);
    color: var(--accent);
    border: 1px solid var(--accent-dim);
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    letter-spacing: 0.02em;
    transition: background 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}
.auth-widget .auth-signin:hover {
    background: hsla(var(--accent-hue), var(--accent-sat), var(--accent-lit), 0.18);
    border-color: var(--accent);
    box-shadow: 0 0 14px -6px var(--accent-glow);
    color: var(--accent);
}
.auth-widget .auth-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 4px;
}
.auth-widget .auth-avatar {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: cover;
    flex: 0 0 auto;
    border: 1px solid var(--border);
}
.auth-widget .auth-user-info {
    flex: 1;
    min-width: 0;
}
.auth-widget .auth-user-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--fg);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.auth-widget .auth-user-role {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fg-mute);
}
.auth-widget .auth-logout {
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--fg-dim);
    cursor: pointer;
    transition: color 0.14s ease, border-color 0.14s ease;
}
.auth-widget .auth-logout:hover {
    color: var(--fg);
    border-color: var(--accent-dim);
}

/* ===== Content frame ===== */
.dashboard-main {
    position: relative;
    overflow: hidden;
    background: transparent;
}
#module-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: transparent;
    display: block;
}

/* ===== Server picker (sidebar footer) =====
 * Sits in the sidebar footer just above the auth widget. Slim, discreet
 * row that opens a popover list anchored above the button (footer is at
 * the bottom of the viewport — list grows upward). Admin route dims the
 * picker since its scope is ignored there. */
.sidebar-server {
    position: relative;
    margin: 0 0 8px;
}
.sidebar-server-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 6px;
    color: var(--fg);
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    text-align: left;
    transition: background 80ms, border-color 80ms;
}
.sidebar-server-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.14);
}
.sidebar-server-btn[aria-expanded="true"] {
    background: var(--accent-faint);
    border-color: var(--accent-dim);
}
.sidebar-server-icon {
    flex: 0 0 auto;
    display: inline-flex;
    color: var(--fg-mute);
}
.sidebar-server-btn[aria-expanded="true"] .sidebar-server-icon,
.sidebar-server-btn:hover .sidebar-server-icon {
    color: var(--accent);
}
.sidebar-server-value {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-mono);
    color: var(--fg);
    font-size: 11.5px;
}
.sidebar-server-caret {
    flex: 0 0 auto;
    color: var(--fg-mute);
    font-size: 10px;
    transition: transform 100ms;
}
.sidebar-server-btn[aria-expanded="true"] .sidebar-server-caret {
    transform: rotate(180deg);
}

/* The popover opens UPWARD because the trigger lives near the bottom of
 * the viewport. `bottom: calc(100% + 4px)` anchors it just above the
 * button. */
.sidebar-server-list {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    right: 0;
    max-height: 320px;
    overflow-y: auto;
    margin: 0;
    padding: 4px;
    list-style: none;
    background: rgba(14, 16, 20, 0.98);
    border: 1px solid var(--accent-dim);
    border-radius: 8px;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.55);
    z-index: 50;
}
.sidebar-server-list[hidden] {
    display: none;
}
.sidebar-server-list li {
    padding: 7px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    color: var(--fg);
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}
.sidebar-server-list li:hover {
    background: var(--accent-faint);
}
.sidebar-server-list li.active {
    background: var(--accent-dim);
    color: #fff;
}
.sidebar-server-list li .ss-slug {
    font-family: var(--font-mono);
    color: var(--fg-mute);
    font-size: 10.5px;
}
.sidebar-server-list li.empty {
    color: var(--fg-mute);
    cursor: default;
    font-style: italic;
}
.sidebar-server-list li.empty:hover {
    background: transparent;
}

/* When the admin route is active we hint visually that the server scope
 * is ignored for that view — dim the picker. */
.sidebar.server-irrelevant .sidebar-server-btn {
    opacity: 0.55;
}

/* ===== Responsive ===== */
@media (max-width: 760px) {
    body.dashboard {
        grid-template-columns: 64px 1fr;  /* collapsed icon-only sidebar */
    }
    .sidebar-header h1   { font-size: 0; }
    .sidebar-header h1::after { content: '◆'; font-size: 20px; color: var(--accent); }
    .sidebar-header .sub { display: none; }
    .nav-label,
    .nav-section-label,
    .sidebar-footer .version,
    [data-i18n-toggle] { display: none; }
    .sidebar-footer { padding: 10px 8px; }
    .nav-item { justify-content: center; padding: 10px; }
}
