/* App shell */

/* ---------- shell frame ---------- */
html.ui .dashboard-topbar-bg,
html.app-shell-page .dashboard-topbar-bg {
    display: none !important;
}

.app-shell-hidden {
    display: none !important;
}

html.ui body {
    padding-left: var(--side-w);
}

html.app-shell-ready body {
    transition: padding-left 240ms var(--ease-out);
}

html.app-shell-ready:not(.app-shell-page) body::before {
    transition: width 240ms var(--ease-out);
}

html.ui:not(.app-shell-page) body::before {
    content: "";
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--side-w);
    background: var(--shell);
    border-right: 1px solid var(--shell-line);
    z-index: 1039;
}

html.app-shell-page .se-pre-con {
    left: var(--side-w) !important;
    background: var(--bg) !important;
}

.app-icon {
    width: 16px;
    height: 16px;
    flex: none;
}

/* ---------- icon rail ---------- */
.app-shell-rail {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1042;
    width: var(--rail-w);
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--shell);
    border-right: 1px solid var(--shell-line);
    color: var(--shell-text);
    padding: 10px 0 12px;
}

.app-shell-rail a,
.app-shell-rail button {
    color: inherit;
    text-decoration: none !important;
}

.app-shell-logo {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    margin: 2px 0 14px;
    border-radius: 12px;
}

.app-shell-logo img {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: block;
}

/* dark mode: white icon */
html[data-theme="dark"] .app-shell-logo img {
    filter: brightness(0) invert(1);
}

.app-shell-rail-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100%;
}

.app-shell-rail-button {
    position: relative;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--shell-muted);
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease, transform 120ms var(--ease-out);
}

.app-shell-rail-button .app-icon {
    width: 20px;
    height: 20px;
}

.app-shell-rail-button:hover {
    background: var(--shell-hover);
    color: var(--shell-text);
}

.app-shell-rail-button:active {
    transform: scale(0.94);
}

.app-shell-rail-button.is-section {
    background: var(--shell-active);
    color: var(--shell-active-ink);
}

.app-shell-rail-button.is-section::before {
    content: "";
    position: absolute;
    left: -10px;
    top: 12px;
    bottom: 12px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--accent);
}

.app-shell-rail-button.is-view:not(.is-section) {
    box-shadow: inset 0 0 0 1.5px var(--border-strong);
}

/* tooltip */
.app-shell-rail-button[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) translateX(-4px);
    white-space: nowrap;
    padding: 6px 9px;
    border-radius: 7px;
    background: var(--text);
    color: var(--bg);
    font: 500 12px var(--font);
    box-shadow: var(--sh-md);
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease, transform 120ms var(--ease-out);
    z-index: 5;
}

.app-shell-rail-button[data-tip]:hover::after,
.app-shell-rail-button[data-tip]:focus-visible::after {
    opacity: 1;
    transform: translateY(-50%);
}

.app-shell-rail-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding-top: 10px;
    width: 44px;
}

.app-shell-rail-separator {
    width: 28px;
    height: 1px;
    background: var(--shell-line);
    margin: 6px 0;
}

/* ---------- section panel ---------- */
.app-shell-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    left: var(--rail-w);
    z-index: 1041;
    width: var(--panel-w);
    display: flex;
    flex-direction: column;
    background: var(--shell-2);
    border-right: 1px solid var(--shell-line);
    color: var(--shell-text);
}

/* desktop: panel slides behind the rail */
@media (min-width: 992px) {
    html.app-shell-no-panel .app-shell-panel {
        transform: translateX(-100%);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }

    html.app-shell-ready .app-shell-panel {
        transition: transform 240ms var(--ease-out), opacity 180ms ease, visibility 0s linear 0s;
    }

    html.app-shell-ready.app-shell-no-panel .app-shell-panel {
        transition: transform 240ms var(--ease-out), opacity 180ms ease 60ms, visibility 0s linear 240ms;
    }

    html.app-shell-ready .app-shell-panel-nav,
    html.app-shell-ready .app-shell-panel-header {
        transition: opacity 160ms ease 80ms, transform 240ms var(--ease-out) 40ms;
    }

    html.app-shell-no-panel .app-shell-panel-nav,
    html.app-shell-no-panel .app-shell-panel-header {
        opacity: 0;
        transform: translateX(-8px);
    }

    html.app-shell-ready.app-shell-no-panel .app-shell-panel-nav,
    html.app-shell-ready.app-shell-no-panel .app-shell-panel-header {
        transition: opacity 100ms ease, transform 160ms ease;
    }
}

