/* Socrates Web UI - Custom Styles */

/* Base Typography */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Serif headings for academic feel */
.font-serif {
    font-family: 'Georgia', 'Times New Roman', serif;
}

/* Chat Message Styles */
.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
}

.message-student {
    background-color: #3b82f6;
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.message-socrates {
    background-color: white;
    color: #1e293b;
    margin-right: auto;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.message-timestamp {
    font-size: 10px;
    opacity: 0.7;
    margin-top: 4px;
}

/* Markdown Content Styles */
.markdown-content {
    font-size: 14px;
}

.markdown-content p {
    margin-bottom: 12px;
}

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

.markdown-content ul, .markdown-content ol {
    margin: 12px 0;
    padding-left: 24px;
}

.markdown-content li {
    margin-bottom: 4px;
}

.markdown-content code {
    background-color: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

.message-socrates .markdown-content code {
    background-color: #f1f5f9;
}

.markdown-content pre {
    background-color: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}

.markdown-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.markdown-content blockquote {
    border-left: 3px solid #3b82f6;
    padding-left: 12px;
    margin: 12px 0;
    color: #64748b;
    font-style: italic;
}

.markdown-content strong {
    font-weight: 600;
}

.markdown-content em {
    font-style: italic;
}

.markdown-content h1, .markdown-content h2, .markdown-content h3 {
    font-weight: 600;
    margin-top: 16px;
    margin-bottom: 8px;
}

.markdown-content h1 { font-size: 1.25em; }
.markdown-content h2 { font-size: 1.125em; }
.markdown-content h3 { font-size: 1em; }

/* KaTeX Math Overrides */
.katex {
    font-size: 1em !important;
}

.katex-display {
    margin: 12px 0 !important;
    overflow-x: auto;
    overflow-y: hidden;
}

/* Competency Badge Styles */
.competency-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
}

.competency-mastered {
    background-color: #dcfce7;
    color: #166534;
}

.competency-practicing {
    background-color: #fef9c3;
    color: #854d0e;
}

.competency-introduced {
    background-color: #dbeafe;
    color: #1e40af;
}

.competency-not-seen {
    background-color: #f1f5f9;
    color: #64748b;
}

/* =============================================================================
   Book Progress Section (Sidebar)
   ============================================================================= */

/* Chapter container */
.chapter-container {
    margin-bottom: 8px;
}

/* Chapter header (clickable, collapsible) */
.chapter-header {
    display: block;
    width: 100%;
    padding: 8px 0 6px 0;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    background: none;
    cursor: pointer;
    text-align: left;
    transition: background-color 0.15s ease;
}

.chapter-header:hover {
    background-color: #f8fafc;
}

.chapter-header-top {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.chapter-chevron {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: #94a3b8;
    transition: transform 0.2s ease;
}

.chapter-chevron.rotated {
    transform: rotate(90deg);
}

.chapter-title {
    font-size: 13px;
    color: #334155;
    font-weight: 600;
}

/* Chapter progress bar row */
.chapter-progress-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 20px; /* Align with title (chevron width + gap) */
}

.chapter-progress-bar {
    flex: 1;
    height: 5px;
    background-color: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
}

.chapter-progress-fill {
    height: 100%;
    background-color: #22c55e;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.chapter-progress-text {
    font-size: 11px;
    color: #64748b;
    font-weight: 500;
    min-width: 36px;
    text-align: right;
}

/* Chapter content (collapsible via accordion) */
.chapter-content {
    padding-left: 20px; /* Align with chapter title */
    margin-bottom: 4px;
}

/* Chapter content uses accordion-content for collapse/expand */
.chapter-content.accordion-content {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.2s ease-out, opacity 0.15s ease-out;
}

.chapter-content.accordion-content.expanded {
    max-height: 5000px; /* Large enough for any chapter */
    opacity: 1;
    transition: max-height 0.3s ease-in, opacity 0.2s ease-in;
}

/* Section progress bar row (inside expanded accordion) */
.section-progress-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0 8px 0;
    margin-bottom: 4px;
    border-bottom: 1px solid #f1f5f9;
}

.section-progress-bar-container {
    flex: 1;
    height: 4px;
    background-color: #e2e8f0;
    border-radius: 2px;
    overflow: hidden;
}

.section-progress-fill {
    height: 100%;
    background-color: #22c55e;
    border-radius: 2px;
    transition: width 0.3s ease;
}

.section-progress-text {
    font-size: 10px;
    color: #94a3b8;
    font-weight: 500;
    min-width: 28px;
    text-align: right;
}

/* Conversation History Items */
.history-item {
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.history-item:hover {
    background-color: #f1f5f9;
}

.history-item-question {
    color: #334155;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-date {
    color: #94a3b8;
    font-size: 10px;
}

/* Loading Animation */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 16px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: #94a3b8;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Error Message */
.error-message {
    background-color: #fef2f2;
    color: #991b1b;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid #fecaca;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    #sidebar {
        width: 100%;
        max-width: 280px;
        position: absolute;
        left: 0;
        top: 56px;
        bottom: 0;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    #sidebar.open {
        transform: translateX(0);
    }

    .message {
        max-width: 90%;
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: #94a3b8;
}

/* Focus Styles */
input:focus, textarea:focus, button:focus {
    outline: none;
}

/* Textarea Auto-resize Helper */
textarea#message-input {
    min-height: 72px;
    max-height: 240px;
    transition: height 0.1s ease;
}

/* =============================================================================
   Welcome Dashboard Styles
   ============================================================================= */

/* Dashboard Cards */
.dashboard-card {
    background-color: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.dashboard-fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.dashboard-loading {
    color: #94a3b8;
    font-size: 14px;
    padding: 8px;
}

/* Mastery Ring */
.mastery-ring {
    position: relative;
    width: 100px;
    height: 100px;
}

.mastery-ring-svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.mastery-ring-bg {
    fill: none;
    stroke: #e2e8f0;
    stroke-width: 8;
}

.mastery-ring-progress {
    fill: none;
    stroke: #22c55e;
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 283;
    transition: stroke-dashoffset 1s ease;
}

.mastery-ring-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Section Progress Cards */
.section-progress-card {
    background-color: #f8fafc;
    border-radius: 8px;
    padding: 12px 16px;
}

.progress-bar-container {
    height: 8px;
    background-color: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
}

.progress-segment {
    height: 100%;
    transition: width 0.5s ease;
}

.progress-mastered {
    background-color: #22c55e;
}

.progress-practicing {
    background-color: #eab308;
}

.progress-introduced {
    background-color: #3b82f6;
}

/* Suggestion Cards */
.suggestion-card {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
}

.suggestion-card:hover {
    background-color: #f1f5f9;
    border-color: #cbd5e1;
    transform: translateX(4px);
}

.suggestion-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background-color: #dbeafe;
    border-radius: 8px;
    color: #2563eb;
    flex-shrink: 0;
}

/* Mastery badges in suggestions */
.suggestion-mastery-badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 500;
}

