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

html, body {
    height: 100%;
    font-family: 'DM Sans', system-ui, sans-serif;
    background: #212121;
    color: #ececec;
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #4a4a4a; }

/* ── App shell ────────────────────────────────────────────────────────────── */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
    position: relative;
}
.error-bubble {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: #2a1a1a;
    border: 1px solid #ff444466;
    border-radius: 10px;
    padding: 10px 14px;
    color: #ff8888;
    font-size: 14px;
    max-width: 100%;
}
/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: #171717;
    border-right: 1px solid #2a2a2a;
    display: flex;
    flex-direction: column;
    transition: width .25s ease, min-width .25s ease;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
}

.sidebar-header {
    padding: 16px 12px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #222;
}

.sidebar-logo {
    width: 34px; height: 34px;
    background: linear-gradient(135deg, #c9a84c, #a8893e);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0;
}

.sidebar-brand {
    font-weight: 700; font-size: 15px; color: #fff;
    white-space: nowrap;
}

.btn-icon {
    margin-left: auto;
    background: transparent;
    border: 1px solid #333;
    border-radius: 8px;
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: #aaa;
    transition: all .15s;
    flex-shrink: 0;
}
.btn-icon:hover { background: #2a2a2a; color: #fff; }

/* Conversation list */
.conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conv-empty {
    text-align: center;
    color: #555;
    font-size: 13px;
    margin-top: 32px;
}

.conv-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border-radius: 9px;
    cursor: pointer;
    margin-bottom: 2px;
    position: relative;
    transition: background .1s;
}
.conv-item:hover   { background: #1f1f1f; }
.conv-item.active  { background: #2a2a2a; }

.conv-icon  { color: #555; flex-shrink: 0; }

.conv-title {
    flex: 1;
    font-size: 13.5px;
    color: #bbb;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-item.active .conv-title { color: #fff; font-weight: 500; }

.conv-delete {
    background: none; border: none; cursor: pointer;
    color: #555; padding: 3px; border-radius: 5px;
    opacity: 0; transition: all .15s; display: flex;
}
.conv-item:hover .conv-delete { opacity: 1; }
.conv-delete:hover { color: #ff4444; background: #2a2a2a; }

/* Sidebar footer */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid #2a2a2a;
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
}

.user-avatar-initials {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: #c9a84c;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; color: #fff;
    flex-shrink: 0;
}

.user-info { flex: 1; overflow: hidden; }
.user-name  { font-size: 13px; color: #ddd; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 11px; color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn-logout {
    background: none; border: none; cursor: pointer;
    color: #555; padding: 6px; border-radius: 8px;
    display: flex; transition: all .15s;
}
.btn-logout:hover { color: #ff4444; background: #2a2a2a; }

/* Sidebar toggle */
.sidebar-toggle {
    position: absolute;
    left: 248px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 8px;
    width: 22px; height: 22px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: #aaa;
    transition: left .25s ease;
}
.sidebar-toggle:hover { color: #fff; }

/* ── Chat main ────────────────────────────────────────────────────────────── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Messages area */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0 8px;
    scroll-behavior: smooth;
}

/* Welcome screen */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    padding: 24px;
    text-align: center;
}

.welcome-logo {
    width: 64px; height: 64px;
    background: linear-gradient(135deg, #c9a84c, #a8893e);
    border-radius: 20px;
    display: flex; align-items: center; justify-content: center;
    font-size: 32px; margin-bottom: 20px;
}

.welcome-title { font-size: 22px; font-weight: 700; color: #eee; margin-bottom: 8px; }
.welcome-sub   { color: #777; font-size: 14px; max-width: 420px; margin-bottom: 28px; }

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

.chip {
    padding: 8px 16px;
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 20px;
    color: #bbb; font-size: 13px;
    cursor: pointer; font-family: inherit;
    transition: all .15s;
}
.chip:hover { background: #333; color: #fff; border-color: #444; }

/* Message rows */
.msg-row {
    display: flex;
    flex-direction: column;
    max-width: 760px;
    margin: 0 auto;
    padding: 4px 24px;
    width: 100%;
}

.msg-row.user      { align-items: flex-end; }
.msg-row.assistant { align-items: flex-start; }

.msg-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 6px;
}
.msg-attachments.user  { justify-content: flex-end; }

.att-image {
    max-width: 260px;
    max-height: 200px;
    border-radius: 10px;
    object-fit: cover;
    border: 1px solid #333;
}

.att-file {
    display: flex; align-items: center; gap: 6px;
    background: #2a2a2a; border: 1px solid #333;
    border-radius: 8px; padding: 6px 12px;
    color: #aaa; font-size: 12px; text-decoration: none;
    transition: background .1s;
}
.att-file:hover { background: #333; color: #ddd; }

/* Bubbles */
.msg-bubble {
    max-width: 80%;
    font-size: 15px;
    line-height: 1.7;
    word-break: break-word;
}

.msg-bubble.user {
    background: #2f6a55;
    color: #fff;
    border-radius: 18px 18px 4px 18px;
    padding: 10px 16px;
    white-space: pre-wrap;
}

.msg-bubble.assistant {
    color: #ddd;
    padding: 2px 0;
    max-width: 100%;
}

/* Typing dots */
.typing-dots {
    display: flex;
    gap: 5px;
    padding: 12px 24px;
    max-width: 760px;
    margin: 0 auto;
    width: 100%;
}
.typing-dots span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #c9a84c;
    animation: tdot 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes tdot {
    0%,80%,100% { transform: scale(.7); opacity: .4; }
    40%         { transform: scale(1.2); opacity: 1; }
}

/* Streaming cursor */
.stream-cursor {
    display: inline-block;
    width: 2px; height: 16px;
    background: #c9a84c;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 1s step-end infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* ── Input area ───────────────────────────────────────────────────────────── */
.input-area {
    padding: 0 16px 18px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.file-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.file-chip {
    display: flex; align-items: center; gap: 6px;
    background: #2a2a2a; border: 1px solid #333;
    border-radius: 8px; padding: 5px 10px;
    font-size: 12px; color: #aaa; max-width: 200px;
}

.file-chip span {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.file-chip-remove {
    background: none; border: none; cursor: pointer;
    color: #555; padding: 0; display: flex; flex-shrink: 0;
}
.file-chip-remove:hover { color: #ff4444; }

.input-box {
    background: #2f2f2f;
    border: 1px solid #3a3a3a;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: border-color .15s;
}
.input-box:focus-within { border-color: #c9a84c44; }

.input-box textarea {
    background: transparent;
    border: none; outline: none;
    color: #ececec;
    font-size: 15px;
    font-family: inherit;
    padding: 14px 16px 4px;
    resize: none;
    line-height: 1.6;
    max-height: 200px;
}

.input-box textarea::placeholder { color: #555; }

.input-actions {
    display: flex;
    align-items: center;
    padding: 4px 12px 10px;
    gap: 8px;
}

.btn-attach {
    cursor: pointer;
    color: #666; padding: 6px;
    border-radius: 8px; display: flex;
    transition: all .15s;
}
.btn-attach input { display: none; }
.btn-attach:hover { color: #aaa; background: #3a3a3a; }

.input-hint { font-size: 11px; color: #444; flex: 1; }

.btn-send {
    background: #c9a84c;
    border: none; cursor: pointer;
    color: #fff; padding: 8px;
    border-radius: 10px; display: flex;
    align-items: center; justify-content: center;
    transition: background .15s;
}
.btn-send:hover    { background: #a8893e; }
.btn-send:disabled { background: #333; cursor: not-allowed; }

.btn-stop {
    background: #3a3a3a;
    border: none; cursor: pointer;
    color: #aaa; padding: 8px;
    border-radius: 10px; display: flex;
    align-items: center; justify-content: center;
    font-size: 13px; gap: 4px;
    transition: background .15s;
}
.btn-stop:hover { background: #4a4a4a; }

.input-disclaimer {
    text-align: center;
    color: #3a3a3a;
    font-size: 11px;
    margin-top: 6px;
}

/* ── Markdown body (inside assistant bubbles) ─────────────────────────────── */
.markdown-body p       { margin-bottom: 12px; }
.markdown-body p:last-child { margin-bottom: 0; }
.markdown-body h1      { font-size: 22px; font-weight: 700; color: #fff; margin: 20px 0 10px; }
.markdown-body h2      { font-size: 18px; font-weight: 600; color: #eee; margin: 16px 0 8px; }
.markdown-body h3      { font-size: 16px; font-weight: 600; color: #ddd; margin: 14px 0 6px; }
.markdown-body ul,
.markdown-body ol      { padding-left: 20px; margin-bottom: 12px; }
.markdown-body li      { margin-bottom: 4px; }
.markdown-body blockquote {
    border-left: 3px solid #c9a84c;
    padding-left: 12px; margin: 8px 0;
    color: #999;
}
.markdown-body code:not([class]) {
    background: #2a2a2a; padding: 2px 6px;
    border-radius: 4px; font-size: 13px;
    color: #e8b4ff;
    font-family: 'JetBrains Mono', monospace;
}
.markdown-body pre {
    background: #1a1a1a;
    border-radius: 10px;
    overflow: hidden;
    margin: 10px 0;
}
.markdown-body pre > div.code-header {
    display: flex; justify-content: space-between;
    align-items: center;
    padding: 6px 14px;
    border-bottom: 1px solid #2a2a2a;
    font-size: 12px; color: #666;
}
.copy-btn {
    background: none; border: none; cursor: pointer;
    color: #666; font-size: 12px; font-family: inherit;
    display: flex; align-items: center; gap: 4px;
    padding: 2px 6px;
    transition: color .15s;
}
.copy-btn:hover { color: #c9a84c; }
.markdown-body pre code {
    display: block;
    padding: 14px 16px !important;
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    line-height: 1.6;
    overflow-x: auto;
    background: transparent !important;
}
.markdown-body table {
    border-collapse: collapse;
    width: 100%; margin-bottom: 12px; font-size: 13px;
    overflow-x: auto; display: block;
}
.markdown-body th {
    background: #2a2a2a; padding: 8px 12px;
    border: 1px solid #333; color: #ccc; text-align: left;
}
.markdown-body td {
    padding: 6px 12px; border: 1px solid #2a2a2a; color: #bbb;
}
.markdown-body a { color: #c9a84c; text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }


/* ── Sidebar sign-in button (guest state) ────────────────────────────────── */
.sidebar-signin-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 8px 0;
    padding: 11px 14px;
    background: #c9a84c18;
    border: 1px solid #c9a84c55;
    border-radius: 10px;
    color: #c9a84c;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all .15s;
}
.sidebar-signin-btn:hover {
    background: #c9a84c2e;
    border-color: #c9a84c99;
    color: #d4b96a;
}

/* ── Sidebar policy links ────────────────────────────────────────────────── */
.sidebar-policy-links {
    display: flex; flex-wrap: wrap; gap: 4px 10px;
    padding: 6px 20px 8px;
}
.sidebar-policy-links a {
    font-size: 11px; color: #2e4060;
    text-decoration: none; transition: color .15s;
    white-space: nowrap;
}
.sidebar-policy-links a:hover { color: #c9a84c; }

/* ── Sidebar admin button ────────────────────────────────────────────────── */
.sidebar-admin-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 8px 6px;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid #c9a84c55;
    background: #c9a84c15;
    color: #c9a84c;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all .15s;
}
.sidebar-admin-btn:hover {
    background: #c9a84c28;
    border-color: #c9a84c99;
    color: #d4b96a;
}

/* ── Sidebar plans button ─────────────────────────────────────────────────── */
.sidebar-plans-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 8px 4px;
    padding: 9px 12px;
    background: linear-gradient(135deg, #c9a84c22, #c9a84c11);
    border: 1px solid #c9a84c44;
    border-radius: 10px;
    color: #c9a84c;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all .15s;
}

    .sidebar-plans-btn:hover {
        background: linear-gradient(135deg, #c9a84c33, #c9a84c22);
        border-color: #c9a84c88;
        color: #d4b96a;
    }

    .sidebar-plans-btn.has-plan {
        background: transparent;
        border-color: #2a2a2a;
        color: #666;
    }

        .sidebar-plans-btn.has-plan:hover {
            color: #aaa;
            border-color: #444;
        }

/* ── Voice buttons ─────────────────────────────────────────────────────────── */
.btn-mic,
.btn-voice {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #888;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, color .15s, transform .1s;
}

.btn-mic:hover,
.btn-voice:hover {
    background: #2a2a2a;
    color: #ccc;
}

/* Recording state — pulsing red */
.btn-mic.recording {
    color: #ff4444;
    background: #2a1a1a;
    animation: mic-pulse 1s ease-in-out infinite;
}

@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,68,68,.4); }
    50%       { box-shadow: 0 0 0 6px rgba(255,68,68,0); }
}

/* TTS active */
.btn-voice.active {
    color: #c9a84c;
}

.btn-voice.active.playing {
    color: #c9a84c;
    animation: speaker-beat .7s ease-in-out infinite alternate;
}

@keyframes speaker-beat {
    from { opacity: .7; }
    to   { opacity: 1; }
}

/* Wave canvas overlay (appears inside input-area above the box) */
.mic-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 0 2px;
}

.mic-overlay canvas {
    border-radius: 4px;
}

/* Transcribing / error status text */
.mic-status {
    text-align: center;
    font-size: 12px;
    color: #888;
    margin: 2px 0 0;
    min-height: 18px;
}

.mic-status:not(.hidden) {
    display: block;
}

/* ── Voice message bubble (audio player in chat) ────────────────────────── */
.voice-bubble {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px !important;
    background: #2a2a2a !important;
}

.voice-msg-icon {
    color: #c9a84c;
    flex-shrink: 0;
    display: flex;
}

.voice-player {
    height: 32px;
    min-width: 180px;
    max-width: 260px;
    accent-color: #c9a84c;
    filter: invert(0);
}
