/* --- 1. Global Variables & Typography --- */
:root {
    /* Colors - Light Mode */
    --bg-body: #f4f6f8;
    --bg-paper: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --accent: #0056b3;
    /* Medical Blue */
    --border-color: #e0e0e0;

    /* Functional Colors */
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;

    /* Layout */
    --sidebar-width: 280px;
    --container-max-width: 900px;
}

[data-theme="dark"] {
    --bg-body: #121212;
    --bg-paper: #1e1e1e;
    --text-primary: #e0e0e0;
    --text-secondary: #aaaaaa;
    --accent: #4db6ac;
    /* Teal for dark mode */
    --border-color: #333333;
}

/* Import Sahel Font (using a CDN or assume local) */
@import url('https://cdn.jsdelivr.net/gh/rastikerdar/sahel-font@v3.4.0/dist/font-face.css');

@font-face {
    font-family: Sahel;
    /* set name */
    src: url(Sahel.ttf);
    /* url of the font */
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: Sahel, 'Vazirmatn', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    direction: rtl;
    /* RIGHT TO LEFT MASTER SWITCH */
    text-align: right;
    margin: 0;
    line-height: 1.8;
    transition: background 0.3s, color 0.3s;
}

/* --- 2. Layout Structure (Desktop First) --- */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Navigation (Right Side) */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-paper);
    border-left: 1px solid var(--border-color);
    /* Border on left because it's RTL */
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    padding: 20px;
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.05);
    z-index: 100;
}

.sidebar h3 {
    margin-top: 0;
    color: var(--accent);
    font-size: 1.2rem;
    border-bottom: 2px solid var(--accent);
    padding-bottom: 10px;
}

.sidebar nav ul {
    list-style: none;
    padding: 0;
}

.sidebar nav li a {
    display: block;
    padding: 8px 10px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.sidebar nav li a:hover,
.sidebar nav li a.active {
    background-color: rgba(0, 86, 179, 0.1);
    /* Light blue tint */
    color: var(--accent);
    font-weight: bold;
}

/* Main Content Area */
.main-content {
    margin-right: var(--sidebar-width);
    /* Push content to left */
    flex: 1;
    padding: 40px;
    display: flex;
    justify-content: center;
}

.paper {
    background: var(--bg-paper);
    padding: 60px;
    width: 100%;
    max-width: var(--container-max-width);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* --- 3. Responsive (Mobile) --- */
@media (max-width: 900px) {
    .sidebar {
        display: none;
        /* Hide sidebar on mobile/tablet */
    }

    .main-content {
        margin-right: 0;
        padding: 15px;
    }

    .paper {
        padding: 25px;
    }
}

/* --- 4. Components --- */

/* Typography */
h1,
h2,
h3,
h4 {
    color: var(--accent);
    margin-top: 1.5em;
}

h1 {
    font-size: 2.2rem;
    margin-top: 0;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
}

p,
.block-text {
    margin-bottom: 1em;
    font-size: 1.1rem;
}

/* Callouts */
.callout {
    padding: 20px;
    border-radius: 8px;
    margin: 25px 0;
    background-color: rgba(var(--box-rgb), 0.1);
    /* Fallback logic handled in inline style usually, or distinct classes */
    border-right: 5px solid var(--box-color, var(--accent));
    /* Right border for RTL */
    background: linear-gradient(to left, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0));
    /* Reset */
    background-color: var(--bg-paper);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: hidden;
}

.callout::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 5px;
    background-color: var(--box-color);
}

.callout strong {
    display: block;
    margin-bottom: 8px;
    color: var(--box-color);
    font-size: 1.1em;
}

/* Images */
.slide-figure {
    margin: 30px 0;
    text-align: center;
}

.slide-figure img {
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.slide-figure figcaption {
    margin-top: 10px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
    /* Horizontal scroll for mobile */
    margin: 20px 0;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
    /* Force scroll on small screens */
}

th,
td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    text-align: right;
}

th {
    background-color: rgba(0, 0, 0, 0.03);
    font-weight: bold;
    color: var(--accent);
}

tr:hover {
    background-color: rgba(0, 0, 0, 0.02);
    /* Row hover effect */
}

/* --- 5. Interactive Components --- */

/* Flashcards */
.flashcard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin: 30px 0;
}

.flashcard {
    background-color: transparent;
    width: 100%;
    height: 200px;
    perspective: 1000px;
    /* Enable 3D space */
    cursor: pointer;
}

.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

.flashcard.flipped .flashcard-inner {
    transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    border-radius: 10px;
    background: var(--bg-paper);
    border: 1px solid var(--border-color);
}

.flashcard-front {
    font-weight: bold;
    color: var(--accent);
}

.flashcard-back {
    transform: rotateY(180deg);
    background-color: rgba(0, 86, 179, 0.05);
    color: var(--text-primary);
    font-size: 0.95rem;
}

