/* === kCube Fine-Tune Demo — Styling === */

:root {
    --blue-dark: #0d2137;
    --blue-mid: #1a3a5c;
    --blue-light: #2c5282;
    --teal: #2b968c;
    --teal-light: #3bbfb2;
    --bg: #f0f4f8;
    --surface: #ffffff;
    --text: #1a202c;
    --text-muted: #64748b;
    --user-bubble: #1a3a5c;
    --user-text: #ffffff;
    --assistant-bubble: #ffffff;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --radius: 12px;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app {
    max-width: 1100px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* — Header — */
header {
    background: linear-gradient(135deg, var(--blue-dark), var(--blue-mid));
    color: #fff;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo {
    height: 40px;
    width: auto;
    background: #ffffff;
    padding: 4px 10px;
    border-radius: 6px;
}

.brand-text h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.brand .accent {
    color: var(--teal-light);
}

.tagline {
    font-size: 0.8rem;
    opacity: 0.75;
    margin-top: 2px;
}

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

.controls label {
    font-size: 0.8rem;
    opacity: 0.8;
}

#model-select {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
}

#model-select option {
    background: var(--blue-dark);
    color: #fff;
}

/* — Tab Bar — */
.tab-bar {
    display: flex;
    background: var(--surface);
    border-bottom: 2px solid var(--border);
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 12px 16px;
    background: none;
    border: none;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text);
    background: rgba(0, 0, 0, 0.02);
}

.tab-btn.active {
    color: var(--teal);
    border-bottom-color: var(--teal);
}

/* — Tab Content — */
.tab-content {
    display: none;
    flex: 1;
    overflow: hidden;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* — Document Bar (replaces sidebar) — */
.doc-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    font-size: 0.82rem;
    flex-shrink: 0;
}

.doc-bar span {
    color: var(--text-muted);
}

.upload-label {
    background: var(--blue-light);
    color: #fff;
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: background 0.15s;
}

.upload-label:hover {
    background: var(--blue-mid);
}

#upload-status {
    font-size: 0.78rem;
    color: var(--teal);
}

/* — Chat Area (flat, same as medical chatbot) — */
main {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

/* — Chat Messages — */
.message {
    display: flex;
    max-width: 80%;
    animation: fadeIn 0.2s ease;
}

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

.message.user {
    align-self: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.bubble {
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.55;
    font-size: 0.95rem;
    box-shadow: var(--shadow);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.user .bubble {
    background: var(--user-bubble);
    color: var(--user-text);
    border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
    background: var(--assistant-bubble);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

/* Markdown inside bubbles */
.bubble p { margin: 0.5em 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble strong { font-weight: 600; }
.bubble em { font-style: italic; }
.bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 0.88em;
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
}
.bubble pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 0.85em;
}
.bubble pre code {
    background: none;
    padding: 0;
    color: inherit;
}
.bubble ul, .bubble ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}
.bubble li { margin: 0.25em 0; }
.bubble h1, .bubble h2, .bubble h3 {
    margin: 0.6em 0 0.3em;
    font-weight: 600;
}
.bubble h1 { font-size: 1.15em; }
.bubble h2 { font-size: 1.05em; }
.bubble h3 { font-size: 1em; }

/* — Sources — */
.sources {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.source-pill {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 0.75rem;
    color: var(--blue-light);
    cursor: default;
}

.source-pill:hover {
    background: var(--border);
}

/* — Typing Indicator — */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 14px 18px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--teal);
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

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

/* — Footer / Input — */
footer {
    padding: 12px 24px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#rag-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#rag-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.45;
    resize: none;
    outline: none;
    max-height: 150px;
    overflow-y: auto;
    transition: border-color 0.15s;
}

#rag-input:focus {
    border-color: var(--teal);
}

.send-btn {
    background: var(--teal);
    color: #fff;
    border: none;
    border-radius: 10px;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}

.send-btn:hover {
    background: var(--teal-light);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.disclaimer {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 8px;
    line-height: 1.4;
}

/* — Compare Tab — */
.compare-container {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.compare-intro {
    margin-bottom: 20px;
}

.compare-intro h3 {
    font-size: 1.15rem;
    color: var(--blue-dark);
    margin-bottom: 6px;
}

.compare-intro p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.compare-live {
    margin-bottom: 24px;
}

#compare-form {
    display: flex;
    gap: 8px;
}

#compare-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

#compare-input:focus {
    border-color: var(--teal);
}

.btn-primary {
    background: var(--teal);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.btn-primary:hover {
    background: var(--teal-light);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* — Comparison Cards — */
.compare-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.compare-card-header {
    background: linear-gradient(135deg, var(--blue-dark), var(--blue-mid));
    color: #fff;
    padding: 12px 16px;
    font-size: 0.95rem;
    font-weight: 600;
}

.compare-card-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
}

.compare-column {
    padding: 16px;
}

.compare-column:first-child {
    border-right: 1px solid var(--border);
}

.compare-column h4 {
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.compare-column h4 .model-badge {
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
}

.compare-column .base-label {
    color: var(--text-muted);
}

.compare-column .ft-label {
    color: var(--teal);
}

.compare-answer {
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--text);
    white-space: pre-wrap;
}

.precomputed-section {
    margin-top: 32px;
}

.precomputed-section h3 {
    font-size: 1.05rem;
    color: var(--blue-dark);
    margin-bottom: 16px;
}

.no-results {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-style: italic;
}

/* — Loading spinner — */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--teal);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* — Error — */
.bubble.error {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #991b1b;
}

/* — Responsive — */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    .brand { justify-content: center; }
    .logo { height: 32px; }
    .message { max-width: 90%; }
    main { padding: 14px 12px; }
    footer { padding: 10px 12px 14px; }
    .compare-card-body {
        grid-template-columns: 1fr;
    }
    .compare-column:first-child {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
}
