/* ===== PreventScripts LMS — Shared Styles ===== */

:root {
    --primary: #003e53;
    --primary-light: #00627a;
    --primary-dark: #002a3a;
    --accent: #ff9e25;
    --accent-hover: #e88a10;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #17a2b8;
    --gray-50: #f8f9fa;
    --gray-100: #f1f3f5;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #adb5bd;
    --gray-600: #6c757d;
    --gray-700: #495057;
    --gray-800: #343a40;
    --gray-900: #212529;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
    --transition: 0.2s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--gray-800);
    background: var(--gray-50);
    line-height: 1.6;
    min-height: 100vh;
}

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

.skip-link {
    position: absolute;
    top: -40px;
    left: 8px;
    background: var(--primary);
    color: #fff;
    padding: 8px 12px;
    border-radius: var(--radius);
    z-index: 2000;
    text-decoration: none;
}

.skip-link:focus {
    top: 8px;
}

:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===== Top Navbar ===== */
.navbar {
    background: var(--primary);
    color: white;
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2rem;
    font-weight: 700;
    color: white;
    text-decoration: none;
}

.navbar-brand a {
    color: white;
    text-decoration: none;
}

.navbar-brand a:hover {
    color: var(--accent);
    text-decoration: none;
}

.navbar-brand:hover { color: var(--accent); text-decoration: none; }

.navbar-brand svg { flex-shrink: 0; }

.navbar-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    list-style: none;
}

.navbar-nav a, .navbar-nav button {
    color: rgba(255, 255, 255, 0.85);
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: var(--transition);
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.navbar-menu {
    display: flex;
    align-items: center;
    gap: 6px;
}

.navbar-menu a,
.navbar-menu button {
    color: rgba(255, 255, 255, 0.92);
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: var(--transition);
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
}

.navbar-menu a:hover,
.navbar-menu button:hover {
    color: white;
    background: rgba(255, 255, 255, 0.12);
    text-decoration: none;
}

.navbar-nav a:hover, .navbar-nav button:hover {
    color: white;
    background: rgba(255, 255, 255, 0.12);
    text-decoration: none;
}

.navbar-nav a.active { color: var(--accent); background: rgba(255, 255, 255, 0.08); }

.user-badge {
    background: rgba(255, 255, 255, 0.15);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.9);
}

/* Mobile nav toggle */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px;
}

.navbar-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px;
}

/* ===== Layout ===== */
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }
.container-sm { max-width: 480px; margin: 0 auto; padding: 24px; }

/* ===== Cards ===== */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

.card-header {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--gray-100);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    text-decoration: none;
}

.btn:hover { text-decoration: none; }

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

.btn-accent { background: var(--accent); color: var(--primary-dark); }
.btn-accent:hover { background: var(--accent-hover); }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary); color: white; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c82333; }

.btn-sm { padding: 6px 14px; font-size: 0.82rem; }
.btn-block { width: 100%; }

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ===== Forms ===== */
.form-group { margin-bottom: 18px; }

/* ===== Course Viewer ===== */
/* ===== Course Viewer ===== */
.course-viewer {
    display: flex;
    height: calc(100vh - 60px);
    background: var(--gray-100);
}

/* Sidebar */
.course-sidebar {
    width: 320px;
    background: white;
    border-right: 1px solid var(--gray-300);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease;
    z-index: 900;
}

.sidebar-header {
    padding: 2rem 1.5rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
}

.sidebar-close {
    display: none;
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 1.5rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

.sidebar-close:hover {
    background: rgba(255,255,255,0.3);
}

.course-sidebar-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    line-height: 1.3;
    color: white;
}

.course-progress-wrapper {
    margin-top: 1rem;
}

.course-progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.course-progress-label {
    font-size: 0.875rem;
    font-weight: 500;
    opacity: 0.9;
}

.course-progress-percent {
    font-size: 1.125rem;
    font-weight: 700;
}

