/**
 * exam-mode.css
 * Styles for Exam Mode: the persistent right-column view toggle and the compact
 * serpentine "exam roadmap" that replaces the schedule + homework during exams.
 *
 * Theme-aware (uses CSS variables only; course/custom accent colors are the sole
 * exception, applied inline and sanitized by cssColor()). Radius matches the app (2px).
 */

/* ============================================================================
   RIGHT-COLUMN STRUCTURE
   #semester-view must stay a flex column so the homework list keeps its scroll.
   ============================================================================ */

#semester-view {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#exam-view {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ============================================================================
   VIEW TOGGLE (segmented Schedule | Exams + Auto reset)
   ============================================================================ */

.right-view-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.rv-pills {
    display: inline-flex;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 2px;
    padding: 2px;
}

.rv-pill {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    padding: 5px 14px;
    border-radius: 2px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.rv-pill:hover {
    color: var(--text-primary);
}

.rv-pill.is-active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.rv-auto {
    border: 1px solid var(--border-secondary);
    background: transparent;
    color: var(--text-tertiary);
    font-size: 11px;
    font-weight: 500;
    padding: 4px 9px;
    border-radius: 2px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.rv-auto:hover {
    color: var(--text-primary);
    border-color: var(--text-tertiary);
}

/* ============================================================================
   ROADMAP TOOLBAR
   ============================================================================ */

.exam-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 18px;
}

.exam-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.exam-countdown {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.exam-countdown-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
}

.exam-countdown-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.exam-countdown-when {
    font-size: 12px;
    font-weight: 500;
    color: var(--accent);
    margin-left: 4px;
}

.exam-progress {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-end;
}

.exam-progress-text {
    font-size: 11px;
    color: var(--text-secondary);
}

.exam-progress-bar {
    width: 110px;
    height: 5px;
    border-radius: 3px;
    background: var(--progress-bg);
    overflow: hidden;
}

.exam-progress-fill {
    display: block;
    height: 100%;
    background: var(--progress-fill);
    transition: width 0.3s ease;
}

.exam-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.exam-filter {
    display: inline-flex;
    border: 1px solid var(--border-primary);
    border-radius: 2px;
    overflow: hidden;
}

.exam-filter-btn {
    border: none;
    border-right: 1px solid var(--border-primary);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    padding: 5px 11px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.exam-filter-btn:last-child {
    border-right: none;
}

.exam-filter-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.exam-filter-btn.is-active {
    background: var(--accent);
    color: var(--bg-secondary);
}

.exam-action-btn {
    border: 1px solid var(--border-secondary);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 500;
    padding: 5px 12px;
    border-radius: 2px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.exam-action-btn:hover {
    background: var(--border-primary);
}

/* ============================================================================
   SERPENTINE BOARD
   ============================================================================ */

.exam-board {
    display: flex;
    flex-direction: column;
}

.exam-row {
    display: flex;
    align-items: stretch;
}

/* ----- Node ----- */

.exam-node {
    flex: 1 1 120px;
    min-width: 0;
    position: relative;
    display: flex;
    border: 1px solid var(--border-primary);
    border-radius: 2px;
    background: var(--bg-secondary);
    overflow: hidden;
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.2s, border-color 0.2s;
}

.exam-node:hover {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.10);
    transform: translateY(-1px);
    border-color: var(--border-secondary);
}

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

/* Keep cards compact on multi-column boards; full width when single column (mobile). */
.exam-board:not([data-cols="1"]) .exam-node,
.exam-board:not([data-cols="1"]) .exam-spacer {
    max-width: 150px;
}

/* Empty placeholder cell that keeps partial rows aligned to the column grid. */
.exam-spacer {
    flex: 1 1 120px;
    min-width: 0;
}

.exam-node-accent {
    flex: 0 0 4px;
    align-self: stretch;
    background: var(--accent);
}

.exam-node-body {
    flex: 1 1 auto;
    min-width: 0;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.exam-node-row1 {
    display: flex;
    align-items: center;
    gap: 6px;
}

.exam-badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 2px 6px;
    border-radius: 2px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    white-space: nowrap;
}

.exam-badge-a {
    color: var(--text-primary);
}

.exam-badge-custom {
    background: transparent;
    color: var(--text-secondary);
    border: 1px dashed var(--border-secondary);
}

.exam-node-next {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border-radius: 2px;
    background: var(--accent);
    color: var(--bg-secondary);
}

.exam-node-remove {
    margin-left: auto;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 16px;
    line-height: 1;
    width: 20px;
    height: 20px;
    border-radius: 2px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.exam-node:hover .exam-node-remove,
.exam-node:focus-within .exam-node-remove {
    opacity: 1;
}

.exam-node-remove:hover {
    background: var(--error-bg);
    color: var(--error-border);
}

.exam-node-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.exam-node-untitled {
    color: var(--text-tertiary);
    font-style: italic;
    font-weight: 500;
}

.exam-node-date {
    font-size: 11px;
    color: var(--text-secondary);
}

.exam-node-custom-actions {
    display: flex;
    gap: 6px;
    margin-top: 2px;
}

.exam-node-mini {
    border: 1px solid var(--border-secondary);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 2px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.exam-node-mini:hover {
    background: var(--border-primary);
    color: var(--text-primary);
}

.exam-node-mini-danger:hover {
    background: var(--error-bg);
    color: var(--error-border);
    border-color: var(--error-border);
}

/* ----- Node states ----- */

.exam-node.state-passed {
    opacity: 0.5;
}

.exam-node.state-passed .exam-node-name {
    font-weight: 500;
}

.exam-node.state-today {
    border-color: var(--success-border);
}

.exam-node.is-custom {
    border-style: dashed;
}

.exam-node.is-next {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

/* ----- Horizontal connector ----- */

.exam-connector {
    flex: 1 1 40px;
    min-width: 30px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
}

.exam-connector-line {
    position: absolute;
    left: -1px;
    right: -1px;
    top: 50%;
    height: 2px;
    background: var(--border-secondary);
    transform: translateY(-50%);
}

.exam-connector-arrow {
    position: relative;
    z-index: 1;
    display: inline-flex;
    color: var(--text-tertiary);
    background: var(--bg-secondary);
    border-radius: 50%;
    padding: 1px;
}

.exam-row-reverse .exam-connector-arrow {
    transform: scaleX(-1);
}

.exam-gap-chip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -150%);
    z-index: 2;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    background: var(--bg-secondary);
    padding: 2px 7px;
    border-radius: 10px;
    border: 1px solid var(--border-primary);
    white-space: nowrap;
}

/* ----- Row-turn connector ----- */

.exam-turn {
    position: relative;
    display: flex;
    align-items: center;
    height: 56px;
    color: var(--text-tertiary);
}

.exam-turn-right {
    justify-content: flex-end;
}

.exam-turn-left {
    justify-content: flex-start;
}

.exam-turn-elbow {
    position: absolute;
    top: -2px;
    height: 50%;
    width: 2px;
    background: var(--border-secondary);
}

.exam-turn-right .exam-turn-elbow {
    right: 19px;
}

.exam-turn-left .exam-turn-elbow {
    left: 19px;
}

.exam-turn-arrow {
    display: inline-flex;
    color: var(--text-tertiary);
    background: var(--bg-secondary);
    border-radius: 50%;
    padding: 1px;
    margin: 0 8px;
    position: relative;
    z-index: 1;
}

.exam-turn-arrow svg {
    width: 18px;
    height: 18px;
}

.exam-turn .exam-gap-chip {
    position: static;
    transform: none;
}

/* ============================================================================
   EMPTY STATE
   ============================================================================ */

.exam-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
    padding: 44px 20px;
    color: var(--text-tertiary);
}

.exam-empty-icon {
    opacity: 0.6;
}

.exam-empty-text {
    font-size: 13px;
    max-width: 320px;
    line-height: 1.5;
}

/* ============================================================================
   HIDDEN TRAY
   ============================================================================ */

.exam-hidden-tray {
    margin-top: 18px;
    border-top: 1px solid var(--border-primary);
    padding-top: 14px;
}

.exam-hidden-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
    margin-bottom: 10px;
}

.exam-hidden-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.exam-hidden-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px dashed var(--border-secondary);
    border-radius: 2px;
    background: var(--bg-tertiary);
}

