/* =============================================================================
   LMS Platform - application styles
   Author: Tim Rice

   Layout and components consume the CSS custom properties that the shared header
   sets from the instance theme. Colors default to the shipped palette.
   ============================================================================= */

:root {
    --brand: #D71105;
    --brand-hover: #5E0C09;
    --header: #0E0E0E;
    --footer: #0E0E0E;
    --body-bg: #FFFFFF;
    --box: #F5F5F5;
    --muted: #686868;
    --success: #0D9700;
    --text: #0E0E0E;
    --radius: 10px;
    --nav-width: 260px;
    --border: #e2e2e2;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--body-bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); text-decoration: underline; }

/* ---------------------------------------------------------------- app shell */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--header);
    color: #fff;
    padding: 0 20px;
    height: 56px;
    flex: 0 0 auto;
}
.topbar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: #fff;
    font-size: 1.05rem;
}
.topbar .brand img { height: 30px; }
.topbar .user-menu { display: flex; align-items: center; gap: 16px; }
.topbar .user-menu a { color: #fff; }
.topbar .user-menu a:hover { color: var(--brand); text-decoration: none; }

/* Impersonation ("view as") banner: deliberately high-contrast so an operator
   never forgets they are acting as someone else. */
.impersonation-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    background-color: #8a5a00;
    color: #fff;
    padding: 8px 20px;
    font-size: 0.9rem;
    flex: 0 0 auto;
}
.impersonation-bar .muted { color: rgba(255, 255, 255, 0.75); }
.impersonation-bar strong { color: #fff; }
.impersonation-bar .btn-sm {
    padding: 4px 12px;
    font-size: 0.85rem;
}

.layout { display: flex; flex: 1 1 auto; min-height: 0; }

/* ------------------------------------------------------------------ sidebar */
.sidebar {
    width: var(--nav-width);
    flex: 0 0 var(--nav-width);
    background-color: var(--box);
    border-right: 1px solid var(--border);
    padding: 8px 0 16px;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.15s ease, flex-basis 0.15s ease;
}

/* Dedicated top row holding the icon-only rail toggle (no overlap with links). */
.sidebar .sidebar-head {
    display: flex;
    justify-content: flex-end;
    padding: 4px 12px;
}
.sidebar .rail-toggle {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    border-radius: var(--radius);
    color: var(--muted);
    cursor: pointer;
}
.sidebar .rail-toggle:hover { color: var(--brand); background-color: #ececec; }

/* Section heading: a button that collapses or expands its links. */
.sidebar .nav-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: transparent;
    border: 0;
    cursor: pointer;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    color: var(--muted);
    padding: 14px 20px 6px;
    text-align: left;
}
.sidebar .nav-section:hover { color: var(--text); }
.sidebar .nav-section-caret { transition: transform 0.15s ease; font-size: 0.7rem; }
.sidebar .nav-group.collapsed .nav-section-caret { transform: rotate(-90deg); }
.sidebar .nav-group.collapsed .nav-group-body { display: none; }

.sidebar a.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--text);
    border-left: 3px solid transparent;
    white-space: nowrap;
}
.sidebar a.nav-link:hover { background-color: #ececec; text-decoration: none; }
.sidebar a.nav-link.active {
    border-left-color: var(--brand);
    color: var(--brand);
    background-color: #fff;
    font-weight: 600;
}
.sidebar a.nav-link i { width: 18px; text-align: center; flex: 0 0 auto; }

/* -------------------------------------------------------------- rail (icon) */
.sidebar.is-rail { width: 60px; flex-basis: 60px; }
.sidebar.is-rail .nav-label,
.sidebar.is-rail .nav-section { display: none; }
/* Thin divider between icon groups in place of the hidden headings. */
.sidebar.is-rail .nav-group + .nav-group { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 6px; }
/* In rail mode every section shows its icons regardless of collapsed state. */
.sidebar.is-rail .nav-group.collapsed .nav-group-body { display: block; }
.sidebar.is-rail a.nav-link { justify-content: center; padding: 10px 0; gap: 0; }
.sidebar.is-rail .sidebar-head { justify-content: center; }

/* --------------------------------------------------------------- main area */
.main {
    flex: 1 1 auto;
    padding: 28px 32px;
    overflow-y: auto;
}
.page-title { margin: 0 0 20px; font-size: 1.5rem; }

/* ------------------------------------------------------- sub navigation tabs */
.subnav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
}
.subnav-link {
    padding: 8px 16px;
    color: var(--text);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.subnav-link:hover { text-decoration: none; color: var(--brand); }
.subnav-link.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
    font-weight: 600;
}

