/* System Guide is intentionally scoped so it does not alter legacy views. */
body.app-shell[data-active-view="systemGuide"] .app-container {
    width: 100%;
    max-width: none;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-layout {
    display: grid;
    grid-template-columns: minmax(15rem, 18rem) minmax(0, 1fr);
    min-height: calc(100vh - 5.5rem);
    overflow: hidden;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-lg);
    background: var(--ui-surface);
    box-shadow: var(--ui-shadow-panel);
}

body.app-shell[data-active-view="systemGuide"] .system-guide-sidebar {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: var(--ui-space-4);
    padding: var(--ui-space-5);
    border-right: 1px solid var(--ui-border);
    background: var(--ui-surface-muted);
}

body.app-shell[data-active-view="systemGuide"] .system-guide-sidebar-heading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-sidebar-heading strong {
    display: block;
    margin-top: 0.15rem;
    color: var(--ui-text);
    font-size: 1.05rem;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-mark {
    display: grid;
    width: 2.55rem;
    height: 2.55rem;
    place-items: center;
    border: 1px solid var(--ui-action);
    border-radius: var(--ui-radius-md);
    background: var(--ui-action);
    color: var(--ui-on-action);
    font-family: var(--ui-font-label);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-eyebrow {
    display: block;
    color: var(--ui-action-text);
    font-family: var(--ui-font-label);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-sidebar-intro,
body.app-shell[data-active-view="systemGuide"] .system-guide-main-header p {
    margin: 0;
    color: var(--ui-text-muted);
    font-size: var(--ui-text-sm);
}

body.app-shell[data-active-view="systemGuide"] .system-guide-nav {
    display: grid;
    gap: 0.4rem;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-nav-button {
    display: grid;
    gap: 0.15rem;
    width: 100%;
    min-height: 3.8rem;
    padding: 0.75rem 0.85rem;
    border: 1px solid transparent;
    border-radius: var(--ui-radius-md);
    background: transparent;
    color: var(--ui-text);
    text-align: start;
    transition: background-color var(--ui-duration-fast) ease, border-color var(--ui-duration-fast) ease, color var(--ui-duration-fast) ease;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-nav-button:hover,
body.app-shell[data-active-view="systemGuide"] .system-guide-nav-button.is-active {
    border-color: var(--ui-border);
    background: var(--ui-surface-raised);
    color: var(--ui-action-text);
    box-shadow: 0 3px 10px rgba(20, 40, 34, 0.05);
}

body.app-shell[data-active-view="systemGuide"] .system-guide-nav-button span {
    font-weight: 700;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-nav-button small {
    color: var(--ui-text-muted);
    font-size: 0.72rem;
    line-height: 1.35;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-sidebar-footer {
    display: grid;
    gap: 0.75rem;
    margin-top: auto;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-secondary-button,
body.app-shell[data-active-view="systemGuide"] .system-guide-primary-button,
body.app-shell[data-active-view="systemGuide"] .system-guide-refresh-button {
    min-height: 2.5rem;
    border-radius: var(--ui-radius-sm);
    font-weight: 700;
    cursor: pointer;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-secondary-button {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--ui-border);
    background: var(--ui-surface-raised);
    color: var(--ui-text-muted);
}

body.app-shell[data-active-view="systemGuide"] .system-guide-secondary-button:hover {
    border-color: var(--ui-action);
    color: var(--ui-action-text);
}

body.app-shell[data-active-view="systemGuide"] .system-guide-status {
    color: var(--ui-text-faint);
    font-size: 0.72rem;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-status i {
    display: inline-block;
    width: 0.45rem;
    height: 0.45rem;
    margin-inline-end: 0.3rem;
    border-radius: 50%;
    background: var(--ui-success-solid);
}

body.app-shell[data-active-view="systemGuide"] .system-guide-main {
    display: grid;
    min-width: 0;
    grid-template-rows: auto minmax(0, 1fr);
    background: var(--ui-surface-raised);
}

body.app-shell[data-active-view="systemGuide"] .system-guide-main-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: clamp(1.15rem, 2vw, 2rem) clamp(1.25rem, 3vw, 3rem);
    border-bottom: 1px solid var(--ui-border-soft);
    background: var(--ui-surface);
}

body.app-shell[data-active-view="systemGuide"] .system-guide-main-header h1 {
    margin: 0.25rem 0 0.35rem;
    font-size: var(--ui-text-xl);
}

body.app-shell[data-active-view="systemGuide"] .system-guide-refresh-button {
    flex: 0 0 2.5rem;
    border: 1px solid var(--ui-border);
    background: var(--ui-surface-raised);
    color: var(--ui-action-text);
    font-size: 1.35rem;
    line-height: 1;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-refresh-button:hover {
    border-color: var(--ui-action);
    background: var(--ui-surface-muted);
}

body.app-shell[data-active-view="systemGuide"] .system-guide-content {
    min-width: 0;
    overflow: auto;
    padding: clamp(1rem, 2vw, 2.5rem) clamp(1.25rem, 3vw, 3rem);
    content-visibility: auto;
    contain: content;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-markdown {
    width: min(100%, 74rem);
    margin: 0 auto;
    color: var(--ui-text);
}

body.app-shell[data-active-view="systemGuide"] .system-guide-document-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    width: min(100%, 74rem);
    margin: 0 auto 1rem;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-document-meta span {
    padding: 0.25rem 0.55rem;
    border: 1px solid var(--ui-border-soft);
    border-radius: var(--ui-radius-pill);
    color: var(--ui-text-muted);
    font-size: 0.7rem;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-markdown h1,
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown h2,
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown h3,
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown h4 {
    margin: 1.65rem 0 0.65rem;
    color: var(--ui-text);
}

body.app-shell[data-active-view="systemGuide"] .system-guide-markdown h1:first-child,
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown h2:first-child {
    margin-top: 0;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-markdown h1 { font-size: clamp(1.55rem, 1.2rem + 1vw, 2.15rem); }
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown h2 { font-size: 1.35rem; }
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown h3 { font-size: 1.1rem; }
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown p { margin: 0.75rem 0; line-height: 1.8; }
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown ul,
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown ol { margin: 0.7rem 0 1rem 1.25rem; padding: 0; }
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown li { margin: 0.35rem 0; padding-inline-start: 0.2rem; }
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown blockquote {
    margin: 1rem 0;
    padding: 0.7rem 1rem;
    border-inline-start: 3px solid var(--ui-action);
    background: var(--ui-surface-muted);
    color: var(--ui-text-muted);
}
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown hr { margin: 1.5rem 0; border: 0; border-top: 1px solid var(--ui-border-soft); }
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown a { color: var(--ui-action-text); text-decoration: underline; }
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown code {
    padding: 0.12rem 0.32rem;
    border-radius: 0.25rem;
    background: var(--ui-surface-muted);
    color: var(--ui-action-text);
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.88em;
}
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown pre {
    overflow: auto;
    margin: 1rem 0;
    padding: 1rem;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-md);
    background: #111827;
    color: #e5e7eb;
}
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown pre code { padding: 0; background: transparent; color: inherit; }
body.app-shell[data-active-view="systemGuide"] .system-guide-table-wrap { overflow-x: auto; margin: 1rem 0 1.25rem; }
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown table { width: 100%; min-width: 34rem; border-collapse: collapse; font-size: var(--ui-text-sm); }
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown th,
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown td { padding: 0.65rem 0.75rem; border: 1px solid var(--ui-border-soft); vertical-align: top; text-align: start; }
body.app-shell[data-active-view="systemGuide"] .system-guide-markdown th { background: var(--ui-surface-muted); color: var(--ui-text); font-weight: 700; }

body.app-shell[data-active-view="systemGuide"] .system-guide-loading,
body.app-shell[data-active-view="systemGuide"] .system-guide-error,
body.app-shell[data-active-view="systemGuide"] .system-guide-denied {
    display: grid;
    place-items: center;
    min-height: 18rem;
    padding: 2rem;
    text-align: center;
}

body.app-shell[data-active-view="systemGuide"] .system-guide-loading { gap: 0.7rem; color: var(--ui-text-muted); }
body.app-shell[data-active-view="systemGuide"] .system-guide-loading-dot {
    width: 1.4rem;
    height: 1.4rem;
    border: 3px solid var(--ui-border);
    border-top-color: var(--ui-action);
    border-radius: 50%;
    animation: system-guide-spin 0.7s linear infinite;
}
@keyframes system-guide-spin { to { transform: rotate(360deg); } }

body.app-shell[data-active-view="systemGuide"] .system-guide-error {
    margin: 0 auto;
    width: min(100%, 38rem);
    border: 1px solid var(--ui-danger);
    border-radius: var(--ui-radius-md);
    background: var(--ui-danger-soft);
    color: var(--ui-danger);
}
body.app-shell[data-active-view="systemGuide"] .system-guide-error p { margin: 0.55rem 0 1rem; }
body.app-shell[data-active-view="systemGuide"] .system-guide-primary-button {
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--ui-action);
    background: var(--ui-action);
    color: var(--ui-on-action);
}
body.app-shell[data-active-view="systemGuide"] .system-guide-primary-button:hover { background: var(--ui-action-hover); }

body.app-shell[data-active-view="systemGuide"] .system-guide-denied {
    min-height: 50vh;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-lg);
    background: var(--ui-surface);
}
body.app-shell[data-active-view="systemGuide"] .system-guide-denied h1 { margin: 0.45rem 0; }
body.app-shell[data-active-view="systemGuide"] .system-guide-denied p { color: var(--ui-text-muted); }

@media (max-width: 48rem) {
    body.app-shell[data-active-view="systemGuide"] .system-guide-layout {
        display: block;
        min-height: calc(100vh - 2rem);
        overflow: visible;
    }

    body.app-shell[data-active-view="systemGuide"] .system-guide-sidebar {
        position: sticky;
        top: max(0.25rem, env(safe-area-inset-top));
        z-index: 20;
        gap: 0.7rem;
        padding: 0.8rem;
        border-right: 0;
        border-bottom: 1px solid var(--ui-border);
        box-shadow: 0 6px 18px rgba(20, 40, 34, 0.08);
    }

    body.app-shell[data-active-view="systemGuide"] .system-guide-sidebar-intro,
    body.app-shell[data-active-view="systemGuide"] .system-guide-sidebar-footer .system-guide-status {
        display: none;
    }

    body.app-shell[data-active-view="systemGuide"] .system-guide-nav {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    body.app-shell[data-active-view="systemGuide"] .system-guide-nav-button {
        min-height: 3.2rem;
        padding: 0.55rem;
    }

    body.app-shell[data-active-view="systemGuide"] .system-guide-nav-button small { display: none; }
    body.app-shell[data-active-view="systemGuide"] .system-guide-sidebar-footer { margin-top: 0; }
    body.app-shell[data-active-view="systemGuide"] .system-guide-secondary-button { width: 100%; }
    body.app-shell[data-active-view="systemGuide"] .system-guide-content { padding: 1rem; }
    body.app-shell[data-active-view="systemGuide"] .system-guide-main-header { padding: 1rem; }
}
