/**
 * Shared styles for Full Stack courses
 * Include this in all course pages
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-dark: #0d1117;
    --bg-card: #161b22;
    --bg-hover: #21262d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #58a6ff;
    --accent-green: #3fb950;
    --accent-orange: #d29922;
    --accent-purple: #a371f7;
    --accent-red: #f85149;
    --border: #30363d;
    --code-bg: #0d1117;
    --header-height: 60px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Header */
header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    height: var(--header-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.15s;
}

.back-link:hover {
    color: var(--accent);
}

.header-brand h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.header-brand h1 span {
    color: var(--accent);
}

.tagline {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Layout */
.page-layout {
    display: flex;
    min-height: calc(100vh - var(--header-height));
}

/* Sidebar */
#sidebar-nav {
    width: 280px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 20px 0;
    overflow-y: auto;
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    flex-shrink: 0;
}

.nav-part {
    margin-bottom: 24px;
}

.nav-part-title {
    padding: 8px 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.nav-section {
    display: block;
    padding: 10px 20px 10px 32px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    border-left: 2px solid transparent;
    transition: all 0.15s;
}

.nav-section:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-section.active {
    background: var(--bg-hover);
    color: var(--accent);
    border-left-color: var(--accent);
}

.nav-section.completed {
    color: var(--accent-green);
}

.nav-section.locked {
    color: var(--text-muted);
    cursor: not-allowed;
}

.nav-section .icon {
    margin-right: 8px;
}

/* Main content */
main {
    flex: 1;
    padding: 40px;
    max-width: 900px;
    min-width: 0;
}

/* Sections — scoped to the renderer's page sections (direct children of
   #course-root): a bare `section` selector also swallowed <section> elements
   widgets create elsewhere (e.g. the anatomy lightbox's tab panels). */
#course-root > section {
    display: none;
}

#course-root > section.active {
    display: block;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    margin-bottom: 24px;
}

.card h2 {
    font-size: 1.5rem;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.card h2 .icon {
    font-size: 1.25rem;
}

/* Lesson content */
.lesson-intro {
    margin-bottom: 24px;
}

.lesson-intro p {
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.lesson-intro strong {
    color: var(--text-primary);
}

.lesson-intro code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.9em;
    color: var(--accent);
}

/* Code blocks */
pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
    margin: 16px 0;
}

pre code {
    background: none;
    padding: 0;
    margin: 0;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    text-indent: 0;
    letter-spacing: normal;
    word-spacing: normal;
    white-space: pre;
    display: block;
}

pre code::first-line {
    text-indent: 0;
}

/* Info boxes */
.info-box {
    background: rgba(88, 166, 255, 0.1);
    border: 1px solid rgba(88, 166, 255, 0.3);
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
}

.info-box strong {
    color: var(--accent);
}

.warning-box {
    background: rgba(210, 153, 34, 0.1);
    border: 1px solid rgba(210, 153, 34, 0.3);
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
}

.warning-box strong {
    color: var(--accent-orange);
}

/* Widgets (shared base) */
.widget {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin: 24px 0;
}

.widget-title {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* Page timing */
#page-timing {
    position: fixed;
    bottom: 8px;
    right: 8px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: monospace;
}

/* Responsive */
@media (max-width: 900px) {
    .page-layout {
        flex-direction: column;
    }

    #sidebar-nav {
        width: 100%;
        height: auto;
        position: relative;
        top: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    main {
        padding: 20px;
    }
}

/* ── Auth gate (auth:'required' only) ─────────────────────────────────────────
   Logged-out visitors to a 'required' instance see this sign-in wall instead of
   the courses. Client-side barrier ("prove interest"), not a security control —
   see DENOMINATOR.md §3.3. */
