/* Math Problem Solver Trainer — same page chrome as AMC / General Math trainers */
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #2563eb;
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
    padding-top: 80px;
    position: relative;
    overflow-x: hidden;
}
@media (max-width: 768px) {
    body { padding-top: 120px; }
}
@media (max-width: 480px) {
    body { padding-top: 140px; }
}
.app-container { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }
.app-header {
    text-align: center;
    margin-bottom: 28px;
    padding: 20px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.app-header h1 {
    margin: 0;
    font-size: 2rem;
    letter-spacing: -0.02em;
    color: #667eea;
    font-weight: 700;
}
.app-header .subtitle { margin: 8px 0 0; font-size: 1rem; color: #666; }

.main-grid {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 20px;
    align-items: stretch;
}
@media (max-width: 900px) {
    .main-grid { grid-template-columns: 1fr; }
}

.sidebar .panel, .workspace .panel {
    background: #fff;
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.panel h3 { margin: 0 0 12px; font-size: 1rem; color: #667eea; }

.radio-row {
    display: block;
    margin: 8px 0;
    cursor: pointer;
    font-size: 14px;
}
.muted { color: #64748b; font-size: 13px; }
.hint { font-size: 13px; color: #64748b; margin: 0 0 12px; }

.btn {
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .05s, box-shadow .15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: #667eea; color: #fff; }
.btn-primary:hover { background: #5a6fd6; box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4); }
.btn-secondary { background: #6c757d; color: #fff; }
.btn-secondary:hover { background: #5a6268; }
.btn-block { width: 100%; margin-bottom: 10px; }

.file-btn input { display: none; }

/* —— Full-height chat workspace —— */
.workspace { min-height: 0; }
.chat-workspace {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 220px);
    padding-bottom: 12px;
}

.chat-messages-outer {
    position: relative;
    flex: 1;
    min-height: 280px;
    margin-bottom: 14px;
    overflow: visible;
    display: flex;
    flex-direction: column;
}
.tts-mount {
    position: absolute;
    top: 10px;
    right: 12px;
    z-index: 20;
}

.chat-messages {
    flex: 1;
    min-height: 0;
    max-height: min(55vh, 520px);
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    padding-top: 48px;
    background: #f8fafc;
}

.bubble {
    margin-bottom: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
}
.bubble.user { background: #e0e7ff; margin-left: 12px; white-space: pre-wrap; }
.bubble.assistant {
    background: #fff;
    border: 1px solid #e2e8f0;
    margin-right: 12px;
}
.bubble.assistant p { margin: 0.4em 0; }
.bubble.assistant p:first-child { margin-top: 0; }
.bubble.assistant p:last-child { margin-bottom: 0; }
.bubble.assistant ul, .bubble.assistant ol {
    margin: 0.5em 0;
    padding-left: 1.35em;
}
.bubble.assistant li { margin: 0.2em 0; }
.bubble.assistant strong, .bubble.assistant b { font-weight: 700; color: #1e293b; }
.bubble.assistant code {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.92em;
    background: #f1f5f9;
    padding: 0.1em 0.35em;
    border-radius: 4px;
}
.bubble.assistant pre {
    margin: 0.5em 0;
    padding: 10px;
    background: #f8fafc;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
}
.bubble.assistant pre code { background: none; padding: 0; }
.bubble.assistant a { color: #4338ca; word-break: break-all; }
.bubble.assistant blockquote {
    margin: 0.5em 0;
    padding-left: 12px;
    border-left: 3px solid #cbd5e1;
    color: #475569;
}
.bubble.system { background: #fef3c7; font-size: 13px; }
.bubble.error { background: #fee2e2; }

/* —— Composer (plain text for user) —— */
.composer-card {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
}

.image-drop-zone {
    padding: 10px;
    border-radius: 0;
    border: none;
    transition: background 0.15s ease;
}
.image-drop-zone.drag-over {
    background: rgba(37, 99, 235, 0.08);
    outline: 2px dashed #2563eb;
    outline-offset: -2px;
}
.image-drop-zone.images-locked .file-btn,
.image-drop-zone.images-locked #imageHint {
    display: none;
}
.image-drop-zone.images-locked .image-preview:empty {
    display: none;
}

.image-drop-zone.images-locked {
    padding-top: 4px;
}

.composer-text-wrap {
    margin-top: 8px;
}
.composer-textarea {
    width: 100%;
    min-height: 120px;
    max-height: 240px;
    padding: 12px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    resize: vertical;
}
.composer-textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.image-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 4px;
}
.image-preview .thumb {
    position: relative;
    width: 72px;
    height: 72px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
}
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.image-preview button.rm {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 4px;
    background: rgba(0,0,0,.55);
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}
.image-preview.readonly button.rm { display: none; }

.composer-bottom {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    justify-content: space-between;
}
.composer-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.saved-list {
    list-style: none;
    padding: 0;
    margin: 8px 0 0;
    max-height: 280px;
    overflow-y: auto;
}
#helpBtn { margin-top: 10px; }
.saved-list li.saved-li {
    padding: 0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    border: 1px solid transparent;
}
.saved-list li.saved-li:hover { background: #f1f5f9; }
.saved-list li.saved-li.active { border-color: #667eea; background: #eef2ff; }
.saved-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
}
.saved-item-text { flex: 1; min-width: 0; }
.saved-delete {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #94a3b8;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}
.saved-delete:hover { background: #fee2e2; color: #b91c1c; }
.saved-list .meta { font-size: 11px; color: #94a3b8; }

.has-navbar .app-container { padding-top: 8px; }

@media (max-width: 600px) {
    .composer-bottom { flex-direction: column; align-items: stretch; }
    .composer-actions { margin-left: 0; justify-content: flex-end; }
}

/* Help modal */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
    background-color: #fff;
    margin: 5% auto;
    padding: 28px 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 640px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
    position: relative;
}
.modal-help h2 {
    margin: 0 0 16px;
    font-size: 1.25rem;
    color: #667eea;
    padding-right: 36px;
}
.modal .close {
    position: absolute;
    top: 16px;
    right: 18px;
    color: #94a3b8;
    font-size: 28px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    border: none;
    background: none;
    padding: 4px 8px;
}
.modal .close:hover { color: #1e293b; }
.help-body { line-height: 1.65; font-size: 14px; color: #334155; }
.help-body h3 {
    margin: 20px 0 8px;
    font-size: 1rem;
    color: #667eea;
}
.help-body h3:first-child { margin-top: 0; }
.help-body ul { margin: 0; padding-left: 1.25em; }
.help-body li { margin: 0.35em 0; }
