/* Import a scholar-friendly font */
@import url('https://fonts.googleapis.com/css2?family=Lato:wght@400;700&family=Lora:ital,wght@0,400;0,700;1,400&display=swap');

/* Main Container & Scoping */
#scholar-analyzer-container {
    --primary-bg: #f8f9fa;
    --secondary-bg: #ffffff;
    --primary-text: #212529;
    --secondary-text: #6c757d;
    --border-color: #dee2e6;
    --accent-color: #007bff;
    --accent-hover: #0056b3;
    --highlight-bg: rgba(0, 123, 255, 0.1);
    --shadow: 0 4px 6px rgba(0,0,0,0.05);
    --progress-bar: #28a745;
    
    font-family: 'Lato', sans-serif;
    background-color: var(--primary-bg);
    color: var(--primary-text);
    padding: 20px;
    border-radius: 12px;
    transition: background-color 0.3s, color 0.3s;
    max-width: 1400px;
    margin: 20px auto;
}

#scholar-analyzer-container.scholar-dark-theme {
    --primary-bg: #1a1a1a;
    --secondary-bg: #2c2c2c;
    --primary-text: #f0f0f0;
    --secondary-text: #a0a0a0;
    --border-color: #444;
    --accent-color: #0d6efd;
    --accent-hover: #3b82f6;
    --highlight-bg: rgba(13, 110, 253, 0.2);
    --shadow: 0 4px 8px rgba(0,0,0,0.2);
    --progress-bar: #198754;
}

/* Header */
.sa-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}
.sa-header h1 {
    font-family: 'Lora', serif;
    font-size: 28px;
    margin: 0;
    color: var(--primary-text);
}
.sa-controls { display: flex; align-items: center; gap: 10px; }
.sa-mode-label { font-size: 14px; color: var(--secondary-text); }

/* Dark Mode Toggle Switch */
.sa-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.sa-switch input { opacity: 0; width: 0; height: 0; }
.sa-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 34px; }
.sa-slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .sa-slider { background-color: var(--accent-color); }
input:checked + .sa-slider:before { transform: translateX(20px); }

/* Main Grid Layout */
.sa-main-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    grid-template-areas:
        "editor metrics"
        "editor aianalysis";
    gap: 20px;
}

/* Panel Styling */
.sa-panel {
    background-color: var(--secondary-bg);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 20px;
    border: 1px solid var(--border-color);
}
.sa-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}
.sa-panel-header h2 {
    font-family: 'Lora', serif;
    font-size: 20px;
    margin: 0;
}

/* Editor Panel */
.sa-editor-panel { grid-area: editor; display: flex; flex-direction: column; }
.sa-editor {
    flex-grow: 1;
    min-height: 500px;
    border: 1px solid var(--border-color);
    padding: 15px;
    font-size: 16px;
    line-height: 1.6;
    border-radius: 6px;
    outline: none;
    overflow-y: auto;
    color: var(--primary-text);
    background-color: var(--primary-bg);
}
.sa-editor:focus { border-color: var(--accent-color); box-shadow: 0 0 0 2px var(--highlight-bg); }
.sa-editor-toolbar { display: flex; gap: 5px; }
.sa-toolbar-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    width: 30px;
    height: 30px;
    color: var(--primary-text);
}
.sa-toolbar-btn:hover { background-color: var(--highlight-bg); }

/* Progress Tracker */
.sa-progress-tracker { margin-top: 20px; }
.sa-progress-tracker label { font-size: 14px; margin-right: 10px; }
.sa-progress-tracker input {
    width: 80px;
    padding: 5px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background-color: var(--primary-bg);
    color: var(--primary-text);
}
.sa-progress-bar-container {
    width: 100%;
    background-color: var(--border-color);
    border-radius: 5px;
    margin: 10px 0;
    overflow: hidden;
}
.sa-progress-bar {
    width: 0%;
    height: 15px;
    background-color: var(--progress-bar);
    border-radius: 5px;
    transition: width 0.5s ease-in-out;
}
#progressText { font-size: 12px; color: var(--secondary-text); }

/* Metrics Panel */
.sa-metrics-panel { grid-area: metrics; }
.sa-metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}
.sa-metric-item {
    background-color: var(--primary-bg);
    padding: 15px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}
.sa-metric-item span { font-size: 13px; color: var(--secondary-text); margin-bottom: 5px; }
.sa-metric-item strong { font-size: 22px; color: var(--accent-color); }

