/* Seargio Chat — uses the same design tokens as search/templates/search/base.html */

:root {
    --blue:        #1a73e8;
    --blue-hover:  #1b66c9;
    --blue-press:  #1557b0;
    --blue-tint:   #e8f0fe;

    --ink:         #202124;
    --ink-2:       #3c4043;
    --ink-3:       #5f6368;
    --ink-4:       #80868b;

    --line:        #dadce0;
    --line-2:      #e8eaed;

    --surface:     #ffffff;
    --bg:          #f6f8fc;
    --hover:       #f1f3f4;

    --green:       #0b8043;
    --red:         #d93025;
    --amber:       #f9ab00;

    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 20px;
    --r-pill: 999px;

    --e1: 0 1px 2px rgba(60,64,67,.20), 0 1px 3px 1px rgba(60,64,67,.08);
    --e2: 0 1px 3px rgba(60,64,67,.22), 0 4px 8px 3px rgba(60,64,67,.10);

    --ease: cubic-bezier(.2,0,0,1);
    --col: 760px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--ink-2);
    font-family: system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-underline-offset: 2px; }
a:hover { color: var(--blue-press); }
::selection { background: var(--blue-tint); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
button { font: inherit; }

/* ------------------------------------------------------------------ top bar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 20px;
    background: rgba(255,255,255,.85);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--line-2);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: 1.45rem;
    font-weight: 500;
    letter-spacing: -.02em;
    color: var(--blue);
    text-decoration: none;
}
.brand:hover { color: var(--blue-press); }
.brand small { font-size: .8rem; color: var(--ink-4); font-weight: 400; }
.brand-tag {
    margin-left: .35rem;
    padding: .2em .65em;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--blue-press);
    background: var(--blue-tint);
    border-radius: var(--r-pill);
}

.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .45rem .9rem;
    border: 0;
    border-radius: var(--r-pill);
    background: transparent;
    color: var(--ink-3);
    font-weight: 500;
    font-size: .92rem;
    text-decoration: none;
    cursor: pointer;
    transition: background-color .15s var(--ease), color .15s var(--ease);
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn i { font-size: 1rem; }

/* ------------------------------------------------------------------ messages */

.chat-scroll {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.chat-messages {
    max-width: var(--col);
    margin: 0 auto;
    padding: 28px 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

/* welcome */
.chat-welcome { text-align: center; padding: 9vh 0 0; }
.welcome-logo {
    margin: 0 0 12px;
    font-size: 3rem;
    font-weight: 500;
    letter-spacing: -.03em;
    color: var(--blue);
}
.welcome-logo small { font-size: .4em; color: var(--ink-4); font-weight: 400; }
.welcome-lead { margin: 0 auto 32px; max-width: 480px; color: var(--ink-3); font-size: 1.02rem; }

.example-questions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    text-align: left;
}
.example-btn {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--line-2);
    border-radius: var(--r-md);
    color: var(--ink-2);
    font-size: .93rem;
    text-align: left;
    cursor: pointer;
    transition: box-shadow .18s var(--ease), border-color .18s var(--ease);
}
.example-btn:hover { box-shadow: var(--e1); border-color: transparent; color: var(--ink); }
.example-btn i { color: var(--blue); font-size: 1.05rem; flex-shrink: 0; }

/* a message */
.message { display: flex; gap: 12px; animation: rise .25s var(--ease); }
.message.user { justify-content: flex-end; }

.avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--blue-tint);
    color: var(--blue);
    font-size: .95rem;
}

.message-content { min-width: 0; flex: 1; }
.message.user .message-content { flex: 0 1 auto; max-width: 80%; }

