/* ==========================================================================
   Module System - Shared "learning module" page components (Sotis AI)
   --------------------------------------------------------------------------
   Single source of truth for the module LIST + DETAIL pages shared by every
   module-style app (app6 mlformation, app8 maths, future ones). Apps link
   this file in their {% block extra_css %} BEFORE their own app CSS, then add
   only app-specific rules on top.

   Canonical values come from app6 mlformation (the reference design). Do NOT
   re-implement these components inside an app stylesheet — extend or override
   here so the design stays identical across apps by construction.
   ========================================================================== */

/* ==========================================================================
   Sync YAML button (fixed, bottom-right) + result toast
   ========================================================================== */
.sync-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    color: var(--violet-dark);
    border: 1px solid var(--violet-dark);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-md);
    z-index: 100;
    opacity: 0.7;
}

.sync-btn:hover {
    background: var(--violet-dark);
    color: white;
    opacity: 1;
}

.sync-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.sync-result {
    position: fixed;
    bottom: 4.5rem;
    right: 2rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    display: none;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.sync-result.success {
    display: block;
    background: rgba(76, 175, 80, 0.1);
    color: #4caf50;
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.sync-result.error {
    display: block;
    background: rgba(244, 67, 54, 0.1);
    color: #f44336;
    border: 1px solid rgba(244, 67, 54, 0.3);
}

/* ==========================================================================
   Filters (list page)
   ========================================================================== */
.filters-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
    padding: var(--space-md);
    background: var(--card-bg);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    max-width: 100%;
    overflow-x: hidden;
}

.filter-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs);
    max-width: 100%;
}

.filter-label {
    font-weight: 600;
    color: var(--text-secondary);
    margin-right: var(--space-xs);
    min-width: 80px;
}

.filter-btn {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition-fast);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.filter-btn:hover {
    background: var(--violet-light);
    border-color: var(--violet-primary);
}

.filter-btn.active {
    background: var(--violet-dark);
    color: var(--white);
    border-color: var(--violet-dark);
}

/* ==========================================================================
   Modules grid + cards (list page)
   ========================================================================== */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-md);
}

.module-card {
    display: flex;
    flex-direction: column;
    padding: var(--space-md);
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--text-primary);
    transition: var(--transition-base);
}

.module-card:hover {
    border-color: var(--violet-primary);
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

.module-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
}

.module-category {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.module-title {
    margin: 0 0 var(--space-xs);
    font-size: 1.2rem;
    color: var(--violet-dark);
}

.module-description {
    flex: 1;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: var(--space-sm);
}

.module-meta {
    display: flex;
    gap: var(--space-md);
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--border-color);
}

.no-modules {
    grid-column: 1 / -1;
    text-align: center;
    padding: var(--space-lg);
    color: var(--text-secondary);
}

/* ==========================================================================
   Difficulty badges (solid light fills, legible on the violet header too)
   ========================================================================== */
