:root {
    --bg: #eef2f7;
    --panel: #ffffff;
    --border: #d6dde8;
    --text: #172033;
    --muted: #56627a;
    --brand: #1e3558;
    --brand-2: #2b4a79;
    --brand-3: #edf3fb;
    --shadow: 0 8px 24px rgba(18, 32, 58, 0.08);
    --radius: 16px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* Header */

.header {
    position: sticky;
    top: 0;
    z-index: 20;
    height: 52px;
    background: rgba(23, 32, 51, 0.97);
    color: white;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
}

.header-inner {
    width: min(1600px, calc(100% - 24px));
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 28px;
    height: 28px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    background: #314c75;
}

.brand-title {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.brand-claim {
    font-size: 11px;
    color: #c5d1e6;
}

.sidebar-toggle {
    border: 0;
    background: rgba(255, 255, 255, 0.08);
    color: white;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    flex: 0 0 34px;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.16);
}

/* Layout */

.layout {
    width: min(1600px, calc(100% - 24px));
    margin: 16px auto;
    display: grid;
    grid-template-columns: 28% minmax(0, 1fr) 56px;
    gap: 16px;
    align-items: start;
    transition: grid-template-columns 0.25s ease;
}

.layout.sidebar-collapsed {
    grid-template-columns: minmax(0, 1fr) 56px;
}

.layout.sidebar-collapsed .sidebar {
    display: none;
}

.layout.sidebar-collapsed.chat-open {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* Sidebar */

.sidebar {
    padding: 12px;
    overflow: auto;
    max-height: calc(100vh - 100px);
    position: sticky;
    top: 68px;
}

.sidebar-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    margin: 4px 4px 10px;
}

.tree-node {
    margin: 2px 0;
}

.tree-button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border: 0;
    background: transparent;
    color: var(--text);
    border-radius: 12px;
    text-align: left;
    cursor: pointer;
    font-size: 14px;
}

.tree-button:hover {
    background: #f4f7fb;
}

.tree-button.active {
    background: var(--brand);
    color: white;
}

.caret {
    width: 14px;
    text-align: center;
    color: inherit;
    flex: 0 0 14px;
}

.tree-children {
    margin-top: 2px;
}

/* Main Content */

.content {
    overflow: hidden;
    min-width: 0;
}

