/* =============================================================================
   chat.css — complete stylesheet for the Aviary platform
   Design: dark theme, purple/blue accent palette
   ============================================================================= */

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

:root {
    --bg-base:        #0f172a;
    --bg-surface:     #1e293b;
    --bg-elevated:    #273549;
    --bg-input:       #1a2535;
    --border:         #334155;
    --border-subtle:  #1e293b;

    --text-primary:   #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted:     #64748b;

    --accent:         #6366f1;
    --accent-hover:   #818cf8;
    --accent-dim:     #312e81;
    --purple:         #a855f7;
    --green:          #22c55e;
    --red:            #ef4444;
    --yellow:         #eab308;

    --avatar-bot:     #6366f1;
    --avatar-user:    #0ea5e9;

    --radius-sm:  4px;
    --radius-md:  8px;
    --radius-lg:  12px;
    --radius-xl:  16px;

    --font-sans: system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
}

html, body { height: 100%; }

body {
    font-family:      var(--font-sans);
    background-color: var(--bg-base);
    color:            var(--text-primary);
    font-size:        15px;
    line-height:      1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-hover); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Site header ───────────────────────────────────────────────────────────── */
.site-header {
    position:         sticky;
    top:              0;
    z-index:          100;
    background:       var(--bg-surface);
    border-bottom:    1px solid var(--border);
    height:           56px;
}
.header-inner {
    max-width:        1400px;
    margin:           0 auto;
    padding:          0 1.5rem;
    height:           100%;
    display:          flex;
    align-items:      center;
    gap:              1.5rem;
}
.site-logo {
    display:          flex;
    align-items:      center;
    gap:              0.4rem;
    font-weight:      700;
    font-size:        1.1rem;
    color:            var(--text-primary);
    text-decoration:  none;
}
.logo-mark { font-size: 1.3rem; color: var(--accent); }
.header-nav { display: flex; gap: 0.25rem; flex: 1; }
.nav-link {
    padding:          0.35rem 0.75rem;
    border-radius:    var(--radius-sm);
    color:            var(--text-secondary);
    font-size:        0.875rem;
    transition:       background 0.15s, color 0.15s;
}
.nav-link:hover     { background: var(--bg-elevated); color: var(--text-primary); text-decoration: none; }
.nav-bot            { color: var(--accent-hover); }
.header-auth        { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; }
.header-username    { font-size: 0.875rem; color: var(--text-secondary); }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary, .btn-ghost {
    display:         inline-flex;
    align-items:     center;
    padding:         0.35rem 0.9rem;
    border-radius:   var(--radius-sm);
    font-size:       0.875rem;
    font-weight:     500;
    cursor:          pointer;
    border:          1px solid transparent;
    transition:      all 0.15s;
}
.btn-primary {
    background:  var(--accent);
    color:       #fff;
}
.btn-primary:hover  { background: var(--accent-hover); text-decoration: none; }
.btn-ghost {
    background:  transparent;
    color:       var(--text-secondary);
    border-color: var(--border);
}
.btn-ghost:hover    { background: var(--bg-elevated); color: var(--text-primary); text-decoration: none; }

/* ── Main layout ───────────────────────────────────────────────────────────── */
.page-main {
    height:          calc(100vh - 56px);
    overflow:        hidden;
}
#chat-root {
    height:          100%;
}
.chat-app {
    height:          100%;
    display:         flex;
    flex-direction:  column;
}
.chat-layout {
    flex:            1;
    display:         flex;
    overflow:        hidden;
}
.chat-main {
    flex:            1;
    display:         flex;
    flex-direction:  column;
    overflow:        hidden;
    min-width:       0;
}

/* ── Connection banners ────────────────────────────────────────────────────── */
.connection-banner {
    padding:         0.5rem 1rem;
    font-size:       0.8rem;
    text-align:      center;
}
.connection-banner.connecting { background: var(--accent-dim); color: var(--accent-hover); }
.connection-banner.error      { background: #450a0a;            color: var(--red); }

/* ── Message list ──────────────────────────────────────────────────────────── */
.message-list {
    flex:            1;
    overflow-y:      auto;
    padding:         1rem;
    display:         flex;
    flex-direction:  column;
    gap:             0.75rem;
    scroll-behavior: smooth;
}
.message-list::-webkit-scrollbar        { width: 6px; }
.message-list::-webkit-scrollbar-track  { background: transparent; }
.message-list::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 3px; }

