/* ============================================================
   CHAT LAYOUT
   ============================================================ */

.chat-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 0;
    background:
        radial-gradient(ellipse at 15% 0%, rgba(95, 245, 255, 0.07), transparent 50%),
        radial-gradient(ellipse at 85% 100%, rgba(255, 111, 242, 0.05), transparent 50%),
        var(--bg-primary);
    overflow: hidden;
}

.network-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.4;
}

/* ============================================================
   HEADER
   ============================================================ */

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 28px;
    z-index: 1;
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(8, 10, 24, 0.8);
    backdrop-filter: blur(12px);
    flex-shrink: 0;
}

.logo-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo {
    width: 30px;
    height: 30px;
    border-radius: 8px;
}

.header-title {
    font-size: 20px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.header-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 400;
    letter-spacing: 0.02em;
}

/* ============================================================
   CHAT CONTAINER
   ============================================================ */

.chat-container {
    flex: 1;
    width: 100%;
    padding: 24px max(20px, calc(50% - 410px)) 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    z-index: 1;
}

/* ============================================================
   WELCOME SCREEN
   ============================================================ */

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    animation: fadeIn 0.6s ease;
}

.welcome-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    color: #080a18;
    margin-bottom: 20px;
}

.welcome-screen h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.welcome-screen p {
    font-size: 15px;
    color: var(--text-secondary);
    max-width: 480px;
    line-height: 1.6;
}

/* ============================================================
   MESSAGES
   ============================================================ */

.message {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    max-width: 615px;
    word-wrap: break-word;
    font-size: 14.5px;
    line-height: 1.6;
    opacity: 0;
    animation: slideFade 0.35s ease forwards;
}

.user {
    align-self: flex-end;
    background: linear-gradient(135deg, rgba(95, 245, 255, 0.12), rgba(127, 139, 255, 0.12));
    border: 1px solid rgba(95, 245, 255, 0.18);
    color: var(--text-primary);
}

.bot {
    align-self: flex-start;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    max-width: 697px;
    position: relative;
}

.bot .status {
    color: var(--accent-cyan);
    font-size: 13px;
    min-height: 0;
}

.bot .sub-status {
    color: var(--text-muted);
    min-height: 0;
}

.bot .sub-status small {
    font-size: 12px;
}

/* ============================================================
   RICH CONTENT (rendered markdown in bot messages)
   ============================================================ */

.bot .result {
    line-height: 1.7;
}

.bot .result > *:first-child {
    margin-top: 0;
}

.bot .result > *:last-child {
    margin-bottom: 0;
}

.bot .result h1,
.bot .result h2,
.bot .result h3,
.bot .result h4 {
    margin-top: 18px;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
}

.bot .result h1 { font-size: 20px; }
.bot .result h2 { font-size: 17px; }
.bot .result h3 { font-size: 15px; }
.bot .result h4 { font-size: 14px; }

.bot .result p {
    margin-bottom: 10px;
}

.bot .result strong {
    color: #fff;
    font-weight: 600;
}

.bot .result em {
    color: var(--text-secondary);
    font-style: italic;
}

.bot .result a {
    color: var(--accent-cyan);
    text-decoration: none;
}

.bot .result a:hover {
    text-decoration: underline;
}

/* Lists */
.bot .result ul,
.bot .result ol {
    margin: 8px 0;
    padding-left: 22px;
}

.bot .result li {
    margin-bottom: 4px;
}

.bot .result li > p {
    margin-bottom: 4px;
}

/* Blockquotes */
.bot .result blockquote {
    margin: 12px 0;
    padding: 10px 16px;
    border-left: 3px solid var(--accent-violet);
    background: rgba(127, 139, 255, 0.06);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
}

.bot .result blockquote p {
    margin-bottom: 0;
}

/* Horizontal rule */
.bot .result hr {
    border: none;
    border-top: 1px solid var(--border-subtle);
    margin: 16px 0;
}

/* Tables */
.bot .result table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
}