.module-difficulty,
.difficulty-beginner,
.difficulty-intermediate,
.difficulty-advanced {
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

.difficulty-beginner {
    background: #d4edda;
    color: #155724;
}

.difficulty-intermediate {
    background: #fff3cd;
    color: #856404;
}

.difficulty-advanced {
    background: #f8d7da;
    color: #721c24;
}

/* ==========================================================================
   Module detail header (solid violet card, white text)
   ========================================================================== */
.module-header {
    margin-bottom: var(--space-lg);
    padding: var(--space-md);
    background: var(--violet-dark);
    border-radius: var(--radius-md);
    position: static;
    box-shadow: none;
}

.module-header h1 {
    font-size: 2.2rem;
    color: var(--white);
    margin-bottom: var(--space-xs);
    line-height: 1.2;
}

.module-header .module-description {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1rem;
    margin-bottom: var(--space-sm);
}

.module-breadcrumb {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: var(--space-sm);
}

.module-breadcrumb a {
    color: var(--white);
    text-decoration: none;
}

.module-breadcrumb a:hover {
    text-decoration: underline;
}

.module-breadcrumb span {
    color: rgba(255, 255, 255, 0.6);
}

.module-meta-header {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin: var(--space-sm) 0;
    align-items: center;
}

.module-duration,
.module-sections-count {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
}

/* ==========================================================================
   Learning objectives & prerequisites
   ========================================================================== */
.learning-objectives,
.prerequisites {
    background: var(--card-bg);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    border: 1px solid var(--border-color);
}

.learning-objectives h2,
.prerequisites h2 {
    font-size: 1.1rem;
    color: var(--violet-dark);
    margin-bottom: var(--space-sm);
}

/* ==========================================================================
   Notebook cells (section framework)
   ========================================================================== */
.notebook-cells {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.cell {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.cell-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.cell-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
}

.cell-content {
    padding: var(--space-md);
    line-height: 1.7;
}

/* Cell-type badges — union of all module apps' section types.
   Solid light fills + dark text so they read on every card/theme. */
.cell-type-badge {
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cell-type-badge.theory        { background: var(--violet-light); color: var(--violet-dark); }
.cell-type-badge.code          { background: #e3f2fd; color: #1565c0; }
.cell-type-badge.exercise      { background: #fff3cd; color: #856404; }
.cell-type-badge.advanced      { background: #f3e5f5; color: #7b1fa2; }
.cell-type-badge.formula       { background: #fff3cd; color: #856404; }
.cell-type-badge.visualization { background: #e3f2fd; color: #1565c0; }
.cell-type-badge.quiz          { background: #e8f5e9; color: #2e7d32; }
.cell-type-badge.locked        { background: rgba(158, 158, 158, 0.2); color: var(--text-secondary); }

/* ==========================================================================
   Markdown content (rendered by each app's render_markdown filter)
   ========================================================================== */
.markdown-content {
    max-width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.markdown-content p {
    margin: 0 0 1em;
    color: var(--text-primary);
}

.markdown-content p:last-child {
    margin-bottom: 0;
}

/* Subheaders (lines ending with :) */
.markdown-content .md-subheader {
    font-weight: 600;
    color: var(--violet-dark);
    margin: 1.5em 0 0.5em;
    font-size: 1.05em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
}

.markdown-content .md-subheader:first-child {
    margin-top: 0;
}

/* Bold text */
.markdown-content strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Lists */
.markdown-content .md-list {
    margin: 0.5em 0 1em;
    padding-left: 1.5em;
}

.markdown-content .md-list li {
    margin: 0.4em 0;
    color: var(--text-primary);
    position: relative;
}

.markdown-content ul.md-list {
    list-style: none;
}

.markdown-content ul.md-list li::before {
    content: '';
    position: absolute;
    left: -1.2em;
    top: 0.55em;
    width: 6px;
    height: 6px;
    background: var(--violet-dark);
    border-radius: 50%;
}

.markdown-content ol.md-list {
    list-style: decimal;
}

.markdown-content ol.md-list li::marker {
    color: var(--violet-dark);
    font-weight: 600;
}

/* Tables - responsive wrapper */
.markdown-content .md-table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: 1em 0;
    -webkit-overflow-scrolling: touch;
}

.markdown-content .md-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
    margin: 0;
}

.markdown-content .md-table th,
.markdown-content .md-table td {
    padding: 0.75em 1em;
    text-align: left;
    border: 1px solid var(--border-color);
}

.markdown-content .md-table th {
    background: var(--violet-light);
    color: var(--violet-dark);
    font-weight: 600;
}

.markdown-content .md-table tbody tr:nth-child(even) {
    background: var(--bg-secondary);
}

.markdown-content .md-table tbody tr:hover {
    background: rgba(192, 156, 240, 0.1);
}

/* Dark mode table adjustments */
[data-theme="dark"] .markdown-content .md-table th {
    background: rgba(155, 122, 196, 0.3);
    color: var(--violet-light);
}

[data-theme="dark"] .markdown-content .md-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .markdown-content .md-table tbody tr:hover {
    background: rgba(192, 156, 240, 0.15);
}

/* Horizontal separator */
.markdown-content .md-separator {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--violet-primary), transparent);
    margin: var(--space-md) 0;
    opacity: 0.6;
}

/* Inline code */
.markdown-content .md-inline-code {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    font-size: 0.9em;
    color: var(--violet-dark);
}

[data-theme="dark"] .markdown-content .md-inline-code {
    background: #2d2d2d;
    border-color: #444;
}

/* Code blocks */
.markdown-content .md-code-block {
    background: #1e1e1e;
    border: 1px solid #3a3a3a;
    border-radius: var(--radius-sm);
    padding: 1em 1.5em;
    margin: 1em 0;
    overflow-x: auto;
    font-family: 'JetBrains Mono', 'Fira Code', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.9em;
    line-height: 1.5;
    color: #d4d4d4;
    white-space: pre;
    tab-size: 4;
}

.markdown-content .md-code-block code {
    background: transparent;
    border: none;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
    white-space: pre;
    display: block;
}

[data-theme="light"] .markdown-content .md-code-block {
    background: #f5f5f5;
    border-color: #ddd;
    color: #333;
}

/* KaTeX math formulas */
.markdown-content .katex-display {
    margin: 1em 0;
    padding: 0.5em;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    overflow-x: auto;
}

.markdown-content .katex {
    font-size: 1.1em;
}

/* ==========================================================================
   Bottom navigation (back link)
   ========================================================================== */
.module-nav {
    margin-top: var(--space-lg);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-color);
}

.nav-back {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    color: var(--violet-dark);
    text-decoration: none;
    font-weight: 500;
}

.nav-back:hover {
    text-decoration: underline;
}

.nav-back::before {
    content: '<-';
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 768px) {
    .module-header {
        padding: var(--space-sm);
    }

    .module-header h1 {
        font-size: 1.6rem;
    }

    .filters-section {
        padding: var(--space-sm);
    }

    .filter-label {
        width: 100%;
        margin-bottom: var(--space-xs);
    }

    .modules-grid {
        grid-template-columns: 1fr;
    }

    .module-meta-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .filters-section {
        padding: var(--space-xs);
        border-radius: var(--radius-sm);
    }

    .cell-content {
        padding: var(--space-sm);
    }

    .filter-btn {
        padding: 0.3rem 0.5rem;
        font-size: 0.7rem;
    }

    .filter-label {
        min-width: auto;
        font-size: 0.8rem;
    }

    .module-card {
        padding: var(--space-sm);
    }
}
