/* =========================================
   1. VARIABLES Y RESETEO
   ========================================= */
:root {
    --primary: #0f2c4c;
    --secondary: #1a4a7c;
    --accent: #c5a059;
    --bg-body: #f4f6f8;
    --bg-card: #ffffff;
    --text-main: #333333;
    --text-muted: #666666;
    --border: #e0e0e0;
    --success: #27ae60;
    --danger: #e74c3c;
    --toast-bg: #333;
    --toast-text: #fff;
    --nav-btn-bg: #e0e0e0;
    --nav-btn-hover: #d0d0d0;
}

/* Dark Mode Variables - Professional Legal Theme */
body.dark-mode {
    --primary: #60a5fa;
    /* Soft Blue for readability */
    --secondary: #3b82f6;
    /* Slightly darker blue for accents */
    --accent: #fbbf24;
    /* Gold/Amber for legal highlights */
    --bg-body: #111827;
    /* Deep Slate (Main Background) */
    --bg-card: #1f2937;
    /* Lighter Slate (Cards) */
    --text-main: #f9fafb;
    /* Off-white for main text */
    --text-muted: #9ca3af;
    /* Gray for muted text */
    --border: #374151;
    /* Subtle dark border */
    --success: #34d399;
    /* Softer Green */
    --danger: #f87171;
    /* Softer Red */
    --toast-bg: #f3f4f6;
    /* Light toast background for contrast */
    --toast-text: #1f2937;
    /* Dark text for toast */
    --nav-btn-bg: #374151;
    /* Dark Button BG */
    --nav-btn-hover: #4b5563;
    /* Dark Button Hover */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* =========================================
   2. HEADER
   ========================================= */
.top-bar {
    background-color: var(--primary);
    color: white;
    padding: 0 20px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 15px;
}

.brand h1 {
    font-size: 1.2rem;
    font-weight: 500;
    margin-right: auto;
}

#themeToggle {
    display: inline-block;
    font-size: 1.2rem;
    margin-left: 10px;
    cursor: pointer;
}

.icon-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    display: none;
}

.progress-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
}

.progress-bg {
    width: 150px;
    height: 10px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: var(--success);
    width: 0%;
    transition: width 0.5s ease;
}

/* =========================================
   3. LAYOUT
   ========================================= */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: white;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.sidebar-header-mobile {
    color: white;
    justify-content: space-between;
    align-items: center;
}

/* DARK MODE SPECIFIC OVERRIDES */
body.dark-mode .sidebar {
    background-color: var(--bg-card);
    border-right-color: var(--border);
}

body.dark-mode #lessonList li {
    color: var(--text-muted);
    /* Better contrast for unselected items */
    border-bottom-color: var(--border);
}

body.dark-mode #lessonList li:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

body.dark-mode #lessonList li.active {
    background-color: var(--secondary);
    color: white;
    /* Active item stays white */
}

/* Dark Mode Components/Containers */
body.dark-mode .lesson-card,
body.dark-mode .summary-container,
body.dark-mode .doc-wrapper,
body.dark-mode .audio-wrapper,
body.dark-mode .quiz-item,
body.dark-mode .tab-btn.active,
body.dark-mode .sidebar-search input {
    background-color: var(--bg-card);
    border-color: var(--border);
    color: var(--text-main);
}

body.dark-mode .sidebar-search input {
    background-color: #111827;
    /* Slightly darker input bg */
    color: var(--text-main);
}

/* Flashcards Dark Mode */
body.dark-mode .flashcard {
    background-color: var(--bg-card);
    border-color: var(--border);
    color: var(--text-main);
}

body.dark-mode .flashcard:hover {
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
    border-color: var(--primary);
}

/* Quiz Answers Dark Mode */
body.dark-mode .quiz-answer {
    background-color: #1e3a8a;
    /* Dark Blue for answers */
    color: #e0f2fe;
}

/* Error/Loading Messages */
body.dark-mode .error-message {
    background-color: rgba(248, 113, 113, 0.2);
    /* Low opacity red */
    color: #fca5a5;
    border: 1px solid #7f1d1d;
}

body.dark-mode .loading-message {
    color: var(--text-muted);
}

.sidebar-search {
    padding: 10px 15px;
    border-bottom: 1px solid var(--border);
}

.sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background-color: var(--bg-body);
    color: var(--text-main);
}

#lessonList {
    list-style: none;
}

#lessonList li {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.2s;
}

#lessonList li:hover {
    background-color: #f0f4f8;
}

#lessonList li.active {
    background-color: var(--secondary);
    color: white;
    border-left: 5px solid var(--accent);
}

#lessonList li.completed-item {
    color: var(--success);
}

#lessonList li.completed-item::after {
    content: ' ✓';
    font-weight: bold;
}

#lessonList li.active.completed-item {
    color: white;
}

#lessonList li.bookmarked::before {
    content: '🔖 ';
}

/* Content Area */
.content-area {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    position: relative;
}

.lesson-card {
    background-color: var(--bg-card);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    max-width: 1000px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 80vh;
}

.hidden {
    display: none !important;
}

/* Spinner */
#loadingSpinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--secondary);
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* =========================================
   4. COMPONENTES
   ========================================= */