.bot .result th,
.bot .result td {
    padding: 8px 12px;
    border: 1px solid var(--border-subtle);
    text-align: left;
}

.bot .result th {
    background: rgba(127, 139, 255, 0.08);
    font-weight: 600;
}

/* Code blocks */
.bot .result pre {
    margin: 12px 0;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    position: relative;
}

.bot .result pre code {
    display: block;
    padding: 14px 16px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.55;
    background: #0d1117;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(100, 120, 180, 0.1);
    tab-size: 4;
    color: #e6edf3;
}

/* Inline code */
.bot .result code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    padding: 2px 6px;
    background: rgba(127, 139, 255, 0.1);
    border-radius: 4px;
    color: var(--accent-cyan);
}

/* Override: code inside pre blocks uses block styles */
.bot .result pre code {
    padding: 14px 16px;
    background: #0d1117;
    color: #e6edf3;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

/* ============================================================
   INPUT AREA
   ============================================================ */

.input-area {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    width: 100%;
    max-width: 820px;
    margin: 0 auto;
    padding: 12px 20px 24px;
    z-index: 1;
    flex-shrink: 0;
}

textarea {
    flex: 1;
    resize: none;
    padding: 12px 16px;
    font-size: 14.5px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-medium);
    height: 48px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-family: var(--font-sans);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    caret-color: var(--accent-cyan);
}

textarea::placeholder {
    color: var(--text-muted);
}

textarea:focus {
    outline: none;
    border-color: rgba(95, 245, 255, 0.35);
    box-shadow: 0 0 0 3px rgba(95, 245, 255, 0.06);
}

/* ============================================================
   SEND BUTTON
   ============================================================ */

#sendBtn {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: var(--radius-md);
    border: none;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-violet));
    color: #080a18;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
    box-shadow: 0 4px 16px rgba(95, 245, 255, 0.15);
    padding: 0;
}

#sendBtn:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(95, 245, 255, 0.25);
}

#sendBtn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    box-shadow: none;
}

#sendBtn.animate {
    animation: pulse 0.25s ease;
}

/* ============================================================
   FLOW OPEN BUTTON (in chat)
   ============================================================ */

.flow-button-open {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    background: rgba(127, 139, 255, 0.08);
    border: 1px solid rgba(127, 139, 255, 0.18);
    color: var(--accent-violet);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    font-family: var(--font-sans);
}

.flow-button-open:hover {
    background: rgba(127, 139, 255, 0.16);
    border-color: rgba(127, 139, 255, 0.3);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 640px) {
    .chat-header {
        padding: 12px 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .chat-container {
        padding: 16px 12px 10px;
    }

    .message {
        max-width: 92%;
    }

    .bot {
        max-width: 92%;
    }

    .input-area {
        padding: 10px 12px 18px;
    }
}

/* ============================================================
   COPY BUTTONS
   ============================================================ */

.copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--border-subtle);
    background: rgba(18, 21, 45, 0.85);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    font-family: var(--font-sans);
    backdrop-filter: blur(4px);
}

.copy-btn:hover {
    background: rgba(127, 139, 255, 0.15);
    color: var(--text-primary);
    border-color: rgba(127, 139, 255, 0.3);
}

.copy-btn.copied {
    color: var(--accent-cyan);
    border-color: rgba(95, 245, 255, 0.3);
    pointer-events: none;
}

/* Message-level copy button */
.bot > .msg-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    z-index: 2;
}

.bot:hover > .msg-copy-btn,
.bot > .msg-copy-btn.copied {
    opacity: 1;
}

/* Code block wrapper with copy button */
.code-block-wrapper {
    position: relative;
    margin: 12px 0;
}

.code-block-wrapper > pre {
    margin: 0;
}

.code-block-wrapper > .code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    z-index: 2;
}

.code-block-wrapper:hover > .code-copy-btn,
.code-block-wrapper > .code-copy-btn.copied {
    opacity: 1;
}