.progress-bar-modern {
    height: 8px;
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
    overflow: hidden;
}

.progress-bar-fill-modern {
    height: 100%;
    background: var(--accent);
    border-radius: 10px;
    transition: width 0.5s ease;
    width: 0%;
}

.course-closed-pill {
    margin-top: 0.85rem;
    background: rgba(40, 167, 69, 0.22);
    color: #e9fff0;
    border: 1px solid rgba(40, 167, 69, 0.4);
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    font-size: 0.78rem;
    font-weight: 700;
    display: inline-block;
}

/* Section navigation */
.section-nav-header {
    padding: 1rem 1.5rem 0.75rem;
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
}

.section-nav-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-600);
    margin: 0;
}

.section-nav-modern {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.section-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    margin-bottom: 0.25rem;
    border-radius: var(--radius);
    color: var(--gray-700);
    text-decoration: none;
    transition: var(--transition);
    border: 1px solid transparent;
}

.section-nav-item:hover {
    background: var(--gray-50);
    color: var(--primary);
    text-decoration: none;
    border-color: var(--gray-200);
}

.section-nav-item.active {
    background: var(--primary);
    color: white;
    font-weight: 600;
}

.section-nav-item.completed {
    background: var(--gray-50);
}

.section-nav-item.completed .section-nav-check {
    background: var(--success);
    color: white;
}

.section-nav-check {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-200);
    color: var(--gray-600);
    font-size: 0.75rem;
    font-weight: 600;
    transition: var(--transition);
}

.section-nav-item.active .section-nav-check {
    background: var(--accent);
    color: var(--gray-900);
}

.section-nav-title {
    flex: 1;
    font-size: 0.9rem;
    line-height: 1.4;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
    background: white;
}

.quiz-summary-panel {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: var(--gray-50);
}

.quiz-summary-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--gray-700);
    margin-bottom: 0.35rem;
}

.quiz-summary-stats {
    font-size: 0.82rem;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

.quiz-rationales {
    max-height: 140px;
    overflow-y: auto;
    margin-bottom: 0.6rem;
}

.quiz-rationale-item {
    font-size: 0.78rem;
    color: var(--gray-700);
    border-left: 3px solid var(--gray-300);
    padding: 0.25rem 0.45rem;
    margin-bottom: 0.35rem;
    background: white;
}

.quiz-rationale-item.correct { border-left-color: var(--success); }
.quiz-rationale-item.incorrect { border-left-color: var(--danger); }

/* Main content area */
.course-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.sidebar-toggle-btn {
    display: none;
    position: fixed;
    top: 70px;
    left: 1rem;
    z-index: 800;
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    gap: 0.5rem;
    align-items: center;
    transition: var(--transition);
}

.sidebar-toggle-btn:hover {
    background: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}

.sidebar-toggle-icon {
    font-size: 1.25rem;
}

.sidebar-toggle-text {
    font-family: inherit;
}

.course-content-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow: auto;
    padding: 2rem;
    background: var(--gray-100);
}

#course-iframe {
    display: none;
    width: 100%;
    max-width: 900px;
    height: 100%;
    min-height: calc(100vh - 140px);
    border: none;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.course-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.course-loading-text {
    margin-top: 1rem;
    color: var(--gray-600);
    font-size: 1rem;
}

/* Mobile responsive */
@media (max-width: 992px) {
    .course-sidebar {
        width: 280px;
    }
    
    .course-content-wrapper {
        padding: 1.5rem;
    }
}

