:root { 
    --bg: #FFFFFF; 
    --sidebar: #F0F2F6; 
    --text: #111111; 
    --accent: #0068C9; 
}

/* Theme Overrides */
:root[data-theme="Classic White"] { --bg: #FFFFFF; --sidebar: #F0F2F6; --text: #111111; --accent: #0068C9; }
:root[data-theme="Warm Paper"] { --bg: #FDFCF0; --sidebar: #F7F5E6; --text: #3E2723; --accent: #D84315; }
:root[data-theme="Mint Fresh"] { --bg: #F1F8E9; --sidebar: #DCEDC8; --text: #1B5E20; --accent: #2E7D32; }
:root[data-theme="Sky Blue"] { --bg: #E3F2FD; --sidebar: #BBDEFB; --text: #0D47A1; --accent: #1565C0; }
:root[data-theme="Lavender Mist"] { --bg: #F3E5F5; --sidebar: #E1BEE7; --text: #4A148C; --accent: #7B1FA2; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
}

.app-container { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: 300px;
    background-color: var(--sidebar);
    padding: 2rem;
    border-right: 1px solid rgba(0,0,0,0.1);
}

.sidebar label { display: block; margin-top: 1rem; margin-bottom: 0.5rem; font-weight: 500; color: var(--text); }
.sidebar input:not([type="checkbox"]), .sidebar select {
    width: 100%; padding: 0.5rem; border: 1px solid #ccc; border-radius: 8px; background: #fff; color: #000; margin-bottom: 0.5rem; box-sizing: border-box;
}

/* Main Content */
.main-content { flex: 1; padding: 2rem 4rem; }
.caption { color: var(--text); opacity: 0.7; margin-bottom: 2rem; }

/* Tabs */
.tabs { display: flex; gap: 1rem; border-bottom: 2px solid #ccc; margin-bottom: 2rem; }
.tab-btn {
    background: none; border: none; padding: 1rem; cursor: pointer; color: var(--text); font-size: 1rem; font-weight: bold; border-bottom: 3px solid transparent;
}
.tab-btn.active { border-bottom-color: var(--accent); color: var(--accent); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Inputs and Buttons */
.input-section { display: none; margin-top: 1rem; }
.input-section.active { display: block; }
.radio-group { margin-bottom: 1rem; display: flex; gap: 1rem; }

textarea { width: 100%; padding: 0.5rem; border: 1px solid #ccc; border-radius: 8px; background: #fff; color: #000; box-sizing: border-box; }
input[type="text"], input[type="file"] { width: 100%; padding: 0.5rem; border: 1px solid #ccc; border-radius: 8px; margin-bottom: 1rem; background: #fff; color: #000; box-sizing: border-box;}

.action-btn {
    background-color: var(--accent); color: white; border: none; padding: 0.8rem 1.5rem; border-radius: 8px; font-weight: bold; cursor: pointer; margin-top: 1rem; width: 100%;
}
.action-btn:hover { opacity: 0.9; box-shadow: 0px 2px 5px rgba(0,0,0,0.2); }

/* Feedback */
.info-box { background-color: rgba(255,255,255,0.7); padding: 1rem; border-radius: 8px; border-left: 4px solid var(--accent); margin-bottom: 1rem; color: #000;}
.error-box { background-color: #ffebee; color: #c62828; padding: 1rem; border-radius: 8px; margin-top: 1rem; }
.hidden { display: none; }

/* Flashcards & Quiz */
.flashcard { border: 1px solid #ccc; border-radius: 8px; margin-bottom: 1rem; padding: 1rem; background: rgba(255,255,255,0.5); }
.flashcard summary { font-weight: bold; cursor: pointer; color: var(--text); }
.flashcard-answer { margin-top: 1rem; padding: 1rem; background: rgba(0,0,0,0.05); border-radius: 4px; }

.quiz-question { margin-bottom: 2rem; border-bottom: 1px solid #ccc; padding-bottom: 1rem; }
.quiz-options label { display: block; margin: 0.5rem 0; cursor: pointer; }

/* --- NEW: Animated Loader Styles --- */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 2rem;
    padding: 2rem;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    border: 1px dashed var(--accent);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Ensure hidden class works perfectly with flexbox */
.hidden { display: none !important; }

/* --- Markdown Table Styling --- */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
    font-size: 0.95rem;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    overflow: hidden; /* Keeps the rounded corners intact */
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
}

table thead tr {
    background-color: var(--accent);
    color: #ffffff;
    text-align: left;
}

table th, table td {
    padding: 12px 15px;
    border: 1px solid rgba(0,0,0,0.1);
}

table tbody tr {
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

/* Alternating row colors for better readability */
table tbody tr:nth-of-type(even) {
    background-color: rgba(0, 0, 0, 0.02);
}

table tbody tr:last-of-type {
    border-bottom: 2px solid var(--accent);
}

/* =========================================
   MEDIA QUERIES - RESPONSIVE DESIGN
   ========================================= */

/* =========================================
   LAPTOP / SMALL DESKTOP (1024px)
   ========================================= */
@media (max-width: 1024px) {
    .main-content { 
        padding: 2rem; /* Reduce extreme side padding */
    }
    .sidebar { 
        width: 250px; /* Slightly shrink sidebar */
    }
}

/* =========================================
   TABLET (768px) 
========================================= */
@media (max-width: 768px) {
    .app-container { 
        flex-direction: column; /* Stacks sidebar on top of main content */
    }
    
    .sidebar {
        width: 100%;
        padding: 1.5rem;
        border-right: none;
        border-bottom: 1px solid rgba(0,0,0,0.1);
    }

    .main-content { 
        width: 100%;
        padding: 1.5rem; 
        box-sizing: border-box; /* Ensures padding doesn't overflow screen */
    }

    /* Wrap tabs to next line if there are too many */
    .tabs { 
        flex-wrap: wrap; 
        gap: 0.5rem; 
    }
    
    .tab-btn {
        flex: 1; /* Makes tabs stretch evenly */
        text-align: center;
    }

    /* Make tables scrollable horizontally on smaller devices */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* =========================================
   LARGE MOBILE (425px) 
========================================= */
@media (max-width: 425px) {
    .main-content { padding: 1rem; }
    .sidebar { padding: 1rem; }
    
    h1 { font-size: 2.2rem; }
    .action-btn { padding: 0.7rem 1rem; }
}

/* =========================================
   MEDIUM MOBILE (375px) 
========================================= */
@media (max-width: 375px) {
    .main-content { padding: 0.8rem; }
    .sidebar { padding: 0.8rem; }
    
    h1 { font-size: 2rem; }
    .tab-btn { font-size: 0.95rem; padding: 0.6rem; }
}

/* =========================================
   SMALL MOBILE (320px) 
========================================= */
@media (max-width: 320px) {
    .main-content { padding: 0.5rem; }
    .sidebar { padding: 0.5rem; }
    
    h1 { font-size: 1.75rem; }
    
    /* Stack inline elements that might be too wide */
    .radio-group { 
        flex-direction: column; 
        gap: 0.5rem; 
    }
    .tabs { gap: 0; }
    .tab-btn { padding: 0.5rem; font-size: 0.85rem; }
}