/* Quiz - Type A (Accordion) */
details.quiz-accordion {
    background: var(--bg-paper);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin: 15px 0;
    overflow: hidden;
}

details.quiz-accordion summary {
    padding: 15px;
    cursor: pointer;
    background-color: rgba(0, 0, 0, 0.02);
    font-weight: bold;
    list-style: none;
    /* Hide default triangle */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

details.quiz-accordion summary::after {
    content: '+';
    font-size: 1.5rem;
    color: var(--accent);
}

details.quiz-accordion[open] summary::after {
    content: '-';
}

.quiz-content {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    background-color: #fff;
}

[data-theme="dark"] .quiz-content {
    background-color: #252525;
}

/* Quiz - Type B (MCQ) */
.mcq-box {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin: 30px 0;
    background: var(--bg-paper);
}

.mcq-question {
    font-weight: bold;
    margin-bottom: 15px;
    display: block;
}

.mcq-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mcq-option {
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.mcq-option:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

.mcq-option input[type="radio"] {
    margin-left: 10px;
}

/* Margin on left due to RTL */

.mcq-check-btn {
    margin-top: 20px;
    padding: 10px 20px;
    background-color: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
}

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

/* MCQ Feedback States */
.mcq-option.correct {
    background-color: rgba(40, 167, 69, 0.2);
    border-color: var(--success);
}

.mcq-option.incorrect {
    background-color: rgba(220, 53, 69, 0.2);
    border-color: var(--danger);
}

.mcq-explanation {
    margin-top: 15px;
    padding: 15px;
    background-color: rgba(0, 0, 0, 0.03);
    border-radius: 6px;
    border-right: 4px solid var(--accent);
    display: none;
    /* Hidden by default */
}

/* Theme Toggle Button */
.theme-toggle {
    position: fixed;
    bottom: 30px;
    left: 30px;
    /* Bottom Left corner */
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: var(--accent);
    color: white;
    border: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    font-size: 1.5rem;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar nav li a:hover,
.sidebar nav li a.active {
    /* This class is applied by the JS above */
    background-color: rgba(0, 86, 179, 0.1);
    color: var(--accent);
    font-weight: bold;
}

/* --- 6. Slideshow Components --- */
.slideshow-container {
    max-width: 100%;
    position: relative;
    margin: auto;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
}

.mySlides {
    display: none;
    text-align: center;
}

.mySlides img {
    vertical-align: middle;
    max-height: 500px;
    object-fit: contain;
    background-color: #f0f0f0;
}

/* Next & previous buttons */
.prev,
.next {
    cursor: pointer;
    position: absolute;
    top: 50%;
    width: auto;
    padding: 16px;
    margin-top: -22px;
    color: white;
    font-weight: bold;
    font-size: 18px;
    transition: 0.6s ease;
    border-radius: 0 3px 3px 0;
    user-select: none;
    background-color: rgba(0, 0, 0, 0.3);
}

/* Position the "next button" to the right */
.next {
    right: 0;
    border-radius: 3px 0 0 3px;
}

/* Position the "prev button" to the left */
.prev {
    left: 0;
    border-radius: 0 3px 3px 0;
}

/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
    background-color: rgba(0, 0, 0, 0.8);
}

/* Caption text */
.text {
    color: #f2f2f2;
    font-size: 15px;
    padding: 8px 12px;
    position: absolute;
    bottom: 8px;
    width: 100%;
    text-align: center;
}

/* Number text (1/3 etc) */
.numbertext {
    color: #f2f2f2;
    font-size: 12px;
    padding: 8px 12px;
    position: absolute;
    top: 0;
    left: 0;
    background-color: rgba(0, 0, 0, 0.5);
    border-bottom-right-radius: 8px;
}

/* The dots/bullets/indicators */
.dot {
    cursor: pointer;
    height: 15px;
    width: 15px;
    margin: 0 2px;
    background-color: #bbb;
    border-radius: 50%;
    display: inline-block;
    transition: background-color 0.6s ease;
}

.active,
.dot:hover {
    background-color: var(--accent);
}

/* Fading animation */
.fade {
    animation-name: fade;
    animation-duration: 1.5s;
}

@keyframes fade {
    from {
        opacity: .4
    }

    to {
        opacity: 1
    }
}

/* --- 7. Third-Party Overrides (KaTeX) --- */
/* Fix KaTeX display in RTL context */
.katex {
    direction: ltr;
    unicode-bidi: isolate;
}

.katex-display {
    direction: ltr;
    unicode-bidi: isolate;
    text-align: center;
    margin: 1em 0;
    display: -webkit-inline-flex;
    width: 100%;
}

.katex-html {
    white-space: nowrap;
    /* Prevent inline formulas from wrapping awkwardly */
}