@media (max-width: 768px) {
    .course-sidebar {
        position: fixed;
        top: 60px;
        left: 0;
        bottom: 0;
        width: 280px;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    
    .course-sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-close {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .sidebar-toggle-btn {
        display: flex;
    }
    
    .course-content-wrapper {
        padding: 1rem;
    }
    
    #course-iframe {
        max-width: none;
        border-radius: 0;
    }
}

@media (max-width: 480px) {
    .course-sidebar {
        width: 100%;
    }
    
    .course-sidebar-title {
        font-size: 1.1rem;
        padding-right: 2rem;
    }
    
    .sidebar-header {
        padding: 1.5rem 1rem;
    }
    
    .section-nav-modern {
        padding: 0.25rem;
    }
    
    .section-nav-item {
        padding: 0.75rem;
    }
    
    .course-content-wrapper {
        padding: 0.5rem;
    }
}

/* Accent text for branding */
.brand-accent { color: var(--accent); }

/* ===== Utilities ===== */
.mb-1 { margin-bottom: 1rem; }
.mb-1-5 { margin-bottom: 1.5rem; }
.mt-2 { margin-top: 2rem; }
.mt-1 { margin-top: 1rem; }
.mt-0-5 { margin-top: 0.5rem; }
.mb-0 { margin-bottom: 0; }
.pt-1-5 { padding-top: 1.5rem; }
.p-1 { padding: 1rem; }
.p-1-5 { padding: 1.5rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.gap-0-5 { gap: 0.5rem; }
.gap-1 { gap: 1rem; }
.text-center { text-align: center; }
.border-bottom { border-bottom: 2px solid var(--border); }
.hidden { display: none; }

/* additional utilities */
.font-weight-bold { font-weight: 600; }
.max-w-640 { max-width: 640px; }
.max-w-200 { max-width: 200px; }
.profile-grid { display: grid; grid-template-columns: 120px 1fr; gap: 0.75rem; align-items: center; }
.profile-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.profile-avatar-wrap { display: flex; align-items: center; gap: 0.75rem; }
.profile-avatar,
.profile-avatar-fallback {
    width: 56px;
    height: 56px;
    border-radius: 999px;
    border: 2px solid var(--gray-300);
}
.profile-avatar { object-fit: cover; }
.profile-avatar-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    color: var(--primary);
    font-weight: 700;
}

/* ===== Loading Spinner ===== */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--gray-300);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-spinner.large {
    width: 40px;
    height: 40px;
    border-width: 4px;
}

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

/* ===== Admin Panel ===== */
.admin-tabs {
    /* container styles applied via utility classes */
}
.admin-tab {
    padding: 0.75rem 1.5rem;
    border: none;
    background: none;
    cursor: pointer;
    font-weight: 600;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}
.admin-tab.active {
    border-bottom-color: var(--accent);
}

.exec-heatmap-table td,
.exec-heatmap-table th {
    font-size: 0.82rem;
}

.traffic-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 42px;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}

.traffic-pill.green {
    background: rgba(40, 167, 69, 0.14);
    color: var(--success);
}

.traffic-pill.amber {
    background: rgba(255, 193, 7, 0.18);
    color: var(--gray-800);
}

.traffic-pill.red {
    background: rgba(220, 53, 69, 0.14);
    color: var(--danger);
}