.content-head {
    background: linear-gradient(180deg, #22395d 0%, #1a2c48 100%);
    color: white;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.content-kicker {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: #cad5e6;
    margin-bottom: 6px;
}

.content-title {
    margin: 0;
    font-size: 28px;
    line-height: 1.15;
}

.content-path {
    margin-top: 10px;
    color: #d4dceb;
    font-size: 14px;
    line-height: 1.5;
}

.content-body {
    padding: 20px;
}

.video-wrap {
    border: 1px solid var(--border);
    border-radius: 18px;
    overflow: hidden;
    background: #0a0d12;
    margin-bottom: 18px;
    min-height: 220px;
    position: relative;
}

video {
    width: 100%;
    display: block;
    background: black;
}

.empty-box {
    display: none;
    min-height: 220px;
    align-items: center;
    justify-content: center;
    color: #b7c1d3;
    font-size: 14px;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
    align-items: start;
}

.section-title {
    font-size: 18px;
    margin: 0 0 10px;
}

/* Die card-Optik auf das details-Element übertragen */
.fulltext-details {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}

/* Der klickbare Header */
.section-summary {
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    background-color: #fcfcfc;
    transition: background 0.2s;
}

.section-summary::-webkit-details-marker {
    display: none;
}

.section-summary:hover {
    background-color: #f5f5f5;
}

.section-summary .section-title {
    margin: 0;
    font-size: 1.1rem;
    color: #333;
}

.expand-icon {
    font-size: 1.2rem;
    color: #00568a;
    transition: transform 0.3s ease;
}

.fulltext-details[open] .expand-icon {
    transform: rotate(180deg);
}

/* Der eigentliche Textbereich */
.section-content {
    padding: 16px;
    border-top: 1px solid #eee;
    line-height: 1.6;
    white-space: pre-wrap;
    /* Wichtig für die Formatierung */
}

.text-card,
.meta-card {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: white;
    padding: 16px;
}

.fulltext {
    white-space: pre-wrap;
    line-height: 1.7;
    color: #253249;
    font-size: 15px;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag {
    background: var(--brand-3);
    color: var(--brand);
    border-radius: 999px;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 600;
}

.related-courses-list .btn-secondary {
    background: #ffffff;
    border: 1px solid #00568a;
    color: #00568a;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s ease;
}

.related-courses-list .btn-secondary:hover {
    background: #00568a;
    color: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}


.download-btn {
    display: inline-flex;
    width: 100%;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    border-radius: 12px;
    padding: 12px 14px;
    background: var(--brand);
    color: white;
    font-weight: 700;
}

.download-btn:hover {
    background: var(--brand-2);
}

.empty {
    color: var(--muted);
    font-size: 14px;
}

/* Chat Drawer */

.chat-panel {
    position: sticky;
    top: 68px;
    height: calc(100vh - 84px);
    max-height: calc(100vh - 84px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    width: 56px;
    min-width: 56px;
    max-width: 56px;
    transition: width 0.25s ease, min-width 0.25s ease, max-width 0.25s ease;
}

.chat-panel.collapsed {
    width: 56px;
    min-width: 56px;
    max-width: 56px;
}

.chat-panel.open {
    width: 100%;
    min-width: 0;
    max-width: none;
}

.chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #22395d 0%, #1a2c48 100%);
    color: white;
    min-height: 64px;
    flex: 0 0 64px;
}

.chat-kicker {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: #cad5e6;
    margin-bottom: 4px;
}

.chat-title {
    font-size: 16px;
    font-weight: 700;
}

.chat-toggle {
    border: 0;
    background: rgba(255, 255, 255, 0.10);
    color: white;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 18px;
    flex: 0 0 34px;
}

.chat-toggle:hover {
    background: rgba(255, 255, 255, 0.18);
}

.chat-panel-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-panel.collapsed .chat-panel-body {
    display: none;
}

.chat-panel.collapsed .chat-title,
.chat-panel.collapsed .chat-kicker {
    display: none;
}

.chat-panel.collapsed .chat-head {
    justify-content: center;
    padding: 10px 8px;
}

.chat {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 14px;
    background: #fbfcfe;
}

.chat-composer {
    flex: 0 0 auto;
    padding: 14px;
    border-top: 1px solid var(--border);
    background: white;
}

.chat-input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 10px;
    align-items: stretch;
    width: 100%;
}

.chat-composer textarea {
    width: 100%;
    min-width: 0;
    min-height: 72px;
    max-height: 180px;
    resize: vertical;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid #cfd7e3;
    font: inherit;
    box-sizing: border-box;
    line-height: 1.45;

    overflow-x: hidden;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}

#chat-send-btn {
    border: 0;
    border-radius: 12px;
    background: var(--brand);
    color: white;
    cursor: pointer;
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    height: 72px;
    font-size: 18px;
    font-weight: 700;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 44px;
    white-space: nowrap;
}

#chat-send-btn:hover {
    background: var(--brand-2);
}

.msg {
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: 12px;
    line-height: 1.55;
    font-size: 14px;
}

.msg.user {
    background: #e8f1ff;
}

.msg.assistant {
    background: #eef3f9;
}

.msg-body {
    line-height: 1.45;
    white-space: normal;
}

.msg-body>*:first-child {
    margin-top: 0;
}

.msg-body>*:last-child {
    margin-bottom: 0;
}

.msg-body p {
    margin: 0 0 5px;
}

.msg-body ul,
.msg-body ol {
    margin: 4px 0 8px 0;
    padding-left: 22px;
}

.msg-body li {
    margin: 2px 0;
    padding-left: 2px;
}

.msg-body h1,
.msg-body h2,
.msg-body h3,
.msg-body h4 {
    margin: 8px 0 4px;
    line-height: 1.25;
}

.msg-body pre {
    margin: 6px 0;
    padding: 10px 12px;
}

.msg-body blockquote {
    margin: 6px 0;
}

.chat-meta {
    margin-top: 10px;
    font-size: 13px;
    color: var(--muted);
}

.chat-meta a {
    color: var(--brand);
    text-decoration: none;
}


.chat-system-prompt {
    padding: 12px 14px 0;
    background: white;
    border-top: 1px solid var(--border);
}