.load-more-spinner, .history-end {
    text-align:      center;
    font-size:       0.8rem;
    color:           var(--text-muted);
    padding:         0.5rem;
}

/* ── Message row ───────────────────────────────────────────────────────────── */
.message-row {
    display:         flex;
    gap:             0.75rem;
    align-items:     flex-start;
}
.message-avatar   { flex-shrink: 0; padding-top: 2px; }
.avatar-circle {
    width:           36px;
    height:          36px;
    border-radius:   50%;
    display:         flex;
    align-items:     center;
    justify-content: center;
    font-weight:     700;
    font-size:       0.9rem;
    color:           #fff;
}
.avatar-bot  { background: var(--avatar-bot); }
.avatar-user { background: var(--avatar-user); }

.message-bubble-wrap { flex: 1; min-width: 0; }

.message-meta {
    display:         flex;
    align-items:     baseline;
    gap:             0.5rem;
    margin-bottom:   0.25rem;
}
.message-author {
    font-weight:     600;
    font-size:       0.9rem;
}
.author-bot   { color: var(--accent-hover); }
.message-time { font-size: 0.75rem; color: var(--text-muted); }

/* Reply preview */
.reply-preview {
    display:         flex;
    flex-direction:  column;
    background:      var(--bg-elevated);
    border-left:     3px solid var(--accent);
    border-radius:   var(--radius-sm);
    padding:         0.35rem 0.6rem;
    margin-bottom:   0.4rem;
    gap:             0.1rem;
}
.reply-label   { font-size: 0.75rem; color: var(--accent-hover); font-weight: 600; }
.reply-snippet { font-size: 0.8rem;  color: var(--text-muted); }

/* Message content */
.message-content {
    font-size:       0.925rem;
    line-height:     1.55;
    color:           var(--text-primary);
    word-break:      break-word;
}

/* @mention chips */
.mention-chip {
    display:         inline;
    color:           var(--accent-hover);
    font-weight:     600;
    background:      rgba(99,102,241,0.12);
    border-radius:   var(--radius-sm);
    padding:         0 3px;
}

/* Action bar */
.message-actions {
    display:         flex;
    gap:             0.4rem;
    margin-top:      0.35rem;
    opacity:         0;
    transition:      opacity 0.15s;
}
.message-row:hover .message-actions { opacity: 1; }

.reaction-btn, .reply-btn {
    background:      transparent;
    border:          1px solid transparent;
    border-radius:   var(--radius-sm);
    padding:         2px 6px;
    font-size:       0.8rem;
    cursor:          pointer;
    color:           var(--text-muted);
    display:         inline-flex;
    align-items:     center;
    gap:             3px;
    transition:      all 0.15s;
}
.reaction-btn:hover:not(:disabled), .reply-btn:hover {
    background:  var(--bg-elevated);
    color:       var(--text-primary);
    border-color: var(--border);
}
.reaction-btn.reacted    { color: var(--red); border-color: var(--red); }
.reaction-btn:disabled   { cursor: default; opacity: 0.4; }
.reaction-count          { font-size: 0.75rem; }

/* ── Typing banner ─────────────────────────────────────────────────────────── */
.typing-banner {
    min-height:      24px;
    padding:         0 1rem;
}
.typing-banner-inner {
    display:         inline-flex;
    align-items:     center;
    gap:             3px;
    font-size:       0.8rem;
    color:           var(--text-muted);
}
.typing-banner-text { margin-left: 4px; }

/* Animated dots */
.typing-dot {
    width:           5px;
    height:          5px;
    border-radius:   50%;
    background:      var(--text-muted);
    display:         inline-block;
    animation:       typing-bounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40%            { transform: translateY(-5px); opacity: 1; }
}