.trend-bars {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.trend-row {
    display: grid;
    grid-template-columns: 110px 1fr 56px;
    gap: 0.5rem;
    align-items: center;
}

.trend-label,
.trend-value {
    font-size: 0.76rem;
    color: var(--gray-700);
}

.trend-value {
    text-align: right;
    font-weight: 600;
}

.trend-bar-track {
    background: var(--gray-200);
    height: 8px;
    border-radius: 8px;
    overflow: hidden;
}

.trend-bar-fill {
    height: 100%;
    background: var(--primary-light);
}

.ai-thread-list,
.ai-chat-history {
    max-height: 340px;
    overflow-y: auto;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.75rem;
    background: #fff;
}

.scene-editor-shell {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.scene-editor-toolbar,
.scene-editor-main,
.scene-editor-thread-dock {
    width: 100%;
}

.scene-toolbar-grid {
    display: grid;
    grid-template-columns: minmax(220px, 1.2fr) minmax(180px, 0.8fr) minmax(220px, 1fr) auto;
    gap: 0.75rem;
    align-items: end;
}

.scene-toolbar-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 0.2rem;
}

.scene-editor-main {
    display: grid;
    grid-template-columns: minmax(260px, 0.9fr) minmax(0, 2.1fr);
    gap: 0.85rem;
    align-items: start;
}

.scene-editor-rail,
.scene-editor-canvas,
.scene-editor-thread-dock {
    border: 1px solid var(--gray-200);
}

.scene-editor-rail {
    min-height: 480px;
}

.scene-editor-canvas {
    min-height: 480px;
}

.scene-editor-canvas .grid-two-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.scene-preview-placeholder {
    border: 1px dashed var(--gray-300);
    border-radius: var(--radius);
    background: var(--gray-100);
    min-height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1rem;
}

.scene-diff-summary {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: var(--gray-100);
    padding: 0.55rem 0.65rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.scene-diff-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid var(--gray-300);
    background: var(--gray-50);
    color: var(--gray-700);
}

.scene-diff-chip.added {
    border-color: var(--success);
    background: var(--gray-50);
    color: var(--success);
}

.scene-diff-chip.removed {
    border-color: var(--danger);
    background: var(--gray-50);
    color: var(--danger);
}

.scene-preview-surface {
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    background: var(--gray-50);
    min-height: 210px;
    max-height: 300px;
    overflow: auto;
    padding: 0.7rem;
    font-size: 0.9rem;
    line-height: 1.45;
}

.scene-preview-surface:empty::before {
    content: 'No content to preview';
    color: var(--gray-500);
}

.scene-editor-thread-dock .ai-chat-history {
    max-height: 220px;
}

.scene-thread-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}

.scene-thread-controls {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
}

.scene-editor-rail .ai-thread-list {
    max-height: 420px;
}

@media (max-width: 1200px) {
    .scene-toolbar-grid {
        grid-template-columns: repeat(2, minmax(200px, 1fr));
    }

    .scene-toolbar-actions {
        grid-column: 1 / -1;
        justify-content: flex-start;
        padding-bottom: 0;
    }

    .scene-editor-main {
        grid-template-columns: 1fr;
    }

    .scene-editor-rail,
    .scene-editor-canvas {
        min-height: 0;
    }
}

@media (max-width: 768px) {
    .scene-toolbar-grid {
        grid-template-columns: 1fr;
    }

    .scene-editor-canvas .grid-two-col {
        grid-template-columns: 1fr;
    }

    .scene-editor-thread-dock .ai-chat-history,
    .scene-editor-rail .ai-thread-list {
        max-height: 260px;
    }

    .scene-thread-header {
        flex-direction: column;
    }
}

.ai-thread-item {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.6rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
}

.ai-thread-item.active {
    border-color: var(--primary-light);
    background: rgba(0, 98, 122, 0.06);
}

.scene-timeline-item {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.65rem;
    margin-bottom: 0.55rem;
    cursor: pointer;
    background: #fff;
    transition: var(--transition);
}

.scene-timeline-item[draggable="true"] {
    cursor: grab;
}

.scene-timeline-item[draggable="true"]:active {
    cursor: grabbing;
}

.scene-timeline-item:hover {
    border-color: var(--primary-light);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.scene-timeline-item.active {
    border-color: var(--primary-light);
    background: rgba(0, 98, 122, 0.06);
}

.scene-timeline-item.drop-target {
    border-color: var(--accent);
    background: var(--gray-100);
    box-shadow: var(--shadow);
}

.scene-timeline-top {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.45rem;
    margin-bottom: 0.35rem;
}

.scene-index {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--gray-200);
    color: var(--gray-700);
    font-size: 0.72rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.scene-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-800);
    line-height: 1.3;
}