.app-shell-panel a,
.app-shell-panel button {
    color: inherit;
    text-decoration: none !important;
}

.app-shell-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    height: var(--top-h);
    border-bottom: 1px solid var(--shell-line);
    flex: none;
}

.app-shell-panel-title {
    min-width: 0;
}

.app-shell-panel-title b {
    display: block;
    font: 700 14px/1.2 var(--font);
    color: var(--text);
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-shell-panel-title small {
    display: block;
    margin-top: 2px;
    font: 500 11px/1.2 var(--font);
    color: var(--shell-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-shell-panel-close {
    width: 30px;
    height: 30px;
    flex: none;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--shell-muted);
    cursor: pointer;
}

.app-shell-panel-close:hover {
    background: var(--shell-hover);
    color: var(--text);
}

.app-shell-panel-close .app-icon {
    width: 15px;
    height: 15px;
}

.app-shell-panel-search {
    padding: 12px 12px 4px;
    flex: none;
}

.app-shell-search {
    position: relative;
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    height: 36px;
    padding: 0 9px 0 11px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--muted);
    font: 400 13px var(--font);
    cursor: text;
    text-align: left;
    box-shadow: var(--sh-xs);
    transition: border-color 140ms ease, box-shadow 140ms ease;
}

.app-shell-search:hover {
    border-color: var(--border-strong);
}

.app-shell-search.is-open {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.app-shell-search.is-open kbd {
    visibility: hidden;
}

.app-shell-search .app-icon {
    width: 15px;
    height: 15px;
}

.app-shell-search > .app-shell-search-input,
.app-shell-search > .app-shell-search-input:focus {
    flex: 1;
    min-width: 0;
    height: 100%;
    border: 0 !important;
    outline: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    border-radius: 0 !important;
    padding: 0 !important;
    font: 400 13px var(--font);
    color: var(--text) !important;
}

.app-shell-search-input::placeholder {
    color: var(--muted);
}

.app-shell-search span {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-shell-search kbd {
    font: 500 10.5px var(--font);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 2px 5px;
    background: var(--surface-2);
    white-space: nowrap;
}

.app-shell-panel-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px 16px;
}

.app-shell-panel-label {
    display: block;
    padding: 10px 8px 6px;
    font: 600 10.5px/1 var(--font);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--shell-muted);
}

.app-shell-panel-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 36px;
    padding: 7px 10px;
    border-radius: 9px;
    color: var(--shell-text);
    font: 500 13.5px/1.25 var(--font);
    white-space: nowrap;
    transition: background-color 120ms ease, color 120ms ease;
}

.app-shell-panel-item .app-icon {
    width: 16px;
    height: 16px;
    color: var(--shell-muted);
}

.app-shell-panel-item > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-shell-panel-item:hover {
    background: var(--shell-hover);
    color: var(--text);
}

.app-shell-panel-item.is-active {
    background: var(--shell-active);
    color: var(--shell-active-ink);
    font-weight: 600;
}

.app-shell-panel-item.is-active .app-icon {
    color: var(--shell-active-ink);
}

.app-shell-panel-item .app-shell-kbd {
    font: 500 10.5px var(--font);
    color: var(--shell-muted);
    border: 1px solid var(--shell-line);
    border-radius: 5px;
    padding: 1px 5px;
    opacity: 0;
    transition: opacity 120ms ease;
}

.app-shell-panel-item:hover .app-shell-kbd {
    opacity: 1;
}

.app-shell-panel-footer {
    flex: none;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--shell-line);
}

.app-shell-panel-footer .app-shell-cta {
    width: 100%;
    justify-content: center;
}

/* rail button that reopens the panel */
.app-shell-panel-open-button {
    display: none;
}

html.app-shell-no-panel .app-shell-panel-open-button {
    display: grid;
}

/* ---------- top bar ---------- */
.app-shell-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border);
}

@supports not (background: color-mix(in srgb, red 50%, blue)) {
    .app-shell-topbar {
        background: var(--bg);
    }
}

.app-shell-topbar-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--top-h);
    padding: 0 var(--gutter);
}

.app-shell-icon-button {
    width: 36px;
    height: 36px;
    flex: none;
    display: grid;
    place-items: center;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
    transition: background-color 120ms ease, transform 120ms var(--ease-out), border-color 120ms ease;
}

.app-shell-icon-button:hover {
    background: var(--surface-3);
    color: var(--text);
}

.app-shell-icon-button:active {
    transform: scale(0.95);
}

