/* ==========================================================================
   Design System & Styling Rules - GoodNotes OCR & Summary Website
   ========================================================================== */

:root {
    /* Color Tokens (Clean Light Theme Default) */
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-header: rgba(255, 255, 255, 0.9);
    --bg-modal: #ffffff;
    
    --border-color: #e2e8f0;
    --border-hover: rgba(37, 99, 235, 0.4);
    
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    
    --accent-blue: #2563eb;
    --accent-purple: #7c3aed;
    --accent-emerald: #059669;
    --accent-gradient: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    
    --card-shadow: 0 4px 20px -4px rgba(0, 0, 0, 0.05), 0 2px 6px -2px rgba(0, 0, 0, 0.03);
    --modal-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.2);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

/* Dark Theme Variables (Optional toggle) */
html.dark {
    --bg-main: #0b0f19;
    --bg-card: #131b2e;
    --bg-sidebar: #0e1424;
    --bg-header: rgba(14, 20, 36, 0.85);
    --bg-modal: #131a2a;
    
    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(59, 130, 246, 0.4);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --card-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    --modal-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}

/* Base Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* App Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: var(--accent-gradient);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
}

.brand-text h2 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.brand-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

.sidebar-nav {
    padding: 24px 16px;
    flex: 1;
    overflow-y: auto;
}

.nav-section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 600;
    padding: 0 12px 12px;
}

/* Accordion Tree Styling (École -> Année -> Matière) */
.accordion-tree {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.accordion-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    border: 1px solid transparent;
    user-select: none;
}

.accordion-item:hover {
    background-color: rgba(37, 99, 235, 0.06);
    color: var(--text-primary);
}

.accordion-item.active {
    background-color: rgba(37, 99, 235, 0.12);
    color: var(--accent-blue);
    border-color: rgba(37, 99, 235, 0.3);
}

.tree-chevron {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.tree-chevron.open {
    transform: rotate(90deg);
}

.years-subtree {
    list-style: none;
    padding-left: 12px;
    margin-left: 14px;
    border-left: 2px solid var(--border-color);
    margin-top: 2px;
    margin-bottom: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.year-tree-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    user-select: none;
}

.year-tree-item:hover {
    background-color: rgba(124, 58, 237, 0.06);
    color: var(--text-primary);
}

.year-tree-item.active {
    background-color: rgba(124, 58, 237, 0.12);
    color: var(--accent-purple);
}

.subjects-subtree {
    list-style: none;
    padding-left: 12px;
    margin-left: 12px;
    border-left: 2px solid rgba(124, 58, 237, 0.2);
    margin-top: 2px;
    margin-bottom: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.subject-tree-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.subject-tree-item:hover {
    background-color: rgba(59, 130, 246, 0.08);
    color: var(--text-primary);
}

.subject-tree-item.active {
    background-color: rgba(59, 130, 246, 0.16);
    color: var(--accent-blue);
    font-weight: 600;
}

.tree-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-count {
    font-size: 11.5px;
    background-color: rgba(0, 0, 0, 0.05);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    color: var(--text-muted);
    font-weight: 500;
}

.accordion-item.active .tree-count,
.year-tree-item.active .tree-count,
.subject-tree-item.active .tree-count {
    background-color: rgba(37, 99, 235, 0.18);
    color: var(--accent-blue);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.profile-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: rgba(59, 130, 246, 0.2);
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
}

.profile-info {
    display: flex;
    flex-direction: column;
}

.profile-name {
    font-size: 13px;
    font-weight: 600;
}

.profile-status {
    font-size: 11px;
    color: var(--accent-emerald);
}

/* Main Content Area */
.main-content {
    margin-left: 280px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Topbar */
.topbar {
    height: 70px;
    background-color: var(--bg-header);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 30;
}

.mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: var(--radius-full);
    width: 420px;
    transition: border-color 0.2s ease;
}

.search-box:focus-within {
    border-color: var(--accent-blue);
}

.search-icon {
    color: var(--text-muted);
    width: 18px;
    height: 18px;
}

.search-box input {
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 14px;
    width: 100%;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Dashboard Body */
.dashboard-body {
    padding: 32px;
    max-width: 1300px;
    width: 100%;
    margin: 0 auto;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 28px;
}

.page-title {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.page-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
}

.stats-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 13px;
    color: var(--text-secondary);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px dashed var(--border-color);
    margin-top: 20px;
}

.empty-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-muted);
    font-size: 14px;
    max-width: 400px;
    margin: 0 auto;
}