.scene-count {
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: var(--gray-200);
    color: var(--gray-700);
    padding: 0 0.45rem;
    font-size: 0.72rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.scene-latest {
    font-size: 0.78rem;
    margin-bottom: 0.45rem;
    line-height: 1.35;
}

.scene-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.scene-thread-chip {
    padding: 0.18rem 0.5rem;
    font-size: 0.72rem;
    line-height: 1.2;
}

.scene-thread-chip.active {
    border-color: var(--primary-light);
    background: rgba(0, 98, 122, 0.08);
    color: var(--primary);
}

.ai-chat-msg {
    margin-bottom: 0.6rem;
    padding: 0.55rem 0.65rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.ai-chat-group {
    margin-bottom: 0.8rem;
}

.ai-chat-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.35rem;
    font-size: 0.75rem;
    color: var(--gray-600);
}

.ai-chat-group-role {
    font-weight: 700;
    letter-spacing: 0.02em;
}

.ai-chat-group-time {
    font-size: 0.72rem;
}

.ai-chat-msg-actions {
    margin-top: 0.45rem;
}

.ai-chat-msg-admin {
    background: rgba(0, 98, 122, 0.08);
    border: 1px solid rgba(0, 98, 122, 0.18);
}

.ai-chat-msg-ai {
    background: rgba(255, 158, 37, 0.12);
    border: 1px solid rgba(255, 158, 37, 0.25);
}

.ai-chat-msg-system {
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    transition: var(--transition);
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(0, 98, 122, 0.15);
}

select.form-control { cursor: pointer; }

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 0.9rem;
    display: none;
}

.alert.show { display: block; }

.alert-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* ===== Progress Bars ===== */
.progress-bar-container {
    background: var(--gray-200);
    border-radius: 10px;
    height: 10px;
    overflow: hidden;
    width: 100%;
}

.progress-bar-fill {
    background: var(--accent);
    height: 100%;
    border-radius: 10px;
    transition: width 0.4s ease;
    min-width: 0;
}

.progress-bar-fill.complete { background: var(--success); }

/* ===== Stats Row ===== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.82rem;
    color: var(--gray-600);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== Course Cards ===== */
.course-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.course-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

.course-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }

.course-card-header {
    background: var(--primary);
    color: white;
    padding: 16px 20px;
    font-size: 1rem;
    font-weight: 600;
}

.course-card-header .badge {
    display: inline-block;
    background: var(--accent);
    color: var(--primary-dark);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 700;
    margin-left: 8px;
    text-transform: uppercase;
    vertical-align: middle;
}

.course-card-body {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.course-card-headline {
    display: flex;
    align-items: center;
    margin-bottom: 0.55rem;
}

.course-card-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid var(--gray-300);
    background: var(--gray-100);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
}

.course-card-category {
    display: inline-block;
    font-size: 0.8rem;
    color: var(--gray-600);
    margin-bottom: 0.35rem;
}

.course-card-title {
    font-size: 1.35rem;
    color: var(--gray-900);
    margin-bottom: 0.45rem;
    line-height: 1.25;
}

.course-card-desc {
    color: var(--gray-600);
    font-size: 0.95rem;
    margin-bottom: 0.85rem;
    line-height: 1.5;
    flex: 1;
}

.course-card-meta {
    display: flex;
    gap: 0.65rem;
    align-items: center;
    color: var(--gray-700);
    font-size: 0.85rem;
    margin-bottom: 0.55rem;
}

.course-card-body p {
    color: var(--gray-600);
    font-size: 0.88rem;
    margin-bottom: 16px;
    flex: 1;
}

.course-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
    color: var(--gray-500);
    margin-bottom: 12px;
}

.course-card-footer {
    padding: 0 20px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.course-card-footer .progress-bar-container { flex: 1; }

.progress-label { font-size: 0.82rem; font-weight: 600; color: var(--gray-700); white-space: nowrap; }

.library-filters-grid {
    gap: 0.75rem;
    align-items: end;
}

.cb-citation-badge {
    font-size: 0.72rem;
}

/* ===== Section headings ===== */
.section-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 20px;
}

.section-title .count {
    font-weight: 400;
    color: var(--gray-500);
    font-size: 1rem;
}

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

