/* ===== Reset & Base ===== */
:root {
    --bg: #faf9f7;
    --surface: #ffffff;
    --surface2: #f1f5f9;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #596070;
    --primary: #0f766e;
    --primary-hover: #115e59;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0284c7;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
    /* Custom easing curves — Emil Kowalski: built-in easings lack punch */
    --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
    --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f172a;
        --surface: #1e293b;
        --surface2: #334155;
        --border: #334155;
        --text: #f1f5f9;
        --text-muted: #94a3b8;
        --primary: #14b8a6;       /* teal-500: 6:1 contrast on dark surface */
        --primary-hover: #2dd4bf;
    }
}

/* Focus visible — keyboard navigation indicator */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 2px;
}

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

body {
    font-family: 'Heebo', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    direction: rtl;
    font-size: 16px;
    line-height: 1.6;
    min-height: 100vh;
}

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

/* ===== Navbar ===== */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 16px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.nav-brand {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 7px;
}
.nav-logo {
    display: block;
    flex-shrink: 0;
}
.nav-start { display: flex; align-items: center; gap: 10px; }
.nav-actions { display: flex; gap: 8px; align-items: center; }
.btn-icon { padding: 6px; line-height: 0; }
.sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border-radius: 6px;
    transition: color 0.12s var(--ease-out), background 0.12s var(--ease-out), transform 100ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
    .sidebar-toggle:hover { background: var(--surface2); color: var(--text); }
}
.sidebar-toggle:active { transform: scale(0.9); }

.provider-form { display: flex; align-items: center; gap: 6px; }
.provider-label { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; }
.provider-select {
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
}

/* ===== App layout with sidebar ===== */
.app-layout {
    display: flex;
    max-width: 1340px;
    margin: 0 auto;
    min-height: calc(100vh - 56px);
}

/* Sidebar (RTL: appears on the right — flex start in RTL) */
.sidebar {
    width: 220px;
    flex-shrink: 0;
    border-left: 1px solid var(--border);
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
    overflow-y: auto;
    background: var(--surface);
    padding: 16px 0;
    transition: width 220ms var(--ease-out), padding 220ms var(--ease-out), border-color 220ms var(--ease-out);
}
body:not(.sidebar-open) .sidebar {
    width: 0;
    padding: 0;
    overflow: hidden;
    border-color: transparent;
}
.sidebar-nav { display: flex; flex-direction: column; }
.sidebar-home {
    display: block;
    padding: 7px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 6px;
    margin: 0 8px 4px;
    transition: background 0.12s var(--ease-out), color 0.12s var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
    .sidebar-home:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
}
.sidebar-home-active { background: var(--surface2); color: var(--text); }
.sidebar-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 10px 16px 4px;
    opacity: 0.6;
}
.sidebar-course {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 16px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 6px;
    margin: 1px 8px;
    transition: background 0.12s var(--ease-out), color 0.12s var(--ease-out);
    overflow: hidden;
}
@media (hover: hover) and (pointer: fine) {
    .sidebar-course:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
}
.sidebar-course-active { background: var(--surface2); color: var(--text); font-weight: 600; }
.sidebar-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--course-color, var(--border));
    flex-shrink: 0;
}
.sidebar-course-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.main-content {
    flex: 1;
    min-width: 0;
    padding: 24px 20px;
}

/* ===== Container (kept for any direct use) ===== */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 16px;
}

