/* ======================================================
   ROOT & THEME
====================================================== */
:root {
    --bg-1: #1f1c2c;
    --bg-2: #928dab;
    --card-bg: #ffffff;
    --card-bg-strong: #ffffff;
    --text: #0f172a;
    --muted: rgba(15,23,42,0.7);
    --accent: #2563eb;
    --accent-strong: #1d4ed8;
    --success: #10b981;
    --danger: #ef4444;
}

body.theme-dark {
    --bg-1: #485071;
    --bg-2: #1d202d;
    --card-bg: #0f172a;
    --card-bg-strong: #020617;
    --text: #ffffff;
    --muted: rgba(255,255,255,0.75);
    --accent: #6366f1;
    --accent-strong: #4f46e5;
}

/* ======================================================
   GLOBAL
====================================================== */
* { box-sizing: border-box; }
html, body { height: 100%; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, Arial;
    background: linear-gradient(135deg, var(--bg-1), var(--bg-2));
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.hidden { display: none !important; }

/* ======================================================
   THEME TOGGLE
====================================================== */
.theme-toggle {
    position: fixed;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    border: none;
    background: var(--card-bg);
    color: var(--text);
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(2,6,23,0.25);
}

/* ======================================================
   AUTH CONTAINER
====================================================== */
.container {
    width: 100%;
    max-width: 420px;
    background: var(--card-bg);
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 12px 40px rgba(2,6,23,0.35);
}

.header { text-align: center; margin-bottom: 18px; }
.header h1 { font-size: 26px; margin-bottom: 6px; }
.header p  { font-size: 14px; color: var(--muted); }

.auth-form { display: block; }

.input-group { margin-bottom: 14px; }
.input-group label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.input-group input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: none;
    background: #f1f5f9;
    font-size: 15px;
}
body.theme-dark .input-group input { background: #020617; color: #ffffff; }

.btn {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: none;
    background: var(--accent-strong);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.switch { margin-top: 10px; text-align: center; font-size: 14px; color: var(--muted); }
.switch a { color: var(--accent); cursor: pointer; }

/* ALERTS */
.alert { margin-top: 12px; padding: 10px; border-radius: 8px; font-size: 14px; text-align: center; }
.alert.success { background: #dcfce7; color: #065f46; }
.alert.error   { background: #fee2e2; color: #991b1b; }

/* ======================================================
   CHAT CONTAINER
====================================================== */
.chat-container {
    width: 100%;
    max-width: 900px;
    height: 90vh;
    background: var(--card-bg);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 12px 50px rgba(2,6,23,0.4);
}

/* HEADER */
.chat-header {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 14px 18px;
    background: var(--card-bg-strong);
    border-bottom: 1px solid rgba(0,0,0,0.05);
}
.chat-header-left h2 { margin: 0; font-size: 18px; }
.bot-subtitle { font-size: 13px; color: var(--muted); }

.chat-header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}
.chat-header-right .logout-btn { order: 1; }
.chat-header-right .userinfo {
    order: 2;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    line-height: 1;
}

.logout-btn { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text); }

/* ======================================================
   CHAT BODY
====================================================== */
.chat-body {
    flex: 1;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
}

.message { display: flex; gap: 10px; align-items: flex-end; }
.message.user { justify-content: flex-end; }

.bubble {
    padding: 12px 14px;
    border-radius: 12px;
    max-width: 75%;
    font-size: 15px;
    line-height: 1.5;
}

.message.user .bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.message.bot .bubble {
    background: #f1f5f9;
}
body.theme-dark .message.bot .bubble { background: #020617; }

.icon { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; color: var(--accent); }

/* ======================================================
   CHAT FOOTER
====================================================== */
.chat-footer {
    position: sticky;
    bottom: 0;
    padding: 12px;
    display: flex;
    gap: 10px;
    background: var(--card-bg-strong);
    border-top: 1px solid rgba(0,0,0,0.05);
}
.chat-footer input {
    flex: 1;
    padding: 12px;
    border-radius: 10px;
    border: none;
    background: #f1f5f9;
}
body.theme-dark .chat-footer input { background: #020617; color: #fff; }

.mic-btn,
.send-btn {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    border: none;
    background: var(--accent-strong);
    color: #fff;
    cursor: pointer;
}
.mic-btn {
    background: none;
    color: var(--text);
    border: 1px solid rgba(0,0,0,0.15);
}

/* ======================================================
   MARKDOWN RENDERING
====================================================== */
.message.bot .bubble ol,
.message.bot .bubble ul  { margin: 6px 0; padding-left: 20px; }
.message.bot .bubble li  { margin-bottom: 4px; line-height: 1.5; }
.message.bot .bubble p   { margin: 4px 0; }
.message.bot .bubble h4  { margin: 8px 0 4px; font-size: 15px; font-weight: 600; }
.message.bot .bubble strong { font-weight: 600; }

/* ======================================================
   BOT MESAJ BUTONLARI (Hoparlör + Kopyala)
====================================================== */
.msg-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-self: flex-end;
    padding-bottom: 4px;
}

.action-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.12);
    background: var(--card-bg);
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: background 0.2s, color 0.2s;
}
.action-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

/* Hoparlör aktifken (okuma sırasında) */
.speak-btn.speaking {
    background: #ef4444;
    color: #fff;
    border-color: transparent;
    animation: pulse 1.2s infinite;
}

/* Mikrofon kayıt aktifken */
.mic-btn.recording {
    background: #ef4444 !important;
    color: #fff !important;
    border-color: transparent !important;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.55; }
}

/* ======================================================
   MOBILE
====================================================== */
@media (max-width: 700px) {
    body { padding: 0; justify-content: flex-start; align-items: stretch; }

    #authBox {
        width: 100vw;
        min-height: 100dvh;
        border-radius: 0;
    }

    #chatContainer {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100dvh;
        border-radius: 0;
        z-index: 40;
    }

    .chat-body { padding: 8px; }
    .bubble { max-width: 88%; }

    /* Bot balonu: sağdaki action butonları alta taşı, balonu genişlet */
    .message.bot { flex-wrap: wrap; align-items: flex-start; }
    .message.bot .bubble { max-width: calc(100% - 50px); }
    .message.bot .msg-actions {
        flex-direction: row;
        margin-left: 44px;
        padding-bottom: 0;
        align-self: auto;
    }
}