.system-prompt-toggle {
    border: 0;
    background: #e9eef6;
    color: var(--text);
    border-radius: 10px;
    padding: 8px 12px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.system-prompt-toggle:hover {
    background: #dfe7f2;
}

.system-prompt-wrap {
    margin-top: 10px;
}

.chat-system-prompt label {
    display: block;
    font-size: 13px;
    margin-bottom: 6px;
    color: var(--muted);
}

#system-prompt {
    width: 100%;
    min-height: 110px;
    max-height: 220px;
    resize: vertical;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid #cfd7e3;
    font: inherit;
    line-height: 1.45;
    box-sizing: border-box;
}

/* Responsive */

@media (max-width: 980px) {

    .layout,
    .layout.sidebar-collapsed,
    .layout.sidebar-collapsed.chat-open {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        max-height: none;
    }

    .chat-panel,
    .chat-panel.collapsed,
    .chat-panel.open {
        position: static;
        width: 100%;
        min-width: 0;
        max-width: none;
        height: auto;
        max-height: none;
    }

    .chat-panel.collapsed .chat-panel-body {
        display: none;
    }
}

.test-toolbar {
    margin: 10px 0 18px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    align-items: center;
}

.toolbar-link {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.primary-btn,
.secondary-btn {
    border: 0;
    border-radius: 12px;
    padding: 10px 14px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.primary-btn {
    background: var(--brand);
    color: white;
}

.primary-btn:hover {
    background: var(--brand-2);
}

.secondary-btn {
    background: #e9eef6;
    color: var(--text);
}

.secondary-btn:hover {
    background: #dfe7f2;
}

.hidden {
    display: none !important;
}

.test-panel {
    margin: 0 0 28px;
    overflow: hidden;
    opacity: 1;
    transform: translateY(0);
    max-height: 5000px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    transition:
        max-height 0.4s ease,
        opacity 0.25s ease,
        transform 0.32s ease,
        margin 0.32s ease,
        border-width 0.25s ease,
        box-shadow 0.25s ease;
}

.test-panel .content-kicker {
    color: var(--brand);
    font-weight: 800;
    letter-spacing: 0.14em;
    font-size: 12px;
}

.test-panel-collapsed {
    max-height: 0;
    opacity: 0;
    transform: translateY(-18px);
    margin: 0;
    border-width: 0;
    box-shadow: none;
}

.test-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(180deg, #22395d 0%, #1a2c48 100%);
    color: white;
}

.test-panel-head .section-title {
    color: white;
    margin: 0;

}

.test-panel-head .content-kicker {
    color: #cad5e6;
    font-weight: 700;
    letter-spacing: 0.14em;
    font-size: 12px;
}

.test-progress {
    margin: 0 0 12px;
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}

.test-question {
    white-space: pre-wrap;
    line-height: 1.6;
    font-size: 15px;
    color: #253249;
}

.test-answer {
    width: 100%;
    min-height: 140px;
    resize: vertical;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid #cfd7e3;
    font: inherit;
    box-sizing: border-box;
    line-height: 1.5;
    overflow-x: hidden;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.test-actions {
    display: flex;
    gap: 10px;
    justify-content: space-between;
    align-items: center;
    margin-top: 14px;
    flex-wrap: wrap;
}

.test-result-item {
    margin-top: 16px;
}

.test-result-item h4 {
    margin: 0 0 8px;
    font-size: 16px;
}

.test-result-meta {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 8px;
}

.test-answer-preview {
    white-space: pre-wrap;
    line-height: 1.5;
    margin-bottom: 10px;
}

@media (max-width: 700px) {
    .test-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .test-panel-head {
        flex-direction: column;
        align-items: flex-start;
    }
}

.test-summary-loading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    margin-top: 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #f8fbff;
}

.test-summary-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid #cfd7e3;
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: test-spin 0.8s linear infinite;
    flex: 0 0 18px;
}

.test-summary-loading-text {
    font-size: 14px;
    color: var(--muted);
    font-weight: 600;
}

@keyframes test-spin {
    to {
        transform: rotate(360deg);
    }
}


@media (max-width: 1100px) {
    .two-col {
        grid-template-columns: 1fr;
    }
}