.lesson-header {
    padding: 20px 30px;
    border-bottom: 1px solid var(--border);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.lesson-header h2 {
    color: var(--primary);
    font-size: 1.6rem;
    margin: 0;
}

.bookmark-btn {
    display: inline-block;
    color: var(--text-muted);
    font-size: 1.5rem;
    transition: color 0.3s;
}

.bookmark-btn.active {
    color: #f1c40f;
}

/* Gold color for active bookmark */

/* Tabs */
.tabs-nav {
    display: flex;
    background-color: #fafafa;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tab-btn {
    padding: 15px 25px;
    border: none;
    background: none;
    font-size: 1rem;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--accent);
    font-weight: 500;
    background-color: white;
}

/* Tab Content */
.tab-content {
    padding: 30px;
    flex: 1;
}

#resumen.tab-pane {
    padding: 0;
    /* Remove padding for the summary tab to let iframe fit better */
}

.tab-pane {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-pane.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Texto Resumen - Dark Mode Fix */
.text-body {
    line-height: 1.6;
    color: inherit;
    /* Ensure it inherits from container in dark mode */
}

body.dark-mode .text-body {
    color: var(--text-main);
}

.text-body h3 {
    color: var(--secondary);
    margin-top: 20px;
}

.text-body p,
.text-body ul {
    margin-bottom: 15px;
}

.summary-container {
    padding: 20px;
    background-color: white;
    min-height: 50vh;
    border-radius: 4px;
}

.loading-message {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-style: italic;
}

.error-message {
    color: var(--danger);
    padding: 20px;
    text-align: center;
    background-color: #fee;
    border-radius: 4px;
}

/* Tabla */
.table-responsive {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.data-table th {
    background-color: #f8f9fa;
    color: var(--primary);
}

body.dark-mode .data-table th {
    background-color: var(--bg-card);
    /* Consistent with card bg in dark mode */
    border-bottom: 2px solid var(--border);
}

/* VIDEO RESPONSIVE */
.video-wrapper {
    max-width: 850px;
    margin: 0 auto;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.video-responsive {
    position: relative;
    padding-bottom: 56.25%;
    /* 16:9 Aspect Ratio */
    height: 0;
    overflow: hidden;
}

.video-responsive iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* AUDIO Y DOCUMENTOS */
.audio-wrapper {
    text-align: center;
    padding: 30px;
    background-color: #f1f3f5;
    border-radius: 8px;
    margin-bottom: 20px;
}

audio {
    width: 100%;
    max-width: 600px;
    margin-top: 10px;
}

.doc-wrapper {
    text-align: center;
    padding: 30px;
    background-color: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.doc-wrapper h3 {
    color: var(--secondary);
    margin-bottom: 10px;
}

.doc-wrapper p {
    color: var(--text-muted);
    margin-bottom: 20px;
}

.btn-download {
    display: inline-block;
    background-color: var(--primary);
    color: white;
    padding: 12px 25px;
    text-decoration: none;
    border-radius: 5px;
    font-weight: 500;
    transition: background 0.3s, transform 0.2s;
}

.btn-download:hover {
    background-color: var(--secondary);
    transform: translateY(-2px);
}

/* Flashcards */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.flashcard {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    cursor: pointer;
    min-height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.flashcard:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.flashcard.flipped {
    background-color: var(--secondary);
    color: white;
}

/* Quiz */
.quiz-item {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
}

.quiz-question {
    font-weight: 500;
    margin-bottom: 10px;
    color: var(--primary);
}

.btn-reveal {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
}

.quiz-answer {
    margin-top: 10px;
    padding: 10px;
    background-color: #e3f2fd;
    border-radius: 4px;
    color: #0d47a1;
}

/* Footer & Buttons */
.lesson-footer {
    padding: 20px 30px;
    border-top: 1px solid var(--border);
    background-color: transparent;
}

.nav-buttons {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.btn-nav {
    background-color: var(--nav-btn-bg);
    color: var(--text-main);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-nav:hover {
    background-color: var(--nav-btn-hover);
}

.completion-area {
    text-align: right;
    padding: 10px 30px 20px;
}

.btn-primary {
    background-color: var(--success);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1rem;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-primary:hover {
    background-color: #219150;
}

/* Nuevo Estilo para botón "Desmarcar" (Rojo/Danger) */
.btn-secondary {
    background-color: var(--danger);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1rem;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-secondary:hover {
    background-color: #c0392b;
}

/* =========================================
   5. MOBILE
   ========================================= */
@media (max-width: 768px) {
    .icon-btn {
        display: block;
    }

    .progress-info span:first-child {
        display: none;
    }

    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        transform: translateX(-100%);
        z-index: 1000;
        width: 80%;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-header-mobile {
        display: flex;
    }

    .content-area {
        padding: 10px;
    }

    .tab-btn {
        padding: 12px 15px;
        font-size: 0.9rem;
    }

    .lesson-header h2 {
        font-size: 1.3rem;
    }
}

/* Toasts */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background-color: var(--toast-bg);
    color: var(--toast-text);
    padding: 12px 20px;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    min-width: 250px;
    animation: slideIn 0.3s ease;
    border-left: 4px solid var(--primary);
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.info {
    border-left-color: var(--secondary);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}