/* search.css — Search results, clarification, and error page styles */

/* ---- Search Results Page ---- */

.search-results-page {
    padding: var(--space-lg) var(--space-md);
}

.search-results-container {
    max-width: 960px;
    margin: 0 auto;
}

.search-results-header {
    margin-bottom: var(--space-lg);
}

.back-to-search {
    display: inline-block;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin-bottom: var(--space-sm);
}

.back-to-search:hover {
    color: var(--color-accent);
    text-decoration: none;
}

.results-query {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.4;
}

/* ---- Answer Panel ---- */

.search-answer {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-lg);
}

.answer-meta {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
}

.answer-provider,
.answer-model {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    background-color: var(--color-bg);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
}

/* Answer bodies hold rendered markdown (.md-content) — never use
   white-space: pre-wrap here, or the newlines between generated HTML
   tags render as phantom blank lines. */
.answer-content {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--color-text);
}

.answer-reasoning {
    margin-top: var(--space-lg);
    border-top: 1px solid var(--color-border);
    padding-top: var(--space-md);
}

.answer-reasoning summary {
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-muted);
    padding: var(--space-xs) 0;
}

.answer-reasoning summary:hover {
    color: var(--color-accent);
}

.reasoning-content {
    margin-top: var(--space-sm);
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--color-text-muted);
    padding: var(--space-sm);
    background-color: var(--color-bg);
    border-radius: var(--radius-sm);
}

/* ---- Sources Section (collapsed, inside the answer card) ---- */

.search-sources {
    margin-top: var(--space-md);
    border-top: 1px solid var(--color-border);
    padding-top: var(--space-md);
}

.sources-heading {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: var(--space-xs) 0;
    user-select: none;
}

.sources-heading:hover {
    color: var(--color-accent);
}

.search-sources[open] > .sources-heading {
    margin-bottom: var(--space-sm);
}

.sources-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.source-item {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
}

.source-link {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-accent);
    text-decoration: none;
    margin-bottom: var(--space-xs);
}

.source-link:hover {
    text-decoration: underline;
}

.source-snippet {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--color-text-muted);
    margin-bottom: var(--space-xs);
}

.source-url {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    word-break: break-all;
}

/* ---- Collapsed conversation history ----
   Earlier exchanges in the session, shown above the newest answer.
   Each exchange is a native <details> with the truncated question as
   its summary; opening it reveals the full question and answer. */

.conversation-history {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.conversation-history-heading {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.history-exchange {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.history-question {
    cursor: pointer;
    padding: var(--space-sm) var(--space-md);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--color-text-muted);
    user-select: none;
    overflow-wrap: anywhere;
}

.history-question:hover {
    color: var(--color-accent);
}

.history-exchange[open] > .history-question {
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
}

.history-body {
    padding: var(--space-md);
}

.history-full-question {
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-md);
    overflow-wrap: anywhere;
}

.history-answer {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--color-text);
}

.history-model {
    display: inline-block;
    margin-top: var(--space-md);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    background-color: var(--color-bg);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
}

/* The current answer card moved into history by search-stream.js
   keeps its own card chrome; flatten it inside the exchange body. */
.history-body > .search-answer {
    border: none;
    box-shadow: none;
    padding: 0;
    margin-bottom: 0;
}

/* ---- Conversation actions (below the answer) ---- */

.conversation-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

/* ---- Follow-up Form ----
   (the .followup-form composer itself is styled in components.css) */

.search-followup {
    margin-top: var(--space-lg);
}

/* ---- Error Panel ---- */

.search-error-panel {
    background-color: var(--color-surface);
    border: 1px solid var(--color-danger);
    border-left: 4px solid var(--color-danger);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
}

.error-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-danger);
    margin-bottom: var(--space-sm);
}

.error-message {
    color: var(--color-text);
    line-height: 1.6;
}

.search-error-actions {
    text-align: center;
}

/* ---- Clarification Page ---- */

.clarification-page {
    padding: var(--space-lg) var(--space-md);
}

.clarification-container {
    max-width: 640px;
    margin: 0 auto;
}

.clarification-header {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.clarification-query {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-sm);
    line-height: 1.4;
}

.clarification-prompt {
    color: var(--color-text-muted);
    font-size: 1rem;
}

