/* Document reader + page layout shared by module pages and course material pages
   (templates/opportunities/module_detail.html, templates/elearning/view_material.html). */
/* The theme sets overflow hidden/auto on html+body, which turns body into a
   non-scrolling scroll container and breaks position:sticky. clip keeps the
   horizontal clipping without that side effect. */
html, body { overflow-x: clip !important; overflow-y: visible !important; }

.md-page-wrap {
    --md-red: #9C1C1C;
    --md-red-dark: #7a1515;
    --md-yellow: #ECA72C;
    --md-ink: #151515;
    --md-muted: #6b6f76;
    --md-line: #ececf0;
    --md-bg: #f5f5f7;
    --md-radius: 18px;
    --md-shadow: 0 10px 30px rgba(21, 21, 21, .08);
    background: var(--md-bg);
    padding-bottom: 72px;
    color: var(--md-ink);
}
.md-container { max-width: 1240px; margin: 0 auto; padding: 0 20px; }

/* ── Buttons ── */
.md-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 9px;
    padding: 11px 20px; border-radius: 999px; border: 1px solid transparent;
    font-weight: 600; font-size: .95rem; line-height: 1.2; text-decoration: none !important;
    cursor: pointer; transition: transform .18s ease, box-shadow .18s ease, background .18s ease, color .18s ease;
    white-space: nowrap; width: auto; height: auto; margin: 0; text-transform: none; letter-spacing: normal;
}
.md-btn:hover { transform: translateY(-2px); }
.md-btn-lg { padding: 14px 26px; font-size: 1rem; }
.md-btn-block { width: 100%; }
.md-btn-primary { background: var(--md-red); color: #fff !important; box-shadow: 0 8px 20px rgba(156, 28, 28, .35); }
.md-btn-primary:hover { background: var(--md-red-dark); box-shadow: 0 12px 26px rgba(156, 28, 28, .4); }
.md-btn-light { background: #fff; color: var(--md-red) !important; box-shadow: 0 6px 18px rgba(0, 0, 0, .12); }
.md-btn-light:hover { color: var(--md-red-dark) !important; }
.md-btn-glass { background: rgba(255, 255, 255, .14); color: #fff !important; border-color: rgba(255, 255, 255, .35); backdrop-filter: blur(6px); }
.md-btn-glass:hover { background: rgba(255, 255, 255, .24); }
.md-btn-ghost { background: transparent; color: var(--md-ink) !important; border-color: var(--md-line); }

/* ── Hero ── */
.md-hero { position: relative; overflow: hidden; color: #fff; background: #1b0b0b; }
.md-hero-bg {
    position: absolute; inset: -40px; background-size: cover; background-position: center;
    filter: blur(18px) saturate(1.1); transform: scale(1.08); opacity: .55;
}
.md-hero::after {
    content: ""; position: absolute; inset: 0;
    background: rgba(122, 21, 21, .9);
}
.md-hero-inner {
    position: relative; z-index: 1; display: grid; grid-template-columns: minmax(0, 1fr) auto;
    align-items: center; gap: 48px; padding-top: 56px; padding-bottom: 96px;
}
.md-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: .85rem; opacity: .85; margin-bottom: 18px; }
.md-crumbs a { color: #fff; text-decoration: none; }
.md-crumbs a:hover { text-decoration: underline; }
.md-crumbs i { font-size: .6rem; opacity: .7; }
.md-type-badge {
    display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px;
    background: rgba(255, 255, 255, .15); border: 1px solid rgba(255, 255, 255, .25);
    font-size: .78rem; font-weight: 700; letter-spacing: .06em; margin-bottom: 16px;
}
.md-type-badge i { color: var(--md-yellow); }
.md-title { color: #fff; font-size: clamp(1.9rem, 4vw, 3.1rem); line-height: 1.12; font-weight: 800; margin: 0 0 18px; letter-spacing: -.01em; }
.md-meta { list-style: none; padding: 0; margin: 0 0 28px; display: flex; flex-wrap: wrap; gap: 10px 22px; font-size: .93rem; opacity: .92; }
.md-meta li { display: inline-flex; align-items: center; gap: 8px; color: #fff; margin: 0; }
.md-meta i { color: var(--md-yellow); }
.md-meta span { color: rgba(255, 255, 255, .8); }
.md-hero-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.md-hero-cover img {
    display: block; width: auto; height: auto; max-width: 380px; max-height: 400px; border-radius: 16px; /* keeps the cover's own shape (most modules are landscape slides) */
    box-shadow: 0 30px 60px rgba(0, 0, 0, .45); transform: rotate(2deg);
    border: 4px solid rgba(255, 255, 255, .9); transition: transform .4s ease;
}
.md-hero-cover img:hover { transform: rotate(0) scale(1.02); }

/* ── Body grid ── */
.md-body {
    position: relative; z-index: 2; margin-top: -56px;
    display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; align-items: start;
}

/* ── Reader ── */
.md-reader {
    background: #fff; border-radius: var(--md-radius); box-shadow: var(--md-shadow);
    overflow: clip; display: flex; flex-direction: column; /* clip (not hidden) keeps the toolbar sticky */
}
.md-toolbar {
    position: sticky; top: var(--md-header, 0px); z-index: 5; border-radius: var(--md-radius) var(--md-radius) 0 0;
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
    padding: 12px 16px; background: rgba(255, 255, 255, .92); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--md-line);
}
.md-tool-group { display: flex; align-items: center; gap: 6px; }
.md-icon-btn {
    width: 38px; height: 38px; min-width: 0; padding: 0; margin: 0; display: inline-grid; place-items: center; border-radius: 10px;
    border: 1px solid var(--md-line); background: #fff; color: var(--md-ink) !important; cursor: pointer;
    transition: background .15s, color .15s, border-color .15s, transform .15s; text-decoration: none !important;
}
.md-icon-btn:hover:not(:disabled) { border-color: var(--md-red); color: var(--md-red) !important; transform: translateY(-1px); }
.md-icon-btn:disabled { opacity: .35; cursor: default; }
.md-chip-btn {
    display: inline-flex; align-items: center; gap: 6px; width: auto; height: 38px; padding: 0 14px; margin: 0; border-radius: 10px;
    border: 1px solid var(--md-line); background: #fff; color: var(--md-ink); font-weight: 600; font-size: .85rem; cursor: pointer;
    transition: all .15s;
}
.md-chip-btn:hover { border-color: var(--md-red); color: var(--md-red); }
.md-chip-btn.is-active { background: var(--md-red); border-color: var(--md-red); color: #fff; }
.md-page-jump { display: inline-flex; align-items: center; gap: 6px; margin: 0 4px; font-size: .9rem; color: var(--md-muted); }
.md-page-jump input {
    width: 54px !important; height: 38px !important; min-height: 0; line-height: 38px; margin: 0; padding: 0 !important; text-align: center; border: 1px solid var(--md-line); border-radius: 10px;
    font-weight: 700; color: var(--md-ink); background: var(--md-bg); -moz-appearance: textfield; padding: 0;
}
.md-page-jump input::-webkit-inner-spin-button, .md-page-jump input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.md-page-jump input:focus { outline: 2px solid var(--md-red); outline-offset: 1px; background: #fff; }
.md-page-jump b { color: var(--md-ink); }
.md-zoom-label { min-width: 52px; text-align: center; font-weight: 700; font-size: .85rem; font-variant-numeric: tabular-nums; }
.md-doc-label { font-weight: 700; display: inline-flex; gap: 8px; align-items: center; }
.md-doc-label i { color: var(--md-red); }
.md-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; background: transparent; }
.md-progress span { display: block; height: 100%; width: 0; background: var(--md-red); transition: width .15s linear; }

/* Pages flow in the normal page: reading = scrolling the website itself. */
.md-scroll { position: relative; padding: 20px 20px 32px; background: #fff; overflow-x: auto; }
.md-pages { display: flex; flex-direction: column; align-items: center; gap: 14px; min-width: min-content; }
.md-page {
    position: relative; background: #fff; border-radius: 4px; overflow: hidden; flex: none;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .05), 0 4px 14px rgba(0, 0, 0, .06);
}
.md-page canvas, .md-page img { display: block; opacity: 0; transition: opacity .35s ease; }
.md-page img, .md-page canvas { width: 100% !important; height: 100% !important; }
.md-page.is-rendered .md-page-skeleton { display: none; }
.md-page.is-rendered canvas, .md-page.is-rendered img { opacity: 1; }
.md-page.is-rendered .md-page-skeleton { opacity: 0; }
.md-page-loading { width: min(100%, 760px); aspect-ratio: 1 / 1.4; }
.md-page-skeleton {
    position: absolute; inset: 0; transition: opacity .3s;
    background: #f2f3f5; animation: md-pulse 1.4s ease-in-out infinite;
}
.md-skeleton-lines { position: relative; height: 420px; border-radius: 8px; }
@keyframes md-pulse { 50% { opacity: .55; } }
.md-page-num {
    position: absolute; right: 10px; bottom: 8px; z-index: 2; font-size: .72rem; font-weight: 700;
    color: var(--md-muted); background: rgba(255, 255, 255, .85); padding: 2px 8px; border-radius: 999px;
}
.md-status {
    position: relative; z-index: 3; margin: 0 auto 16px; width: max-content; max-width: 100%;
    padding: 8px 16px; border-radius: 999px; background: var(--md-ink); color: #fff; font-size: .85rem; font-weight: 600;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .2);
}
.md-status[hidden] { display: none; }

.md-paper {
    max-width: 820px; margin: 0 auto; background: #fff; padding: 36px 44px;
    min-height: 40vh; opacity: .6; transition: opacity .3s;
}
.md-paper.is-ready { opacity: 1; }
.md-word { line-height: 1.75; font-size: 1.02rem; color: #2b2b2b; }
.md-word h1, .md-word h2, .md-word h3 { color: var(--md-red); margin: 1.6em 0 .6em; line-height: 1.25; }
.md-word img { max-width: 100%; height: auto; border-radius: 8px; }
.md-word table { width: 100%; border-collapse: collapse; margin: 1.5em 0; }
.md-word td, .md-word th { border: 1px solid var(--md-line); padding: 10px 12px; }
.md-excel { padding: 0; overflow: auto; max-width: none; }
.md-excel table { border-collapse: collapse; font-size: .88rem; min-width: 100%; }
.md-excel td, .md-excel th { border: 1px solid var(--md-line); padding: 8px 12px; white-space: nowrap; }
.md-excel tr:first-child td { position: sticky; top: 0; background: #faf6f6; font-weight: 700; color: var(--md-red); }
.md-excel tr:hover td { background: #fbf7f7; }
.md-sheet-tabs { flex-wrap: wrap; }
.md-scroll-image { display: grid; place-items: start center; background: var(--md-bg); }
.md-doc-image { max-width: 100%; height: auto; border-radius: 8px; box-shadow: 0 10px 28px rgba(0, 0, 0, .12); background: #fff; }

/* Fullscreen */
.md-reader:fullscreen { border-radius: 0; }
.md-reader:fullscreen .md-toolbar { top: 0; }
.md-reader:fullscreen .md-scroll { flex: 1; overflow: auto; background: #eef0f3; overscroll-behavior: contain; }

/* Empty / error states */
.md-state { text-align: center; padding: 72px 24px; max-width: 520px; margin: 0 auto; }
.md-state-icon {
    width: 76px; height: 76px; margin: 0 auto 20px; border-radius: 22px; display: grid; place-items: center;
    font-size: 1.9rem; color: var(--md-red); background: rgba(156, 28, 28, .08);
}
.md-state-icon.is-error { color: #c2410c; background: rgba(194, 65, 12, .1); }
.md-state h3 { font-size: 1.35rem; margin-bottom: 8px; }
.md-state p { color: var(--md-muted); margin-bottom: 22px; }
.md-state-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

/* ── Sidebar ── */
/* Desktop: the sidebar stays in view while the pages scroll; it scrolls on its own if taller than the screen. */
.md-side {
    display: flex; flex-direction: column; gap: 20px;
    position: sticky; top: calc(var(--md-header, 0px) + 16px);
    max-height: calc(100vh - var(--md-header, 0px) - 32px); overflow-y: auto;
    overscroll-behavior: contain; scrollbar-width: thin; padding: 0 4px 4px; margin: 0 -4px;
}
.md-side > .md-card { flex: none; }
.md-side::-webkit-scrollbar { width: 6px; }
.md-side::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, .15); border-radius: 6px; }

.md-nav-label { margin-left: auto; font-size: .78rem; font-weight: 600; color: var(--md-muted); }
.md-nav {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px;
    max-height: 196px; overflow-y: auto; padding: 2px; position: relative; scrollbar-width: thin;
}
.md-nav button {
    height: 34px; min-width: 0; width: auto; margin: 0; padding: 0; border-radius: 8px;
    border: 1px solid var(--md-line); background: #fff; color: var(--md-ink);
    font-size: .82rem; font-weight: 600; cursor: pointer; transition: all .15s;
}
.md-nav button:hover { border-color: var(--md-red); color: var(--md-red); }
.md-nav button.is-active { background: var(--md-red); border-color: var(--md-red); color: #fff; box-shadow: 0 4px 10px rgba(156, 28, 28, .3); }
.md-card { background: #fff; border-radius: var(--md-radius); box-shadow: var(--md-shadow); padding: 22px; }
.md-card-title { display: flex; align-items: center; gap: 10px; font-size: 1.02rem; font-weight: 700; margin: 0 0 14px; color: var(--md-ink); }
.md-card-title i { color: var(--md-red); }
.md-desc, .md-rich { color: #444; line-height: 1.7; font-size: .95rem; margin: 0; }
.md-rich { margin-top: 10px; }
.md-rich img { max-width: 100%; height: auto; border-radius: 8px; }
.md-details { margin: 0; }
.md-details > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--md-line); font-size: .92rem; }
.md-details > div:last-child { border-bottom: 0; }
.md-details dt { color: var(--md-muted); font-weight: 500; }
.md-details dd { margin: 0; font-weight: 700; text-align: right; }

.md-cta { background: var(--md-red); color: #fff; text-align: center; position: relative; overflow: hidden; }
.md-cta::before { content: ""; position: absolute; width: 180px; height: 180px; border-radius: 50%; background: rgba(236, 167, 44, .25); top: -70px; right: -60px; }
.md-cta > * { position: relative; }
.md-cta-icon { width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 16px; display: grid; place-items: center; background: rgba(255, 255, 255, .15); font-size: 1.5rem; }
.md-cta h2 { color: #fff; font-size: 1.15rem; margin: 0 0 6px; }
.md-cta p { color: rgba(255, 255, 255, .85); font-size: .9rem; margin: 0 0 16px; }

.md-related { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.md-related a { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 12px; text-decoration: none; color: var(--md-ink); transition: background .15s; }
.md-related a:hover { background: var(--md-bg); }
.md-related-thumb { flex: none; width: 52px; height: 52px; border-radius: 10px; overflow: hidden; background: rgba(156, 28, 28, .08); display: grid; place-items: center; color: var(--md-red); }
.md-related-thumb img { width: 100%; height: 100%; object-fit: cover; }
.md-related-text { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.md-related-text strong { font-size: .9rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.md-related-text small { color: var(--md-muted); font-size: .78rem; margin-top: 2px; }
.md-related-go { color: var(--md-muted); font-size: .8rem; transition: transform .15s, color .15s; }
.md-related a:hover .md-related-go { color: var(--md-red); transform: translateX(3px); }
.md-link-all { display: inline-flex; align-items: center; gap: 8px; margin-top: 12px; font-weight: 700; color: var(--md-red); text-decoration: none; font-size: .9rem; }

/* Toast */
.md-toast {
    position: fixed; left: 50%; bottom: 28px; z-index: 10050; transform: translate(-50%, 20px); opacity: 0;
    background: var(--md-ink); color: #fff; padding: 12px 20px; border-radius: 999px; font-weight: 600; font-size: .9rem;
    box-shadow: 0 12px 28px rgba(0, 0, 0, .25); transition: opacity .25s, transform .25s;
}
.md-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ── Responsive ── */
@media (max-width: 1100px) {
    .md-body { grid-template-columns: minmax(0, 1fr); }
    .md-side { position: static; max-height: none; overflow: visible; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
    .md-hero-cover img { max-width: 260px; max-height: 300px; }
}
@media (max-width: 760px) {
    .md-hero-inner { grid-template-columns: 1fr; padding-top: 36px; padding-bottom: 84px; gap: 0; }
    .md-hero-cover { display: none; }
    .md-hero-actions .md-btn-lg { padding: 12px 18px; font-size: .95rem; }
    .md-container { padding: 0 14px; }
    .md-toolbar { padding: 8px 10px; gap: 4px; flex-wrap: nowrap; }
    .md-tool-group { gap: 3px; }
    .md-icon-btn { width: 34px; height: 34px; border-radius: 9px; }
    .md-page-jump { margin: 0 2px; gap: 4px; font-size: .82rem; }
    .md-page-jump input { width: 44px !important; height: 34px !important; line-height: 34px; padding: 0 !important; font-size: .85rem; }
    .md-zoom-label { min-width: 38px; font-size: .78rem; }
    .md-scroll { padding: 10px 8px 24px; }
    .md-paper { padding: 28px 20px; }
    .md-hide-sm { display: none !important; }
    .md-side { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
    .md-page-wrap * { transition: none !important; animation: none !important; }
}

/* ── Read mode: the document as a web page (includes/pdf_reader.html) ── */
[hidden] { display: none !important; }
.md-modes { background: var(--md-bg); border-radius: 12px; padding: 3px; gap: 2px; }
.md-modes .md-chip-btn { border: 0; background: transparent; height: 34px; }
.md-modes .md-chip-btn.is-active { background: #fff; color: var(--md-red); box-shadow: 0 1px 4px rgba(0, 0, 0, .1); }
.md-read-time { display: inline-flex; align-items: center; gap: 6px; color: var(--md-muted); font-size: .85rem; font-weight: 600; margin-right: 6px; }
.md-font-btn { font-weight: 800; font-size: .95rem; }
.md-font-btn sup { font-size: .6em; }
.md-article-wrap { background: #fff; padding: 40px 28px 56px; }
.md-article { --md-article-size: 1.08rem; max-width: 720px; margin: 0 auto; font-size: var(--md-article-size); line-height: 1.8; color: #262626; overflow-wrap: anywhere; }
.md-article p { margin: 0 0 1.05em; }
.md-article h2, .md-article h3 { font-family: 'Montserrat', sans-serif; color: var(--md-ink); line-height: 1.3; scroll-margin-top: 140px; }
.md-article h2 { font-size: 1.55em; margin: 1.6em 0 .6em; }
.md-article h3 { font-size: 1.15em; margin: 1.6em 0 .5em; padding-top: .2em; }
.md-article > :first-child { margin-top: 0; }
.md-article ul { margin: 0 0 1.1em; padding-left: 1.3em; }
.md-article li { margin: .35em 0; padding-left: .2em; }
.md-article li::marker { color: var(--md-red); }
.md-article figure { margin: 1.6em 0; text-align: center; }
.md-article figure img { max-width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--md-line); background: #fff; }
.md-toc { display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; scrollbar-width: thin; margin: 0 -6px; }
.md-toc a { display: block; padding: 7px 10px; border-radius: 8px; color: #444; font-size: .88rem; line-height: 1.35; text-decoration: none; border-left: 3px solid transparent; }
.md-toc a.is-h3 { padding-left: 22px; font-size: .84rem; color: var(--md-muted); }
.md-toc a:hover { background: var(--md-bg); color: var(--md-red); }
.md-toc a.is-active { background: rgba(156, 28, 28, .07); color: var(--md-red); border-left-color: var(--md-red); font-weight: 700; }
@media (max-width: 760px) {
  .md-article-wrap { padding: 24px 16px 40px; }
  .md-article { line-height: 1.75; }
  .md-modes .md-chip-btn { padding: 0 10px; }
}

/* ── End-of-material "up next" card ── */
.md-next { display: flex; align-items: center; gap: 16px; margin-top: 20px; background: #fff; border-radius: var(--md-radius); box-shadow: var(--md-shadow); padding: 20px 22px; }
.md-next-icon { flex: none; width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: rgba(0, 138, 72, .1); color: #008A48; font-size: 1.2rem; }
.md-next-text { flex: 1; min-width: 0; }
.md-next-text small { display: block; color: var(--md-muted); font-weight: 700; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
.md-next-text strong { display: block; font-size: 1.05rem; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 600px) { .md-next { flex-wrap: wrap; } .md-next .md-btn { width: 100% !important; } }
.md-article p, .md-article li { color: #262626; font-size: 1em; line-height: inherit; }
.md-font-btn { font-family: 'Montserrat', sans-serif; letter-spacing: -.02em; }

/* ── Documents converted to a page (Word, PowerPoint, Excel, text): elearning/docview.py ── */
.dv { overflow-wrap: anywhere; }
.dv img { max-width: 100%; height: auto; border-radius: 10px; }
.dv figure { margin: 18px 0; text-align: center; }
.dv table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: .92rem; }
.dv th, .dv td { border: 1px solid #e6e6ec; padding: 8px 10px; text-align: left; vertical-align: top; }
.dv th { background: #f7f7fa; font-weight: 700; }
.dv-table { overflow-x: auto; margin: 0 0 18px; }
.dv-slide { border: 1px solid #ececf0; border-radius: 16px; padding: 22px 24px; margin: 0 0 18px; background: #fff; box-shadow: 0 4px 16px rgba(21, 21, 21, .04); }
.dv-slide header span { display: inline-block; font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #9c1c1c; margin-bottom: 6px; }
.dv-slide h2 { margin: 0 0 12px; font-size: 1.3rem; }
.dv-slide li.lvl-1 { margin-left: 18px; } .dv-slide li.lvl-2 { margin-left: 36px; } .dv-slide li.lvl-3 { margin-left: 54px; }
.dv-slide blockquote { margin: 14px 0 0; padding: 10px 14px; background: #f7f7fa; border-radius: 10px; font-size: .9rem; color: #545a63; }
.dv h1 { font-size: 1.6rem; margin: 0 0 12px; } .dv h2 { font-size: 1.3rem; } .dv h3 { font-size: 1.12rem; }
