/* Custom styles for the interpretability study interface */

/* ============== Base Styles ============== */

/* Uniform scale: every size here and in Tailwind is rem-based, so this one knob grows
   all text (and spacing) together. 112.5% = 18px on a default 16px browser. */
html {
    font-size: 112.5%;
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
}

/* ============== Token Attribution Styles ============== */

.token-attribution {
    display: inline-block;
    padding: 2px 6px;
    margin: 2px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.875rem;
}

.token-attribution:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.token-attribution[data-score] {
    /* Colors set dynamically via JS */
}

/* Attribution tooltip */
.token-tooltip {
    position: absolute;
    background: #1f2937;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    pointer-events: none;
    z-index: 100;
    white-space: nowrap;
}

.token-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1f2937;
}

/* ============== Chat Interface Styles ============== */

.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #f9fafb;
    border-radius: 8px;
    margin-bottom: 12px;
}

.chat-row {
    display: flex;
    flex-direction: column;
    margin-bottom: 12px;
}

.chat-row.user {
    align-items: flex-end;
}

.chat-row.assistant {
    align-items: flex-start;
}

.chat-message {
    padding: 10px 14px;
    border-radius: 12px;
    max-width: 85%;
    line-height: 1.55;
    animation: messageSlide 0.3s ease;
}

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

.chat-message.user {
    background: #dbeafe;
    color: #1e40af;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant {
    background: white;
    border: 1px solid #e5e7eb;
    color: #374151;
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

.chat-input-container {
    display: flex;
    gap: 8px;
}

.chat-input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.875rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input:focus {
    outline: none;
    border-color: #8b5cf6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.chat-send-btn {
    padding: 10px 16px;
    background: #8b5cf6;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.chat-send-btn:hover {
    background: #7c3aed;
}

.chat-send-btn:disabled {
    background: #c4b5fd;
    cursor: not-allowed;
}

/* ============== Survey Styles ============== */

.survey-question {
    padding: 16px 0;
    border-bottom: 1px solid #e5e7eb;
}

.survey-question:last-child {
    border-bottom: none;
}

.survey-question-text {
    font-weight: 500;
    color: #374151;
    margin-bottom: 12px;
}

/* Confidence follow-ups read as sub-questions of the item above them */
.survey-question:has(+ .survey-question.sub) {
    border-bottom: none;
    padding-bottom: 4px;
}
.survey-question.sub {
    margin-left: 1.5rem;
    padding: 6px 0 16px 1rem;
    border-left: 2px solid #e5e7eb;
}
.survey-question.sub .survey-question-text {
    font-size: 0.875rem;
    font-weight: 400;
    color: #6b7280;
    margin-bottom: 8px;
}

.survey-help-text {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 12px;
}

/* Single/Multiple choice */
.survey-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.survey-option {
    padding: 8px 16px;
    border: 2px solid #d1d5db;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
}

.survey-option:hover {
    border-color: #3b82f6;
}

.survey-option.selected {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

/* Likert scale */
.likert-scale {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.likert-label {
    font-size: 0.75rem;
    color: #6b7280;
    width: 80px;
    text-align: center;
}

.likert-label.left {
    text-align: left;
}

.likert-label.right {
    text-align: right;
}

.likert-options {
    display: flex;
    gap: 8px;
}

.likert-option {
    width: 44px;
    height: 44px;
    border: 2px solid #d1d5db;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    background: white;
}

.likert-option:hover {
    border-color: #3b82f6;
    transform: scale(1.1);
}

.likert-option.selected {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

/* Free text */
.survey-textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    resize: vertical;
    min-height: 100px;
    font-family: inherit;
    font-size: 0.875rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.survey-textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Validation */
.survey-error {
    color: #dc2626;
    font-size: 0.875rem;
    margin-top: 4px;
}

/* ============== QA Display Styles ============== */

.qa-question {
    font-size: 1rem;
    color: #374151;
    line-height: 1.7;
}

.qa-choices {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.qa-choice {
    padding: 0.85rem 1.1rem;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f9fafb;
    transition: all 0.2s;
}

.qa-choice.model-answer {
    background: #ecfdf5;
    border-color: #6ee7b7;
}

.qa-choice.model-answer::after {
    content: " (Model's Answer)";
    color: #059669;
    font-size: 0.875rem;
    font-weight: 500;
}

.model-reasoning {
    background: #f9fafb;
    padding: 16px;
    border-radius: 8px;
    color: #4b5563;
    line-height: 1.7;
    border-left: 4px solid #3b82f6;
}

/* ============== Loading States ============== */

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ============== Responsive Adjustments ============== */

@media (max-width: 1024px) {
    .chat-container {
        min-height: 60vh;
    }
}

@media (max-width: 768px) {
    .likert-scale {
        flex-direction: column;
        align-items: stretch;
    }
    
    .likert-label {
        width: 100%;
        text-align: center !important;
    }
    
    .likert-options {
        justify-content: center;
    }
}

/* J-lens hover spotlight: the hovered token goes solid indigo at every depth, the rest dim */
.jl-tok {
    transition: opacity 0.12s, background-color 0.12s, color 0.12s;
}
.jl-grid.jl-hovering .jl-tok {
    opacity: 0.25;
}
.jl-grid.jl-hovering .jl-tok.jl-hit {
    opacity: 1;
    background: #4338ca !important;
    color: #fff;
}

/* ============== Tutorial (?mode=tutorial) ============== */

body.tutorial-mode { padding-top: 2.75rem; }            /* fixed Step N of 5 bar */
body.tutorial-mode header.sticky { top: 2.75rem; }

.tut-note {
    background: #fef08a;
    border: 1px solid #facc15;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
    color: #422006;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.35;
    padding: 6px 10px;
    max-width: 40rem;
}
.tut-note.tut-inline { display: inline-block; vertical-align: top; margin-left: 0.75rem; max-width: 22rem; }

/* Notes in a right margin beside each survey item, never over the item itself */
.tut-notes-right { padding-right: 19rem !important; }   /* beats Tailwind p-6, injected later */
.tut-notes-right > * { position: relative; }
.tut-note.tut-side { position: absolute; top: 0.75rem; left: calc(100% + 1.5rem); width: 16.5rem; }