.suggestion-mastery-badge.mastery-practicing {
    background-color: #fef3c7;
    color: #92400e;
}

.suggestion-mastery-badge.mastery-introduced {
    background-color: #dbeafe;
    color: #1e40af;
}

/* Quick Start Prompts */
.quick-prompt-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    background-color: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    color: #475569;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
}

.quick-prompt-btn:hover {
    background-color: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}

.quick-prompt-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #3b82f6;
    flex-shrink: 0;
}

/* History Cards */
.history-card {
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-card:hover {
    background-color: #f1f5f9;
    border-color: #cbd5e1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.history-card-timestamp {
    font-size: 11px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-card-question {
    font-weight: 500;
    color: #334155;
    font-size: 14px;
    line-height: 1.4;
}

.history-card-preview {
    font-size: 13px;
    color: #64748b;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-card-resume {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    color: #3b82f6;
    font-weight: 500;
    margin-top: 4px;
    padding: 4px 0;
}

.history-card-resume:hover {
    color: #1d4ed8;
}

/* Textbook Citation */
.textbook-citation {
    text-align: center;
    padding: 16px 24px;
    color: #94a3b8;
    font-size: 13px;
}

.textbook-citation em {
    font-style: italic;
}

/* =============================================================================
   Assessment Modal Styles
   ============================================================================= */

/* Suggestion card container for assessment button */
.suggestion-card-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Test My Understanding button */
.suggestion-assess-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    background-color: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    color: #2563eb;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.suggestion-assess-btn:hover {
    background-color: #dbeafe;
    border-color: #93c5fd;
    color: #1d4ed8;
}

/* Assessment question card */
.assessment-question-card {
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px;
}

/* Assessment icon styling */
.assessment-icon-large {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Difficulty badge colors */
.difficulty-basic {
    background-color: #dcfce7;
    color: #166534;
}

.difficulty-intermediate {
    background-color: #fef9c3;
    color: #854d0e;
}

.difficulty-advanced {
    background-color: #fee2e2;
    color: #991b1b;
}

/* =============================================================================
   Accordion Styles
   ============================================================================= */

/* Accordion header (chapter/section level) */
.accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 0;
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 500;
    color: #475569;
    transition: color 0.15s ease;
}

.accordion-header:hover {
    color: #1e293b;
}

/* Chapter-level accordion */
.accordion-chapter {
    margin-bottom: 8px;
}

.accordion-chapter-header {
    font-size: 13px;
    color: #334155;
    font-weight: 600;
    padding: 10px 0;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 4px;
}

.accordion-chapter-header:hover {
    color: #1e40af;
}

/* Section-level accordion */
.accordion-section {
    padding-left: 12px;
    margin-bottom: 4px;
}

.accordion-section-header {
    font-size: 12px;
    color: #64748b;
    font-weight: 500;
    padding: 6px 0;
}

.accordion-section-header:hover {
    color: #3b82f6;
}

/* Accordion content container */
.accordion-content {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.2s ease-out, opacity 0.15s ease-out;
}

.accordion-content.expanded {
    max-height: 2000px;
    opacity: 1;
    transition: max-height 0.3s ease-in, opacity 0.2s ease-in;
}

/* Competency items within accordion */
.accordion-competencies {
    padding-left: 16px;
    padding-top: 4px;
    padding-bottom: 4px;
}

.accordion-competency-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

/* Chevron icon styles */
.accordion-chevron {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    transition: transform 0.2s ease;
    color: #94a3b8;
}

.accordion-chevron.rotated {
    transform: rotate(180deg);
}

/* Expand/Collapse All controls */
.accordion-controls {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f1f5f9;
}

.accordion-control-link {
    font-size: 11px;
    color: #64748b;
    cursor: pointer;
    transition: color 0.15s ease;
    background: none;
    border: none;
    padding: 0;
}

.accordion-control-link:hover {
    color: #3b82f6;
    text-decoration: underline;
}

/* Section progress in accordion */
.accordion-section-progress {
    font-size: 10px;
    color: #94a3b8;
    margin-left: auto;
    padding-right: 8px;
}

/* Chapter progress */
.accordion-chapter-progress {
    font-size: 11px;
    color: #64748b;
    font-weight: normal;
    margin-left: 8px;
}

/* Print Styles */
@media print {
    header, #sidebar, form, #welcome-dashboard {
        display: none !important;
    }

    #messages-container {
        overflow: visible;
        padding: 0;
    }

    .message {
        max-width: 100%;
        page-break-inside: avoid;
    }
}
