/* ============================================
   CSS Variables – UPeL / Moodle theme
   ============================================ */
:root {
    --primary: #00a0b0;
    --primary-dark: #008a99;
    --primary-light: #e6f7f9;

    --bg: #fff;
    --bg-white: #ffffff;
    --bg-question: #daecf8;
    --bg-info: #eeeeee;

    --text: #333333;
    --text-light: #555555;
    --text-muted: #888888;

    --border: #bbb;
    --border-light: #ddd;
    --border-question: #c4daea;
    --border-info: #d8d8d8;

    --danger: #d9534f;

    --header-bg: #ffffff;
    --header-border: #e0e0e0;

    --font: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    min-height: 100vh;
}

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

/* ============================================
   Header – UPeL style (white, 85px tall)
   ============================================ */
.moodle-header {
    background: var(--header-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    height: 85px;
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 1px solid var(--header-border);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 32px;
}

.logo-link {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.site-logo {
    height: 60px;
    width: auto;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-link {
    color: var(--text);
    font-size: 16px;
    font-weight: 400;
    letter-spacing: 0.3px;
    padding: 8px 14px 22px;
    border-radius: 3px;
    text-decoration: none;
    transition: color 0.15s, background 0.15s;
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    position: relative;
}

.nav-link:hover {
    color: var(--primary);
    text-decoration: none;
}

.nav-link.active {
    color: var(--text);
    border-bottom-color: var(--primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.header-link {
    margin-right: 4px;
    font-size: 16px;
}

/* Day/night toggle switch */
.theme-toggle {
    cursor: pointer;
    margin-right: 4px;
}

.toggle-track {
    width: 50px;
    height: 22px;
    border-radius: 11px;
    background: #ccc;
    position: relative;
    transition: background 0.2s;
}

.toggle-thumb {
    position: absolute;
    top: -3px;
    left: -1px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: left 0.2s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.toggle-thumb svg {
    display: block;
}

.header-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    border-radius: 50%;
    color: #555;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

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

/* Avatar: white bg, turquoise border & text */
.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #fff;
    color: var(--primary);
    border: 2px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    font-weight: 700;
    margin-left: 4px;
    cursor: pointer;
}

/* ============================================
   Breadcrumb
   ============================================ */
.breadcrumb {
    background: var(--bg-white);
    padding: 10px 28px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-light);
}

.breadcrumb a {
    color: var(--primary);
    font-size: 12px;
}

.breadcrumb .sep {
    margin: 0 5px;
    color: #ccc;
}

.breadcrumb .current {
    color: var(--text-muted);
}

/* ============================================
   Main layout
   ============================================ */
.main-layout {
    display: flex;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    gap: 20px;
    align-items: flex-start;
}

.quiz-content {
    flex: 1;
    min-width: 0;
}

/* ============================================
   Left sidebar
   ============================================ */
.quiz-sidebar {
    width: 220px;
    flex-shrink: 0;
    position: sticky;
    top: 105px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sidebar-block {
    background: var(--bg-info);
    border: 1px solid var(--border-info);
    border-radius: 6px;
    overflow: hidden;
}

.sidebar-block-header {
    padding: 10px 14px;
    font-size: 18px;
    font-weight: 700;
    color: #777;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.fold-arrow {
    font-size: 9px;
    color: var(--text-muted);
}

.sidebar-block-body {
    padding: 10px 14px 14px;
}

/* Nav grid: white squares, black border, turquoise numbers */
.quiz-nav-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    margin-bottom: 12px;
}

.nav-btn {
    width: 100%;
    aspect-ratio: 1;
    border: 1.5px solid #333;
    border-radius: 2px;
    background: #fff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
}

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

.nav-btn.answered {
    background: #d0eaf5;
    border-color: var(--primary);
}

/* Finish link: blue text, looks like <a> */
.finish-link {
    display: block;
    color: var(--primary);
    font-size: 13px;
    margin-bottom: 12px;
    text-decoration: none;
}

.finish-link:hover {
    text-decoration: underline;
}

/* Timer */
.quiz-timer-block {
    font-size: 13px;
    color: var(--text);
}

.timer-label {
    color: var(--text);
}

.timer-value {
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* ============================================
   Question cards
   ============================================ */
.question-card {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    position: relative;
    align-items: flex-start;
}

/* Left info panel */
.question-info-panel {
    width: 130px;
    flex-shrink: 0;
    padding: 14px 12px;
    background: var(--bg-info);
    border: 1px solid var(--border-info);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 12px;
    color: var(--text-light);
    margin-right: 8px;
}

.question-label-number {
    display: flex;
    align-items: flex-end;
    gap: 5px;
}

.question-label {
    font-weight: 700;
    font-size: 13px;
    color: var(--text);
}

.question-number {
    font-weight: 700;
    font-size: 16px;
    color: var(--text);
    line-height: 1.2;
}

.question-status-text {
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.5;
}

.question-marks {
    color: var(--text-muted);
    font-size: 11px;
}

.question-flag {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 11px;
}

.question-flag:hover {
    color: var(--primary);
}

.flag-icon {
    font-size: 13px;
}

/* Right content area */
.question-main {
    flex: 1;
    min-width: 0;
    background: var(--bg-question);
    border: 1px solid var(--border-question);
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}

.question-body {
    padding: 16px 18px;
}

.question-text {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);
    margin-bottom: 16px;
}

.question-instruction {
    font-size: 13px;
    color: var(--text);
    margin-bottom: 8px;
    font-style: italic;
}

/* Answer options – gray bullets */
.answer-options {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-left: 4px;
}

.answer-option {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 3px 0;
    cursor: pointer;
    border-radius: 3px;
}

.answer-option:hover {
    background: rgba(255,255,255,0.35);
}

.answer-option.selected {
    background: rgba(255,255,255,0.45);
}

.answer-option input[type="radio"] {
    margin-top: 4px;
    accent-color: #888;
    flex-shrink: 0;
}

.answer-option label {
    cursor: pointer;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
}

/* ============================================
   Chat toggle button (subtle white dot)
   ============================================ */
.chat-toggle-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.5);
    background: rgba(255,255,255,0.5);
    cursor: pointer;
    opacity: 0.3;
    transition: opacity 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    color: #aaa;
    z-index: 10;
    padding: 0;
}

.chat-toggle-btn:hover {
    opacity: 0.7;
    box-shadow: 0 0 6px rgba(0,0,0,0.08);
}

.chat-toggle-btn.active {
    opacity: 0.8;
    background: #fff;
    border-color: var(--primary);
    color: var(--primary);
}

/* ============================================
   Chat panel
   ============================================ */
.chat-panel {
    display: none;
    border-top: 1px solid var(--border-question);
    background: #f0f6fb;
}

.chat-panel.visible {
    display: block;
}

.chat-messages {
    max-height: 350px;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.chat-message.user {
    align-self: flex-end;
}

.chat-message.assistant {
    align-self: flex-start;
}

.chat-bubble {
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chat-message.user .chat-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant .chat-bubble {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border-light);
    border-bottom-left-radius: 4px;
}

.chat-bubble img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 6px;
    margin-top: 4px;
}

.chat-bubble .streaming-cursor::after {
    content: '▊';
    animation: blink 0.8s step-end infinite;
    color: var(--text-muted);
}

@keyframes blink {
    50% { opacity: 0; }
}

/* Chat input area */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 5px;
    padding: 8px 16px 10px;
    border-top: 1px solid var(--border-question);
    background: #eaf2f9;
}

.chat-input-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-image-preview {
    display: none;
    position: relative;
    width: fit-content;
}

.chat-image-preview.has-image {
    display: block;
}

.chat-image-preview img {
    max-height: 60px;
    border-radius: 3px;
    border: 1px solid var(--border-light);
}

.chat-image-preview .remove-image {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--danger);
    color: white;
    border: none;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.chat-text-input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font);
    font-size: 13px;
    resize: none;
    outline: none;
    min-height: 34px;
    max-height: 100px;
}

.chat-text-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0,160,176,0.15);
}

.chat-btn {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--text-light);
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

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

.chat-btn.send-btn {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.chat-btn.send-btn:hover {
    background: var(--primary-dark);
}

.chat-btn.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-btn.reset-btn:hover {
    background: #fce8e8;
    color: var(--danger);
    border-color: var(--danger);
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    padding: 7px 16px;
    border-radius: 3px;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}

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

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

.btn-secondary {
    background: #fff;
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: #eee;
}

.quiz-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    padding: 16px 0;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
    }
    .quiz-sidebar {
        width: 100%;
        position: static;
        order: -1;
    }
    .quiz-nav-grid {
        grid-template-columns: repeat(10, 1fr);
    }
    .header-nav {
        display: none;
    }
    .header-link {
        display: none;
    }
    .question-card {
        flex-direction: column;
    }
    .question-info-panel {
        width: 100%;
        margin-right: 0;
        margin-bottom: 8px;
    }
}

@media (max-width: 600px) {
    .quiz-nav-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* ============================================
   Scrollbar (chat)
   ============================================ */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}
