/* ── Theme ────────────────────────────────────────────────────────────────────
   Colours, fonts, radii and densities come from the Aurum theme kit (theme-kit/aurum-theme.css), chosen by
   data-theme / data-density on <html>; ThemeService builds the matching MudTheme. Style with the kit's semantic
   tokens (--bg-*, --fg-*, --line, --accent, --st-*-bg/-fg, --font-*, --r-*), never raw colours. */

html, body {
    font-family: var(--font-body);
    background: var(--bg-canvas);
    color: var(--fg-1);
}

/* Fonts follow the theme (Mud's typography classes set their own family from the MudTheme as well). */
.mud-typography-h1, .mud-typography-h2, .mud-typography-h3,
.mud-typography-h4, .mud-typography-h5, .mud-typography-h6 {
    font-family: var(--font-display);
    letter-spacing: var(--display-tracking);
}

/* Small upper-case section labels in the navigation drawer */
.nav-section {
    display: block;
    height: 26px;
    line-height: 26px;
    margin-bottom: 4px !important;
    white-space: nowrap;
    overflow: hidden;
    font-family: var(--font-mono);
    font-size: var(--fz-2xs);
    letter-spacing: var(--tracking-nav);
    text-transform: uppercase;
    color: var(--fg-chrome-2);
    transition: opacity var(--dur-med) var(--ease);
}

/* ── Shell: top bar and left rail (kit chrome tokens) ─────────────────────── */
/* The workflow app's floating shell: rail and top bar are separate rounded panels on the canvas, one shell gap apart. */
.mud-layout {
    --shell-rail: var(--rail-w, 64px);
}

.mud-layout.nav-pinned {
    --shell-rail: 248px;
}

.app-topbar.mud-appbar {
    margin: var(--gap-shell) var(--gap-shell) 0 calc(var(--shell-rail) + 2 * var(--gap-shell)) !important;
    width: calc(100% - var(--shell-rail) - 3 * var(--gap-shell)) !important;
    border-radius: var(--r-chrome);
    border: var(--hdr-border);
    box-shadow: var(--hdr-shadow);
    transition: margin var(--dur-med) var(--ease), width var(--dur-med) var(--ease);
}

.mud-layout .mud-main-content {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    box-sizing: border-box;
    padding: calc(var(--mud-appbar-height, 64px) + 2 * var(--gap-shell)) var(--gap-shell) var(--gap-shell) calc(2 * var(--gap-shell));
}

/* The workspace: a rounded, bordered panel the same width as the top bar; the page scrolls inside it. */
.page-surface {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: var(--r-chrome);
    padding: var(--gap-page);
}


/* The rail is 64px with the A-symbol. Hovering or tabbing into it expands it over the page (nothing moves);
   "Pin navigation" keeps it open and pushes the page (Mud's open state). "Peek" = hover or keyboard focus. */
.app-rail.mud-drawer {
    top: var(--gap-shell);
    left: var(--gap-shell);
    height: calc(100% - 2 * var(--gap-shell));
    border-radius: var(--r-chrome);
    overflow: hidden;
    transition: width var(--dur-med) var(--ease), box-shadow var(--dur-med) var(--ease);
}

.app-rail .mud-drawer-content {
    height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
}

.app-rail .mud-drawer-content::-webkit-scrollbar {
    display: none;
}

.app-rail.mud-drawer--closed:is(:hover, :has(:focus-visible)) {
    width: var(--mud-drawer-width-left, 248px) !important;
    box-shadow: var(--shadow-modal);
    z-index: 1300;
}

.rail-brand {
    flex: 0 0 auto; /* never shrink: the drawer content is a flex column, and a long nav list squashed this and clipped the A */
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-chrome);
    display: flex;
    align-items: center;
    height: var(--mud-appbar-height, 64px);
    padding: 0 20px;
    border-bottom: 1px solid var(--line-chrome);
    color: var(--fg-chrome-1);
}

/* The Alchelyst wordmark (the logo PNG cropped to its alpha, white + alpha), filled with the theme's brand colour
   like the kit's own wordmark, so it stays readable in every theme. */
