:root {
    color-scheme: light;
    --bg: #f5f6f8;
    --card: #ffffff;
    --border: #e2e4e9;
    --text: #1a1d24;
    --muted: #6b7280;
    --accent: #0049fe;
    --accent-hover: #003ecc;
    --error: #c02b3c;
    --kept: #1f8a4c;
    --dropped: #9aa0ab;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
}

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

#results-meta { margin-top: .5rem; }
.error { color: var(--error); font-size: 0.9rem; }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.spinner {
    display: inline-block;
    vertical-align: middle;
    color: var(--accent);
    animation: spin 0.8s linear infinite;
}

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

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
    margin: 1rem auto;
    max-width: 960px;
}

h1 { margin-top: 0; }
h2 { margin-top: 0; font-size: 1.1rem; }

label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    margin: 0.75rem 0 0.25rem;
}

input, textarea, select {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
}

input[readonly] { background: var(--bg); cursor: text; }
input[aria-invalid="true"] { border-color: var(--error); }
.field-hint, .field-error { margin: 0.3rem 0 0; font-size: 0.8rem; }

.copy-field { display: flex; gap: 0.5rem; }
.copy-field input { flex: 1; min-width: 0; }
.copy-btn { margin-top: 0; flex-shrink: 0; }
.created-back { margin: 0.75rem 0 0; }
.created-back a { color: var(--accent); }

.link-btn {
    margin: 0;
    font-size: 1rem;
    background: none;
    color: var(--accent);
    text-decoration: none;
    padding: .6rem 1rem;
    border-radius: 6px;
}

button {
    margin-top: 1.25rem;
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
}

.link-btn:hover,button:hover { background: var(--accent-hover); color: white; }
.link-btn:hover { background: var(--accent); color: white; }
button:disabled { opacity: 0.6; cursor: default; }


.auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-inline: 1rem;
}

.auth-card { width: 100%; max-width: 380px; }

.topbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding: .6rem 1.5rem;
    background: #eef1ff;
    box-shadow: 0px 0px 4px 1px var(--accent);
}

.logo-link { display: inline-flex; align-items: center; }
.logo { height: 28px; width: auto; display: block; }

.brand { font-weight: 700; color: inherit; text-decoration: none; }
.topbar .muted { flex: 1; }

.layout { padding-inline: 1rem; padding-block: 1rem; }

.field { margin-bottom: 0.5rem; }

.provider-toggle {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.25rem;
}

.provider-btn {
    flex: 1;
    margin-top: 0;
    padding: 0.85rem 1rem;
    background: var(--card);
    color: var(--text);
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
}

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

.provider-btn.active {
    background: #eef1ff;
    border-color: var(--accent);
    color: var(--accent);
}

/* "Use 3 LLMs" checked: every button gets the same highlight a plain
   button shows on hover, so all three read as selected. */
.provider-toggle.all-selected .provider-btn {
    background: var(--accent-hover);
    border-color: var(--accent);
    color: #fff;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin: 1.5rem 0 0;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
}

/* Custom checkbox: accent-bordered rounded box; when checked, a smaller
   rounded square fills its centre (no tick mark). */
.checkbox-label input {
    appearance: none;
    -webkit-appearance: none;
    display: inline-grid;
    place-content: center;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin: 0;
    padding: 0;
    border: 1px solid var(--accent);
    border-radius: 5px;
    background: var(--card);
    cursor: pointer;
}

.checkbox-label input::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: var(--accent);
    transform: scale(0);
    transition: transform 0.12s ease-in-out;
}

.checkbox-label input:checked::before { transform: scale(1); }

.checkbox-label input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* "Seed keyword + persona" / "Own prompt" switch above the form fields. */
.input-mode-toggle { margin: 0 0 0.25rem; }

/* Own-prompt results/history use the (usually long) first prompt as the
   headline, so it's set smaller than a seed keyword. */
.query-summary .seed-keyword-hero.prompt-hero { font-size: 1.3rem; }

/* One section per provider when a query ran on several LLMs. */
.provider-sections { display: flex; flex-direction: column; gap: 1.75rem; margin-top: 0.75rem; }
.provider-section h3 { margin: 0; font-size: 1rem; color: var(--accent); }
.provider-section .muted { margin: 0.25rem 0 0; }
.provider-section .error { margin: 0.5rem 0 0; }
.history-item .provider-sections { padding-bottom: 0.75rem; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; margin-top: 0.75rem; font-size: 0.9rem; }

th, td {
    text-align: left;
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }

.question-blocks { display: flex; flex-direction: column; gap: 1rem; margin-top: 0.75rem; }

.question-block {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
}

.question-block.dropped { background: #fafbfc; }

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.question-header .question-text { font-weight: 600; }
.question-block.dropped .question-text { font-weight: 500; color: var(--dropped); }
.question-header .badge { flex-shrink: 0; white-space: nowrap; }

.question-block .table-wrap { margin-top: 0.75rem; }
.question-block table { margin-top: 0; }

.dropped-note { margin: 0.5rem 0 0; }

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    background: #e8ecff;
    color: var(--accent);
}

.badge.kept { background: #e5f6ec; color: var(--kept); }
.badge.dropped { background: #eee; color: var(--dropped); }

.results-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }

.header-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.4rem;
    flex-shrink: 0;
}

.header-actions .link-btn { padding: 0.3rem 0.6rem; font-size: 0.85rem; }

.download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.header-actions .download-btn { padding: 0.4rem; }

.download-btn svg { display: block; }

.query-summary { font-size: 0.9rem; margin: 0 0 0.75rem; }
.query-summary div { margin-bottom: 0.15rem; }
.query-summary strong { font-weight: 600; }

.query-summary .seed-keyword-hero {
    font-size: 2rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 1rem;
}

.history-list { display: flex; flex-direction: column; gap: 0.4rem; }

.history-item { border-bottom: 1px solid var(--border); }

.history-item summary {
    padding: 0.6rem 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 6px;
}

.history-item summary .history-summary-text div { margin-bottom: 0.1rem; }

.history-summary-text .seed-keyword-hero {
    font-size: 1.4rem;
    color: var(--accent);
    font-weight: 600;
}

.history-item summary:hover { background: #f2f4f9; }

/* Distinct background per opened item, so with several expanded at once
   it's clear where one ends and the next begins. */
.history-item[open] {
    background: #f7f8fc;
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    margin-bottom: 0.4rem;
}

.history-item[open] summary {
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.history-item[open] > *:not(summary) {
    padding: 0 0.75rem 0.75rem;
}

.history-item .table-wrap { padding-bottom: 0.75rem; }

/* Date + download button of a history entry. The real one is laid over the
   summary's right edge (outside <summary>, see loadHistory in app.js); an
   invisible copy inside <summary> keeps the layout identical. Clicks pass
   through the overlay to the summary except on the button itself. */
.history-entry { position: relative; }

.history-actions-placeholder { visibility: hidden; }

.history-actions {
    position: absolute;
    top: 0.6rem;
    right: 0.75rem;
    font-size: 0.9rem;
    pointer-events: none;
}

.history-actions .history-download-btn { pointer-events: auto; }

/* An open item gains a 1px border (3px on the left), shifting the summary;
   follow it, and match the summary's bold text. */
.history-entry:has(.history-item[open]) .history-actions {
    top: calc(0.6rem + 1px);
    right: calc(0.75rem + 1px);
    font-weight: 600;
}

/* All providers failed: one message per provider, one per line. */
#research-error { white-space: pre-line; }