/* ===== Course accent colors ===== */
.cc-0 { --course-color: #86efac; }
.cc-1 { --course-color: #fcd34d; }
.cc-2 { --course-color: #fda4af; }
.cc-3 { --course-color: #7dd3fc; }
.cc-4 { --course-color: #5eead4; }
.cc-5 { --course-color: #5eead4; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s var(--ease-out), border-color 0.15s var(--ease-out), transform 100ms var(--ease-out);
    text-decoration: none;
    user-select: none;
}
@media (hover: hover) and (pointer: fine) {
    .btn:hover { background: var(--surface2); text-decoration: none; }
}
.btn:active { transform: scale(0.97); }
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
@media (hover: hover) and (pointer: fine) {
    .btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
    .btn-secondary:hover { background: var(--surface); color: var(--text); }
}
.btn-secondary { background: var(--surface2); border-color: var(--border); color: var(--text-muted); }
.btn-large { padding: 12px 24px; font-size: 1rem; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    border-width: 1px;
    border-style: solid;
}
.alert-success { background: #dcfce7; border-color: #86efac; color: #15803d; }
.alert-error   { background: #fee2e2; border-color: #fca5a5; color: #b91c1c; }
.alert-info    { background: #dbeafe; border-color: #93c5fd; color: #1d4ed8; }

/* ===== Page header ===== */
.page-header { margin-bottom: 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page-header h1 { font-size: 1.8rem; font-weight: 700; margin: 0; }
.breadcrumb { margin-bottom: 12px; font-size: 0.9rem; color: var(--text-muted); }
.breadcrumb a { color: var(--text-muted); }

/* ===== Progress summary bar ===== */
.psb-wrap { margin-bottom: 28px; }
.psb-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.psb-text { font-size: 0.88rem; color: var(--text-muted); font-weight: 500; }
.psb-track {
    height: 5px;
    background: var(--surface2);
    border-radius: 999px;
    overflow: hidden;
}
.psb-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
    transition: width 600ms var(--ease-out);
    min-width: 2px;
}
.attn-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 600;
}
.attn-pill-error   { background: #fee2e2; color: #b91c1c; }
.attn-pill-pending { background: #fef9c3; color: #854d0e; }

/* ===== Course cards grid ===== */
.courses-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.course-card-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-right: 3px solid var(--course-color, var(--border));
    border-radius: var(--radius);
    overflow: hidden;
    transition: box-shadow 0.2s var(--ease-out), border-color 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
    .course-card-wrap:hover { box-shadow: var(--shadow-md); border-color: var(--primary); transform: translateY(-2px); }
}
.course-card {
    display: block;
    text-decoration: none;
    color: var(--text);
}
.course-card:hover { text-decoration: none; }
.course-card-inner { padding: 20px 20px 12px; }
.course-name { font-size: 1.05rem; font-weight: 600; margin-bottom: 4px; }
.course-shortname { font-size: 0.8rem; color: var(--text-muted); display: block; margin-bottom: 12px; }
.course-stats { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.last-synced { font-size: 0.75rem; color: var(--text-muted); }

/* ── 3-dot card menu ── */
.course-card-wrap { position: relative; }
.card-menu-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 28px; height: 28px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    z-index: 10;
    transition: background 0.1s var(--ease-out), color 0.1s var(--ease-out), transform 100ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
    .card-menu-btn:hover { background: var(--border); color: var(--text); }
}
.card-menu-btn:active { transform: scale(0.92); }
.card-menu {
    position: absolute;
    top: 36px;
    left: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    padding: 4px;
    min-width: 150px;
    z-index: 100;
    /* Animate in/out with opacity + scale instead of display toggle */
    display: flex;
    flex-direction: column;
    gap: 2px;
    opacity: 0;
    transform: scale(0.95);
    transform-origin: top left;
    pointer-events: none;
    transition: opacity 150ms var(--ease-out), transform 150ms var(--ease-out);
}
.card-menu.open { opacity: 1; transform: scale(1); pointer-events: auto; }
.card-menu-item {
    display: flex; align-items: center; gap: 8px;
    width: 100%;
    padding: 7px 12px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    text-align: right;
    transition: background 0.1s var(--ease-out), transform 100ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
    .card-menu-item:hover { background: var(--surface2); }
}
.card-menu-item:active { transform: scale(0.98); }
.card-menu-item.item-active      { color: var(--primary); font-weight: 600; }
.card-menu-item.item-active-auto { color: var(--success); font-weight: 600; }
.card-menu-item.item-active-semi { color: #d97706; font-weight: 600; }
.card-menu-divider { height: 1px; background: var(--border); margin: 2px 0; }
.card-mode-row { margin: 6px 0 4px; }
.card-mode-badge {
    display: inline-block;
    font-size: 0.72rem; padding: 2px 9px; border-radius: 999px;
    font-weight: 600;
}
.card-mode-auto   { background: #dcfce7; color: #15803d; }
.card-mode-semi   { background: #fef3c7; color: #92400e; }
.card-mode-manual { background: var(--surface2); color: var(--text-muted); }

.hidden-courses-section { margin-top: 32px; }
.hidden-courses-toggle {
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
    list-style: none;
    padding: 8px 0;
    border-top: 1px solid var(--border);
    user-select: none;
}
.hidden-courses-toggle::-webkit-details-marker { display: none; }
.hidden-courses-toggle:hover { color: var(--text); }
.course-card-wrap-hidden { opacity: 0.6; }

/* ── Video sort bar ── */
.sort-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.sort-bar-label { font-size: 0.82rem; color: var(--text-muted); }
.sort-btn {
    padding: 4px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s var(--ease-out), color 0.15s var(--ease-out), border-color 0.15s var(--ease-out), transform 100ms var(--ease-out);
    user-select: none;
}
@media (hover: hover) and (pointer: fine) {
    .sort-btn:hover { background: var(--border); color: var(--text); }
}
.sort-btn:active { transform: scale(0.95); }
.sort-btn.sort-active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-total   { background: var(--surface2); color: var(--text-muted); }
.badge-done    { background: #dcfce7; color: #15803d; }
.badge-pending { background: #fef9c3; color: #854d0e; }
.badge-error   { background: #fee2e2; color: #b91c1c; }

/* ===== Section header ===== */
.section-header {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 600;
    margin: 24px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

/* ===== Video list ===== */
.video-list { display: flex; flex-direction: column; gap: 4px; }
.video-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.12s var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
    .video-card:hover { background: var(--surface2); }
}
.video-info { flex: 1; min-width: 0; }
.video-title { font-weight: 600; font-size: 0.92rem; display: block; color: var(--text); text-decoration: none; }
.video-title:hover { text-decoration: underline; }
.video-subject { font-size: 0.8rem; color: var(--text-muted); display: block; margin-top: 1px; }
.video-meta-row { display: flex; align-items: center; gap: 8px; margin-top: 3px; flex-wrap: wrap; }
.video-lecturer { font-size: 0.78rem; color: var(--primary); font-weight: 500; }
.video-duration { font-size: 0.78rem; color: var(--text-muted); }
.video-date { font-size: 0.78rem; color: var(--text-muted); }
.video-meta { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.error-msg { font-size: 0.78rem; color: var(--danger); background: #fee2e2; padding: 6px 16px 8px; border-radius: 0 0 var(--radius) var(--radius); margin-top: -4px; border: 1px solid #fca5a5; border-top: none; }

/* ===== Status dot ===== */
.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-dot.status-done    { background: #22c55e; }
.status-dot.status-pending { background: #94a3b8; }
.status-dot.status-error   { background: #ef4444; }
.status-dot.status-awaiting_approval { background: #f59e0b; }
.status-dot.status-downloading,
.status-dot.status-transcribing,
.status-dot.status-summarizing { background: #3b82f6; animation: statusPulse 1.4s ease-in-out infinite; }
.status-dot.status-briefed  { background: #22c55e; }
.status-dot.status-briefing { background: #3b82f6; animation: statusPulse 1.4s ease-in-out infinite; }

/* ===== Skeleton shimmer ===== */
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.skel-line {
    border-radius: 4px;
    background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
    background-size: 400% 100%;
    animation: shimmer 1.8s ease-in-out infinite;
}
.skel-title   { height: 13px; width: 55%; margin-bottom: 7px; }
.skel-subject { height: 10px; width: 30%; }

/* ===== Processing step indicator ===== */
.proc-steps {
    display: flex;
    align-items: center;
    gap: 0;
    margin-top: 8px;
}
.proc-step {
    display: flex;
    align-items: center;
    gap: 5px;
}
.proc-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    flex-shrink: 0;
    transition: background 0.3s;
}
.proc-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    transition: color 0.3s;
}
.proc-connector {
    flex: 1;
    height: 1px;
    background: var(--border);
    min-width: 16px;
    margin: 0 4px;
}
.proc-step-done .proc-dot  { background: color-mix(in srgb, var(--primary) 40%, transparent); }
.proc-step-done .proc-label { color: color-mix(in srgb, var(--primary) 60%, var(--text-muted)); }
.proc-step-active .proc-dot {
    background: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
    animation: proc-pulse 1.4s ease-in-out infinite;
}
.proc-step-active .proc-label { color: var(--primary); font-weight: 600; }
@keyframes proc-pulse {
    0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
    50%       { box-shadow: 0 0 0 5px color-mix(in srgb, var(--primary) 10%, transparent); }
}

/* ===== Status badges ===== */
.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}
.status-badge.status-done              { background: #dcfce7; color: #15803d; }
.status-badge.status-pending           { background: #fef9c3; color: #854d0e; }
.status-badge.status-awaiting_approval { background: #fde68a; color: #92400e; }
.status-badge.status-error             { background: #fee2e2; color: #b91c1c; }
.status-badge.status-downloading,
.status-badge.status-transcribing,
.status-badge.status-summarizing       { background: #dbeafe; color: #1d4ed8; animation: statusPulse 1.4s ease-in-out infinite; }
@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.55; }
}

.difficulty-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    background: var(--surface2);
    color: var(--text-muted);
}

/* ===== Single video summary — document style ===== */
.doc-page { max-width: 800px; margin: 0 auto; }

/* ── Header ── */
.doc-header { padding: 28px 0 24px; border-bottom: 2px solid var(--border); margin-bottom: 8px; }
.doc-meta { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.doc-course { font-size: 13px; font-weight: 600; color: var(--primary); text-transform: uppercase; letter-spacing: 0.06em; }
.diff-pill  { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.diff-introductory { background: #dcfce7; color: #15803d; }
.diff-intermediate  { background: #dbeafe; color: #1d4ed8; }
.diff-advanced      { background: #fee2e2; color: #b91c1c; }
.doc-title   { font-size: 2rem; font-weight: 800; line-height: 1.25; margin-bottom: 8px; color: var(--text); }
.doc-subtitle { font-size: 0.88rem; color: var(--text-muted); }

/* ── Shared section wrapper ── */
.doc-section { margin-top: 20px; border-radius: 12px; padding: 24px; }
.doc-section-heading {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* ── Context ── */
.doc-section-context {
    background: color-mix(in srgb, var(--primary) 7%, transparent);
    border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
}
.doc-context {
    font-size: 0.95rem;
    line-height: 1.8;
    color: var(--text);
    margin: 0;
}

/* ── Overview ── */
.doc-section-overview {
    background: var(--surface);
    border: 1px solid var(--border);
    border-right: 5px solid var(--primary);
}
.doc-overview { font-size: 1.05rem; line-height: 1.85; color: var(--text); margin: 0; }

/* ── Key points ── */
.doc-section-keypoints { background: var(--surface); border: 1px solid var(--border); }
.doc-points { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.doc-point  { display: flex; align-items: flex-start; gap: 14px; }
.kp-num {
    min-width: 28px; height: 28px;
    background: var(--primary); color: #fff;
    border-radius: 50%;
    font-size: 13px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; margin-top: 2px;
}
.kp-text { font-size: 0.97rem; line-height: 1.75; color: var(--text); padding-top: 3px; flex: 1; min-width: 0; }

/* ── Important notes ── */
.doc-section-notes { background: #fffbeb; border: 1px solid #fde68a; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .doc-section-notes { background: #1c1506; border-color: #78350f; }
}
.doc-notes { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.doc-note {
    padding: 12px 16px 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-right: 4px solid var(--warning);
    border-radius: 8px;
    font-size: 0.97rem; line-height: 1.75; color: var(--text);
}

/* ── Reading ── */
.doc-section-reading { background: var(--surface); border: 1px solid var(--border); }
.doc-reading-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.doc-reading-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px; padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.doc-reading-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.doc-reading-title { font-size: 0.93rem; font-weight: 600; color: var(--text); line-height: 1.45; }
.doc-reading-links { display: flex; flex-wrap: wrap; gap: 6px; }
.doc-reading-links a {
    font-size: 12px; padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    color: var(--text-muted);
    background: var(--surface);
    text-decoration: none; font-weight: 500;
}
.doc-reading-links a:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Inline reading reference chip */
.inline-ref {
    display: inline-block;
    margin-right: 8px;
    margin-top: 4px;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    vertical-align: middle;
    white-space: nowrap;
}
.inline-ref::before { content: "→ "; }
.inline-ref:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── KaTeX formula styling — RTL/LTR isolation ── */

/* Isolate every formula from the surrounding Hebrew (RTL) context */
.katex {
    direction: ltr !important;
    unicode-bidi: isolate;
    display: inline-block;
    font-size: 1.06em !important;
    vertical-align: middle;
}

/* Display (block) formulas */
.katex-display {
    direction: ltr !important;
    unicode-bidi: isolate;
    margin: 16px auto !important;
    padding: 14px 20px;
    background: var(--surface2);
    border-radius: 8px;
    border: 1px solid var(--border);
    overflow-x: auto;
    text-align: center;
}

/* Tell these containers to use the actual character direction
   (plaintext mode) instead of inheriting RTL for everything */
.kp-text,
.doc-overview,
.doc-note {
    unicode-bidi: plaintext;
}

.kp-text .katex, .doc-note .katex { font-size: 1em !important; }

/* ── Terms (מונחים) ── */
.doc-section-terms { }
.term-chips { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }
.term-chip {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--primary);
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
    cursor: pointer;
}
.term-chip:hover { background: var(--primary); color: #fff; border-color: var(--primary); text-decoration: none; }
.term-chip-plain { color: var(--text); cursor: default; }
.term-chip-plain:hover { background: var(--surface2); color: var(--text); border-color: var(--border); }

/* ── Actions ── */
.doc-actions { display: flex; align-items: center; gap: 12px; padding: 24px 0 4px; flex-wrap: wrap; }
.doc-footer-meta { font-size: 0.78rem; color: var(--text-muted); margin-right: auto; }

/* Difficulty badge (course list) */
.difficulty-badge { display:inline-block; padding:2px 8px; border-radius:4px; font-size:0.75rem; background:var(--surface2); color:var(--text-muted); }

/* ===== Transcript ===== */
.transcript-details { margin-bottom: 24px; }
.transcript-details summary {
    cursor: pointer;
    padding: 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    user-select: none;
}
.transcript-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 16px;
    font-size: 0.88rem;
    line-height: 1.8;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
}

/* ===== Empty state ===== */
.empty-state {
    text-align: center;
    padding: 64px 24px;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.empty-state-icon {
    width: 48px;
    height: 48px;
    color: var(--border);
    margin: 0 auto 16px;
    display: block;
}
.empty-state h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}
.empty-state p { font-size: 0.88rem; margin-bottom: 20px; }

/* ===== Setup page ===== */
.setup-page { max-width: 680px; margin: 0 auto; }
.setup-page h1 { font-size: 1.8rem; margin-bottom: 8px; }
.subtitle { color: var(--text-muted); margin-bottom: 32px; }
.setup-form { display: flex; flex-direction: column; gap: 0; }
.setup-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
}
.setup-section h2 { font-size: 1.05rem; margin-bottom: 16px; font-weight: 700; }
.form-group { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-weight: 600; font-size: 0.9rem; }
.form-group input {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
    width: 100%;
}
.form-group input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.hint { font-size: 0.82rem; color: var(--text-muted); }
.help-box {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 14px;
    font-size: 0.88rem;
    margin-top: 8px;
}
.help-box ol { padding-right: 20px; margin-top: 8px; }
.help-box li { margin-bottom: 4px; }
.prereqs {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 24px;
}
.prereqs h3 { margin-bottom: 10px; font-size: 0.95rem; }
.prereqs ul { padding-right: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 0.88rem; }
.prereqs code { background: var(--surface2); padding: 2px 6px; border-radius: 4px; font-size: 0.85rem; }

/* ===== New extraction fields ===== */
.badge-exam {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    background: #fef9c3;
    color: #854d0e;
    border: 1px solid #fde047;
    border-radius: 20px;
    padding: 1px 8px;
    margin-right: 6px;
    vertical-align: middle;
    white-space: nowrap;
}
.badge-ts {
    display: inline-block;
    font-size: 0.72rem;
    color: var(--text-muted);
    background: var(--surface2);
    border-radius: 20px;
    padding: 1px 7px;
    margin-right: 4px;
    vertical-align: middle;
    white-space: nowrap;
}
.doc-section-prereqs { border-right: 3px solid var(--primary); }
.prereq-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.prereq-item {
    display: flex; align-items: flex-start; gap: 8px;
    font-size: 0.9rem; color: var(--text);
}
.prereq-item::before {
    content: "✓";
    color: var(--primary);
    font-weight: 700;
    flex-shrink: 0;
}
.doc-note-mistake { border-right: 3px solid #f87171 !important; background: #fff5f5 !important; color: #1e1e1e !important; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .doc-note-mistake { background: #2a1515 !important; color: var(--text) !important; }
}

/* ===== Tab pane transitions ===== */
.tab-pane {
    animation: tabFadeIn 150ms var(--ease-out) both;
}
@keyframes tabFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ===== Video / assignment card stagger ===== */
.video-list .video-card {
    animation: cardSlideIn 200ms var(--ease-out) both;
    /* Cap at 150ms total so long lists never create perceived latency */
    animation-delay: min(calc(var(--stagger-i, 0) * 35ms), 150ms);
}
@keyframes cardSlideIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ===== Course cards stagger ===== */
.course-card-wrap {
    animation: cardSlideIn 200ms var(--ease-out) both;
    animation-delay: min(calc(var(--stagger-i, 0) * 35ms), 150ms);
}

/* ===== prefers-reduced-motion ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-delay: 0ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { padding: 16px; }
}
@media (max-width: 600px) {
    .courses-grid { grid-template-columns: 1fr; }
    .video-meta { flex-wrap: wrap; }
}

/* ===== PDF confirm dialog ===== */
.pdf-dialog {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(420px, calc(100vw - 32px));
    padding: 28px 28px 24px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 8px 40px rgba(0,0,0,.12);
    /* Modal scales from center — no translateY (Emil: modals keep transform-origin:center) */
    transition: opacity 220ms cubic-bezier(.23,1,.32,1),
                transform 220ms cubic-bezier(.23,1,.32,1),
                display 220ms allow-discrete,
                overlay 220ms allow-discrete;
}
.pdf-dialog[open] {
    opacity: 1;
    transform: scale(1);
}
@starting-style {
    .pdf-dialog[open] {
        opacity: 0;
        transform: scale(0.95);
    }
}
.pdf-dialog::backdrop {
    background: rgba(15,23,42,.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    transition: opacity 220ms cubic-bezier(.23,1,.32,1),
                display 220ms allow-discrete,
                overlay 220ms allow-discrete;
}
@starting-style {
    .pdf-dialog[open]::backdrop {
        opacity: 0;
    }
}
.pdf-dialog-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 10px;
}
.pdf-dialog-body {
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.7;
    margin-bottom: 22px;
}
.pdf-dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}
