/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f4f6fb;
    color: #222;
    overflow: hidden;
}

/* ── Layout: full-screen column ─────────────────────────── */
body {
    display: flex;
    flex-direction: column;
}

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .65rem 1.25rem;
    background: #0d2240;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
}
.brand-icon { font-size: 1.6rem; }
.brand-name  { font-size: .95rem; font-weight: 700; line-height: 1.2; }
.brand-sub   { font-size: .62rem; color: #90aac8; }

.topbar-center {
    flex: 1;
    text-align: center;
    font-size: .88rem;
    font-weight: 600;
    color: #c8d8f0;
    letter-spacing: .02em;
}

.topbar-actions { display: flex; gap: .5rem; }

.btn-clear {
    background: rgba(255,255,255,.1);
    border: 1px solid rgba(255,255,255,.2);
    color: #c8d8f0;
    border-radius: 6px;
    padding: .3rem .6rem;
    font-size: .82rem;
    cursor: pointer;
    transition: all .15s;
}
.btn-clear:hover { background: rgba(255,255,255,.18); color: #fff; }

/* ── Messages area ───────────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    scroll-behavior: smooth;
}

/* center messages in wide screens */
.msg {
    display: flex;
    gap: .75rem;
    align-items: flex-start;
    max-width: 760px;
    width: 100%;
    animation: fadeUp .2s ease;
}
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.msg-ai  { align-self: flex-start; }
.msg-user {
    flex-direction: row-reverse;
    align-self: flex-end;
}
.msg-user .msg-body { align-items: flex-end; }

/* Center column on wide screens */
@media (min-width: 900px) {
    .chat-messages { padding: 1.5rem calc(50% - 380px); }
    .typing-indicator { padding-left: calc(50% - 380px); padding-right: calc(50% - 380px); }
    .input-area { padding: .85rem calc(50% - 380px); }
}

/* Avatars */
.msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.1);
}
.msg-user .msg-avatar { background: #1a56db; }

/* Bubbles */
.msg-body {
    display: flex;
    flex-direction: column;
    gap: .4rem;
    min-width: 0;
}
.msg-content {
    padding: .8rem 1.05rem;
    font-size: .88rem;
    line-height: 1.7;
    word-break: break-word;
    border-radius: 4px 18px 18px 18px;
    background: #fff;
    color: #222;
    box-shadow: 0 2px 8px rgba(0,0,0,.07);
}
.msg-user .msg-content {
    background: linear-gradient(135deg, #1a56db, #1e6af0);
    color: #fff;
    border-radius: 18px 4px 18px 18px;
    box-shadow: none;
}
.msg-content p { margin: 0 0 .5rem; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content ul { margin: .3rem 0 .5rem 1.3rem; }
.msg-content li { margin-bottom: .25rem; }
.msg-hint { color: #90aac8; font-size: .8rem; font-style: italic; }

/* Confidence badge row */
.confidence-bar {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .72rem;
    padding: .2rem .4rem;
}
.confidence-badge {
    padding: .18rem .55rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: .68rem;
}
.conf-high { background: #d1fae5; color: #065f46; }
.conf-med  { background: #fef3c7; color: #92400e; }
.conf-low  { background: #fee2e2; color: #991b1b; }
.confidence-score { color: #666; }

/* Sources accordion */
.sources-toggle {
    background: none;
    border: 1px solid #dde4ef;
    border-radius: 6px;
    padding: .35rem .75rem;
    font-size: .72rem;
    color: #1a56db;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: .4rem;
    transition: all .15s;
    align-self: flex-start;
}
.sources-toggle:hover { background: #f0f4ff; }

.sources-panel {
    display: none;
    border: 1px solid #dde4ef;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}
.sources-panel.open { display: block; }

.source-card {
    padding: .7rem .85rem;
    border-bottom: 1px solid #f0f4f8;
    font-size: .76rem;
}
.source-card:last-child { border-bottom: none; }
.source-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .3rem;
}
.source-name { font-weight: 700; color: #1a2e5a; }
.source-score {
    font-size: .68rem;
    background: #eef2ff;
    color: #4338ca;
    padding: .15rem .45rem;
    border-radius: 12px;
}
.source-meta { color: #666; margin-bottom: .35rem; }
.source-excerpt { color: #555; line-height: 1.5; font-style: italic; }

/* ── Typing indicator ────────────────────────────────────── */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 0 1rem .5rem;
    flex-shrink: 0;
}
.typing-dots {
    display: flex;
    gap: .3rem;
    padding: .6rem .85rem;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.typing-dots span {
    width: 7px; height: 7px;
    background: #aab8d0;
    border-radius: 50%;
    animation: bounce .9s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .30s; }
@keyframes bounce {
    0%, 80%, 100% { transform: scale(1); opacity: .5; }
    40%            { transform: scale(1.3); opacity: 1; }
}

/* ── Input area ──────────────────────────────────────────── */
.input-area {
    padding: .85rem 1rem;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}
.input-wrapper {
    border: 2px solid #d1d9e6;
    border-radius: 14px;
    background: #fff;
    transition: border-color .2s;
    overflow: hidden;
}
.input-wrapper:focus-within { border-color: #1a56db; }
.chat-textarea {
    width: 100%;
    padding: .8rem 1rem .5rem;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: .9rem;
    line-height: 1.6;
    color: #222;
    background: transparent;
    max-height: 140px;
    overflow-y: auto;
}
.input-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .3rem .75rem .6rem;
}
.char-count { font-size: .68rem; color: #aaa; }
.btn-send {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .45rem 1.2rem;
    background: linear-gradient(135deg, #1a56db, #1e6af0);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: .82rem;
    font-weight: 700;
    cursor: pointer;
    transition: all .15s;
}
.btn-send:hover:not(:disabled) {
    background: linear-gradient(135deg, #1344b0, #1a56db);
    transform: translateY(-1px);
}
.btn-send:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.send-icon { font-size: .85rem; }

/* ── Scrollbar ───────────────────────────────────────────── */
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 600px) {
    .topbar-center { display: none; }
    .msg { max-width: 100%; }
}