table.data-table th {
    background: var(--gray-100);
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--gray-700);
    border-bottom: 2px solid var(--gray-300);
    white-space: nowrap;
}

table.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--gray-200);
    vertical-align: middle;
}

table.data-table tr:hover { background: var(--gray-50); }

/* ===== Badges ===== */
.role-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.role-badge.admin { background: #e8d4f5; color: #6f42c1; }
.role-badge.front_end { background: #d1ecf1; color: #0c5460; }
.role-badge.back_end_non_clinical { background: #fff3cd; color: #856404; }
.role-badge.back_end_clinical { background: #d4edda; color: #155724; }
.role-badge.ancillary { background: #f8d7da; color: #721c24; }

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.status-dot.active { background: var(--success); }
.status-dot.inactive { background: var(--danger); }

/* ===== Tabs ===== */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 20px;
    gap: 4px;
}

.tab-btn {
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-600);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--accent); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-overlay.show { display: flex; }

.modal {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 { font-size: 1.1rem; color: var(--primary); }

.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--gray-500);
    cursor: pointer;
    line-height: 1;
}

.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 10px; }

/* ===== Login page specific ===== */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    padding: 24px;
}

.login-card {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo h1 {
    font-size: 1.5rem;
    color: var(--primary);
    margin-top: 12px;
}

.login-logo p {
    color: var(--gray-600);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* ===== Course Viewer ===== */
.viewer-layout {
    display: flex;
    height: calc(100vh - 60px);
}

.viewer-sidebar {
    width: 280px;
    background: white;
    border-right: 1px solid var(--gray-200);
    overflow-y: auto;
    flex-shrink: 0;
    padding: 16px 0;
}

.viewer-sidebar h3 {
    padding: 0 16px 12px;
    font-size: 0.95rem;
    color: var(--primary);
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 8px;
}

.sidebar-section {
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.88rem;
    color: var(--gray-700);
    cursor: pointer;
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.sidebar-section:hover { background: var(--gray-50); }
.sidebar-section.active { background: var(--gray-100); border-left-color: var(--accent); font-weight: 600; }

.sidebar-section .check {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--gray-300);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: white;
}

.sidebar-section .check.done {
    background: var(--success);
    border-color: var(--success);
}

.viewer-main {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.viewer-main iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.viewer-toolbar {
    position: sticky;
    bottom: 0;
    background: white;
    border-top: 1px solid var(--gray-200);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .navbar { padding: 0 16px; }

    .nav-toggle,
    .navbar-toggle { display: block; }

    .navbar-nav {
        display: none;
        position: absolute;
        top: 60px;
        left: 0;
        right: 0;
        background: var(--primary-dark);
        flex-direction: column;
        padding: 12px;
        gap: 2px;
    }

    .navbar-nav.show { display: flex; }

    .navbar-menu {
        display: none;
        position: absolute;
        top: 60px;
        left: 0;
        right: 0;
        background: var(--primary-dark);
        flex-direction: column;
        padding: 12px;
        gap: 2px;
    }

    .navbar-menu.open,
    .navbar-menu.show { display: flex; }

    .navbar-nav a, .navbar-nav button {
        width: 100%;
        text-align: left;
        padding: 12px 16px;
    }

    .navbar-menu a, .navbar-menu button {
        width: 100%;
        text-align: left;
        padding: 12px 16px;
    }

    .container { padding: 16px; }

    .course-grid { grid-template-columns: 1fr; }

    .stats-row { grid-template-columns: repeat(2, 1fr); }

    .viewer-layout { flex-direction: column; }
    .viewer-sidebar { width: 100%; height: auto; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--gray-200); }

    .tabs { overflow-x: auto; }
    .profile-form-grid { grid-template-columns: 1fr; }
}

/* ===== Utility ===== */
.text-center { text-align: center; }
.text-muted { color: var(--gray-600); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.d-flex { display: flex; }
.gap-2 { gap: 16px; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }

/* ===== Loading spinner ===== */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}
