/* ============================================
   Conference Search
   Paper, ink, and one pencil mark.
   Literata for what you read; Instrument Sans for what you operate.
   ============================================ */

:root {
    /* Color */
    --paper: #F1F2ED;          /* cool scripture-paper page */
    --sheet: #FBFBF8;          /* fields and raised surfaces */
    --ink: #1E2433;            /* blue-black body text */
    --ink-muted: #5B6273;      /* secondary text (5.6:1 on paper) */
    --binding: #1F3A5F;        /* actions, links, selected state */
    --binding-hover: #172C49;
    --rule: #D9DBD3;           /* dividers and field borders */
    --pencil: #F2D46B;         /* the only accent: marked passages */
    --error: #9E2F2B;
    --ready: #2F6B4F;

    /* Type */
    --serif: 'Literata', Georgia, 'Times New Roman', serif;
    --sans: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --step--1: 0.8125rem;      /* 13 */
    --step-0: 0.9375rem;       /* 15  UI text */
    --step-1: 1.0625rem;       /* 17  reading text */
    --step-2: 1.25rem;         /* 20 */
    --step-3: 1.625rem;        /* 26 */
    --step-4: 2.125rem;        /* 34 */
    --step-5: 2.75rem;         /* 44 */

    /* Space */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
    --space-8: 4.5rem;

    --measure: 66ch;
    --radius: 6px;

    color-scheme: light;
}

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

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--sans);
    font-size: var(--step-0);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p,
ul,
ol,
figure,
blockquote {
    margin: 0;
}

a {
    color: var(--binding);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.18em;
}

a:hover {
    color: var(--binding-hover);
}

:focus-visible {
    outline: 2px solid var(--binding);
    outline-offset: 2px;
}

button {
    font: inherit;
    color: inherit;
}

.hidden {
    display: none !important;
}

mark {
    /* A pencil underline that reaches halfway up the letters, like marking scriptures. */
    background: linear-gradient(transparent 55%, var(--pencil) 55%, var(--pencil) 92%, transparent 92%);
    color: inherit;
    padding: 0 0.05em;
}

/* ============================================
   Shared type and controls
   ============================================ */

.display {
    font-family: var(--serif);
    font-optical-sizing: auto;
    font-weight: 500;
    font-size: var(--step-5);
    line-height: 1.1;
    letter-spacing: -0.015em;
    max-width: 18ch;
    text-wrap: balance;
}

.btn-primary {
    flex: none;
    border: 1px solid var(--binding);
    border-radius: var(--radius);
    background: var(--binding);
    color: #fff;
    font-weight: 600;
    padding: 0 var(--space-5);
    min-height: 3rem;
    cursor: pointer;
}

.btn-primary:hover:not(:disabled) {
    background: var(--binding-hover);
}

.btn-primary:disabled {
    background: transparent;
    border-color: var(--rule);
    color: var(--ink-muted);
    cursor: not-allowed;
}

.btn-quiet {
    border: 0;
    background: none;
    color: var(--binding);
    padding: var(--space-1) 0;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.18em;
}

input[type="text"],
input[type="email"] {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--sheet);
    color: var(--ink);
    font: inherit;
    padding: 0 var(--space-4);
    min-height: 3rem;
}

input::placeholder {
    color: var(--ink-muted);
    opacity: 0.75;
}

input:focus {
    outline: none;
    border-color: var(--binding);
    box-shadow: 0 0 0 1px var(--binding);
}

input:disabled {
    background: transparent;
    cursor: not-allowed;
}

/* ============================================
   Page frame
   ============================================ */

.screen {
    flex: 1;
}

.site-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
    max-width: 76rem;
    margin: 0 auto;
    padding: var(--space-5) var(--space-5) 0;
}

.wordmark {
    font-family: var(--serif);
    font-weight: 600;
    font-size: var(--step-1);
}

.user-info {
    display: flex;
    align-items: baseline;
    gap: var(--space-4);
    color: var(--ink-muted);
    font-size: var(--step--1);
    min-width: 0;
}

.user-info #user-email {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.site-footer {
    max-width: 76rem;
    width: 100%;
    margin: 0 auto;
    padding: var(--space-7) var(--space-5) var(--space-5);
    color: var(--ink-muted);
    font-size: var(--step--1);
}

/* ============================================
   Sign-in screen
   ============================================ */

.login {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: var(--space-8);
    align-items: end;
    max-width: 76rem;
    margin: 0 auto;
    padding: var(--space-8) var(--space-5) 0;
}

.lede {
    margin-top: var(--space-5);
    max-width: 46ch;
    font-family: var(--serif);
    font-size: var(--step-2);
    line-height: 1.55;
    color: var(--ink-muted);
}

.login-form {
    margin-top: var(--space-6);
    max-width: 34rem;
}

.login-form label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.field-row {
    display: flex;
    gap: var(--space-2);
}

.info-text {
    margin-top: var(--space-2);
    color: var(--ink-muted);
    font-size: var(--step--1);
}