.message.user .message-text {
    padding: 10px 16px;
    background: var(--blue-tint);
    color: var(--ink);
    border-radius: var(--r-lg) var(--r-lg) 6px var(--r-lg);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message.assistant .message-text { color: var(--ink); padding-top: 4px; word-wrap: break-word; }
.message-text > :first-child { margin-top: 0; }
.message-text > :last-child { margin-bottom: 0; }
.message-text p { margin: 0 0 .8em; }
.message-text ul, .message-text ol { margin: 0 0 .8em; padding-left: 1.4em; }
.message-text li { margin: .2em 0; }
.message-text h3, .message-text h4 { margin: 1.1em 0 .4em; font-size: 1.02rem; color: var(--ink); }
.message-text code {
    padding: .1em .35em;
    font-size: .88em;
    background: var(--hover);
    border-radius: 4px;
}
.message-text pre {
    margin: 0 0 .8em;
    padding: 12px 14px;
    overflow-x: auto;
    background: var(--hover);
    border-radius: var(--r-sm);
}
.message-text pre code { padding: 0; background: none; }

/* inline citation [1] */
.cite {
    display: inline-block;
    min-width: 1.35em;
    padding: 0 .35em;
    margin: 0 1px;
    font-size: .72em;
    font-weight: 600;
    line-height: 1.5;
    text-align: center;
    vertical-align: .2em;
    color: var(--blue-press);
    background: var(--blue-tint);
    border-radius: var(--r-pill);
    text-decoration: none;
}
a.cite:hover { background: var(--blue); color: #fff; }

.cursor {
    display: inline-block;
    width: .5em;
    height: 1.1em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: var(--blue);
    border-radius: 2px;
    animation: blink 1s steps(2, start) infinite;
}

/* "thinking" dots before the first token */
.loading-message { display: flex; gap: 5px; padding: 10px 0 2px; }
.loading-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ink-4);
    animation: pulse 1.2s infinite ease-in-out;
}
.loading-dot:nth-child(2) { animation-delay: .15s; }
.loading-dot:nth-child(3) { animation-delay: .3s; }

/* sources */
.message-sources { margin-top: 14px; }
.sources-title, .search-results-header {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-bottom: 8px;
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--ink-4);
}
.sources-list { display: flex; flex-wrap: wrap; gap: 6px; }
.source-link {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    max-width: 100%;
    padding: 5px 12px 5px 6px;
    background: var(--surface);
    border: 1px solid var(--line-2);
    border-radius: var(--r-pill);
    color: var(--ink-2);
    font-size: .82rem;
    text-decoration: none;
    transition: box-shadow .15s var(--ease), border-color .15s var(--ease);
}
.source-link:hover { box-shadow: var(--e1); border-color: transparent; color: var(--ink); }
.source-index {
    display: grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    padding: 0 4px;
    font-size: .7rem;
    font-weight: 600;
    color: var(--blue-press);
    background: var(--blue-tint);
    border-radius: var(--r-pill);
}
.source-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.source-domain { color: var(--green); white-space: nowrap; }

/* search results under an answer */
.search-results-container { margin-top: 18px; }
.search-results-list { display: flex; flex-direction: column; gap: 8px; }
.search-result-card {
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--line-2);
    border-radius: var(--r-md);
    transition: box-shadow .18s var(--ease), border-color .18s var(--ease);
    animation: rise .25s var(--ease);
}
.search-result-card:hover { box-shadow: var(--e1); border-color: transparent; }
.search-result-url { font-size: .8rem; color: var(--green); margin-bottom: 2px; word-break: break-all; }
.search-result-title {
    display: block;
    font-size: 1.02rem;
    font-weight: 500;
    line-height: 1.4;
    color: var(--blue);
    text-decoration: none;
}
.search-result-title:hover { text-decoration: underline; }
.search-result-title:visited { color: #681da8; }
.search-result-number { color: var(--ink-4); font-weight: 400; margin-right: .3em; }
.search-result-description {
    margin-top: 4px;
    font-size: .9rem;
    color: var(--ink-3);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.search-result-description mark { background: var(--blue-tint); color: var(--ink); padding: 0 .15em; border-radius: 3px; }

.show-more-container { margin-top: 10px; text-align: center; }
.show-more-btn {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .5rem 1.1rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-pill);
    color: var(--blue);
    font-weight: 500;
    font-size: .88rem;
    cursor: pointer;
    transition: background-color .15s var(--ease), border-color .15s var(--ease);
}
.show-more-btn:hover:not(:disabled) { background: var(--blue-tint); border-color: transparent; }
.show-more-btn:disabled { color: var(--ink-4); cursor: default; }

.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--line);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

