:root {
    color-scheme: light;
    --background: #f5f7fb;
    --surface: #ffffff;
    --surface-muted: #eef2f7;
    --text: #172033;
    --muted: #657089;
    --border: #dce2ec;
    --primary: #0b66d8;
    --primary-hover: #084fa8;
    --danger-bg: #fff0f0;
    --danger-text: #9b1c1c;
    --code-bg: #f3f5f8;
    --shadow: 0 18px 45px rgba(23, 32, 51, 0.1);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --background: #0d1118;
    --surface: #151b25;
    --surface-muted: #1c2431;
    --text: #e8edf5;
    --muted: #9aa7ba;
    --border: #2a3545;
    --primary: #5ca4ff;
    --primary-hover: #86bbff;
    --danger-bg: #3b1c22;
    --danger-text: #ffb4b4;
    --code-bg: #0b1017;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--background);
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--background);
    font: 16px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 20%, rgba(11, 102, 216, 0.16), transparent 34rem),
        var(--background);
}

.login-card {
    width: min(100%, 430px);
    padding: 38px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

h1,
h2,
h3,
h4 {
    line-height: 1.2;
}

.login-card h1 {
    margin: 24px 0 10px;
    font-size: 2rem;
}

.login-actions {
    position: fixed;
    z-index: 5;
    top: 18px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.login-brand {
    display: inline-flex;
    max-width: 270px;
}

.brand-logo {
    display: block;
    width: 100%;
    height: auto;
    transition: filter 160ms ease;
}

:root[data-theme="dark"] .brand-logo,
:root[data-theme="dark"] .portal-logo {
    filter: invert(1) hue-rotate(180deg);
}

.eyebrow {
    margin: 0;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.muted {
    color: var(--muted);
}

.login-form {
    display: grid;
    gap: 18px;
    margin-top: 28px;
}

.login-form label {
    display: grid;
    gap: 7px;
    font-size: 0.9rem;
    font-weight: 700;
}

.login-form input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--text);
    background: var(--background);
    outline: none;
}

.login-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

.primary-button,
.secondary-button,
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
}

.primary-button {
    min-height: 46px;
    padding: 0 20px;
    color: #fff;
    background: var(--primary);
    font-weight: 800;
}

.primary-button:hover {
    background: var(--primary-hover);
}

.primary-button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.secondary-button {
    min-height: 38px;
    padding: 0 14px;
    border: 1px solid var(--border);
    color: var(--text);
    background: var(--surface);
    font-size: 0.88rem;
    font-weight: 700;
}

.secondary-button:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.is-disabled {
    pointer-events: none;
    opacity: 0.45;
}

.alert {
    padding: 11px 13px;
    border-radius: 8px;
    font-size: 0.88rem;
}

.alert {
    color: var(--danger-text);
    background: var(--danger-bg);
}

.topbar {
    position: sticky;
    z-index: 20;
    top: 0;
    display: flex;
    align-items: center;
    min-height: 64px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(14px);
}

.portal-brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: var(--text);
    font-weight: 850;
    text-decoration: none;
}

.portal-logo {
    display: block;
    width: 190px;
    height: auto;
    transition: filter 160ms ease;
}

.portal-brand span {
    color: var(--primary);
    font-size: 1.2rem;
    font-weight: 800;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.user-info {
    display: grid;
    text-align: right;
    line-height: 1.15;
}

.user-info small {
    margin-top: 4px;
    color: var(--muted);
}

.icon-button {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    color: var(--text);
    background: var(--surface);
}

.mobile-menu {
    display: none;
    margin-right: 10px;
}

.portal-layout {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    min-height: calc(100vh - 64px);
}

.sidebar {
    position: sticky;
    top: 64px;
    align-self: start;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 64px);
    overflow: hidden;
    padding: 24px 18px 18px;
    border-right: 1px solid var(--border);
    background: var(--surface);
}

.sidebar-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0 8px 14px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.tree-actions {
    display: inline-flex;
    gap: 4px;
}

.tree-action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 25px;
    height: 25px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--muted);
    background: transparent;
    cursor: pointer;
}

.tree-action-button:hover {
    border-color: var(--border);
    color: var(--primary);
    background: var(--surface-muted);
}

