/* Minimal Theme Variables */
:root {
    --bg-color: #fbfbfa;
    --text-primary: #37352f;
    --text-secondary: #767676;
    --accent-orange: #d9730d;
    --accent-blue: #ebf5fa;
    --text-blue: #2383e2;
    --input-bg: #ffffff;
    --border-color: #e0e0e0;
    --btn-hover: #f5f5f5;
    --shadow-light: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08);
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 56px;
}

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

button,
input,
select,
textarea {
    font: inherit;
}

html,
body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* App Shell */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    height: 100vh;
    /* Changed from min-height: 100vh to strictly constrain to viewport */
    width: 100%;
    overflow: hidden;
    /* Ensure nothing spills out of the shell */
}


body.sidebar-collapsed .app-shell {
    grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr);
}

/* Sidebar */
.chat-sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: #f3f3f0;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease, transform 0.2s ease;
    z-index: 200;
    flex-shrink: 0;
    position: sticky;
    top: 0;
}

.chat-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 12px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-toggle,
.sidebar-new {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: #fff;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-light);
}

.sidebar-toggle:hover,
.sidebar-new:hover {
    background: var(--btn-hover);
    color: var(--text-primary);
    box-shadow: var(--shadow-hover);
}

.sidebar-toggle svg,
.sidebar-new svg {
    width: 18px;
    height: 18px;
}

.chat-sidebar.collapsed .sidebar-title,
.chat-sidebar.collapsed .chat-list {
    display: none;
}

.chat-sidebar.collapsed .sidebar-new {
    display: none;
}

.chat-sidebar.collapsed .sidebar-header {
    justify-content: center;
}

.chat-sidebar.collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

.chat-list {
    padding: 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.chat-empty {
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 12px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s ease;
}

.chat-item:hover {
    background: #ececea;
}

.chat-item.active {
    background: #e7f2fb;
    border: 1px solid #cfe4f7;
}

.chat-item-main {
    flex: 1;
    min-width: 0;
}

.chat-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.chat-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.chat-item:hover .chat-actions,
.chat-item.active .chat-actions {
    opacity: 1;
}

.chat-action-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: #fff;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.chat-action-btn:hover {
    background: var(--btn-hover);
    color: var(--text-primary);
}

.chat-action-btn svg {
    width: 14px;
    height: 14px;
}

.chat-rename-input {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 0.9rem;
    font-family: inherit;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 150;
}

body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
}

/* Top Navigation */
.top-nav {
    position: absolute;
    top: 20px;
    right: 30px;
    display: flex;
    gap: 16px;
    z-index: 100;
    align-items: center;
}

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.2s;
}

.nav-link:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

.nav-menu {
    position: relative;
    display: flex;
    align-items: center;
    margin-left: 4px;
}

.hamburger-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-direction: column;
    padding: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-light);
}

.hamburger-btn span {
    width: 16px;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 2px;
    transition: background 0.2s ease;
}

.hamburger-btn:hover {
    background: var(--btn-hover);
    box-shadow: var(--shadow-hover);
}

.hamburger-btn:hover span {
    background: var(--text-primary);
}

.nav-dropdown {
    position: absolute;
    top: 120%;
    right: 0;
    min-width: 190px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    padding: 8px 0;
    display: none;
    animation: fadeIn 0.12s ease-out;
}

.nav-dropdown.visible {
    display: block;
}

.dropdown-item {
    padding: 10px 14px;
    font-size: 0.95rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s ease;
    white-space: nowrap;
}

.dropdown-item:hover {
    background: #f7f7f5;
}

/* Main Container */
.main-container {
    width: 100%;
    /* max-width: 800px;  Removed to allow full width scrolling */
    padding: 24px 32px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 0;
    /* Important for flex/grid scrolling */
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    body.sidebar-collapsed .app-shell {
        grid-template-columns: 1fr;
    }

    .chat-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        transform: translateX(-100%);
        width: 260px;
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
    }

    body.sidebar-open .chat-sidebar {
        transform: translateX(0);
    }

    .chat-sidebar.collapsed {
        width: 260px;
    }

    .chat-sidebar.collapsed .chat-list {
        display: flex;
    }

    .chat-sidebar.collapsed .sidebar-title {
        display: block;
    }

    .chat-sidebar.collapsed .sidebar-new {
        display: inline-flex;
    }

    .chat-sidebar.collapsed .sidebar-header {
        justify-content: flex-start;
    }

    .chat-sidebar.collapsed .sidebar-toggle svg {
        transform: none;
    }
}

