:root {
    --purple: #4D1979;
    --purple-dark: #3A125C;
    --purple-wash: #F1EBF7;
    --paper: #FAF9F7;
    --card: #FFFFFF;
    --ink: #221C2C;
    --muted: #6E6680;
    --line: #E7E3ED;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--paper);
    color: var(--ink);
    font: 16px/1.6 "Segoe UI", system-ui, -apple-system, sans-serif;
}

.shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 780px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ---- Header ---- */
.topbar {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 4px 14px;
    border-bottom: 1px solid var(--line);
}

.wordmark {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 22px;
    letter-spacing: 0.2px;
}

.wordmark em {
    font-style: italic;
    color: var(--purple);
}

.pilot-tag {
    font-family: "Segoe UI", system-ui, sans-serif;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 2px 8px;
    margin-left: 6px;
    vertical-align: 3px;
}

.role {
    font-size: 13px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.role select {
    font: inherit;
    color: var(--ink);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 5px 8px;
}

/* ---- Messages ---- */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 4px 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.empty {
    margin: auto;
    text-align: center;
    max-width: 520px;
}

.empty-lead {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 19px;
    color: var(--ink);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 14px;
}

.chip {
    font: 14px/1.2 "Segoe UI", system-ui, sans-serif;
    color: var(--purple);
    background: var(--card);
    border: 1px solid var(--purple);
    border-radius: 999px;
    padding: 8px 14px;
    cursor: pointer;
}

.chip:hover { background: var(--purple-wash); }

.msg { display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg.bot { align-items: flex-start; }

.bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.msg.user .bubble {
    background: var(--purple);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg.bot .bubble {
    background: var(--card);
    border: 1px solid var(--line);
    border-bottom-left-radius: 4px;
}

.thinking { color: var(--muted); font-style: italic; }

/* ---- Grounded sources strip: the point of the whole product ---- */
.grounded {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 12px;
    max-width: 85%;
    margin-top: 6px;
    padding: 8px 12px;
    background: var(--purple-wash);
    border-left: 3px solid var(--purple);
    font-size: 13px;
}

.grounded-label {
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 11px;
    color: var(--purple-dark);
}

.src {
    color: var(--purple-dark);
    text-decoration: none;
    border-bottom: 1px solid transparent;
}

.src:hover { border-bottom-color: var(--purple-dark); }

/* ---- Streaming caret: the one deliberate piece of motion ---- */
.caret {
    display: inline-block;
    width: 8px;
    height: 1.05em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: var(--purple);
}

@media (prefers-reduced-motion: no-preference) {
    .caret { animation: blink 1s steps(2, start) infinite; }
    @keyframes blink { to { visibility: hidden; } }
}

/* ---- Composer ---- */
.composer {
    display: flex;
    gap: 10px;
    padding: 12px 4px 18px;
    border-top: 1px solid var(--line);
    background: var(--paper);
}

.composer input {
    flex: 1;
    font: inherit;
    color: var(--ink);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
}

.composer input:focus-visible,
.chip:focus-visible,
.ask:focus-visible,
.role select:focus-visible,
.src:focus-visible {
    outline: 2px solid var(--purple);
    outline-offset: 2px;
}

.ask {
    font: 600 15px/1 "Segoe UI", system-ui, sans-serif;
    color: #fff;
    background: var(--purple);
    border: none;
    border-radius: 12px;
    padding: 0 22px;
    cursor: pointer;
}

.ask:hover:not(:disabled) { background: var(--purple-dark); }
.ask:disabled { opacity: 0.45; cursor: default; }

@media (max-width: 560px) {
    .topbar { flex-direction: column; align-items: flex-start; gap: 8px; }
    .bubble, .grounded { max-width: 100%; }
}