.clarification-options {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.clarification-option-form {
    margin: 0;
}

.clarification-option-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: var(--space-md) var(--space-lg);
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 1rem;
    text-align: left;
    color: var(--color-text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.clarification-option-btn:hover {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-sm);
}

.option-label {
    font-weight: 500;
}

.option-arrow {
    color: var(--color-accent);
    font-size: 1.2rem;
}

/* "Other" — a native disclosure that reveals a free-text clarification. */
.clarification-other {
    margin: 0;
}

.clarification-other-summary {
    /* Reuses .clarification-option-btn styling; strip the native marker. */
    list-style: none;
    user-select: none;
}

.clarification-other-summary::-webkit-details-marker {
    display: none;
}

.clarification-other[open] .clarification-other-summary {
    border-color: var(--color-accent);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.clarification-other[open] .clarification-other-summary .option-arrow {
    transform: rotate(45deg);
}

.clarification-other-summary .option-arrow {
    display: inline-block;
    transition: transform 0.15s ease;
}

.clarification-other-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background-color: var(--color-surface);
    border: 1px solid var(--color-accent);
    border-top: none;
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
}

.clarification-other-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.clarification-other-label {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.clarification-other-input {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.5;
    resize: none;
    overflow-y: hidden;
}

.clarification-other-input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: var(--shadow-sm);
}

.clarification-other-submit {
    align-self: flex-end;
    padding: var(--space-sm) var(--space-lg);
    background-color: var(--color-accent);
    border: 1px solid var(--color-accent);
    border-radius: var(--radius-md);
    color: #fff;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.clarification-other-submit:hover {
    opacity: 0.9;
}

.clarification-footer {
    text-align: center;
    margin-top: var(--space-xl);
}

.refine-link {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.refine-link:hover {
    color: var(--color-accent);
    text-decoration: none;
}

/* ---- Search Error Page ---- */

.search-error-page {
    padding: var(--space-lg) var(--space-md);
}

.search-error-container {
    max-width: 640px;
    margin: 0 auto;
}

.search-error-header {
    margin-bottom: var(--space-lg);
}

.error-query {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--color-text);
}

/* ---- Live streaming search view ----
   Built by static/js/search-stream.js while a search is in flight:
   a progress timeline fed by server events, then the streaming answer. */

.search-live {
    padding: var(--space-lg) var(--space-md);
}

.search-live-container {
    max-width: 960px;
    margin: 0 auto;
}

.search-live-progress {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-lg);
}

.progress-steps {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.progress-step {
    position: relative;
    padding-left: 1.6rem;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--color-text-muted);
}

.progress-step::before {
    position: absolute;
    left: 0;
    top: 0;
}

.progress-step.is-done {
    color: var(--color-text-muted);
}

.progress-step.is-done::before {
    content: "✓";
    color: var(--color-success);
}

.progress-step.is-active {
    color: var(--color-text);
    font-weight: 500;
}

.progress-step.is-active::before {
    content: "";
    width: 0.85rem;
    height: 0.85rem;
    margin-top: 0.28rem;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: progress-step-spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .progress-step.is-active::before {
        animation-duration: 2s;
    }
}

.progress-step.is-failed::before {
    content: "✕";
    color: var(--color-danger);
}

.progress-source-list {
    list-style: none;
    padding: var(--space-xs) 0 0 0;
    margin: 0;
}

