/* Custom styles for SuperBot */

/* --- Layout containment ---
   The chat view is a flex child of <main class="flex flex-grow">. Without
   `min-width: 0` flex children expand to their content's intrinsic
   min-width, which long unbroken URLs / code blocks can push past the
   viewport. min-width:0 lets them shrink, then word-break on the actual
   text containers wraps the long tokens.
*/
#chat-view, #search-view {
    min-width: 0;
}
#messages {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.turn, .turn-text, .message-text {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.message-text a, .turn-text a {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* --- Unified, minimal scrollbars site-wide --- */
* {
    scrollbar-width: thin;                       /* Firefox */
    scrollbar-color: #4a5568 transparent;        /* Firefox: thumb track */
}
*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
*::-webkit-scrollbar-track {
    background: transparent;
}
*::-webkit-scrollbar-thumb {
    background: #4a5568;
    border-radius: 4px;
    border: 2px solid transparent;               /* visual padding */
    background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
    background: #718096;
    background-clip: padding-box;
}
*::-webkit-scrollbar-corner {
    background: transparent;
}
/* #messages scrollbar styles are inherited from the site-wide rule below. */

/* Conversation item hover controls */
.conv-item .conv-controls {
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.15s ease-in-out;
}
.conv-item:hover .conv-controls {
    visibility: visible;
    opacity: 1;
}
.conv-icon {
    width: 1.25rem;
    height: 1.25rem;
}