.message {
    margin-top: var(--space-4);
    max-width: 34rem;
    padding-left: var(--space-3);
    border-left: 3px solid var(--ready);
}

.message.error {
    border-left-color: var(--error);
    color: var(--error);
}

/* A real passage, shown the way results look: the memorable example */
.login-sample {
    padding-left: var(--space-5);
    border-left: 1px solid var(--rule);
}

.login-sample blockquote p {
    font-family: var(--serif);
    font-size: var(--step-4);
    line-height: 1.25;
    letter-spacing: -0.01em;
}

.login-sample figcaption {
    margin-top: var(--space-4);
    color: var(--ink-muted);
}

.login-sample cite {
    display: block;
    font-family: var(--serif);
    font-style: italic;
    font-size: var(--step-1);
    color: var(--ink);
}

.sample-note {
    margin-top: var(--space-5);
    max-width: 38ch;
    color: var(--ink-muted);
    font-size: var(--step--1);
}

/* ============================================
   Workspace: study column + question history margin
   ============================================ */

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 18rem;
    gap: var(--space-8);
    max-width: 76rem;
    margin: 0 auto;
    padding: var(--space-7) var(--space-5) 0;
}

.study {
    min-width: 0;
}

/* Mode switch */
.mode-switch {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-5);
    margin-top: var(--space-6);
    border-bottom: 1px solid var(--rule);
}

.mode-tab {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    border: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    background: none;
    color: var(--ink-muted);
    padding: var(--space-3) 0;
    cursor: pointer;
    font-weight: 500;
}

.mode-tab:hover {
    color: var(--ink);
}

.mode-tab[aria-selected="true"] {
    color: var(--ink);
    border-bottom-color: var(--binding);
}

/* Readiness: a dot; the text stays for screen readers */
.status-badge {
    flex: none;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    overflow: hidden;
    white-space: nowrap;
    text-indent: 1rem;
    background: var(--rule);
}

.status-badge.ready {
    background: var(--ready);
}

/* Panels */
.search-panel {
    padding-top: var(--space-5);
}

.panel-input {
    display: flex;
    gap: var(--space-2);
}

/* Two classes, so it outranks input[type="text"] { font: inherit } */
.panel-input .question-field {
    font-family: var(--serif);
    font-size: var(--step-2);
    min-height: 3.5rem;
}

.panel-input .btn-primary {
    min-height: 3.5rem;
}

.panel-description {
    margin-top: var(--space-2);
    color: var(--ink-muted);
    font-size: var(--step--1);
    max-width: 60ch;
}

.panel-not-ready .panel-description::after {
    content: " Not available yet on this site.";
    color: var(--error);
}

/* ============================================
   Results
   ============================================ */

.search-results {
    margin-top: var(--space-6);
}

.searching,
.no-results {
    color: var(--ink-muted);
    font-family: var(--serif);
    font-size: var(--step-1);
}

.result-error {
    color: var(--error);
    padding-left: var(--space-3);
    border-left: 3px solid var(--error);
}

/* A found passage: title, speaker, then the text. Separated by rules, not boxes. */
.result-card {
    padding: var(--space-5) 0;
    border-top: 1px solid var(--rule);
    max-width: var(--measure);
}

.result-card:first-child {
    border-top: 0;
    padding-top: 0;
}

.result-card-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-4);
}

.result-title {
    font-family: var(--serif);
    font-weight: 600;
    font-size: var(--step-1);
}

.result-title-link {
    text-decoration: none;
}

.result-title-link:hover {
    text-decoration: underline;
}

.result-speaker {
    color: var(--ink-muted);
    font-size: var(--step--1);
}

.result-sentences {
    margin-top: var(--space-3);
    font-family: var(--serif);
    font-size: var(--step-1);
    line-height: 1.65;
}

.similarity-badge {
    flex: none;
    font-family: var(--sans);
    font-size: var(--step--1);
    color: var(--ink-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.similarity-badge.similarity-high {
    color: var(--ready);
    font-weight: 600;
}

/* The written answer: set like a page you'd read, not a widget */
.rag-answer {
    padding: 0 0 var(--space-6);
    border-top: 0;
}

.rag-answer .result-title {
    font-family: var(--sans);
    font-size: var(--step--1);
    font-weight: 600;
    color: var(--ink-muted);
}

.rag-answer .result-sentences {
    margin-top: var(--space-3);
    font-size: var(--step-2);
    line-height: 1.7;
    white-space: pre-wrap;
}

.result-sources {
    max-width: var(--measure);
    padding-top: var(--space-5);
    border-top: 1px solid var(--rule);
}

.result-sources h3 {
    font-size: var(--step-0);
    font-weight: 600;
}

.source-list {
    margin-top: var(--space-3);
    padding-left: 1.5rem;
    font-family: var(--serif);
}

.source-list li {
    padding: var(--space-2) 0;
}

.source-list li::marker {
    color: var(--ink-muted);
    font-family: var(--sans);
    font-size: var(--step--1);
}

.source-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-4);
}

