/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --topbar-height: 52px;
    --sidebar-width: 220px;
    --sidebar-bg: #1a1a2e;
    --accent: #60a5fa;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: #1a1a2e;
    background: #f8f9fa;
}

a { color: #0066cc; text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.3; margin-bottom: 0.75rem; color: #1a1a2e; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.4rem; margin-top: 1.5rem; }
h3 { font-size: 1.15rem; margin-top: 1.25rem; }

p { margin-bottom: 0.75rem; }
ul, ol { margin-left: 1.5rem; margin-bottom: 0.75rem; }
code { background: #eef; padding: 2px 6px; border-radius: 3px; font-size: 0.9em; }
pre { background: #1e1e2e; color: #cdd6f4; padding: 1rem; border-radius: 6px; overflow-x: auto; margin-bottom: 1rem; }
pre code { background: none; padding: 0; color: inherit; }

/* ===== App Layout ===== */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ===== Top Bar ===== */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    height: var(--topbar-height);
    padding: 0 1.25rem;
    background: #12122a;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.app-topbar__brand {
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.01em;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.app-topbar__brand:hover { color: rgba(255, 255, 255, 0.8); text-decoration: none; }

/* ===== Hamburger ===== */
.hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: background 0.15s;
}
.hamburger:hover { background: rgba(255, 255, 255, 0.1); }
.hamburger:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hamburger__line {
    display: block;
    width: 100%;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1),
                opacity  0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
.hamburger--open .hamburger__line:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger--open .hamburger__line:nth-child(2) { opacity: 0; transform: scaleX(0); }
.hamburger--open .hamburger__line:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ===== App Body ===== */
.app-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0;
    position: sticky;
    top: var(--topbar-height);
    height: calc(100vh - var(--topbar-height));
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                min-width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar--collapsed {
    width: 0;
    min-width: 0;
}

/* ===== Sidebar Backdrop (mobile drawer overlay) ===== */
.sidebar-backdrop {
    display: none;
}

/* ===== Sidebar Module List ===== */
.sidebar__modules {
    list-style: none;
    margin: 0;
    padding: 0.25rem 0;
}

.sidebar__section-header {
    margin: 0.6rem 0.75rem 0.2rem;
    padding: 0.2rem 0.3rem;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(176, 184, 204, 0.82);
}

.sidebar__module a {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0.45rem 0.875rem;
    color: #b0b8cc;
    font-size: 0.825rem;
    line-height: 1.4;
    border-left: 3px solid transparent;
    text-decoration: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar__module a:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
    text-decoration: none;
}

.sidebar__check-slot {
    width: 1.1rem;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
}

.sidebar__check {
    font-size: 0.65rem;
    color: #7ec8a0;
    line-height: 1;
}

.sidebar__label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar__module--complete a { color: #8dcfac; }

/* ===== Active module (current page) ===== */
.sidebar__module--active > a {
    background: rgba(96, 165, 250, 0.13);
    color: #fff;
    border-left-color: var(--accent);
    font-weight: 600;
}
.sidebar__module--active > a:hover {
    background: rgba(96, 165, 250, 0.2);
}
.sidebar__module--active.sidebar__module--complete > a { color: #fff; }
.sidebar__module--active .sidebar__check { color: #7ec8a0; }

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    padding: 2rem 2.5rem;
    max-width: 860px;
    min-width: 0;
}

/* ===== Home Page ===== */
.home-page { max-width: 780px; }

.home-page__subtitle {
    color: #666;
    font-size: 1.05rem;
    margin-bottom: 2rem;
}

.module-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.module-card {
    background: #fff;
    border: 1px solid #e0e4ef;
    border-radius: 8px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: box-shadow 0.15s;
}

.module-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,0.08); }

.module-card--complete { border-color: #7ec8a0; background: #f0fff6; }

.module-card__number { font-size: 0.75rem; color: #888; text-transform: uppercase; letter-spacing: 0.05em; }

.module-card__title { font-weight: 600; font-size: 1rem; color: #1a1a2e; }

.module-card__badge { font-size: 0.8rem; color: #2a8a56; font-weight: 600; }

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    padding: 0.45rem 1rem;
    border-radius: 5px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    text-decoration: none;
}

.btn-start {
    background: #0066cc;
    color: #fff;
    margin-top: auto;
    text-align: center;
}
.btn-start:hover { background: #0052a3; color: #fff; text-decoration: none; }

.btn-copy {
    background: #f0f4ff;
    color: #0066cc;
    border-color: #c5d5f0;
    font-size: 0.8rem;
    padding: 0.3rem 0.75rem;
    margin-left: auto;
}
.btn-copy:hover { background: #0066cc; color: #fff; }

.btn-reveal {
    background: #fff;
    color: #555;
    border: 1px solid #ccc;
    margin-top: 0.75rem;
}
.btn-reveal:hover { background: #f5f5f5; }

.btn-complete {
    background: #1a8a5a;
    color: #fff;
    font-size: 1rem;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    margin-top: 1.5rem;
    display: inline-block;
}
.btn-complete:hover { background: #157048; }

/* ===== Safety Badge ===== */
.safety-badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.safety-badge--readonly { background: #d4edda; color: #1a5c2a; }
.safety-badge--makeschanges { background: #fff3cd; color: #7a5200; }
.safety-badge--destructive { background: #f8d7da; color: #7c1c22; }

/* ===== Module Page ===== */
.module-page { max-width: 780px; }

.module-page__header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e0e4ef;
}

.module-page__meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.module-page__time { font-size: 0.875rem; color: #666; }

/* ===== Section Nav ===== */
.section-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 1.75rem;
    border-bottom: 2px solid #e0e4ef;
    padding-bottom: 0;
}

.section-nav__btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    color: #555;
    cursor: pointer;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}
.section-nav__btn:hover { color: #0066cc; }
.section-nav__btn--active { color: #0066cc; border-bottom-color: #0066cc; font-weight: 600; }

/* ===== Prompt Card ===== */
.prompt-card {
    border: 1px solid #c5d5f0;
    border-radius: 8px;
    margin-bottom: 1rem;
    overflow: hidden;
}
.prompt-card--optional { border-color: #d8d8e8; opacity: 0.85; }

.prompt-card__header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: #f0f4ff;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid #c5d5f0;
}
.prompt-card--optional .prompt-card__header { background: #f5f5f8; border-bottom-color: #d8d8e8; }

.prompt-card__label { font-weight: 600; font-size: 0.875rem; color: #1a1a2e; flex: 1; }
.prompt-card__optional-tag { font-size: 0.75rem; color: #888; background: #e8e8ef; padding: 2px 8px; border-radius: 999px; }

.prompt-card__intro {
    padding: 0.875rem 1rem 0.125rem;
    background: #fff;
}
.prompt-card__intro .markdown-section { margin: 0; }
.prompt-card__intro .markdown-section > :last-child { margin-bottom: 0; }

.prompt-card__text {
    padding: 1rem;
    font-size: 0.875rem;
    line-height: 1.6;
    white-space: pre-wrap;
    background: #fff;
    color: #1a1a2e;
    margin: 0;
    font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
}

/* ===== Checklist Panel ===== */
.checklist-panel { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }

.checklist-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: #333;
}
.checklist-item input[type="checkbox"] { margin-top: 3px; flex-shrink: 0; cursor: pointer; }

/* ===== Skill Check Panel ===== */
.skill-check-panel {
    background: #fff;
    border: 1px solid #e0e4ef;
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.skill-check-panel__question { margin-bottom: 0.75rem; }

.skill-check-panel__response {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 0.9rem;
    font-family: inherit;
    resize: vertical;
}

.skill-check-panel__expected {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: #f0fff6;
    border: 1px solid #7ec8a0;
    border-radius: 6px;
    font-size: 0.9rem;
}

/* ===== Reflection Form ===== */
.reflection-form { display: flex; flex-direction: column; gap: 1.25rem; }

.reflection-form__summary label,
.reflection-form__question label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
    color: #333;
}

.reflection-form__summary textarea,
.reflection-form__question textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 0.9rem;
    font-family: inherit;
    resize: vertical;
}

/* ===== Module Completion ===== */
.module-completion { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid #e0e4ef; }
.module-completion__done {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 1rem;
    color: #1a8a5a;
    font-weight: 600;
}

/* ===== Markdown Content ===== */
.markdown-content h1, .markdown-content h2, .markdown-content h3 { margin-top: 1rem; }
.markdown-content ul, .markdown-content ol { margin-left: 1.5rem; margin-bottom: 0.5rem; }
.markdown-content p { margin-bottom: 0.5rem; }
.markdown-content code { background: #eef; padding: 2px 5px; border-radius: 3px; font-size: 0.88em; }
.markdown-content pre { background: #1e1e2e; color: #cdd6f4; padding: 1rem; border-radius: 6px; overflow-x: auto; }
.markdown-content pre code { background: none; color: inherit; }

/* Tables */
.markdown-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    margin: 0.75rem 0 1rem;
    overflow-x: auto;
    display: block;
}
.markdown-content thead {
    background: #f0f4ff;
}
.markdown-content th {
    padding: 0.55rem 0.875rem;
    text-align: left;
    font-weight: 600;
    color: #1a1a2e;
    border-bottom: 2px solid #c5d5f0;
    white-space: nowrap;
}
.markdown-content td {
    padding: 0.5rem 0.875rem;
    border-bottom: 1px solid #e0e4ef;
    vertical-align: top;
    line-height: 1.5;
}
.markdown-content tbody tr:last-child td {
    border-bottom: none;
}
.markdown-content tbody tr:hover td {
    background: #f8f9ff;
}

/* ===== Loading / Error UI (from template) ===== */
.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem;
}
.loading-progress circle {
    fill: none;
    stroke: #e0e4ef;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}
.loading-progress circle:last-child {
    stroke: #0066cc;
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}
.loading-progress-text::after {
    content: var(--blazor-load-percentage-text, "Loading");
    display: block;
    text-align: center;
    color: #888;
    font-size: 0.875rem;
}
#blazor-error-ui {
    background: #f8d7da;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0,0,0,0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

/* ===== Responsive: Mobile (drawer sidebar) ===== */
@media (max-width: 767px) {
    /* Sidebar becomes a fixed full-height drawer */
    .sidebar {
        position: fixed;
        top: var(--topbar-height);
        left: 0;
        height: calc(100vh - var(--topbar-height));
        /* Override the desktop width-collapse: always physically 220px, control via transform */
        width: var(--sidebar-width) !important;
        min-width: var(--sidebar-width) !important;
        transform: translateX(calc(-1 * var(--sidebar-width) - 1px));
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 150;
        box-shadow: none;
    }

    /* Open state on mobile: slide in */
    .sidebar:not(.sidebar--collapsed) {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
    }

    /* Backdrop: only shown on mobile */
    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: var(--topbar-height) 0 0 0;
        background: rgba(0, 0, 0, 0.48);
        z-index: 140;
        animation: backdropIn 0.2s ease forwards;
    }

    .main-content {
        padding: 1.25rem 1rem;
    }
}

/* ===== Responsive: Tablet ===== */
@media (min-width: 768px) and (max-width: 1023px) {
    :root { --sidebar-width: 200px; }

    .main-content {
        padding: 1.5rem 1.75rem;
    }
}

@keyframes backdropIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