/* Header Area */
.header-area {
    margin-top: 24px;
    text-align: center;
    margin-bottom: 28px;
    transition: all 0.3s ease;
}

.header-area.minimized {
    margin-top: 20px;
    margin-bottom: 20px;
    transform: scale(0.8);
    display: none;
    /* Hide full header in chat mode to save space */
}

.logo-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 10px;
}

.star-icon {
    color: var(--accent-orange);
    font-size: 2rem;
    display: flex;
    align-items: center;
}

.app-title {
    font-family: "Times New Roman", Times, serif;
    font-size: 2.5rem;
    font-weight: 400;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

/* Chat History Area */
.chat-scroll-area {
    flex: 1 1 0;
    /* Force basis to 0 to ensure it shrinks properly */
    width: 100%;
    overflow-y: auto;
    margin-bottom: 20px;
    padding: 10px;
    padding-top: 24px;
    display: none;
    min-height: 0;
    /* Crucial for scrolling within flex container */
}

.chat-scroll-area.active {
    display: block;
}

.chat-content {
    width: 100%;
    max-width: 700px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

.message {
    margin-bottom: 24px;
    line-height: 1.6;
    max-width: 90%;
}

.message.user {
    margin-left: auto;
    margin-right: 20px;
    background: #f0f0f0;
    padding: 12px 16px;
    border-radius: 12px;
    border-bottom-right-radius: 2px;
    width: fit-content;
    max-width: 55%;
    /* Prevent chat bubbles from extending too far right */
}

.message.bot {
    margin-right: auto;
    padding: 0 10px;
    width: fit-content;
}

.sender-name {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.message-content {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Loading State */
.message.loading .message-content {
    color: var(--text-secondary);
    font-style: italic;
}

.message.loading .message-content::after {
    content: '';
    animation: dots 1.5s infinite;
}

@keyframes dots {

    0%,
    20% {
        content: '';
    }

    40% {
        content: '.';
    }

    60% {
        content: '..';
    }

    80%,
    100% {
        content: '...';
    }
}

/* Input Interaction Area */
.input-interaction-container {
    width: 100%;
    max-width: 700px;
    position: relative;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-light);
    transition: box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    padding: 16px;
    min-height: 120px;
    /* Give it some height like the screenshot */
}

.input-interaction-container:focus-within {
    box-shadow: var(--shadow-hover);
    border-color: #d0d0d0;
}

/* Input Field (Top Part) */
.chat-input {
    width: 100%;
    border: none;
    outline: none;
    font-size: 1.1rem;
    color: var(--text-primary);
    background: transparent;
    padding: 0;
    margin-bottom: 20px;
    font-family: inherit;
    resize: none;
}

.chat-input::placeholder {
    color: #999;
    font-weight: 400;
}

/* Controls Row (Bottom Part) */
.controls-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.left-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Square Buttons */
.square-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: #fff;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

.square-btn.active {
    border-color: var(--text-blue);
    color: var(--text-blue);
    background: var(--accent-blue);
}

.square-btn svg {
    width: 18px;
    height: 18px;
}

/* Send Button */
.send-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #e0e0e0;
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    transition: all 0.2s;
}

.send-btn.ready {
    background: var(--accent-orange);
    cursor: pointer;
}

/* Popover Menu */
.popover-menu {
    position: absolute;
    bottom: 70px;
    /* Above controls row */
    left: 16px;
    min-width: 250px;
    width: max-content;
    /* Allow it to grow to fit content */
    max-width: 600px;
    /* Cap it at a generous width */
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    padding: 6px;
    z-index: 100;
    display: none;
    animation: slideUp 0.1s ease-out;
}

.popover-menu.visible {
    display: block;
}

.menu-item {
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;

    /* Handle long text */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.menu-item:hover {
    background: #f7f7f5;
    /* On hover, let it expand if possible, or use title attribute for native tooltip */
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-overlay.visible {
    display: flex;
    opacity: 1;
}

/* Modal Container */
.modal-container {
    background: #fff;
    width: min(92vw, 640px);
    max-width: 640px;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    transform: translateY(20px);
    transition: transform 0.2s ease;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.modal-overlay.visible .modal-container {
    transform: translateY(0);
}

/* Modal Header */
.modal-header {
    padding: 22px 28px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 650;
    color: var(--text-primary);
    margin: 0;
}

.modal-close {
    width: 38px;
    height: 38px;
    background: transparent;
    border: none;
    border-radius: 8px;
    font-size: 1.6rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    position: absolute;
    top: 14px;
    right: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.modal-close:hover {
    background: var(--btn-hover);
    color: var(--text-primary);
}

/* Modal Body */
.modal-body {
    padding: 26px 28px;
    overflow-y: auto;
    max-height: min(68vh, 720px);
}

/* Modal Footer */
.modal-footer {
    padding: 16px 24px;
    background: #fafafa;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-select,
.form-input {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #d6d6d3;
    font-size: 0.95rem;
    line-height: 1.35;
    color: var(--text-primary);
    background: #fff;
    width: 100%;
    min-height: 42px;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.form-select {
    appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--text-primary) 50%),
        linear-gradient(135deg, var(--text-primary) 50%, transparent 50%);
    background-position:
        calc(100% - 18px) 50%,
        calc(100% - 12px) 50%;
    background-repeat: no-repeat;
    background-size: 6px 6px, 6px 6px;
    height: 42px;
    line-height: 42px;
    padding: 0 42px 0 12px;
}

.form-input::placeholder {
    color: #8a8a86;
    font-weight: 400;
    opacity: 1;
}

textarea.form-input {
    min-height: 76px;
}

.form-select:focus,
.form-input:focus {
    border-color: var(--text-blue);
    box-shadow: 0 0 0 3px rgba(35, 131, 226, 0.14);
    outline: none;
}

.row-group {
    display: flex;
    gap: 16px;
}

.form-group.half {
    flex: 1;
}

/* Subject Selection Row */
.subject-select-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.text-btn {
    background: none;
    border: none;
    color: var(--text-blue);
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
}

.text-btn:hover {
    text-decoration: underline;
}

.new-subject-input {
    margin-top: 8px;
    padding: 12px;
    background: #f7f7f5;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.new-subject-input.hidden {
    display: none;
}

.small-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* File Drop Area */
.file-drop-area {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #fafafa;
    color: var(--text-secondary);
}

.file-drop-area:hover,
.file-drop-area.dragover {
    border-color: var(--text-blue);
    background: var(--accent-blue);
    color: var(--text-blue);
}

.file-preview {
    margin-top: 10px;
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 500;
}

/* Buttons */
.modal-btn {
    min-height: 42px;
    padding: 0 18px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 650;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid var(--border-color);
    background: #fff;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    white-space: nowrap;
    appearance: none;
}

.modal-btn.primary {
    background: var(--text-primary);
    color: #fff;
    border-color: var(--text-primary);
}

.modal-btn.primary:hover {
    background: #2f2d28;
}

.modal-btn:hover:not(.primary):not(.danger) {
    background: var(--btn-hover);
}

.modal-btn:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

.modal-btn.danger {
    color: #dc2626;
    border-color: #fca5a5;
}

.modal-btn.danger:hover {
    background: #fef2f2;
}

.small-btn {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    border: 1px solid var(--border-color);
    background: #fff;
}

.small-btn.primary {
    background: var(--text-primary);
    color: #fff;
    border-color: var(--text-primary);
}

/* API Key Input Row */
.api-key-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.api-key-input-row .form-input {
    flex: 1;
}

.api-key-input-row .small-btn {
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.api-key-input-row .small-btn svg {
    width: 16px;
    height: 16px;
    stroke: var(--text-secondary);
}

.api-key-input-row .small-btn:hover svg {
    stroke: var(--text-primary);
}

.form-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
    line-height: 1.4;
}

/* --- Verification Results --- */

.hidden {
    display: none !important;
}

.result-summary {
    background: #f9f9f9;
    padding: 16px;
    border-radius: 12px;
    text-align: center;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.result-summary.good {
    background: #f0fff4;
    border-color: #c6f6d5;
    color: #22543d;
}

.result-summary.average {
    background: #fffaf0;
    border-color: #fbd38d;
    color: #744210;
}

.score-label {
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
    margin-bottom: 4px;
}

.score-value {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1;
}

.overall-feedback {
    margin-top: 8px;
    font-size: 0.95rem;
    opacity: 0.9;
}

.questions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.question-card {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s;
}

.question-card.correct .q-header {
    border-left: 4px solid #48bb78;
}

.question-card.incorrect .q-header {
    border-left: 4px solid #e53e3e;
}

.q-header {
    padding: 12px 16px;
    background: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}

.q-header:hover {
    background: #f9f9f9;
}

.q-status svg {
    width: 20px;
    height: 20px;
    display: block;
}

.icon-correct {
    stroke: #48bb78;
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-incorrect {
    stroke: #e53e3e;
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.q-title {
    flex: 1;
    font-weight: 500;
    font-size: 0.95rem;
}

.q-toggle svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: var(--text-secondary);
    stroke-width: 2;
    transition: transform 0.2s;
}

.question-card.expanded .q-toggle svg {
    transform: rotate(180deg);
}

.q-body {
    display: none;
    padding: 16px;
    background: #fafafa;
    border-top: 1px solid var(--border-color);
}

.question-card.expanded .q-body {
    display: block;
}

.q-section {
    margin-bottom: 12px;
}

.q-section:last-child {
    margin-bottom: 0;
}

.q-section .label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
}

.q-section .text {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-primary);
}

.q-section.feedback .text {
    color: #c53030;
    /* darker red for text */
}

.no-details {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    padding: 20px;
}

/* ==================== Question Type Controls ==================== */

.type-select-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.type-select-row .form-select {
    flex: 1;
    width: auto;
    min-width: 0;
}

.icon-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: #fff;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 500;
    transition: all 0.15s;
}

.icon-btn:hover {
    background: var(--btn-hover);
    color: var(--text-primary);
    border-color: #ccc;
}

/* ==========================================
   Markdown & LaTeX Rendering Styles
   ========================================== */

/* Paragraphs in rendered content */
.message.bot .message-content p {
    margin: 0 0 0.75em 0;
    white-space: normal;
}

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

/* Inline code */
.message.bot .message-content code {
    background: rgba(0, 0, 0, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 0.9em;
}

/* Code blocks */
.message.bot .message-content pre {
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: 8px;
    padding: 14px 16px;
    overflow-x: auto;
    font-family: 'SF Mono', 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 0.85em;
    margin: 0.75em 0;
    white-space: pre;
}

.message.bot .message-content pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

/* KaTeX display math blocks */
.message.bot .message-content .katex-display {
    margin: 1em 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 0;
}

/* Inline math sizing */
.message.bot .message-content .katex {
    font-size: 1.1em;
}

/* Math fallback (when KaTeX not loaded) */
.message.bot .message-content .math-fallback {
    background: rgba(100, 100, 200, 0.1);
    color: #666;
    font-style: italic;
}

/* Math error styling */
.message.bot .message-content .math-error {
    background: rgba(255, 100, 100, 0.15);
    color: #c00;
    border: 1px dashed #faa;
}

/* Lists */
.message.bot .message-content ul,
.message.bot .message-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.message.bot .message-content li {
    margin-bottom: 0.25em;
}

/* Blockquotes */
.message.bot .message-content blockquote {
    border-left: 3px solid #ccc;
    margin: 0.75em 0;
    padding-left: 1em;
    color: #666;
}

/* Tables */
.message.bot .message-content table {
    border-collapse: collapse;
    margin: 0.75em 0;
    width: 100%;
    font-size: 0.95em;
}

.message.bot .message-content th,
.message.bot .message-content td {
    border: 1px solid #ddd;
    padding: 8px 12px;
    text-align: left;
}

.message.bot .message-content th {
    background: #f5f5f5;
    font-weight: 600;
}

/* Strong and emphasis */
.message.bot .message-content strong {
    font-weight: 600;
}

.message.bot .message-content em {
    font-style: italic;
}

/* Links */
.message.bot .message-content a {
    color: #0066cc;
    text-decoration: none;
}

.message.bot .message-content a:hover {
    text-decoration: underline;
}

/* Horizontal rules */
.message.bot .message-content hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 1em 0;
}