.tree-action-button svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

#navigation-tree ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

#navigation-tree {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 18px;
}

#navigation-tree ul ul {
    margin-left: 13px;
    padding-left: 11px;
    border-left: 1px solid var(--border);
}

#navigation-tree details > summary {
    display: flex;
    align-items: center;
    min-height: 34px;
    color: var(--text);
    cursor: pointer;
    font-weight: 750;
    list-style: none;
}

#navigation-tree details > summary::before {
    content: "›";
    margin-right: 7px;
    color: var(--muted);
    transform: rotate(0deg);
    transition: transform 120ms ease;
}

#navigation-tree details[open] > summary::before {
    transform: rotate(90deg);
}

.tree-document,
.tree-folder-link {
    width: 100%;
    padding: 7px 9px;
    border: 0;
    border-radius: 7px;
    color: var(--muted);
    background: transparent;
    cursor: pointer;
    text-align: left;
}

.tree-folder-link {
    padding-left: 0;
    color: var(--text);
    font-weight: 750;
}

.tree-document:hover,
.tree-document.is-active,
.tree-folder-link:hover,
.tree-folder-link.is-active {
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 10%, transparent);
}

.sidebar-footer {
    flex: 0 0 auto;
    padding: 15px 8px 2px;
    border-top: 1px solid var(--border);
}

.sidebar-main-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--primary);
    font-size: 0.83rem;
    font-weight: 750;
    text-decoration: none;
}

.sidebar-main-link svg,
.download-link svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.sidebar-footer p {
    margin: 9px 0 0;
    color: var(--muted);
    font-size: 0.7rem;
    line-height: 1.4;
}

.document-main {
    width: min(100%, 1100px);
    padding: 38px clamp(24px, 5vw, 74px) 100px;
}

.document-toolbar {
    padding-bottom: 22px;
    border-bottom: 1px solid var(--border);
}

.document-heading {
    min-width: 0;
}

.document-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 18px;
    min-width: 0;
}

.document-meta .eyebrow {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.download-link {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 5px;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 750;
    text-decoration: none;
}

.download-link:hover {
    color: var(--primary);
}

.document-toolbar h1 {
    margin: 9px 0 0;
    font-size: clamp(1.65rem, 4vw, 2.35rem);
}

.markdown-body {
    max-width: 850px;
    padding-top: 24px;
}

.markdown-body h1:first-child {
    display: none;
}

.markdown-body h2,
.markdown-body h3 {
    margin-top: 2em;
    scroll-margin-top: 88px;
}

.markdown-body a {
    color: var(--primary);
}

.markdown-body img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.markdown-body pre {
    overflow: auto;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--code-bg);
    font-size: 0.875rem;
    line-height: 1.55;
}

.markdown-body code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.markdown-body pre code.hljs {
    padding: 0;
    background: transparent;
}

.markdown-body :not(pre) > code {
    padding: 0.15em 0.35em;
    border-radius: 4px;
    background: var(--code-bg);
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
}

.markdown-body th,
.markdown-body td {
    padding: 9px 11px;
    border: 1px solid var(--border);
    text-align: left;
}

.markdown-body blockquote {
    margin-left: 0;
    padding-left: 18px;
    border-left: 4px solid var(--primary);
    color: var(--muted);
}

.mermaid {
    overflow: auto;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    text-align: center;
}

@media (max-width: 820px) {
    .mobile-menu {
        display: inline-flex;
    }

    .user-info {
        display: none;
    }

    .portal-layout {
        display: block;
    }

    .sidebar {
        position: fixed;
        z-index: 15;
        top: 64px;
        left: 0;
        width: min(88vw, 320px);
        transform: translateX(-105%);
        transition: transform 160ms ease;
        box-shadow: var(--shadow);
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .document-main {
        padding: 28px 20px 80px;
    }

    .document-toolbar {
        padding-bottom: 18px;
    }

    .document-meta {
        gap: 8px 14px;
    }
}

@media (max-width: 480px) {
    .login-actions {
        top: 12px;
        right: 12px;
    }

    .login-card {
        padding: 30px 22px;
    }

    .portal-logo {
        width: 145px;
    }

    .portal-brand {
        gap: 7px;
    }
}