/* AI Analysis Panel */
.sa-ai-panel { grid-area: aianalysis; }
.sa-ai-score-container { text-align: center; margin-bottom: 20px; }
.sa-ai-score-container h3 { margin: 0 0 10px; font-size: 16px; font-weight: normal; color: var(--secondary-text); }
.sa-score-circle {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    background: conic-gradient(var(--accent-color) 0deg, var(--border-color) 0deg);
    transition: background 1s;
}
.sa-score-circle span {
    font-size: 32px;
    font-weight: bold;
    color: var(--primary-text);
    background-color: var(--secondary-bg);
    width: 85px;
    height: 85px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}
.sa-analysis-results p { margin: 8px 0; font-size: 14px; }
.sa-analysis-results strong { color: var(--primary-text); }

/* Tabs for AI analysis */
.sa-tabs { overflow: hidden; border-bottom: 1px solid var(--border-color); margin-bottom: 15px; }
.sa-tab-link {
    background-color: inherit;
    float: left;
    border: none;
    outline: none;
    cursor: pointer;
    padding: 10px 14px;
    transition: 0.3s;
    font-size: 14px;
    color: var(--secondary-text);
}
.sa-tab-link:hover { background-color: var(--highlight-bg); }
.sa-tab-link.active { color: var(--accent-color); border-bottom: 2px solid var(--accent-color); }
.sa-tab-content { display: none; padding: 6px 0; animation: fadeEffect 0.5s; }
#keywordList { list-style-type: none; padding-left: 0; font-size: 14px; }
#keywordList li { padding: 4px 0; border-bottom: 1px solid var(--border-color); }
#keywordList li:last-child { border-bottom: none; }
@keyframes fadeEffect { from {opacity: 0;} to {opacity: 1;} }

/* Section Balance Chart */
.sa-chart-container { margin-top: 20px; }
.sa-chart-container h3 { font-size: 16px; text-align: center; margin-bottom: 10px; }
#sectionBalanceChart { display: flex; justify-content: space-around; height: 100px; border-bottom: 2px solid var(--border-color); }
.chart-bar { display: flex; flex-direction: column; justify-content: flex-end; width: 30%; text-align: center; }
.bar-fill { background-color: var(--accent-color); transition: height 0.5s ease-out; }
.bar-label { font-size: 12px; margin-top: 5px; color: var(--secondary-text); }

/* General Buttons */
.sa-button {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: background-color 0.2s;
}
.sa-button:hover { background-color: var(--accent-hover); }

/* Footer */
.sa-footer {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

/* Modal Styling */
.sa-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.6);
}
.sa-modal-content {
    background-color: var(--secondary-bg);
    margin: 10% auto;
    padding: 30px;
    border: 1px solid var(--border-color);
    width: 80%;
    max-width: 900px;
    border-radius: 8px;
    position: relative;
}
.sa-close-btn {
    color: var(--secondary-text);
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}
.sa-comparison-container { display: flex; gap: 20px; margin-bottom: 20px; }
.sa-compare-box { flex: 1; }
.sa-compare-box h3 { font-size: 16px; margin-bottom: 10px; }
.sa-compare-box textarea {
    width: 100%;
    height: 250px;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background-color: var(--primary-bg);
    color: var(--primary-text);
    font-family: inherit;
    resize: vertical;
}
#diffOutput {
    margin-top: 20px;
    padding: 15px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    max-height: 300px;
    overflow-y: auto;
}
#diffOutput ins { background-color: #d4edda; color: #155724; text-decoration: none; }
#diffOutput del { background-color: #f8d7da; color: #721c24; text-decoration: none; }

/* Responsive Design */
@media (max-width: 1200px) {
    .sa-main-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "editor editor"
            "metrics aianalysis";
    }
}
@media (max-width: 768px) {
    #scholar-analyzer-container { padding: 15px; }
    .sa-header { flex-direction: column; gap: 15px; text-align: center; }
    .sa-main-grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "editor"
            "metrics"
            "aianalysis";
    }
    .sa-metrics-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
    .sa-footer { flex-direction: column; align-items: stretch; }
    .sa-footer .sa-button { width: 100%; }
    .sa-modal-content { width: 95%; margin: 20% auto; }
    .sa-comparison-container { flex-direction: column; }
}