.app-shell-icon-button .app-icon {
    width: 18px;
    height: 18px;
}

.app-shell-icon-button.app-shell-ghost-button {
    border-color: var(--border);
    background: var(--surface);
    box-shadow: var(--sh-xs);
}

.app-shell-icon-button.app-shell-ghost-button:hover {
    border-color: var(--border-strong);
}

.app-shell-burger {
    display: none;
}

.app-shell-crumbs {
    display: flex;
    align-items: center;
    gap: 2px;
    min-width: 0;
    flex: 1;
    font: 500 13.5px var(--font);
    color: var(--muted);
}

.app-shell-crumbs a,
.app-shell-crumbs span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-shell-crumbs a {
    color: var(--muted) !important;
    padding: 4px 7px;
    border-radius: 6px;
}

.app-shell-crumbs a:hover {
    color: var(--text) !important;
    background: var(--surface-3);
    text-decoration: none;
}

.app-shell-crumbs .app-shell-crumb-separator {
    width: 14px;
    height: 14px;
    flex: none;
    color: var(--faint);
}

.app-shell-crumbs .is-current {
    color: var(--text);
    font-weight: 600;
    max-width: 48ch;
    padding: 0 7px;
}

.app-shell-topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    flex: none;
}

.theme-switch-button .theme-switch-sun,
.theme-switch-button .theme-switch-moon {
    display: none;
}

html[data-theme="dark"] .theme-switch-button .theme-switch-sun {
    display: block;
}

html:not([data-theme="dark"]) .theme-switch-button .theme-switch-moon {
    display: block;
}

.app-shell-cta {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 36px;
    padding: 0 14px;
    border: 0;
    border-radius: 10px;
    background: var(--grad);
    color: var(--on-accent) !important;
    font: 600 13px var(--font);
    white-space: nowrap;
    text-decoration: none !important;
    box-shadow: var(--accent-glow);
    cursor: pointer;
    transition: filter 140ms ease, transform 120ms var(--ease-out), box-shadow 140ms ease;
}

.app-shell-cta:hover {
    filter: brightness(1.06);
    text-decoration: none;
}

.app-shell-cta:active {
    transform: scale(0.97);
}

.app-shell-cta .app-icon {
    width: 15px;
    height: 15px;
}

.app-shell-user {
    position: relative;
}

.app-shell-user > button {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 8px 0 4px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    font: 500 13px var(--font);
    cursor: pointer;
}

.app-shell-user > button:hover {
    background: var(--surface-3);
}

.app-shell-user-name {
    max-width: 14ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.person-avatar {
    width: 30px;
    height: 30px;
    flex: none;
    border-radius: 50%;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: var(--grad);
    color: #fff;
    font: 700 11.5px var(--font);
}

.person-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.person-avatar-small {
    width: 22px;
    height: 22px;
    font-size: 9.5px;
    background: var(--accent-soft-2);
    color: var(--accent-ink);
}

.app-shell-user-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 250px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--sh-md);
    transform-origin: top right;
    animation: app-shell-pop 150ms var(--ease-out) both;
    z-index: 1100;
}

.app-shell-user-menu[hidden] {
    display: none;
}

.app-shell-user-menu-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px 10px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.app-shell-user-menu-head b {
    display: block;
    color: var(--text);
    font-size: 13.5px;
}

.app-shell-user-menu-head small {
    color: var(--muted);
    font-size: 12px;
}

.app-shell-user-menu a,
.app-shell-user-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-2) !important;
    font: 500 13px var(--font);
    text-align: left;
    cursor: pointer;
    text-decoration: none !important;
}

.app-shell-user-menu a:hover,
.app-shell-user-menu button:hover {
    background: var(--surface-3);
    color: var(--text) !important;
}

.app-shell-user-menu .app-icon {
    color: var(--muted);
}

.app-shell-user-menu .app-shell-theme-row {
    justify-content: space-between;
}

.app-shell-user-menu .app-shell-theme-row small {
    color: var(--muted);
    font-size: 11.5px;
}

.app-shell-user-menu .app-shell-logout {
    border-top: 1px solid var(--border);
    border-radius: 0 0 8px 8px;
    padding-top: 10px;
    color: var(--crit) !important;
}

.app-shell-user-chevron {
    width: 12px;
    height: 12px;
    opacity: 0.6;
}

