/* Mitra — BC-branded stylesheet for class session pages
   Boston College colors: maroon #4a001e, gold #b29a5b, blue #005a9c
*/

@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,600;1,400&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400&family=Noto+Sans+Devanagari&display=swap');

/* ─── Variables ─────────────────────────────────────────────────────────────── */
:root {
    --bc-maroon:        #4a001e;
    --bc-maroon-mid:    #720030;
    --bc-maroon-light:  #9a1b3b;
    --bc-gold:          #b29a5b;
    --bc-gold-light:    #d4bc82;
    --bc-blue:          #005a9c;
    --bc-blue-light:    #e8f0f8;
    --bg-page:          #f4f1ec;
    --bg-white:         #ffffff;
    --bg-card:          #ffffff;
    --text-primary:     #1a1a1a;
    --text-secondary:   #555555;
    --text-muted:       #888888;
    --border-light:     #e5e0d8;
    --border-mid:       #ccc7bc;
    --brad-bg:          #fdf8f2;
    --brad-border:      #c9a96e;
    --student-bg:       #f2f6fd;
    --student-border:   #7ba7d0;
    --navbar-height:    48px;
    --player-height:    58px;
    --tabs-height:      42px;
    --sticky-offset:    calc(var(--navbar-height) + var(--player-height) + var(--tabs-height));
    --shadow-sm:        0 2px 6px rgba(0,0,0,0.09), 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md:        0 4px 16px rgba(0,0,0,0.13);
    --radius:           6px;
}

/* ─── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.75;
    margin: 0;
    padding: 0;
    background-color: var(--bg-page);
    color: var(--text-primary);
}

a { color: var(--bc-blue); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--bc-maroon); }

h1, h2, h3 { font-family: 'Lora', Georgia, serif; }

/* ─── Sticky Top Bar: Course Nav ─────────────────────────────────────────────── */
.navbar {
    background-color: var(--bc-maroon);
    color: white;
    padding: 0 24px;
    height: var(--navbar-height);
    position: sticky;
    top: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    /* transition for auto-hide on mobile */
    transition: transform 0.25s ease;
}

.navbar .course-title {
    font-weight: 600;
    font-size: 0.9em;
    color: white;
    letter-spacing: 0.01em;
}

.navbar nav a {
    color: var(--bc-gold-light);
    font-size: 0.85em;
    margin-left: 20px;
    transition: color 0.15s;
}
.navbar nav a:hover { color: white; text-decoration: none; }

/* ─── Sticky Audio Player ─────────────────────────────────────────────────────── */
.audio-bar {
    background: linear-gradient(90deg, var(--bc-maroon-mid), #5a0025);
    height: var(--player-height);
    position: sticky;
    top: var(--navbar-height);
    z-index: 190;
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    /* transition for auto-hide on mobile */
    transition: transform 0.25s ease;
}

.audio-bar .audio-label {
    color: var(--bc-gold-light);
    font-size: 0.78em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    flex-shrink: 0;
}

.audio-bar audio {
    flex: 1;
    height: 36px;
    min-width: 0;
    border-radius: 4px;
    background: transparent;
}

.audio-kb-hint {
    color: rgba(255,255,255,0.45);
    font-size: 0.72em;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ─── Sticky Section Tabs ─────────────────────────────────────────────────────── */
.section-tabs {
    background: var(--bg-white);
    height: var(--tabs-height);
    position: sticky;
    top: calc(var(--navbar-height) + var(--player-height));
    z-index: 180;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    border-bottom: 2px solid var(--border-light);
    box-shadow: 0 2px 4px rgba(0,0,0,0.06);
    scrollbar-width: none;
    /* Relative for the fade-hint pseudo-element */
    position: sticky;
}
.section-tabs::-webkit-scrollbar { display: none; }

/* Fade hint on right edge to signal scrollability */
.section-tabs::after {
    content: '';
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 36px;
    background: linear-gradient(to right, transparent, white);
    pointer-events: none;
    z-index: 1;
}

.section-tab {
    display: inline-flex;
    align-items: center;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.78em;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    color: var(--text-secondary);
    background: var(--bg-page);
    border: 1px solid var(--border-light);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    user-select: none;
    /* ensure minimum tap target height */
    min-height: 32px;
}
.section-tab:hover {
    background: var(--bc-blue-light);
    color: var(--bc-blue);
    border-color: var(--bc-blue);
}
.section-tab.active {
    background: var(--bc-maroon);
    color: white;
    border-color: var(--bc-maroon);
    font-weight: 600;
}

/* ─── Page Container ──────────────────────────────────────────────────────────── */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 32px 32px 60px;
}

/* ─── Page Header ─────────────────────────────────────────────────────────────── */
.session-header {
    text-align: center;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 2px solid var(--border-light);
}

.session-header h1 {
    color: var(--bc-maroon);
    font-size: 1.9em;
    font-weight: 600;
    margin: 0 0 8px;
    line-height: 1.3;
}

.session-header .meta {
    color: var(--text-muted);
    font-size: 0.9em;
}

/* ─── Cards (Synopsis, Outline, Takeaways) ────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 24px 28px;
    margin-bottom: 24px;
    border: 1px solid var(--border-light);
    transition: box-shadow 0.2s;
}
.card:hover { box-shadow: var(--shadow-md); }

.card h2 {
    color: var(--bc-maroon);
    font-size: 1.15em;
    font-weight: 600;
    margin: 0 0 14px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--bc-gold);
    display: flex;
    align-items: center;
    gap: 8px;
}
.card h2 .card-icon { font-size: 1.1em; }

/* ─── Two-column card row (desktop) ──────────────────────────────────────────── */
.cards-row {
    margin-bottom: 24px;
}
@media (min-width: 769px) {
    .cards-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }
    .cards-row .card { margin-bottom: 0; }
}