.alc-wordmark {
    display: inline-block;
    aspect-ratio: 2986 / 487;
    background-color: var(--brand-fill, var(--brand-wordmark));
    -webkit-mask: url('../theme-kit/brand/alchelyst-wordmark-mask.png') center / contain no-repeat;
    mask: url('../theme-kit/brand/alchelyst-wordmark-mask.png') center / contain no-repeat;
}

.rail-brand .brand-lockup {
    display: none;
    align-items: center;
    gap: 10px;
}

.rail-brand-by {
    padding-top: 2px;
    font-family: var(--font-mono);
    font-size: var(--fz-xs);
    white-space: nowrap;
    color: var(--fg-chrome-2);
}

.app-rail.mud-drawer--closed .rail-brand {
    justify-content: center;
    padding: 0;
}

/* Expanded (pinned, or peeking): the lockup replaces the A-symbol */
.app-rail:not(.mud-drawer--closed) .rail-brand .brand-mark,
.app-rail:is(:hover, :has(:focus-visible)) .rail-brand .brand-mark {
    display: none;
}

.app-rail:not(.mud-drawer--closed) .rail-brand .brand-lockup,
.app-rail:is(:hover, :has(:focus-visible)) .rail-brand .brand-lockup {
    display: flex;
}

.app-rail:not(.mud-drawer--closed) .rail-brand,
.app-rail:is(:hover, :has(:focus-visible)) .rail-brand {
    justify-content: flex-start;
    padding: 0 20px;
}

/* Same box in the collapsed and expanded rail: fixed height, fixed left padding (the icon sits centred in the
   64px rail: 8px margin + 12px padding + half of a 24px icon), so expanding moves nothing under the pointer. */
.app-rail .mud-nav-link {
    color: var(--nav-item-fg);
    border-radius: var(--r-ctl);
    margin: 2px 8px;
    height: 40px;
    padding: 0 12px;
    line-height: 1.2;
}

.app-rail .mud-nav-link:hover:not(.active) {
    background: var(--nav-hover-bg);
}

/* Mud's own active-link rule is more specific than a plain class, so these need !important */
.app-rail .mud-nav-link.active:not(.mud-nav-link-disabled) {
    background-color: var(--nav-active-bg) !important;
    color: var(--nav-active-fg) !important;
    font-weight: 600 !important;
    border-inline-end-width: 0;
}

.app-rail .mud-nav-link .mud-nav-link-icon,
.app-rail .mud-nav-link.active .mud-nav-link-icon {
    color: inherit;
}

/* Collapsed and not peeking: icons only. Labels fade out but keep their height, and the link text is hidden. */
.app-rail.mud-drawer--closed:not(:hover):not(:has(:focus-visible)) .mud-nav-link-text {
    display: none;
}

.app-rail.mud-drawer--closed:not(:hover):not(:has(:focus-visible)) .nav-section {
    opacity: 0;
}

/* Peeking: undo Mud's collapsed-state hiding of the link text */
.app-rail.mud-drawer--closed:is(:hover, :has(:focus-visible)) .mud-nav-link-text {
    display: inline !important;
}

.rail-footer {
    flex: 0 0 auto;
    display: none;
    position: sticky;
    bottom: 0;
    margin-top: 8px;
    padding: 10px 12px;
    background: var(--bg-chrome);
    border-top: 1px solid var(--line-chrome-soft);
}

.app-rail:not(.mud-drawer--closed) .rail-footer,
.app-rail:is(:hover, :has(:focus-visible)) .rail-footer {
    display: block;
}

.rail-pin {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: 40px;
    padding: 0 12px;
    cursor: pointer;
    border: 1px solid var(--line-chrome);
    border-radius: var(--r-ctl);
    background: var(--bg-chrome-2);
    color: var(--fg-chrome-1);
    font-family: var(--font-body);
    font-size: var(--fz-md);
    font-weight: 600;
}

.rail-pin span:nth-of-type(1) {
    flex: 1;
    text-align: left;
}