/* Markdown Styling */
.message-text p { margin-bottom: 0.75rem; }
.message-text p:last-child { margin-bottom: 0; }
.message-text ul { list-style-type: disc; padding-left: 1.5rem; margin-bottom: 0.75rem; }
.message-text ol { list-style-type: decimal; padding-left: 1.5rem; margin-bottom: 0.75rem; }
.message-text pre { background-color: #1a202c; padding: 1rem; border-radius: 0.5rem; overflow-x: auto; margin-bottom: 0.75rem; }
.message-text code { font-family: monospace; background-color: #2d3748; padding: 0.2rem 0.4rem; border-radius: 0.25rem; font-size: 0.875em; }
.message-text pre code { background-color: transparent; padding: 0; }

/* --- Flat-block conversation styling (CLI feel) --- */
.turn {
    padding: 0.75rem 0;
}
.turn-user {
    border-left: 2px solid #3b82f6;
    background: rgba(59, 130, 246, 0.05);
    padding-left: 1rem;
    padding-right: 1rem;
    border-radius: 0 0.375rem 0.375rem 0;
}
.turn-user .turn-marker {
    color: #60a5fa;
    font-weight: 600;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}
.turn-user .turn-text {
    color: #e5e7eb;
    white-space: pre-wrap;
    word-break: break-word;
}
.turn-assistant {
    padding-left: 1rem;
    padding-right: 1rem;
}
.turn-assistant .turn-marker {
    color: #94a3b8;
    font-weight: 600;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}
.turn-assistant .message-text {
    color: #e5e7eb;
}

.turn-controls {
    opacity: 0;
    transition: opacity 0.15s ease-in-out;
}
.turn-assistant:hover .turn-controls {
    opacity: 1;
}

/* Tool block pill */
.tool-block {
    margin: 0.5rem 0;
    border: 1px solid #374151;
    border-radius: 0.375rem;
    background: #111827;
    overflow: hidden;
    font-size: 0.85em;
}
.tool-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.7rem;
    cursor: pointer;
    user-select: none;
    color: #cbd5e1;
}
.tool-header:hover { background: #1f2937; }
.tool-icon { color: #60a5fa; }
.tool-name { font-weight: 600; color: #e5e7eb; font-family: monospace; }
.tool-args { color: #94a3b8; font-family: monospace; flex-grow: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-status { font-size: 0.85em; }
.tool-status.pending { color: #fbbf24; }
.tool-status.done { color: #34d399; }
.tool-status.error { color: #f87171; }
.tool-body {
    padding: 0.6rem 0.7rem;
    border-top: 1px solid #374151;
    color: #cbd5e1;
    font-family: monospace;
    font-size: 0.85em;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 18rem;
    overflow-y: auto;
}
.tool-body.hidden { display: none; }
.tool-error { color: #fca5a5; }

/* Caret */
.tool-caret { transition: transform 0.15s ease-in-out; }
.tool-caret.open { transform: rotate(90deg); }

/* Thinking drawer */
.thinking-block {
    margin: 0.5rem 0;
    border-left: 2px solid #6b7280;
    padding-left: 0.75rem;
    color: #94a3b8;
    font-size: 0.9em;
}
.thinking-block.streaming { border-left-color: #fbbf24; }
.thinking-block.done       { border-left-color: #475569; }
.thinking-header {
    display: flex; align-items: center; gap: 0.4rem;
    cursor: pointer; user-select: none;
    color: #cbd5e1; font-size: 0.85em;
}
.thinking-header:hover { color: #e5e7eb; }
.thinking-icon { color: #fbbf24; }
.thinking-block.streaming .thinking-icon { animation: thinking-pulse 1.5s ease-in-out infinite; }
@keyframes thinking-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
.thinking-label { font-weight: 600; }
.thinking-caret { color: #64748b; transition: transform 0.15s; }
.thinking-block.collapsed .thinking-caret { transform: rotate(-90deg); }
.thinking-body {
    margin-top: 0.4rem;
    font-family: monospace;
    white-space: pre-wrap; word-break: break-word;
    font-size: 0.85em;
    color: #94a3b8;
    max-height: 16rem;
    overflow-y: auto;
}
.thinking-body.hidden { display: none; }


/* Plan card */
.plan-card {
    margin: 0.75rem 0;
    border: 1px solid #374151;
    background: #0f172a;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
}
.plan-card.accepted { border-color: #34d399; }
.plan-header {
    display: flex; align-items: center; gap: 0.4rem;
    color: #e5e7eb; font-weight: 600;
    margin-bottom: 0.5rem;
}
.plan-steps {
    list-style: none; padding: 0; margin: 0;
    counter-reset: step;
}
.plan-step {
    margin: 0.25rem 0;
}
.plan-step-title {
    cursor: pointer; user-select: none;
    color: #cbd5e1;
    padding: 0.2rem 0;
}
.plan-step-title:hover { color: #e5e7eb; }
.plan-step-marker { color: #94a3b8; margin-right: 0.4rem; }
.plan-step.active .plan-step-marker { color: #fbbf24; }
.plan-step.done .plan-step-marker { color: #34d399; }
.plan-step-desc {
    color: #94a3b8; font-size: 0.9em;
    margin: 0.25rem 0 0.5rem 1.6rem;
    white-space: pre-wrap;
}
.plan-step-desc.hidden { display: none; }
.plan-accept-btn {
    margin-top: 0.5rem;
    padding: 0.4rem 1rem;
    background: #2563eb;
    color: white; font-weight: 600;
    border-radius: 0.25rem;
    transition: background 0.15s;
}
.plan-accept-btn:hover:not(:disabled) { background: #3b82f6; }
.plan-accept-btn:disabled {
    background: #1e3a8a; opacity: 0.7; cursor: default;
}

/* Step block (the live execution area for one plan step) */
.plan-step-block {
    margin: 0.5rem 0;
    padding-left: 0.5rem;
    border-left: 2px solid #475569;
}
.plan-step-block-header {
    color: #94a3b8;
    font-size: 0.8em; font-weight: 600;
    letter-spacing: 0.05em;
    margin: 0.5rem 0 0.25rem 0;
}

/* --- Welcome card (default = small, mid-conversation empty state) --- */
.welcome-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 2rem 1rem;
    opacity: 0.6;
    user-select: none;
    pointer-events: none;
}
.welcome-emoji  { font-size: 2.5rem; margin-bottom: 0.5rem; }
.welcome-title  { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.5rem; }
.welcome-subtitle { font-size: 0.875rem; max-width: 28rem; line-height: 1.5; color: #94a3b8; }

/* --- Welcome MODE: section has no turns yet (new chat / empty state) ---
   Vertically centers the welcome card + input bar as a hero unit.
   `:has(...)` is supported in all evergreen browsers since 2023. */
section:not(:has(#messages > .turn)) {
    justify-content: center;
}
section:not(:has(#messages > .turn)) #messages {
    flex-grow: 0;
}
section:not(:has(#messages > .turn)) #messages .welcome-card {
    padding: 3rem 2rem 2rem;
    opacity: 1;
}
section:not(:has(#messages > .turn)) .welcome-emoji {
    font-size: 5rem;
    margin-bottom: 1rem;
}
section:not(:has(#messages > .turn)) .welcome-title {
    font-size: 2.25rem;
    margin-bottom: 0.75rem;
    color: #e5e7eb;
}
section:not(:has(#messages > .turn)) .welcome-subtitle {
    font-size: 1rem;
    color: #94a3b8;
}
/* In welcome mode, the input area is the hero search bar — no border-top
   line above it, so it visually belongs with the welcome above. */
section:not(:has(#messages > .turn)) > div:last-child {
    border-top: 0;
}

/* Per-thinking-block elapsed timer (right side of header) */
.thinking-elapsed {
    color: #94a3b8;
    font-family: monospace;
    font-size: 0.8em;
    margin-left: auto;
    margin-right: 0.4rem;
    font-variant-numeric: tabular-nums;
}
.thinking-block.streaming .thinking-elapsed { color: #fbbf24; }

/* Per-turn observability status line above the input form */
#metrics-line {
    color: #64748b;
    font-family: monospace;
    font-size: 0.75rem;
    padding: 0.25rem 0.25rem 0.5rem 0.25rem;
    letter-spacing: 0.02em;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
}
#metrics-line.hidden { display: none; }

/* Hide the metrics line in welcome mode (no turns yet) — there's nothing
   to report. */
section:not(:has(#messages > .turn)) #metrics-line { display: none; }

/* User-stopped indicator on a cancelled assistant turn */
.turn-stopped {
    color: #f87171;
    font-size: 0.8em;
    font-style: italic;
    margin-top: 0.5rem;
    opacity: 0.8;
    user-select: none;
}

/* --- Ask card (ask_user / ask_user_structured) --- */
.ask-card {
    margin: 0.6rem 0;
    border: 1px solid #374151;
    background: #0f172a;
    border-radius: 0.5rem;
    padding: 0.6rem 0.85rem;
}
.ask-card.answered { border-color: #34d399; opacity: 0.85; }
.ask-header {
    display: flex; align-items: flex-start; gap: 0.5rem;
    color: #e5e7eb; font-weight: 500;
    margin-bottom: 0.4rem;
}
.ask-icon { color: #60a5fa; font-size: 1.05em; line-height: 1.2; }
.ask-question { flex: 1; line-height: 1.4; }
.ask-options {
    display: flex; flex-direction: column; gap: 0.25rem;
    margin: 0.3rem 0 0.5rem 0;
}
.ask-option {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.25rem 0.4rem;
    border-radius: 0.25rem;
    cursor: pointer;
    color: #cbd5e1;
}
.ask-option:hover { background: #1e293b; color: #e5e7eb; }
.ask-card.answered .ask-option { cursor: default; }
.ask-card.answered .ask-option:hover { background: transparent; }
.ask-option input[type="radio"] {
    accent-color: #2563eb;
}
.ask-submit-btn {
    margin-top: 0.25rem;
    padding: 0.35rem 0.9rem;
    background: #2563eb;
    color: white; font-weight: 600; font-size: 0.85em;
    border-radius: 0.25rem;
    transition: background 0.15s;
}
.ask-submit-btn:hover:not(:disabled) { background: #3b82f6; }
.ask-submit-btn:disabled {
    background: #1e3a8a; opacity: 0.6; cursor: default;
}
.ask-hint {
    color: #94a3b8;
    font-size: 0.85em;
    font-style: italic;
}
.ask-status {
    margin-top: 0.4rem;
    color: #34d399;
    font-size: 0.85em;
    font-style: italic;
}

/* --- Citations (RAG source pills) --- */
.citation {
    display: inline-flex;
    align-items: baseline;
    gap: 0.05rem;
    padding: 0.05rem 0.35rem;
    margin: 0 0.1rem;
    border-radius: 0.25rem;
    background: #1e293b;
    color: #93c5fd;
    border: 1px solid #2563eb33;
    font-size: 0.8em;
    font-family: monospace;
    cursor: pointer;
    user-select: none;
    transition: background 0.1s, color 0.1s;
    line-height: 1.3;
    vertical-align: baseline;
}
.citation:hover {
    background: #2563eb;
    color: white;
    border-color: #2563eb;
}
/* Web citations get a green palette to distinguish them from RAG (blue). */
.citation-web {
    background: #14532d;
    color: #86efac;
    border-color: #16a34a33;
}
.citation-web:hover {
    background: #16a34a;
    color: white;
    border-color: #16a34a;
}
.citation sup {
    font-size: 0.75em;
    font-weight: 600;
    padding-left: 0.05rem;
}
.citation-popover-header a {
    color: inherit;
    text-decoration: underline;
}

.citation-popover {
    position: fixed;
    z-index: 1000;
    width: 28rem;
    max-width: 90vw;
    background: #0f172a;
    border: 1px solid #2563eb;
    border-radius: 0.5rem;
    padding: 0.6rem 0.8rem;
    color: #e5e7eb;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    font-size: 0.85em;
    line-height: 1.5;
}
.citation-popover-header {
    color: #60a5fa;
    font-weight: 600;
    font-size: 0.95em;
    margin-bottom: 0.4rem;
    border-bottom: 1px solid #1e293b;
    padding-bottom: 0.3rem;
}
.citation-popover-body {
    color: #cbd5e1;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 16rem;
    overflow-y: auto;
    font-family: monospace;
    font-size: 0.95em;
}

/* Brief highlight applied to the target message after a click-to-jump from
   the Search Conversations view. */
.turn-jump-flash {
    animation: turn-jump-flash 2s ease-out 1;
}

@keyframes turn-jump-flash {
    0% {
        background-color: rgba(250, 204, 21, 0.35);
        box-shadow: 0 0 0 4px rgba(250, 204, 21, 0.35);
    }
    100% {
        background-color: transparent;
        box-shadow: none;
    }
}

/* Compaction debug-message rendering (Task 14). */
.debug-message.compaction {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin: 0.5rem auto;
    padding: 0.5rem 0.75rem;
    background: rgb(31 41 55);
    border-left: 3px solid rgb(59 130 246);
    border-radius: 0.25rem;
    font-size: 0.85rem;
    color: rgb(209 213 219);
    max-width: 80%;
    font-family: ui-monospace, monospace;
}
.debug-message.compaction.compaction-pending {
    border-left-color: rgb(234 179 8);
    font-style: italic;
}
.debug-message.compaction.compaction-failed {
    border-left-color: rgb(239 68 68);
    color: rgb(252 165 165);
}
.debug-message.compaction.compaction-overflow {
    border-left-color: rgb(245 158 11);
    color: rgb(253 186 116);
}
.debug-message.compaction .debug-icon {
    margin-right: 0.25rem;
}
.compaction-expand {
    margin-left: 0.5rem;
    text-decoration: underline;
    font-size: 0.8rem;
    background: none;
    border: none;
    color: rgb(96 165 250);
    cursor: pointer;
    padding: 0;
}
.compaction-summary-text {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: rgb(17 24 39);
    border: 1px solid rgb(55 65 81);
    border-radius: 0.25rem;
    white-space: pre-wrap;
    word-break: break-word;
    color: rgb(229 231 235);
}