/* ── Compose bar ───────────────────────────────────────────────────────────── */
.compose-bar {
    border-top:      1px solid var(--border);
    padding:         0.75rem 1rem;
    background:      var(--bg-surface);
    display:         flex;
    flex-direction:  column;
    gap:             0.5rem;
}
.compose-reply-strip {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    background:      var(--bg-elevated);
    border-left:     3px solid var(--accent);
    border-radius:   var(--radius-sm);
    padding:         0.3rem 0.6rem;
    font-size:       0.8rem;
    color:           var(--text-secondary);
}
.compose-reply-cancel {
    background:  transparent;
    border:      none;
    color:       var(--text-muted);
    cursor:      pointer;
    font-size:   0.9rem;
    padding:     0 4px;
}
.compose-reply-cancel:hover { color: var(--text-primary); }
.compose-input-row {
    display:         flex;
    gap:             0.75rem;
    align-items:     flex-end;
}
.compose-textarea {
    flex:            1;
    background:      var(--bg-input);
    border:          1px solid var(--border);
    border-radius:   var(--radius-md);
    color:           var(--text-primary);
    font-family:     var(--font-sans);
    font-size:       0.925rem;
    padding:         0.6rem 0.85rem;
    resize:          none;
    line-height:     1.5;
    transition:      border-color 0.15s;
}
.compose-textarea:focus       { outline: none; border-color: var(--accent); }
.compose-textarea::placeholder { color: var(--text-muted); }
.compose-send-btn {
    background:      var(--accent);
    color:           #fff;
    border:          none;
    border-radius:   var(--radius-md);
    padding:         0.6rem 1.2rem;
    font-size:       0.9rem;
    font-weight:     600;
    cursor:          pointer;
    transition:      background 0.15s;
    white-space:     nowrap;
}
.compose-send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.compose-send-btn:disabled             { opacity: 0.5; cursor: default; }
.compose-send-btn.sending              { opacity: 0.7; }

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
    width:           260px;
    flex-shrink:     0;
    border-left:     1px solid var(--border);
    background:      var(--bg-surface);
    display:         flex;
    flex-direction:  column;
    overflow-y:      auto;
}
.sidebar-header {
    padding:         1rem;
    border-bottom:   1px solid var(--border-subtle);
}
.sidebar-title {
    font-size:       0.8rem;
    font-weight:     700;
    text-transform:  uppercase;
    letter-spacing:  0.06em;
    color:           var(--text-muted);
}
.sidebar-list { padding: 0.5rem; display: flex; flex-direction: column; gap: 2px; }

.bot-card {
    display:         flex;
    align-items:     center;
    gap:             0.65rem;
    padding:         0.55rem 0.6rem;
    border-radius:   var(--radius-md);
    text-decoration: none;
    transition:      background 0.15s;
    color:           var(--text-secondary);
}
.bot-card:hover        { background: var(--bg-elevated); text-decoration: none; }
.bot-card-online       { color: var(--text-primary); }

.bot-card-avatar { position: relative; flex-shrink: 0; }
.presence-dot {
    position:        absolute;
    bottom:          0;
    right:           0;
    width:           10px;
    height:          10px;
    border-radius:   50%;
    border:          2px solid var(--bg-surface);
}
.presence-online  { background: var(--green); }
.presence-offline { background: var(--text-muted); }

.bot-card-info    { flex: 1; min-width: 0; }
.bot-card-name    { font-size: 0.9rem; font-weight: 600; }
.bot-status-text  { font-size: 0.75rem; color: var(--green); }
.bot-status-text.offline { color: var(--text-muted); }

.typing-indicator {
    display:         flex;
    align-items:     center;
    gap:             2px;
    font-size:       0.72rem;
}
.typing-indicator.thinking { color: var(--yellow); }
.typing-indicator.typing   { color: var(--accent-hover); }

.bot-card-balance {
    font-size:       0.75rem;
    color:           var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* ── WASM loading fallback ─────────────────────────────────────────────────── */
.wasm-loading {
    height:          100%;
    display:         flex;
    flex-direction:  column;
    align-items:     center;
    justify-content: center;
    gap:             1rem;
    color:           var(--text-muted);
}
.loading-spinner {
    width:           32px;
    height:          32px;
    border:          3px solid var(--border);
    border-top-color: var(--accent);
    border-radius:   50%;
    animation:       spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar      { display: none; }
    .header-nav   { display: none; }
}