body.auth-gated #sidebar-nav { display: none; }
.auth-gate {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    padding: 2rem;
}
.auth-gate-card {
    max-width: 480px;
    width: 100%;
    text-align: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem 2rem;
}
.auth-gate-card h1 {
    margin: 0 0 0.5rem;
    color: var(--text-primary);
}
.auth-gate-tagline {
    color: var(--text-secondary);
    margin: 0 0 1.5rem;
}
.auth-gate-msg {
    color: var(--text-muted);
    margin: 0 0 1.5rem;
}
.auth-gate-btn {
    background: var(--accent);
    color: #0d1117;
    border: none;
    border-radius: 8px;
    padding: 0.7rem 1.6rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}
.auth-gate-btn:hover { filter: brightness(1.1); }

/* ── Comprehension block (auth-agnostic; the `comprehension` block type) ───────
   Conversational mastery check that replaces MCQs. Uses the engine CSS vars so
   each instance theme colors it automatically. */
.comprehension {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-card);
    padding: 1rem 1.1rem;
    margin: 18px 0;
}
.comp-header {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--accent);
    margin-bottom: 0.6rem;
    font-weight: 700;
}
.comp-transcript {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    max-height: 420px;
    overflow-y: auto;
    margin-bottom: 0.75rem;
}
.comp-msg { max-width: 88%; }
.comp-msg--student { align-self: flex-end; text-align: right; }
.comp-msg--grader { align-self: flex-start; }
.comp-msg-who {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
}
.comp-msg-body {
    display: inline-block;
    padding: 0.55rem 0.8rem;
    border-radius: 12px;
    white-space: pre-wrap;
    line-height: 1.55;
    font-size: 0.92rem;
    border: 1px solid var(--border);
}
.comp-msg--grader .comp-msg-body { background: var(--bg-hover); color: var(--text-primary); }
.comp-msg--student .comp-msg-body {
    background: color-mix(in srgb, var(--accent) 18%, transparent);
    border-color: color-mix(in srgb, var(--accent) 45%, transparent);
    color: var(--text-primary);
}
.comp-input-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.comp-input {
    flex: 1;
    resize: vertical;
    min-height: 2.5rem;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.92rem;
}
.comp-input:focus { outline: none; border-color: var(--accent); }
.comp-send {
    background: var(--accent);
    color: #0a0a14;
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1.1rem;
    font-weight: 600;
    cursor: pointer;
}
.comp-send:hover { filter: brightness(1.1); }
.comp-send:disabled, .comp-input:disabled { opacity: 0.55; cursor: not-allowed; }
.comp-status { margin-top: 0.55rem; font-size: 0.85rem; min-height: 1.1em; }
.comp-status--thinking { color: var(--text-muted); font-style: italic; }
.comp-status--error { color: var(--accent-red); }
.comp-status--mastered { color: var(--accent-green); font-weight: 700; }
.comprehension.comp-mastered { border-color: var(--accent-green); }

/* ── Content search (header box + results dropdown) ───────────────────────────
   Engine-level (every instance gets it). Matches the dark base; colors come
   from the shared CSS vars so an instance theme's --accent flows through. The
   input and result text stay plain, selectable, copyable. */
.search-box {
    position: relative;
    margin-right: 1rem;
}
.search-box input[type="search"] {
    width: 13rem;
    max-width: 40vw;
    padding: 0.35rem 0.7rem;
    background: var(--bg-dark);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.search-box input[type="search"]::placeholder { color: var(--text-muted); }
.search-box input[type="search"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}
.search-results {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 26rem;
    max-width: 80vw;
    max-height: 60vh;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    z-index: 200;
    padding: 0.3rem;
}
.search-results[hidden] { display: none; }
.search-result {
    display: block;
    padding: 0.5rem 0.6rem;
    border-radius: 6px;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
}
.search-result:hover,
.search-result.active {
    background: var(--bg-hover);
}
.search-result .sr-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
}
.search-result .sr-course {
    font-size: 0.72rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.search-result .sr-snippet {
    display: block;
    margin-top: 0.15rem;
    font-size: 0.78rem;
    line-height: 1.4;
    color: var(--text-secondary);
}
.search-result .sr-hit { color: var(--accent); font-weight: 600; }
.search-empty,
.search-status {
    padding: 0.6rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}