/* Synopsis card */
.synopsis-card { border-left: 4px solid var(--bc-gold); }
.synopsis-card p { margin: 0; font-size: 0.97em; color: var(--text-secondary); line-height: 1.8; }

/* Outline card */
.outline-card ol {
    margin: 0;
    padding-left: 22px;
}
.outline-card li {
    margin-bottom: 6px;
    font-size: 0.93em;
}
.outline-card a { color: var(--bc-blue); }
.outline-card a:hover { color: var(--bc-maroon); }

/* Takeaways card */
.takeaways-card { border-left: 4px solid #4a8c5c; }
.takeaways-card ul {
    margin: 0;
    padding-left: 20px;
}
.takeaways-card li {
    margin-bottom: 8px;
    font-size: 0.93em;
    line-height: 1.65;
}

/* Photos */
.chalkboard-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
    margin-bottom: 24px;
}
.chalkboard-photos img {
    max-height: 340px;
    max-width: 100%;
    width: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    object-fit: contain;
}

/* ─── Transcript ──────────────────────────────────────────────────────────────── */
.transcript-container { margin-top: 8px; }

.transcript-section {
    margin-bottom: 32px;
    scroll-margin-top: var(--sticky-offset);
}

.transcript-section .section-header {
    background: var(--bc-maroon);
    color: white;
    padding: 10px 18px;
    border-radius: var(--radius) var(--radius) 0 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.transcript-section .section-header h3 {
    margin: 0;
    font-size: 1em;
    font-weight: 600;
    font-style: normal;
    color: white;
    flex: 1;
}

.transcript-section .utterances {
    border: 1px solid var(--border-light);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    overflow: hidden;
}

/* ─── Utterance rows ──────────────────────────────────────────────────────────── */
.utterance {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-light);
    transition: filter 0.1s;
}
.utterance:last-child { border-bottom: none; }
.utterance:hover { filter: brightness(0.965); }

.utterance.brad {
    background: var(--brad-bg);
    border-left: 3px solid var(--brad-border);
}
.utterance.student {
    background: var(--student-bg);
    border-left: 3px solid var(--student-border);
}
.utterance.low-confidence {
    opacity: 0.85;
}

/* Meta row: speaker label + timestamp button grouped together */
.utt-meta {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-right: 8px;
}

.speaker-label {
    font-weight: 600;
    font-size: 0.8em;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    min-width: 52px;
}
.utterance.brad .speaker-label  { color: var(--bc-maroon); }
.utterance.student .speaker-label { color: var(--bc-blue); }

.timestamp-btn {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.72em;
    color: var(--bc-blue);
    background: var(--bc-blue-light);
    padding: 3px 10px;
    border-radius: 3px;
    flex-shrink: 0;
    cursor: pointer;
    user-select: none;
    border: none;
    vertical-align: middle;
    transition: background 0.15s, color 0.15s;
    line-height: 1.8;
    min-height: 28px;
    display: inline-flex;
    align-items: center;
}
.timestamp-btn:hover {
    background: var(--bc-blue);
    color: white;
}

.utterance-text {
    font-size: 0.94em;
    line-height: 1.7;
    flex: 1;
    color: var(--text-primary);
}
.utterance-text strong {
    color: var(--bc-maroon-light);
    font-weight: 600;
}