.rail-pin-state {
    font-family: var(--font-mono);
    font-size: var(--fz-2xs);
    color: var(--fg-chrome-2);
}

.rail-pin[aria-pressed="true"] .rail-pin-state {
    color: var(--live);
}

/* Environment banner (DEV / STAGING): the theme's "waiting" status colours */
.alc-environment-banner {
    flex: 0 0 auto;
    margin-bottom: var(--gap-shell);
    border-radius: var(--r-chrome);
    border: 1px solid var(--st-wait-dot);
    background: var(--st-wait-bg);
    color: var(--st-wait-fg);
    font-family: var(--font-mono);
    font-size: var(--fz-xs);
    font-weight: 700;
    letter-spacing: .15em;
    padding: 7px 0;
    overflow: hidden;
    white-space: nowrap;
    text-align: center;
    user-select: none;
}

/* ── Density ──────────────────────────────────────────────────────────────────
   The kit's density tokens (--gap-page, --cell-py, --cell-px, --btn-h, --chip-py, …) only change CSS variables, so
   MudBlazor components need these rules to read them. Normal and Detailed share the same spacing; Compact tightens
   rows, buttons, chips, list items and cards. (Form inputs are not touched: their floating labels are positioned
   for Mud's own padding, so those need Margin.Dense per component.) Type sizes never change with density. */
/* The workspace panel supplies the padding (it scales with density), so the container adds none. */
.page-container {
    padding: 0;
}

.mud-table-root .mud-table-cell {
    padding: var(--cell-py) var(--cell-px);
}

.mud-button-root:not(.mud-icon-button):not(.mud-fab) {
    min-height: var(--btn-h);
    padding-top: 0;
    padding-bottom: 0;
}

.mud-chip {
    height: auto;
    min-height: 24px;
    padding: calc(var(--chip-py) + 2px) var(--chip-px);
}

[data-density="compact"] .mud-nav-link {
    padding-top: 4px;
    padding-bottom: 4px;
}

[data-density="compact"] .mud-list-item {
    padding-top: 2px;
    padding-bottom: 2px;
}

[data-density="compact"] .mud-card-content,
[data-density="compact"] .mud-card-header {
    padding: 10px 14px;
}

[data-density="compact"] .mud-tab {
    min-height: 40px;
}

[data-density="compact"] .mud-expand-panel .mud-expand-panel-header {
    min-height: 40px;
}

[data-density="compact"] .pa-3 { padding: 8px !important; }
[data-density="compact"] .pa-4 { padding: 10px !important; }
[data-density="compact"] .pa-5 { padding: 12px !important; }
[data-density="compact"] .mb-4 { margin-bottom: 10px !important; }
[data-density="compact"] .mb-6 { margin-bottom: 14px !important; }
[data-density="compact"] .mt-4 { margin-top: 10px !important; }

/* Card boundary (stronger than --mud-palette-divider) */
:root {
    --alc-card-border: var(--line);
}

/* ── Blazor error UI ──────────────────────────────────────────────────────── */
#blazor-error-ui {
    background: var(--st-fail-bg);
    border-top: 1px solid var(--st-fail-dot);
    color: var(--st-fail-fg);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem;
    position: fixed;
    bottom: 0;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* Compact density: outlined inputs and selects use MudBlazor's own "dense" metrics without each field needing Margin.Dense. */
[data-density="compact"] .mud-input > input.mud-input-root-outlined:not(.mud-input-root-margin-dense),
[data-density="compact"] .mud-input > div.mud-input-slot.mud-input-root-outlined:not(.mud-input-root-margin-dense) {
    padding-top: 10.5px;
    padding-bottom: 10.5px;
}

[data-density="compact"] .mud-input > textarea.mud-input-root-outlined:not(.mud-input-root-margin-dense) {
    margin-top: 10.5px;
    margin-bottom: 10.5px;
}

[data-density="compact"] .mud-input-label-outlined:not(.mud-input-label-margin-dense) {
    transform: translate(14px, 12px) scale(1);
}