.exam-hidden-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.exam-hidden-meta {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
}

.exam-hidden-item .exam-node-mini {
    flex: 0 0 auto;
    margin-left: auto;
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

/* When the right column stacks below the left one, let the whole page scroll
   naturally (no nested scroll container, which iOS can trap) and give the last
   row room to clear the mobile browser chrome and the floating action button. */
@media (max-width: 900px) {
    #exam-view {
        overflow: visible;
        padding-bottom: 56px;
    }
}

@media (max-width: 480px) {
    .exam-node-body {
        padding: 8px 10px;
    }

    .exam-connector {
        flex-basis: 26px;
    }

    .exam-header-top {
        align-items: flex-start;
    }

    .exam-progress {
        align-items: flex-start;
    }
}

/* Touch devices: keep the remove affordance discoverable without hover. */
@media (hover: none) {
    .exam-node-remove {
        opacity: 0.6;
    }
}

/* ============================================================================
   MOTION
   ============================================================================ */

@media (prefers-reduced-motion: no-preference) {
    .exam-node.is-next {
        animation: exam-next-pulse 2.4s ease-in-out infinite;
    }

    @keyframes exam-next-pulse {
        0%, 100% {
            box-shadow: 0 0 0 1px var(--accent);
        }
        50% {
            box-shadow: 0 0 0 3px var(--accent);
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    .exam-node,
    .exam-node:hover,
    .exam-progress-fill,
    .rv-pill,
    .exam-action-btn,
    .exam-filter-btn {
        transition: none;
    }

    .exam-node:hover {
        transform: none;
    }
}