.confidence-warn {
    font-size: 0.8em;
    margin-left: 6px;
    cursor: help;
    flex-shrink: 0;
    opacity: 0.6;
    align-self: flex-start;
    padding-top: 2px;
}

/* Section timestamp pill in section header */
.section-ts {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78em;
    background: rgba(255,255,255,0.2);
    padding: 2px 8px;
    border-radius: 3px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}
.section-ts:hover { background: rgba(255,255,255,0.35); }

/* ─── Floating back-to-top button ────────────────────────────────────────────── */
.back-to-top {
    position: fixed;
    bottom: 24px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bc-maroon);
    color: white;
    font-size: 1.2em;
    font-weight: 700;
    border: none;
    cursor: pointer;
    box-shadow: 0 3px 12px rgba(0,0,0,0.3);
    z-index: 400;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.2s, transform 0.2s, background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.back-to-top.visible {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}
.back-to-top:hover { background: var(--bc-maroon-mid); }

/* ─── Glossary page ───────────────────────────────────────────────────────────── */
.glossary-category { margin-top: 32px; }
.glossary-category h3 {
    font-style: normal;
    color: var(--bc-maroon);
    border-bottom: 2px solid var(--bc-gold);
    padding-bottom: 6px;
    margin-bottom: 16px;
}
.glossary-entry {
    margin-bottom: 14px;
    padding: 10px 16px;
    border-left: 3px solid var(--bc-gold);
    background: var(--bg-card);
    border-radius: 0 var(--radius) var(--radius) 0;
    box-shadow: var(--shadow-sm);
}
.glossary-entry .term { font-weight: 700; color: var(--bc-maroon-light); }
.glossary-entry .original { font-style: italic; color: var(--text-muted); font-size: 0.92em; }
.glossary-entry .definition { font-size: 0.93em; color: var(--text-secondary); margin-top: 4px; }
.glossary-entry .sessions { font-size: 0.8em; color: var(--text-muted); margin-top: 4px; }

/* ─── Index page session list (legacy) ───────────────────────────────────────── */
.session-list { list-style: none; padding: 0; }
.session-list li {
    padding: 12px 18px;
    margin-bottom: 6px;
    border-left: 4px solid var(--bc-maroon);
    background: var(--bg-card);
    border-radius: 0 var(--radius) var(--radius) 0;
    box-shadow: var(--shadow-sm);
    transition: background 0.15s, border-color 0.15s;
}
.session-list li:hover { background: var(--bc-blue-light); border-color: var(--bc-blue); }
.session-list .session-date { font-weight: 600; color: var(--bc-maroon); min-width: 110px; display: inline-block; }
.session-list .session-topic { color: var(--text-secondary); font-size: 0.93em; }

/* ─── Index page session table ────────────────────────────────────────────────── */
.session-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 32px;
}
.session-table thead tr {
    background: var(--bc-maroon);
    color: white;
}
.session-table th {
    padding: 12px 18px;
    text-align: left;
    font-size: 0.82em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}
.session-table th.col-date  { width: 120px; }
.session-table th.col-section { }

.session-table tbody tr {
    border-bottom: 1px solid var(--border-light);
    transition: background 0.12s;
}
.session-table tbody tr:last-child { border-bottom: none; }
.session-table tbody tr:hover { background: var(--bc-blue-light); }

.session-date-cell {
    padding: 14px 18px;
    font-weight: 700;
    font-size: 0.88em;
    color: var(--bc-maroon);
    white-space: nowrap;
    vertical-align: top;
    border-right: 2px solid var(--border-light);
}

.session-link-cell {
    padding: 14px 18px;
    font-size: 0.93em;
    vertical-align: top;
    border-right: 1px solid var(--border-light);
    line-height: 1.45;
}
.session-link-cell:last-child { border-right: none; }
.session-link-cell a { color: var(--bc-blue); }
.session-link-cell a:hover { color: var(--bc-maroon); text-decoration: underline; }

.session-missing {
    color: var(--text-muted);
    font-size: 0.9em;
}

.supplement-row td { border-bottom: none; padding-top: 0; }
.supplement-cell {
    padding: 4px 18px 12px;
    font-size: 0.82em;
    color: #666;
}
.supplement-cell a { color: var(--bc-blue); margin-right: 4px; }
.supplement-cell a:hover { color: var(--bc-maroon); text-decoration: underline; }