.error-message {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 10px 14px;
    background: #fce8e6;
    color: #a50e0e;
    border-radius: var(--r-md);
    font-size: .9rem;
    animation: rise .25s var(--ease);
}

/* ------------------------------------------------------------------ composer */

.composer-wrap {
    padding: 8px 20px max(14px, env(safe-area-inset-bottom));
    background: linear-gradient(to bottom, rgba(246,248,252,0), var(--bg) 22px);
}

.composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: var(--col);
    margin: 0 auto;
    padding: 8px 8px 8px 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 28px;
    transition: box-shadow .18s var(--ease), border-color .18s var(--ease);
}
.composer:hover, .composer:focus-within { box-shadow: var(--e2); border-color: transparent; }

.composer-input {
    flex: 1;
    min-height: 40px;
    max-height: 180px;
    padding: 9px 0;
    border: 0;
    outline: none;
    resize: none;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: 1rem;
    line-height: 1.4;
}
.composer-input::placeholder { color: var(--ink-4); }

.send-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: var(--blue);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background-color .15s var(--ease), transform .1s var(--ease);
}
.send-btn:hover:not(:disabled) { background: var(--blue-hover); }
.send-btn:active:not(:disabled) { transform: scale(.94); }
.send-btn:disabled { background: var(--line); cursor: default; }
.send-btn .spinner { border-color: rgba(255,255,255,.4); border-top-color: #fff; }

.composer-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: var(--col);
    margin: 8px auto 0;
    padding: 0 12px;
    font-size: .76rem;
    color: var(--ink-4);
}
.composer-links { display: flex; gap: 12px; }
.composer-links a { color: var(--ink-4); text-decoration: none; }
.composer-links a:hover { color: var(--blue); text-decoration: underline; }

.status-indicator { display: inline-flex; align-items: center; gap: .4rem; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.status-dot.loading { background: var(--amber); animation: pulse 1.2s infinite ease-in-out; }
.status-dot.error { background: var(--red); }

/* ------------------------------------------------------------------ history drawer */

.history-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    width: min(360px, 88vw);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    box-shadow: var(--e2);
    transform: translateX(100%);
    transition: transform .25s var(--ease);
}
.history-sidebar.active { transform: none; }

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 12px 14px 20px;
    border-bottom: 1px solid var(--line-2);
}
.history-header h2 { margin: 0; font-size: 1.05rem; font-weight: 500; color: var(--ink); }

.history-list { flex: 1; overflow-y: auto; padding: 8px; }
.history-item {
    padding: 10px 12px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background-color .15s var(--ease);
}
.history-item:hover { background: var(--hover); }
.history-item.current { background: var(--blue-tint); }
.history-item-title { color: var(--ink); font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item-date { color: var(--ink-4); font-size: .76rem; }
.history-empty { margin: 24px 12px; color: var(--ink-4); text-align: center; font-size: .9rem; }

.overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(32,33,36,.32);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s var(--ease);
}
.overlay.active { opacity: 1; pointer-events: auto; }

/* ------------------------------------------------------------------ motion */

@keyframes rise  { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes blink { to { visibility: hidden; } }
@keyframes pulse { 0%, 80%, 100% { opacity: .35; } 40% { opacity: 1; } }
@keyframes spin  { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ------------------------------------------------------------------ small screens */

@media (max-width: 640px) {
    .topbar { padding: 8px 12px; }
    .brand { font-size: 1.25rem; }
    .icon-btn span { display: none; }
    .icon-btn { padding: .5rem .6rem; }
    .chat-messages { padding: 20px 16px; gap: 22px; }
    .welcome-logo { font-size: 2.4rem; }
    .example-questions { grid-template-columns: 1fr; }
    .message .avatar { display: none; }
    .message.user .message-content { max-width: 88%; }
    .composer-wrap { padding-left: 12px; padding-right: 12px; }
    .composer-hint { display: none; }
    .source-title { max-width: 180px; }
}