/* Cards Grid */
.courses-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 24px;
}

/* Course Card */
.course-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    cursor: pointer;
    box-shadow: var(--card-shadow);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.course-card:hover {
    transform: translateY(-4px);
    border-color: var(--border-hover);
    box-shadow: 0 15px 35px -10px rgba(59, 130, 246, 0.15);
}

.card-top {
    margin-bottom: 16px;
}

.card-actions-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.card-move-btn, .card-delete-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-move-btn:hover {
    background-color: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
}

.card-delete-btn:hover {
    background-color: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.card-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.card-title {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.card-summary {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-muted);
}

.card-date {
    display: flex;
    align-items: center;
    gap: 6px;
}

.card-action {
    color: var(--accent-blue);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Modal Reader View */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: fadeIn 0.2s ease;
}

.modal-container {
    background-color: var(--bg-modal);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 900px;
    height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--modal-shadow);
    overflow: hidden;
}

.modal-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.subject-tag-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.subject-tag {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s ease;
}

.subject-tag:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

.edit-subject-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    transition: all 0.2s ease;
}

.edit-subject-btn:hover {
    color: var(--accent-blue);
    background-color: rgba(59, 130, 246, 0.1);
}

.modal-course-title {
    font-size: 22px;
    font-weight: 700;
}

.modal-course-date {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.icon-btn.danger-btn {
    color: #ef4444;
}

.icon-btn.danger-btn:hover {
    background-color: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.4);
}

.card-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.card-delete-btn:hover {
    color: #ef4444;
    background-color: rgba(239, 68, 68, 0.12);
}

/* Modal Tabs */
.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background-color: rgba(0, 0, 0, 0.1);
    padding: 0 24px;
}

.tab-btn {
    background: none;
    border: none;
    padding: 14px 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
}

/* Modal Body */
.modal-body {
    padding: 32px;
    flex: 1;
    overflow-y: auto;
}

.tab-content {
    animation: fadeIn 0.2s ease;
}

.hidden {
    display: none !important;
}

/* Markdown & LaTeX Styling */
.markdown-body {
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.7;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
    margin-top: 24px;
    margin-bottom: 12px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.markdown-body h1 { font-size: 24px; color: var(--accent-blue); border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.markdown-body h2 { font-size: 20px; color: var(--text-primary); }
.markdown-body h3 { font-size: 16px; color: var(--text-secondary); }

.markdown-body ul, .markdown-body ol {
    margin-left: 20px;
    margin-bottom: 16px;
}

.markdown-body li {
    margin-bottom: 6px;
}

.markdown-body p {
    margin-bottom: 16px;
}

.markdown-body blockquote {
    border-left: 4px solid var(--accent-blue);
    background-color: rgba(59, 130, 246, 0.08);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
}

.markdown-body code {
    font-family: var(--font-mono);
    background-color: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.katex-display {
    margin: 20px 0 !important;
    padding: 16px;
    background-color: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    overflow-x: auto;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

/* Custom Schema Boxes & Pedagogical Corrections */
.schema-box {
    background: rgba(59, 130, 246, 0.05);
    border: 1px dashed rgba(37, 99, 235, 0.4);
    border-left: 4px solid var(--accent-blue);
    padding: 16px;
    border-radius: var(--radius-md);
    margin: 18px 0;
}

.schema-box .schema-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.note-correction {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-left: 5px solid #f59e0b;
    padding: 14px 18px;
    border-radius: var(--radius-md);
    margin: 18px 0;
}

.note-correction .correction-title {
    font-weight: 700;
    color: #d97706;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.92rem;
}

html.dark .note-correction .correction-title {
    color: #fbbf24;
}

.note-correction p {
    margin-bottom: 6px !important;
    font-size: 0.9rem;
}

/* Responsive Rules */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .mobile-toggle {
        display: block;
    }
    .search-box {
        width: 100%;
    }
}

/* Animations & Toast Notifications */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.spin {
    animation: spin 1s linear infinite;
}

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    background: #1e293b;
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.success {
    background: #065f46;
    border-left: 4px solid #10b981;
}

.toast.error {
    background: #991b1b;
    border-left: 4px solid #ef4444;
}