@media (max-width: 640px) {
    .session-table th.col-date  { width: auto; }
    .session-table, .session-table thead, .session-table tbody,
    .session-table th, .session-table td, .session-table tr {
        display: block;
    }
    .session-table thead tr { display: none; }
    .session-table tbody tr {
        border: 1px solid var(--border-light);
        border-radius: var(--radius);
        margin-bottom: 12px;
        padding: 0;
    }
    .session-date-cell {
        background: var(--bc-maroon);
        color: white;
        padding: 8px 14px;
        border-right: none;
        border-radius: var(--radius) var(--radius) 0 0;
        font-size: 0.9em;
    }
    .session-link-cell {
        padding: 10px 14px;
        border-right: none;
        border-top: 1px solid var(--border-light);
    }
    .session-link-cell::before {
        content: attr(data-label);
        display: block;
        font-size: 0.78em;
        font-weight: 600;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 4px;
    }
}

/* ─── Footer ──────────────────────────────────────────────────────────────────── */
.footer {
    text-align: center;
    padding: 32px 24px;
    margin-top: 48px;
    border-top: 1px solid var(--border-light);
    font-size: 0.82em;
    color: var(--text-muted);
}

/* ─── Responsive — Tablet (≤ 768px) ──────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Bars switch to fixed on mobile so auto-hide works correctly */
    .navbar {
        position: fixed;
        top: 0; left: 0; right: 0;
        z-index: 200;
    }
    .audio-bar {
        position: fixed;
        top: var(--navbar-height);
        left: 0; right: 0;
        z-index: 190;
    }
    /* Compensate for the fixed bars */
    body {
        padding-top: calc(var(--navbar-height) + var(--player-height));
    }
    /* Section tabs sit below the fixed bars normally */
    .section-tabs {
        position: sticky;
        top: 0;            /* sticks at top of scroll viewport after page padding */
        height: 48px;      /* taller for easier tapping */
        --tabs-height: 48px;
        z-index: 180;
    }
    /* Update scroll-margin-top for sections on mobile */
    .transcript-section {
        scroll-margin-top: 48px;   /* just the tabs height — bars are fixed */
    }

    /* Auto-hide: slide navbar + audio-bar off top when scrolling down */
    body.bars-hidden .navbar {
        transform: translateY(calc(-1 * (var(--navbar-height) + var(--player-height))));
    }
    body.bars-hidden .audio-bar {
        transform: translateY(calc(-1 * (var(--navbar-height) + var(--player-height))));
    }

    /* Section tabs still stick at top of viewport regardless */
    .section-tab {
        padding: 8px 14px;
        font-size: 0.8em;
        min-height: 36px;
    }

    .container { padding: 16px 16px 60px; }
    .navbar { padding: 0 14px; }
    .navbar .course-title { font-size: 0.82em; }
    .audio-kb-hint { display: none; }
    .session-header h1 { font-size: 1.4em; }
    .card { padding: 18px 20px; }
    .chalkboard-photos img { max-height: 240px; }
}

/* ─── Responsive — Mobile (≤ 640px) — utterance stacking ─────────────────────── */
@media (max-width: 640px) {
    body { font-size: 16px; }

    /*
     * Stack the utterance: speaker + timestamp stay on the SAME top row,
     * then utterance-text wraps to a full-width second row.
     *
     * This works both with the new HTML (.utt-meta wrapper) AND with the
     * old HTML (speaker-label and timestamp-btn as siblings). In both cases
     * the text block drops below thanks to flex-wrap + order.
     */
    .utterance {
        flex-wrap: wrap;
        align-items: center;
        padding: 10px 12px 10px 9px;
        gap: 0;
    }
    /* utt-meta stays on row 1 (contains speaker + timestamp on desktop HTML too) */
    .utt-meta {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 8px;
        order: 1;
        flex-shrink: 0;
        margin-right: 8px;
    }
    /* Without utt-meta, speaker and timestamp are row-1 siblings */
    .speaker-label {
        order: 1;
        flex-shrink: 0;
        min-width: auto;
    }
    .timestamp-btn {
        order: 2;
        flex-shrink: 0;
        min-height: 32px;
        padding: 4px 10px;
        font-size: 0.78em;
        margin-right: 0;
    }
    /* Text wraps to its own full-width second row */
    .utterance-text {
        order: 10;
        width: 100%;
        flex-basis: 100%;
        font-size: 0.97em;
        margin-top: 4px;
        padding-left: 2px;
    }
    .confidence-warn {
        order: 11;
    }
}

/* ─── Responsive — Small phone (≤ 480px) ─────────────────────────────────────── */
@media (max-width: 480px) {
    .audio-bar { padding: 0 10px; gap: 8px; }
    .audio-bar .audio-label { display: none; }
    /* Hide course title on very narrow screens, keep nav links */
    .navbar .course-title { display: none; }
}