.progress-source {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.progress-source::before {
    content: "· ";
}

.search-live-elapsed {
    margin-top: var(--space-sm);
    color: var(--color-text-muted);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

/* Streamed output arrives as plain text, so pre-wrap is correct here
   (unlike .answer-content, which holds rendered markdown). */
.search-live-answer {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-lg);
}

.live-answer-text {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--color-text);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.live-answer-text:not(:empty)::after {
    content: "▍";
    color: var(--color-accent);
    animation: live-cursor-blink 1s steps(2) infinite;
}

@keyframes live-cursor-blink {
    50% { opacity: 0; }
}

.live-reasoning {
    margin-top: 0;
    margin-bottom: var(--space-md);
    border-top: none;
    padding-top: 0;
}

.live-reasoning-text {
    margin-top: var(--space-sm);
    font-size: 0.85rem;
    line-height: 1.6;
    font-family: var(--font-sans);
    color: var(--color-text-muted);
    padding: var(--space-sm);
    background-color: var(--color-bg);
    border-radius: var(--radius-sm);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* ---- Responsive ---- */

@media (max-width: 768px) {
    .results-query {
        font-size: 1.2rem;
    }

    .clarification-query {
        font-size: 1.2rem;
    }

    .search-answer {
        padding: var(--space-md);
    }
}

/* ---- Recent sessions on the home page ---- */

.recent-sessions {
    margin-top: var(--space-xl);
    text-align: left;
}

.recent-sessions-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: var(--space-sm);
}

.recent-sessions-heading {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.recent-sessions-all {
    font-size: 0.85rem;
}

.recent-sessions-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.recent-session-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background-color: var(--color-surface);
    color: var(--color-text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.recent-session-link:hover {
    text-decoration: none;
    border-color: var(--color-accent);
    box-shadow: var(--shadow-sm);
}

.recent-session-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recent-session-date {
    flex-shrink: 0;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ */
/* Composer action buttons (hamburger, paperclip) and private badge   */
/* ------------------------------------------------------------------ */

.composer-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.composer-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.composer-icon-btn:hover {
    color: var(--color-accent);
    border-color: var(--color-accent);
}

.composer-icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    color: var(--color-text-muted);
    border-color: var(--color-border);
}

.composer-private-badge {
    padding: 0.15rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--color-accent);
    background: var(--color-accent-soft);
    border: 1px solid var(--color-accent);
    border-radius: 999px;
    white-space: nowrap;
}

/* ------------------------------------------------------------------ */
/* Inline file-attach control (hidden input + chosen-file list)       */
/* ------------------------------------------------------------------ */

.search-attach {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.search-attach:not(.has-files) {
    display: none;
}

.search-attach-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
}

/* "Sign in to attach files" / private-session notice shown when files
   are dropped or pasted into a composer that can't accept them. */
.search-attach-notice {
    display: none;
    margin: 0;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.search-attach-notice.is-visible {
    display: block;
}

.followup-private-note {
    margin-top: 0.4rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    text-align: center;
}

/* ------------------------------------------------------------------ */
/* Composer settings modal                                            */
/* ------------------------------------------------------------------ */

.composer-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    background: rgba(0, 0, 0, 0.45);
}

.composer-modal[hidden] {
    display: none;
}

.composer-modal-dialog {
    width: 100%;
    max-width: 26rem;
    max-height: 85vh;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    text-align: left;
}

.composer-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--color-border);
}

.composer-modal-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.composer-modal-close {
    border: none;
    background: none;
    font-size: 1.4rem;
    line-height: 1;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0 0.25rem;
}

.composer-modal-close:hover {
    color: var(--color-accent);
}

.composer-modal-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-md);
}

.composer-modal-footer {
    display: flex;
    justify-content: flex-end;
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid var(--color-border);
}

.composer-setting {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.composer-setting-label {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
}

.composer-setting-hint {
    font-size: 0.78rem;
    font-weight: 400;
    color: var(--color-text-muted);
    line-height: 1.4;
}

.composer-setting-toggle {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
}

.composer-setting-toggle .composer-setting-label {
    flex: 1;
}

/* ------------------------------------------------------------------ */
/* Guest daily-limit modal (create a free account)                    */
/* Reuses the composer-modal shell; markup in guest_limit_modal.html. */
/* ------------------------------------------------------------------ */

.guest-limit-modal .composer-modal-dialog {
    max-width: 24rem;
}

.guest-limit-message {
    font-size: 0.92rem;
    line-height: 1.5;
    color: var(--color-text);
}

.guest-limit-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.guest-limit-signin {
    font-size: 0.85rem;
    text-align: center;
    color: var(--color-text-muted);
}

/* ---- On/off slider switch ---- */

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 2.75rem;
    height: 1.5rem;
    flex-shrink: 0;
}

.toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--color-border);
    border-radius: 999px;
    transition: background 0.15s ease;
    pointer-events: none;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    top: 0.15rem;
    left: 0.15rem;
    width: 1.2rem;
    height: 1.2rem;
    background: var(--color-surface);
    border-radius: 50%;
    transition: transform 0.15s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--color-accent);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(1.25rem);
}

.toggle-switch input:focus-visible + .toggle-slider {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.search-attach-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.search-attach-item {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    max-width: 28rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

.search-attach-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-attach-remove {
    flex-shrink: 0;
    border: none;
    background: none;
    color: var(--color-text-muted);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.2rem;
}

.search-attach-remove:hover {
    color: var(--color-accent);
}