.source-title {
    font-size: var(--step-1);
}

.source-speaker {
    display: block;
    font-family: var(--sans);
    color: var(--ink-muted);
    font-size: var(--step--1);
}

/* ============================================
   Your questions (history)
   ============================================ */

.history {
    align-self: start;
    position: sticky;
    top: var(--space-5);
    padding-top: var(--space-2);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.history-header h2 {
    font-family: var(--serif);
    font-weight: 600;
    font-size: var(--step-2);
}

.history-count {
    color: var(--ink-muted);
    font-size: var(--step--1);
    font-variant-numeric: tabular-nums;
}

.history-note {
    margin-top: var(--space-1);
    color: var(--ink-muted);
    font-size: var(--step--1);
}

.history-list {
    list-style: none;
    margin-top: var(--space-4);
    padding: 0;
    max-height: calc(100vh - 12rem);
    overflow-y: auto;
    border-top: 1px solid var(--rule);
}

.history-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    border-bottom: 1px solid var(--rule);
}

.history-open {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    border: 0;
    background: none;
    text-align: left;
    padding: var(--space-3) 0;
    cursor: pointer;
}

.history-question {
    font-family: var(--serif);
    font-size: var(--step-0);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-open:hover .history-question {
    color: var(--binding);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.18em;
}

.history-date {
    font-size: var(--step--1);
    color: var(--ink-muted);
}

.history-delete {
    flex: none;
    border: 0;
    background: none;
    color: var(--ink-muted);
    font-size: var(--step-1);
    line-height: 1;
    padding: var(--space-3) var(--space-1);
    cursor: pointer;
}

.history-delete:hover {
    color: var(--error);
}

.history-empty {
    padding: var(--space-3) 0;
    color: var(--ink-muted);
    font-size: var(--step--1);
}

/* ============================================
   Loading bar (answers a person's action, so it moves)
   ============================================ */

.loading {
    position: fixed;
    inset: 0 0 auto 0;
    height: 3px;
    overflow: hidden;
    z-index: 100;
    background: color-mix(in srgb, var(--binding) 15%, transparent);
}

.spinner {
    height: 100%;
    width: 30%;
    background: var(--binding);
    animation: loading-slide 1.1s ease-in-out infinite;
}

@keyframes loading-slide {
    from { transform: translateX(-100%); }
    to { transform: translateX(340%); }
}

/* ============================================
   Setup notice (only on a misconfigured copy of the site)
   ============================================ */

.setup-banner {
    border-bottom: 1px solid var(--rule);
    background: var(--sheet);
}

.setup-banner-content {
    max-width: 76rem;
    margin: 0 auto;
    padding: var(--space-5);
}

.setup-banner-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.setup-banner-header h3 {
    font-family: var(--serif);
    font-size: var(--step-2);
    font-weight: 600;
}

.close-btn {
    border: 0;
    background: none;
    font-size: var(--step-3);
    line-height: 1;
    color: var(--ink-muted);
    cursor: pointer;
}

.setup-url-section {
    margin-top: var(--space-4);
}

.setup-label {
    display: block;
    font-weight: 600;
}

.url-copy-container {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: var(--space-1) 0;
}

.url-copy-container code {
    overflow-wrap: anywhere;
}

.copy-btn {
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: none;
    padding: var(--space-1) var(--space-2);
    cursor: pointer;
}

.setup-url-section small {
    color: var(--ink-muted);
}

.setup-checklist {
    margin-top: var(--space-4);
    display: grid;
    gap: var(--space-1);
}

.setup-item {
    display: flex;
    gap: var(--space-2);
}

.setup-item.error {
    color: var(--error);
}

.setup-links {
    margin-top: var(--space-4);
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-5);
}

/* ============================================
   Small screens
   ============================================ */

@media (max-width: 900px) {
    .login,
    .workspace {
        grid-template-columns: minmax(0, 1fr);
        gap: var(--space-7);
    }

    .login {
        padding-top: var(--space-7);
    }

    .history {
        position: static;
    }

    .history-list {
        max-height: none;
    }
}

@media (max-width: 600px) {
    :root {
        --step-5: 2.125rem;
        --step-4: 1.625rem;
    }

    .site-header,
    .login,
    .workspace,
    .site-footer,
    .setup-banner-content {
        padding-left: var(--space-4);
        padding-right: var(--space-4);
    }

    .field-row,
    .panel-input {
        flex-direction: column;
    }

    /* Three equal columns so every mode stays visible on one row */
    .mode-switch {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: var(--space-2);
    }

    .mode-tab {
        align-items: flex-start;
        text-align: left;
        line-height: 1.3;
        font-size: var(--step--1);
    }

    .mode-tab .status-badge {
        margin-top: 0.3em;
    }

    .rag-answer .result-sentences {
        font-size: var(--step-1);
    }

    .user-info #user-email {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation: none;
        width: 100%;
    }
}