/* --------------------------------------------------------------- progress bar */
.progress-bar {
    background: var(--box);
    border: 1px solid var(--border);
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}
.progress-fill {
    background: var(--brand);
    height: 100%;
    border-radius: 999px;
    transition: width 0.3s ease;
}

/* ------------------------------------------------------------- course covers */
/* The cover bleeds to the card edges and keeps a 16:9 shape at every width, so
   it scales with the card instead of being cropped to a fixed height. */
.course-cover {
    display: block;
    width: calc(100% + 2 * var(--card-pad, 18px));
    margin: calc(-1 * var(--card-pad, 18px)) calc(-1 * var(--card-pad, 18px)) 14px;
    aspect-ratio: 16 / 9;
    height: auto;
    object-fit: cover;
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--box);
}
.course-cover-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 2.4rem;
}

/* ------------------------------------------------------------- confirm modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: #fff;
    border-radius: var(--radius);
    padding: 22px 24px;
    max-width: 460px;
    width: 100%;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.modal-title { margin: 0 0 10px; font-size: 1.15rem; }
.modal-message { margin: 0 0 20px; color: var(--text); line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ------------------------------------------------------------------- tables */
.table { border-collapse: collapse; }
.table th {
    text-align: left;
    border-bottom: 2px solid var(--border);
    padding: 6px 10px 6px 0;
    font-size: 0.85rem;
}
.table td { border-bottom: 1px solid #eee; padding: 6px 10px 6px 0; vertical-align: middle; }

/* ---------------------------------------------------- authoring drag handles */
.drag-handle {
    cursor: grab;
    color: var(--muted);
    user-select: none;
    line-height: 1;
}
.drag-handle:active { cursor: grabbing; }
.chapter-card.dragging,
.lesson-list li.dragging {
    opacity: 0.5;
    background: var(--box);
}
.lesson-list li { border-radius: var(--radius); }

/* ---------------------------------------------------------- rich text editor */
.rt-editor { border: 1px solid var(--border); border-radius: var(--radius); }
.rt-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px;
    background: var(--box);
    border-bottom: 1px solid var(--border);
}
.rt-btn {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.82rem;
    cursor: pointer;
    line-height: 1.2;
    color: var(--text);
}
.rt-btn:hover { border-color: var(--brand); color: var(--brand); }
.rt-color { position: relative; display: inline-flex; align-items: center; font-weight: bold; overflow: hidden; }
.rt-color input[type="color"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.rt-surface {
    min-height: 240px;
    border: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    overflow-y: auto;
}
.rt-surface:focus { outline: none; box-shadow: none; }
.lesson-text { line-height: 1.6; }
.lesson-text img { max-width: 100%; height: auto; }
.lesson-text table { border-collapse: collapse; }
.lesson-text td, .lesson-text th { border: 1px solid var(--border); padding: 6px 10px; }
.lesson-text pre,
.rt-surface pre {
    background: var(--box);
    border: 1px solid var(--border);
    padding: 12px 14px;
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9rem;
    white-space: pre-wrap;
}
.lesson-text code,
.rt-surface code {
    background: var(--box);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
}
.lesson-text pre code,
.rt-surface pre code { background: none; padding: 0; }
.lesson-text blockquote,
.rt-surface blockquote { border-left: 3px solid var(--brand); margin: 0; padding-left: 14px; color: var(--muted); }

/* ------------------------------------------------------------------- footer */
.footer {
    background-color: var(--footer);
    color: #cfcfcf;
    text-align: center;
    padding: 14px;
    font-size: 0.85rem;
    flex: 0 0 auto;
}
.footer img { height: 22px; vertical-align: middle; margin-right: 8px; }

/* -------------------------------------------------------------------- cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px;
}
.card {
    --card-pad: 18px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--card-pad);
}
.card h3 { margin: 0 0 8px; font-size: 1.05rem; }
.card .muted { color: var(--muted); font-size: 0.9rem; }

/* ------------------------------------------------------------------ buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: var(--brand);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 10px 18px;
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background-color: var(--brand-hover); color: #fff; text-decoration: none; }
.btn-secondary { background-color: #444; }
.btn-danger { background-color: #b02a1f; }
.btn-danger:hover { background-color: #8f2019; }
.btn-secondary:hover { background-color: #222; }
.btn-block { width: 100%; justify-content: center; }

/* -------------------------------------------------------------------- forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; }
.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
}
.form-control:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

/* ------------------------------------------------------------------- alerts */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }
.alert-error { background: #fdeceb; color: #8b0500; border: 1px solid #f4c4c0; }
.alert-success { background: #eaf7ea; color: #0d5f00; border: 1px solid #bfe6bf; }
.alert-info { background: var(--box); color: var(--text); border: 1px solid var(--border); }
.alert-warning { background: #fff5e6; color: #7a4d00; border: 1px solid #f2d29b; }

/* ------------------------------------------------------------- auth screens */
.auth-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(160deg, var(--header) 0%, #2a2a2a 100%);
    padding: 20px;
}
.auth-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.auth-card .auth-brand {
    text-align: center;
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 6px;
}
.auth-card .auth-sub { text-align: center; color: var(--muted); margin-bottom: 24px; }

/* --------------------------------------------------------------- responsive */
@media (max-width: 800px) {
    .sidebar { display: none; }
    .main { padding: 20px 16px; }
}

/* ------------------------------------------------------------- chat / teams */
.btn-sm { padding: 4px 12px; font-size: 0.85rem; }

.chat-list { list-style: none; padding: 0; margin: 10px 0 0; max-height: 460px; overflow-y: auto; }
.chat-msg { display: flex; gap: 10px; padding: 8px 0; }
.chat-avatar {
    flex: 0 0 34px; width: 34px; height: 34px; border-radius: 50%;
    background: var(--brand); color: #fff; display: flex; align-items: center;
    justify-content: center; font-weight: 700; font-size: 0.9rem;
}
.chat-bubble { flex: 1 1 auto; background: var(--box); border-radius: 10px; padding: 8px 12px; }
.chat-meta { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.chat-author { font-weight: 600; }
.chat-time { color: var(--muted); font-size: 0.78rem; }
.chat-subject { font-weight: 600; margin: 2px 0; }
.chat-body { margin-top: 2px; word-wrap: break-word; overflow-wrap: anywhere; }
.chat-body p { margin: 0 0 6px; }

.chat-composer { margin-top: 12px; }
.chat-toolbar { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; position: relative; margin-bottom: 6px; }
.chat-btn {
    border: 1px solid var(--border); background: #fff; border-radius: 6px;
    min-width: 30px; height: 30px; padding: 0 8px; cursor: pointer; font-size: 0.9rem; line-height: 1;
}
.chat-btn:hover { background: var(--box); }
.chat-surface {
    min-height: 64px; max-height: 200px; overflow-y: auto; text-align: left;
    cursor: text;
}
.chat-surface:empty::before { content: attr(data-placeholder); color: var(--muted); }
.emoji-palette {
    position: absolute; top: 34px; left: 0; z-index: 20; width: 260px;
    background: #fff; border: 1px solid var(--border); border-radius: 8px;
    padding: 6px; display: flex; flex-wrap: wrap; gap: 2px; box-shadow: 0 6px 18px rgba(0,0,0,0.12);
}
.emoji-palette[hidden] { display: none; }
.chat-avatar { position: relative; overflow: hidden; }
.chat-avatar-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.emoji-item { border: 0; background: none; cursor: pointer; font-size: 1.15rem; padding: 3px 5px; border-radius: 6px; }
.emoji-item:hover { background: var(--box); }

/* ------------------------------------------------- backup/restore progress ring */
.bk-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(14, 14, 14, 0.55);
}
.bk-overlay.open { display: flex; }
.bk-card {
    background: var(--body-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 30px 34px;
    width: min(90vw, 340px);
    text-align: center;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}
/* The ring: a brand-colored arc fills to --bk-deg over a track; a lighter arc
   rotates continuously so the control still reads as "working" if a phase stalls. */
.bk-ring {
    position: relative;
    width: 130px;
    height: 130px;
    margin: 0 auto 18px;
    border-radius: 50%;
    background:
        conic-gradient(var(--brand) var(--bk-deg, 0deg), var(--box) 0);
    transition: background 0.3s ease;
}
.bk-ring::before {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: var(--brand);
    opacity: 0.35;
    animation: bk-spin 1s linear infinite;
}
.bk-ring-inner {
    position: absolute;
    inset: 14px;
    background: var(--body-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bk-pct {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
}
.bk-title {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}
.bk-detail {
    color: var(--muted);
    font-size: 0.85rem;
    min-height: 1.1em;
}
@keyframes bk-spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------- report audience typeahead */
.ra-results {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 40;
    margin-top: 4px;
    background: var(--body-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    max-height: 280px;
    overflow-y: auto;
}
.ra-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    border-bottom: 1px solid var(--border);
    padding: 8px 10px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
}
.ra-item:last-child { border-bottom: 0; }
.ra-item:hover, .ra-item.active { background: var(--box); }
.ra-tag {
    flex: 0 0 auto;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 2px 6px;
    border-radius: 999px;
    color: #fff;
}
.ra-tag-user  { background: var(--muted); }
.ra-tag-group { background: var(--brand); }

/* ------------------------------------------------------- status pills (badges) */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 999px;
    white-space: nowrap;
}
.pill-risk { background: var(--brand); color: #fff; }
.pill-ok   { background: var(--box); color: var(--muted); }

/* ------------------------------------------------------- in-course search */
.course-search { margin: 0 0 22px; width: 100%; }
.course-search-box {
    display: flex;
    align-items: center;
    gap: 14px;
    background: #fff;
    border: 2px solid var(--brand);
    border-radius: 16px;
    padding: 10px 10px 10px 24px;
    min-height: 64px;
    box-shadow: 0 1px 2px rgba(14, 14, 14, 0.04), 0 4px 16px rgba(215, 17, 5, 0.10);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.course-search-box:hover { box-shadow: 0 1px 2px rgba(14, 14, 14, 0.05), 0 6px 22px rgba(215, 17, 5, 0.16); }
.course-search-box:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px rgba(215, 17, 5, 0.18);
}
.course-search-icon { color: var(--brand); font-size: 1.5rem; }
.course-search-input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    font-size: 1.2rem;
    padding: 16px 2px;
    color: var(--text);
}
.course-search-input::placeholder { color: var(--muted); }
.course-search-submit {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 15px 28px;
    font-size: 1.02rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    align-self: stretch;
}
.course-search-submit:hover { background: var(--brand-hover); }
.course-search-submit .bi { font-size: 0.85rem; opacity: 0.85; }

/* Results page */
.search-result-list { display: flex; flex-direction: column; gap: 10px; }
.search-result { margin: 0; }
.search-result-link {
    display: block;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    text-decoration: none;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.search-result-link:hover {
    border-color: var(--brand);
    box-shadow: 0 2px 10px rgba(14, 14, 14, 0.06);
    text-decoration: none;
    color: var(--text);
}
.search-result-head {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 5px;
}
.search-result-head .bi { font-size: 0.8rem; }
.search-result-type { color: var(--brand); font-weight: 600; }
.search-result-title { font-size: 1.02rem; font-weight: 600; color: var(--text); }
.search-result-snippet {
    margin-top: 5px;
    font-size: 0.9rem;
    color: var(--muted);
    line-height: 1.5;
}
.search-result-snippet mark,
.search-result-title mark {
    background: rgba(215, 17, 5, 0.16);
    color: inherit;
    padding: 0 1px;
    border-radius: 2px;
}
.course-search-count { font-size: 0.92rem; }

/* Term highlighted in a lesson after arriving from a search result. */
mark.search-hl {
    background: rgba(215, 17, 5, 0.20);
    color: inherit;
    padding: 1px 2px;
    border-radius: 3px;
    box-shadow: 0 0 0 0 rgba(215, 17, 5, 0.45);
    animation: search-hl-pulse 1.6s ease-out 1;
}
@keyframes search-hl-pulse {
    0%   { box-shadow: 0 0 0 6px rgba(215, 17, 5, 0.30); background: rgba(215, 17, 5, 0.38); }
    100% { box-shadow: 0 0 0 0 rgba(215, 17, 5, 0.00); background: rgba(215, 17, 5, 0.20); }
}
@media (prefers-reduced-motion: reduce) {
    mark.search-hl { animation: none; }
}