@keyframes app-shell-pop {
    from {
        opacity: 0;
        transform: translateY(-4px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* drawer backdrop (narrow screens) */
.app-shell-scrim {
    position: fixed;
    inset: 0;
    z-index: 1038;
    background: var(--scrim);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms var(--ease-out);
}

html.app-shell-drawer-open .app-shell-scrim {
    opacity: 1;
    pointer-events: auto;
}

/* ---------- command palette + shortcuts ---------- */
.app-shell-search .command-palette {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 2000;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-lg);
    overflow: hidden;
    cursor: default;
}

.app-shell-search .command-palette[hidden] {
    display: none;
}

.command-palette-list {
    list-style: none;
    margin: 0;
    padding: 6px;
    max-height: min(52vh, 440px);
    overflow: auto;
}

.command-palette-group {
    padding: 10px 10px 4px;
    font: 600 11px var(--font);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.command-palette-list a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    color: var(--text) !important;
    font-size: 14px;
    text-decoration: none !important;
}

.command-palette-list a .app-icon {
    width: 16px;
    height: 16px;
    color: var(--muted);
    flex: none;
}

.command-palette-list a small {
    margin-left: auto;
    color: var(--faint);
    font-size: 12px;
}

.command-palette-list li.on a {
    background: var(--accent);
    color: var(--on-accent) !important;
}

.command-palette-list li.on a .app-icon,
.command-palette-list li.on a small {
    color: rgba(255, 255, 255, 0.85);
}

.command-palette-empty {
    padding: 24px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

.app-shell-help {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1900;
    min-width: 340px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--sh-md);
    padding: 16px 18px;
    font-size: 13px;
    color: var(--text-2);
}

.app-shell-help[hidden] {
    display: none;
}

.app-shell-help b {
    display: block;
    margin-bottom: 8px;
    color: var(--text);
}

.app-shell-help div {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    padding: 4px 0;
}

.app-shell-help kbd {
    font: 500 11px var(--font);
    border: 1px solid var(--border-strong);
    border-radius: 5px;
    padding: 1px 5px;
    margin-left: 3px;
    color: var(--text);
    background: var(--surface-2);
}

/* top bar */
html:not([data-theme="dark"]) .app-shell-topbar {
    background: rgba(255, 255, 255, 0.92);
}

.app-shell-topbar .app-shell-search {
    width: clamp(220px, 24vw, 340px);
    height: 36px;
    box-shadow: none;
    background: var(--surface-2);
}

.app-shell-topbar .app-shell-search:hover,
.app-shell-topbar .app-shell-search.is-open {
    background: var(--surface);
}

.app-shell-topbar .app-shell-search.is-open {
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.app-shell-topbar-right {
    gap: 6px;
}

.app-shell-topbar-right .app-shell-icon-button.app-shell-ghost-button {
    box-shadow: none;
}

.app-shell-broadcast-link {
    color: var(--text-2) !important;
    text-decoration: none !important;
}

.app-shell-user-menu .app-shell-logout {
    margin-top: 4px;
}

/* rail: sections + support only */
.app-shell-rail-footer {
    border-top: 0;
}

/* section panel */
.app-shell-panel-header {
    padding: 0 18px;
}

.app-shell-panel-nav {
    padding-top: 10px;
}

.app-shell-drawer-handle {
    position: fixed;
    top: 50%;
    left: calc(var(--side-w) - 12px);
    z-index: 1044;
    width: 24px;
    height: 24px;
    padding: 0;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--muted);
    box-shadow: var(--sh-sm);
    cursor: pointer;
    transform: translateY(-50%);
    transition: left 240ms var(--ease-out), background-color 120ms ease, color 120ms ease, border-color 120ms ease, transform 120ms var(--ease-out);
}

.app-shell-drawer-handle svg {
    width: 12px;
    height: 12px;
    transition: transform 240ms var(--ease-out);
}

.app-shell-drawer-handle:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.app-shell-drawer-handle:active {
    transform: translateY(-50%) scale(0.92);
}

html.app-shell-no-panel .app-shell-drawer-handle svg {
    transform: rotate(180deg);
}

html:not(.app-shell-page) .app-shell-drawer-handle {
    display: none;
}

/* open-incident count next to "Incidents" */
.app-shell-panel-item > span {
    flex: 0 1 auto;
}

.app-shell-panel-item .app-shell-kbd {
    margin-left: auto;
}

.app-shell-panel-count {
    display: inline-grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--crit);
    color: #fff;
    font: 700 11px/1 var(--font);
    font-variant-numeric: tabular-nums;
}

html[data-theme="dark"] .app-shell-panel-count {
    background: #e5484d;
}

.app-shell-panel-count[hidden] {
    display: none;
}
