:root {
    --shell-rail-width: 108px;
    --shell-topbar-height: 58px;
    --shell-border: #d9e0e6;
    --shell-text: #17212c;
    --shell-muted: #687586;
}

* {
    box-sizing: border-box;
}

.ignis-app-body {
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
    background: var(
        --tenant-page-background,
        #f5f7f9
    );
}

.ignis-shell {
    min-height: 100vh;
}

.app-rail {
    position: fixed;
    z-index: 80;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    width: var(--shell-rail-width);
    color: #fff;
    background:
        linear-gradient(
            180deg,
            var(--tenant-rail-start, #0b2638),
            var(--tenant-rail-end, #126f96)
        );
    box-shadow: 4px 0 18px rgb(0 0 0 / 8%);
}

.rail-brand {
    display: grid;
    justify-items: center;
    gap: 5px;
    min-height: 78px;
    padding: 12px 8px;
    border-bottom: 1px solid rgb(255 255 255 / 10%);
    color: #fff;
    text-decoration: none;
}

.rail-brand-mark {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: var(--tenant-primary, #e85a32);
    font-weight: 800;
}

.rail-brand-text {
    font-size: 12px;
    font-weight: 700;
}

.rail-navigation {
    display: grid;
    gap: 2px;
    padding: 8px 0;
}

.rail-item {
    appearance: none;
    display: grid;
    justify-items: center;
    gap: 4px;
    width: 100%;
    min-height: 63px;
    padding: 8px 5px;
    border: 0;
    border-left: 3px solid transparent;
    color: rgb(255 255 255 / 83%);
    background: transparent;
    font: inherit;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.rail-item:hover {
    color: #fff;
    background: rgb(255 255 255 / 8%);
}

.rail-item.is-active {
    border-left-color: #fff;
    color: #fff;
    background: var(
        --tenant-rail-active,
        #167ca5
    );
}

.rail-item.is-disabled {
    cursor: not-allowed;
    opacity: 0.42;
}

.rail-icon {
    display: grid;
    place-items: center;
    width: 27px;
    height: 27px;
    font-size: 21px;
    line-height: 1;
}

.rail-label {
    max-width: 92px;
    font-size: 11px;
    line-height: 1.15;
}

.rail-footer {
    display: flex;
    justify-content: center;
    margin-top: auto;
    padding: 12px;
}

.rail-footer span {
    padding: 5px 8px;
    border-radius: 999px;
    background: rgb(255 255 255 / 12%);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.shell-main {
    min-width: 0;
    min-height: 100vh;
    margin-left: var(--shell-rail-width);
}

.shell-topbar {
    position: sticky;
    z-index: 60;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--shell-topbar-height);
    padding: 0 18px;
    border-bottom: 1px solid var(--shell-border);
    background: rgb(255 255 255 / 96%);
    backdrop-filter: blur(12px);
}

.topbar-start,
.shell-topbar-actions {
    display: flex;
    align-items: center;
}

.topbar-start {
    gap: 10px;
}

.shell-topbar-actions {
    gap: 10px;
}

.topbar-brand {
    display: grid;
    color: var(--shell-text);
    text-decoration: none;
}

.topbar-brand strong {
    font-size: 13px;
}

.topbar-brand small {
    color: var(--shell-muted);
    font-size: 10px;
}

.mobile-rail-toggle {
    display: none;
    border: 0;
    background: transparent;
    font-size: 21px;
}

.shell-tenant,
.shell-user {
    display: grid;
    text-align: right;
}

.shell-tenant small,
.shell-user small {
    color: var(--shell-muted);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.shell-tenant strong,
.shell-user strong {
    max-width: 240px;
    overflow: hidden;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shell-action-button {
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid var(--shell-border);
    border-radius: 5px;
    color: var(--shell-text);
    background: #fff;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
}

.shell-action-button:hover {
    border-color: var(
        --tenant-primary,
        #e85a32
    );
}

.shell-environment {
    padding: 5px 8px;
    border-radius: 999px;
    color: var(
        --tenant-primary-dark,
        #c94725
    );
    background: #fff0eb;
    font-size: 9px;
    font-weight: 800;
}

.shell-language .language-switcher {
    display: inline-grid;
    grid-template-columns: 1fr 1fr;
    width: 72px;
    padding: 2px;
    border: 1px solid var(--shell-border);
    border-radius: 5px;
    background: #f4f6f8;
}

.shell-language .language-switcher-link {
    min-width: 0;
    min-height: 28px;
    border-radius: 3px;
    color: var(--shell-muted);
    font-size: 10px;
}

.shell-language .language-switcher-link.is-active {
    color: #fff;
    background: var(
        --tenant-primary,
        #e85a32
    );
}

.shell-content {
    min-width: 0;
    padding: 18px 20px 36px;
}

.module-flyout {
    position: fixed;
    z-index: 75;
    top: var(--shell-topbar-height);
    bottom: 0;
    left: var(--shell-rail-width);
    width: min(720px, calc(100vw - var(--shell-rail-width)));
    overflow-y: auto;
    border-right: 1px solid rgb(255 255 255 / 10%);
    color: #fff;
    background: #0b3c59;
    box-shadow: 14px 12px 35px rgb(0 0 0 / 22%);
    transform: translateX(-105%);
    visibility: hidden;
    transition:
        transform 160ms ease,
        visibility 160ms ease;
}

.ignis-shell.flyout-open .module-flyout {
    transform: translateX(0);
    visibility: visible;
}

.flyout-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    padding: 12px 18px;
    border-bottom: 1px solid rgb(255 255 255 / 12%);
}

.flyout-header div {
    display: grid;
}

.flyout-header small {
    color: rgb(255 255 255 / 54%);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.flyout-header strong {
    font-size: 18px;
}

.flyout-close {
    width: 36px;
    height: 36px;
    border: 1px solid rgb(255 255 255 / 16%);
    border-radius: 5px;
    color: #fff;
    background: transparent;
    font-size: 22px;
    cursor: pointer;
}

.flyout-panel {
    grid-template-columns:
        repeat(3, minmax(0, 1fr));
    gap: 28px;
    padding: 22px 20px 30px;
}

.flyout-panel:not([hidden]) {
    display: grid;
}

.flyout-column {
    display: grid;
    align-content: start;
    gap: 2px;
}

.flyout-column h2 {
    margin: 0 0 7px;
    padding-bottom: 7px;
    border-bottom: 1px solid rgb(255 255 255 / 16%);
    color: #55aace;
    font-size: 15px;
    font-weight: 500;
}

.flyout-column a,
.flyout-pending {
    display: block;
    padding: 8px 0;
    color: #fff;
    font-size: 12px;
    line-height: 1.3;
    text-decoration: none;
}

.flyout-column a:hover {
    color: #9edcf2;
}

.flyout-pending {
    color: rgb(255 255 255 / 52%);
}

.shell-overlay {
    position: fixed;
    z-index: 65;
    inset: var(--shell-topbar-height) 0 0
        var(--shell-rail-width);
    border: 0;
    background: rgb(9 23 34 / 26%);
}

@media (max-width: 1000px) {
    .shell-user,
    .shell-tenant small,
    .topbar-brand small {
        display: none;
    }

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

@media (max-width: 760px) {
    :root {
        --shell-rail-width: 104px;
    }

    .app-rail {
        transform: translateX(-100%);
        transition: transform 160ms ease;
    }

    .ignis-shell.rail-open .app-rail {
        transform: translateX(0);
    }

    .shell-main {
        margin-left: 0;
    }

    .mobile-rail-toggle {
        display: block;
    }

    .shell-topbar {
        padding: 0 10px;
    }

    .shell-topbar-actions {
        gap: 5px;
    }

    .shell-action-button {
        padding-inline: 8px;
    }

    .shell-tenant {
        display: none;
    }

    .module-flyout {
        left: 0;
        width: 100%;
    }

    .flyout-panel {
        grid-template-columns: 1fr;
    }

    .shell-overlay {
        left: 0;
    }

    .shell-content {
        padding: 14px 12px 30px;
    }
}

/* Registry-driven navigation */
.navigation-icon {
    display: block;
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.rail-item .navigation-icon {
    width: 17px;
    height: 17px;
}

.module-flyout .flyout-panel[hidden] {
    display: none !important;
}

.module-flyout .flyout-panel {
    display: grid;
    grid-template-columns:
        repeat(
            auto-fit,
            minmax(220px, 1fr)
        );
    gap: 0;
    min-width: min(760px, calc(100vw - 130px));
    max-width: min(1040px, calc(100vw - 130px));
}

.module-flyout .flyout-column {
    min-width: 0;
    padding: 18px;
    border-right: 1px solid
        var(--shell-border, #dce3e8);
}

.module-flyout .flyout-column:last-child {
    border-right: 0;
}

.flyout-column-header {
    min-height: 54px;
    margin-bottom: 12px;
}

.flyout-column-header h3 {
    margin: 0;
    color: var(--shell-text, #182631);
    font-size:
        calc(
            12px
            * var(--ignis-font-scale, 1)
        );
    font-weight: 700;
}

.flyout-column-header p {
    margin: 5px 0 0;
    color: var(--shell-muted, #697985);
    font-size:
        calc(
            9px
            * var(--ignis-font-scale, 1)
        );
    line-height: 1.4;
}

.flyout-links {
    display: grid;
    gap: 4px;
}

.flyout-link {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-height: 48px;
    padding: 9px 10px;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--shell-text, #182631);
    text-decoration: none;
    transition:
        background-color 120ms ease,
        border-color 120ms ease;
}

.flyout-link:hover,
.flyout-link:focus-visible {
    border-color:
        var(--shell-border, #dce3e8);
    background:
        var(--tenant-page-background, #f4f7f9);
    outline: none;
}

.flyout-link.is-active {
    border-color:
        color-mix(
            in srgb,
            var(--tenant-primary, #e94f26) 35%,
            #dce3e8
        );
    background:
        color-mix(
            in srgb,
            var(--tenant-primary, #e94f26) 8%,
            white
        );
}

.flyout-link.is-planned {
    cursor: default;
    opacity: 0.58;
}

.flyout-link-icon {
    display: grid;
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    place-items: center;
    color:
        var(--tenant-primary, #e94f26);
}

.flyout-link-icon .navigation-icon {
    width: 16px;
    height: 16px;
}

.flyout-link-content {
    display: grid;
    flex: 1 1 auto;
    gap: 3px;
    min-width: 0;
}

.flyout-link-content strong {
    overflow: hidden;
    font-size:
        calc(
            10px
            * var(--ignis-font-scale, 1)
        );
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.flyout-link-content small {
    color: var(--shell-muted, #697985);
    font-size:
        calc(
            8.5px
            * var(--ignis-font-scale, 1)
        );
    line-height: 1.35;
}

.flyout-link-badge {
    align-self: center;
    padding: 2px 5px;
    border: 1px solid
        var(--shell-border, #dce3e8);
    border-radius: 999px;
    color: var(--shell-muted, #697985);
    font-size:
        calc(
            7px
            * var(--ignis-font-scale, 1)
        );
    white-space: nowrap;
}

@media (max-width: 900px) {
    .module-flyout .flyout-panel {
        grid-template-columns: 1fr;
        min-width: min(520px, calc(100vw - 90px));
        max-width: min(520px, calc(100vw - 90px));
    }

    .module-flyout .flyout-column {
        border-right: 0;
        border-bottom: 1px solid
            var(--shell-border, #dce3e8);
    }

    .module-flyout .flyout-column:last-child {
        border-bottom: 0;
    }
}

/* Phase 4: planned navigation modules */
.rail-item {
    position: relative;
}

.rail-item.is-planned:not(.is-active) {
    opacity: 0.68;
}

.rail-item.is-planned:hover,
.rail-item.is-planned:focus-visible {
    opacity: 1;
}

.rail-planned-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 5px;
    height: 5px;
    border: 1px solid currentColor;
    border-radius: 50%;
    background: transparent;
}

.flyout-module-notice {
    display: flex;
    grid-column: 1 / -1;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    border-bottom: 1px solid
        var(--shell-border, #dce3e8);
    background:
        var(--tenant-page-background, #f4f7f9);
    color: var(--shell-muted, #697985);
    font-size:
        calc(
            9px
            * var(--ignis-font-scale, 1)
        );
}

.flyout-module-notice strong {
    color: var(--shell-text, #182631);
    font-size:
        calc(
            9.5px
            * var(--ignis-font-scale, 1)
        );
}

.flyout-module-notice strong::before {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 6px;
    border: 1px solid
        var(--tenant-primary, #e94f26);
    border-radius: 50%;
    content: '';
}

/* Phase 5: counters and accessible mobile navigation */
.mobile-nav-toggle {
    display: none;
}

.navigation-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1190;
    border: 0;
    background: rgb(12 25 35 / 45%);
    opacity: 0;
    transition: opacity 180ms ease;
}

.navigation-backdrop.is-visible {
    opacity: 1;
}

.rail-badge,
.flyout-link-counter {
    display: inline-grid;
    flex: 0 0 auto;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    place-items: center;
    border-radius: 999px;
    background:
        var(--tenant-primary, #e94f26);
    color: #fff;
    font-size:
        calc(
            8px
            * var(--ignis-font-scale, 1)
        );
    font-weight: 700;
    line-height: 1;
}

.rail-badge {
    position: absolute;
    top: 7px;
    right: 7px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    font-size:
        calc(
            7px
            * var(--ignis-font-scale, 1)
        );
}

.flyout-link-counter {
    align-self: center;
}

.flyout-back {
    display: none;
}

body.navigation-mobile-open {
    overflow: hidden;
}

@media (max-width: 900px) {
    .mobile-nav-toggle {
        position: fixed;
        top: 9px;
        left: 9px;
        z-index: 1300;
        display: grid;
        width: 38px;
        height: 38px;
        padding: 9px;
        place-content: center;
        gap: 4px;
        border: 1px solid
            var(--shell-border, #dce3e8);
        border-radius: 4px;
        background: #fff;
        color: var(--shell-text, #182631);
        box-shadow:
            0 3px 10px rgb(18 38 53 / 15%);
        cursor: pointer;
    }

    .mobile-nav-toggle span {
        display: block;
        width: 18px;
        height: 2px;
        border-radius: 2px;
        background: currentColor;
    }

    body.navigation-mobile-open
        .mobile-nav-toggle {
        color:
            var(--tenant-primary, #e94f26);
    }

    .app-rail {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 1250;
        width: min(310px, 86vw);
        max-width: none;
        transform: translateX(-102%);
        transition: transform 180ms ease;
        overflow-y: auto;
        box-shadow:
            8px 0 24px rgb(12 25 35 / 18%);
    }

    body.navigation-mobile-open .app-rail {
        transform: translateX(0);
    }

    .app-rail .rail-brand {
        min-height: 58px;
        padding-left: 58px;
    }

    .app-rail .rail-brand-name {
        display: inline;
    }

    .app-rail .rail-navigation {
        padding: 8px;
    }

    .app-rail .rail-item {
        display: grid;
        grid-template-columns:
            28px minmax(0, 1fr) auto;
        width: 100%;
        min-height: 46px;
        padding: 8px 10px;
        text-align: left;
    }

    .app-rail .rail-icon {
        display: grid;
        place-items: center;
    }

    .app-rail .rail-label {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-rail .rail-badge {
        position: static;
        align-self: center;
    }

    .app-rail .rail-planned-dot {
        position: static;
        align-self: center;
        justify-self: center;
    }

    .module-flyout {
        position: fixed;
        inset: 0;
        z-index: 1280;
        width: 100%;
        max-width: none;
        min-width: 0;
        transform: translateX(102%);
        opacity: 1;
        visibility: hidden;
        transition:
            transform 180ms ease,
            visibility 180ms ease;
        overflow-y: auto;
        background: #fff;
    }

    .module-flyout.is-open {
        transform: translateX(0);
        visibility: visible;
    }

    .module-flyout .flyout-header {
        position: sticky;
        top: 0;
        z-index: 2;
        display: grid;
        grid-template-columns:
            auto minmax(0, 1fr) auto;
        align-items: center;
        min-height: 58px;
        padding: 7px 10px;
        background: #fff;
    }

    .flyout-back {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        padding: 7px 8px;
        border: 0;
        background: transparent;
        color:
            var(--tenant-primary, #e94f26);
        cursor: pointer;
    }

    .flyout-heading {
        min-width: 0;
        text-align: center;
    }

    .flyout-heading h2 {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .module-flyout .flyout-panel {
        grid-template-columns: 1fr;
        width: 100%;
        max-width: none;
        min-width: 0;
    }

    .module-flyout .flyout-column {
        padding: 14px;
        border-right: 0;
        border-bottom: 1px solid
            var(--shell-border, #dce3e8);
    }

    .module-flyout .flyout-column:last-child {
        border-bottom: 0;
    }

    .flyout-column-header {
        min-height: 0;
    }

    .flyout-link {
        min-height: 56px;
    }

    .flyout-link-content strong {
        white-space: normal;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-rail,
    .module-flyout,
    .navigation-backdrop {
        transition: none !important;
    }
}

/* Navigation flyout state repair */
.module-flyout {
    display: block;
}

.module-flyout:not(.is-open) {
    transform: translateX(-105%);
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.module-flyout.is-open,
.ignis-shell.flyout-open .module-flyout {
    transform: translateX(0);
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}
