* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

:root {
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --bg-dark: #202123;
    --bg-darker: #1a1b1e;
    --bg-chat: #212121;
    --bg-bubble: #2b2b2b;
    --bg-bubble-user: #2f2f2f;
    --accent: #10a37f;
    --accent-hover: #0d8d6e;
    --text-main: #ececec;
    --text-muted: #8e8e8e;
    --border: #333;
}

body {
    background: var(--bg-chat);
    color: var(--text-main);
    height: 100vh;
    
}

/* ========== APP LAYOUT ========== */
.app {
    display: flex;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    overflow: hidden;
    width: 100%;
}

/* ========== SIDEBAR ========== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-dark);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100%;
    position: relative;
    z-index: 100;
}

.sidebar-header {
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 10px;
    display: none;
}

.new-chat-btn {
    width: 100%;
    padding: 12px 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: .2s;
}

.new-chat-btn:hover {
    background: var(--accent-hover);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    scrollbar-width: thin;
}

.conversation-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 2px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: .15s;
}

.conversation-item:hover {
    background: var(--bg-bubble);
}

.conversation-item.active {
    background: var(--bg-bubble);
}

.conversation-item .conv-title {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.conversation-item .conv-actions {
    display: none;
}

.conversation-item:hover .conv-actions {
    display: flex;
    gap: 2px;
}

.conversation-item .conv-actions button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    font-size: 12px;
    border-radius: 4px;
}

.conversation-item .conv-actions button:hover {
    color: var(--text-main);
    background: var(--bg-bubble-user);
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.usage-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background: var(--bg-bubble);
    border-radius: 8px;
    margin-bottom: 8px;
}

.usage-label {
    font-size: 12px;
    color: var(--text-muted);
}

.usage-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
}

.user-menu {
    position: relative;
}

.user-menu-btn {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-bubble);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.user-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    font-size: 11px;
    color: white;
}

.user-dropdown {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    z-index: 200;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.user-dropdown.show {
    display: block;
}

.user-dropdown a {
    display: block;
    padding: 10px 12px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 13px;
    transition: .15s;
}

.user-dropdown a:hover {
    background: var(--bg-bubble);
}

/* ========== MOBILE SIDEBAR TOGGLE BUTTON ========== */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    margin-right: 8px;
    border-radius: 6px;
    color: var(--text-main);
    align-items: center;
    justify-content: center;
}

.sidebar-toggle:hover {
    background: var(--bg-bubble);
}

.sidebar-toggle svg {
    width: 22px;
    height: 22px;
}

/* ========== MOBILE OVERLAY ========== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 90;
}

.sidebar-overlay.show {
    display: block;
}

/* ========== CHAT AREA ========== */
.chat-area {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    min-width: 0;
    background: var(--bg-chat);
}

/* ========== TOP BAR ========== */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    /* Respect notch / status-bar safe area in PWA standalone & iOS */
    padding-top: env(safe-area-inset-top);
    height: calc(var(--topbar-height) + env(safe-area-inset-top));
    min-height: calc(var(--topbar-height) + env(safe-area-inset-top));
    border-bottom: 1px solid var(--border);
    background: var(--bg-dark);
    flex-shrink: 0;
    z-index: 50;
}

.top-bar-left {
    display: flex;
    align-items: center;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo h2 {
    font-size: 18px;
    font-weight: 600;
}

.login-btn {
    color: var(--text-main);
    text-decoration: none;
    border: 1px solid var(--border);
    padding: 8px 14px;
    border-radius: 6px;
    transition: .2s;
    font-size: 13px;
}

.login-btn:hover {
    background: var(--bg-bubble);
}

.role-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    background: var(--accent);
    color: white;
}

/* ===== TOP-BAR USER AVATAR (green circle, matches sidebar) ===== */
.topbar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    font-size: 13px;
    color: #fff;
}

/* ===== TOP-BAR LOGIN BUTTON (guest only, mobile only) ===== */
/* Hidden by default; JS adds .is-guest for guest sessions, and the mobile
   media query below reveals it. Desktop keeps the sidebar login link. */
.topbar-login-btn {
    display: none;
    align-items: center;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.topbar-login-btn:hover {
    opacity: 0.9;
}
@media (max-width: 768px) {
    .topbar-login-btn.is-guest {
        display: inline-flex;
    }
}

/* ========== MESSAGES ========== */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    min-height: 0;
    scrollbar-width: thin;
    /* Flex column so the welcome screen can be vertically centered via
       margin:auto. Chat bubbles have NO auto-margin, so once a conversation
       starts they stay top-aligned (justify-content: flex-start) and scroll
       normally — only the welcome screen is centered in the middle. */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

/* Welcome screen — centered only while it's the sole child */
.welcome-screen {
    text-align: center;
    max-width: 600px;
    margin: auto;
}

.welcome-icon {
    font-size: 56px;
    margin-bottom: 16px;
}

.welcome-screen h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 10px;
}

.welcome-screen p {
    color: var(--text-muted);
    font-size: 15px;
    margin-bottom: 28px;
}

.quick-prompts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.quick-prompts button {
    padding: 14px 16px;
    background: var(--bg-bubble);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-main);
    cursor: pointer;
    font-size: 14px;
    text-align: left;
    transition: .2s;
}

.quick-prompts button:hover {
    border-color: var(--accent);
    background: var(--bg-dark);
}

/* Message bubbles */
.message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 800px;
    margin: 0 0 20px;
}

.message.user {
    align-items: flex-end;
}

.message-avatar {
    display: none;
}

.message.ai .message-avatar {
    background: var(--accent);
    color: white;
}

.message.user .message-avatar {
    background: #555;
    color: white;
}

.bubble {
    background: var(--bg-bubble);
    padding: 14px 16px;
    border-radius: 12px;
    line-height: 1.6;
    max-width: 75%;
    font-size: 15px;
    word-wrap: break-word;
}

.message.user .bubble {
    background: #10a37f;
    color: white;
    white-space: nowrap;
    overflow: hidden;
}

.bubble h1, .bubble h2, .bubble h3 {
    margin: 10px 0 6px;
}

.bubble p {
    margin-bottom: 6px;
}

.bubble code {
    background: rgba(0,0,0,0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.bubble pre {
    background: rgba(0,0,0,0.3);
    padding: 14px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
}

.bubble pre code {
    background: none;
    padding: 0;
}

/* Typewriter cursor */
.chat-cursor {
    display: inline-block;
    width: 8px;
    height: 16px;
    background: var(--accent);
    margin-left: 2px;
    animation: cursor-blink 1s infinite;
    vertical-align: text-bottom;
}

@keyframes cursor-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Loading pipe animation */
.loading-pipe {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.loading-pipe .pipe {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: pipe-bounce 1.2s infinite ease-in-out;
}

.loading-pipe .pipe:nth-child(2) { animation-delay: 0.2s; }
.loading-pipe .pipe:nth-child(3) { animation-delay: 0.4s; }

@keyframes pipe-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.bubble ul, .bubble ol {
    margin: 6px 0 6px 20px;
}

.bubble li {
    margin-bottom: 3px;
}

/* User-uploaded image inside a chat bubble */
.msg-image {
    display: block;
    max-width: 100%;
    max-height: 280px;
    border-radius: 10px;
    margin-bottom: 8px;
    object-fit: cover;
}

/* Image preview strip above the input box */
.image-preview {
    display: none;
    align-items: center;
    gap: 10px;
    max-width: 800px;
    margin: 0 auto 8px;
    padding: 8px 10px;
    background: var(--bg-bubble);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.image-preview img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 8px;
}

.image-preview .remove-img {
    border: none;
    background: #e04848;
    color: #fff;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 13px;
    line-height: 1;
}

.image-preview .img-hint {
    font-size: 13px;
    color: var(--text-muted);
}

/* Attached file preview strip above the input box */
.file-preview {
    display: none;
    align-items: center;
    gap: 10px;
    max-width: 800px;
    margin: 0 auto 8px;
    padding: 8px 10px;
    background: var(--bg-bubble);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.file-chip {
    font-size: 13px;
    color: var(--text-main);
    word-break: break-all;
}

.file-preview .remove-img {
    border: none;
    background: #e04848;
    color: #fff;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 13px;
    line-height: 1;
}

.message .message-actions {
    display: flex;
    gap: 6px;
    padding: 6px 0;
    align-self: flex-end;
}

.message-actions button {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: .15s;
}

/* User messages have a green bubble (#10a37f) — muted gray text is hard to read.
   Force white text on user-message action buttons for contrast. */
.message.user .message-actions button,
.message.user .edit-actions button {
    color: #ffffff;
    border-color: rgba(255,255,255,0.35);
}

.message.user .message-actions button:hover,
.message.user .edit-actions button:hover {
    color: #ffffff;
    border-color: rgba(255,255,255,0.6);
    background: rgba(255,255,255,0.1);
}

/* Edit mode buttons (Cancel / Save & Resend) inside user bubble */
.edit-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    justify-content: flex-end;
}

.edit-actions button {
    background: none;
    border: 1px solid rgba(255,255,255,0.35);
    color: #ffffff;
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: .15s;
}

.edit-actions button:hover {
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.6);
}

.edit-textarea {
    width: 100%;
    min-height: 60px;
    resize: vertical;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    padding: 8px 10px;
    background: rgba(0,0,0,0.2);
    color: #ffffff;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
}

.edit-textarea:focus {
    outline: none;
    border-color: rgba(255,255,255,0.6);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 6px 0;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Chat cursor */
@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* ========== FOOTER ========== */
footer {
    padding: 12px 16px 16px;
    /* Clear the home-indicator / bottom safe area in PWA standalone & iOS */
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    background: var(--bg-dark);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.composer {
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg-bubble);
    border: none;
    border-radius: 16px;
    padding: 8px 10px 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden;
}

.composer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid var(--accent);
    box-shadow: 0 0 8px rgba(16, 163, 127, 0.22);
    border-radius: 12px;
    padding: 4px 6px;
}

.composer-left, .composer-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.composer-right {
    flex: 1;
    justify-content: flex-end;
}

#send-btn {
    width: 100%;
    border-radius: 10px;
}

/* Voice + image input buttons */
.icon-btn {
    border: none;
    background: transparent;
    color: var(--text-main);
    flex: 0 0 10%;
    width: auto;
    min-width: 44px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: .2s;
}

.icon-btn:hover {
    background: rgba(16, 163, 127, 0.12);
}

.icon-btn.recording {
    background: #e04848;
    border-color: #e04848;
    color: #fff;
    animation: pulse-red 1.2s infinite;
}

@keyframes pulse-red {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

textarea {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    border: none;
    background: transparent;
    resize: none;
    padding: 12px 14px;
    border-radius: 10px;
    color: var(--text-main);
    font-size: 15px;
    min-height: 48px;
    max-height: 160px;
    line-height: 1.4;
    transition: .2s;
}

textarea:focus {
    border-color: var(--accent);
}

textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button[type="submit"], .stop-btn {
    border: none;
    background: var(--accent);
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
    transition: .2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

button[type="submit"]:hover {
    background: var(--accent-hover);
}

button[type="submit"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.stop-btn {
    background: #222222;
}

.stop-btn:hover {
    background: #000;
}

.footer-notice {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
}

.footer-notice a {
    color: var(--accent);
}

/* ========== MODALS ========== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}

.modal {
    background: var(--bg-bubble);
    padding: 32px;
    border-radius: 16px;
    max-width: 380px;
    width: 100%;
    text-align: center;
}

.modal h2 {
    margin-bottom: 10px;
    font-size: 20px;
}

.modal p {
    color: var(--text-muted);
    margin-bottom: 20px;
    font-size: 14px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn-primary {
    background: var(--accent);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: #444;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
}

.btn-secondary:hover {
    background: #555;
}

/* ========== MOBILE RESPONSIVE ========== */
@media (max-width: 768px) {
    .app {
        height: 100dvh;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100dvh;
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 20px rgba(0,0,0,0.4);
        display: flex;
        flex-direction: column;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Pin the footer (usage + user menu) and let the conversation list
       scroll internally so the sidebar never grows past the screen. */
    .sidebar-footer {
        flex-shrink: 0;
    }
    .conversation-list {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
    }

    .sidebar-header h2 {
        display: block;
    }

    .sidebar-toggle {
        display: flex;
    }

    .top-bar {
        padding: 0 12px;
    }

    .logo h2 {
        font-size: 16px;
    }

    .login-btn {
        padding: 6px 12px;
        font-size: 12px;
    }

    .messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    .welcome-screen {
        margin: auto;
    }

    .welcome-screen h1 {
        font-size: 22px;
    }

    .welcome-icon {
        font-size: 42px;
    }

    .quick-prompts {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .quick-prompts button {
        padding: 12px;
        font-size: 13px;
    }

    .bubble {
        max-width: 85%;
        font-size: 14px;
        padding: 12px 14px;
    }

    .message-avatar {
        display: none;
    }

    .composer {
        gap: 4px;
    }

    textarea {
        width: 100%;
        min-height: 44px;
        font-size: 14px;
    }

    button[type="submit"], .stop-btn {
        width: 100%;
        height: 44px;
    }

    /* Mobile: stop button green with text label for clarity */
    .stop-btn {
        background: #10a37f;
        color: #fff;
        gap: 6px;
        font-weight: 600;
    }

    .stop-btn:hover {
        background: #0d8c6c;
    }

    .stop-btn .stop-label {
        font-size: 14px;
        line-height: 1;
    }
}

@media (max-width: 480px) {
    .top-bar {
        padding: 0 8px;
    }

    .logo h2 {
        font-size: 15px;
    }

    .messages {
        padding: 12px 8px;
    }

    footer {
        padding: 8px 10px 12px;
    }

    .message {
        gap: 8px;
    }
}

/* ========== API KEYS MODAL ========== */
.modal-wide {
    max-width: 560px;
    width: 100%;
    text-align: left;
}
.modal-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.modal-header-row h2 { margin: 0; font-size: 20px; }
.modal-close {
    background: none; border: none; color: var(--text-muted);
    font-size: 26px; cursor: pointer; line-height: 1;
}
.modal-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }
.api-key-create {
    display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap;
}
.api-key-create input {
    flex: 1; min-width: 160px; padding: 9px 12px;
    border-radius: 8px; border: 1px solid var(--border, #333);
    background: var(--bg-input, #1e1e1e); color: var(--text);
}
.api-key-create select {
    padding: 9px 10px; border-radius: 8px;
    border: 1px solid var(--border, #333); background: var(--bg-input, #1e1e1e); color: var(--text);
}
.api-key-create input[type="date"] {
    padding: 8px 10px; border-radius: 8px;
    border: 1px solid var(--border, #333); background: var(--bg-input, #1e1e1e);
    color: var(--text); font-size: 13px;
}
.api-key-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.api-key-new {
    background: rgba(16,163,127,0.12);
    border: 1px solid var(--accent, #10a37f);
    border-radius: 10px; padding: 12px; margin-bottom: 14px;
}
.api-key-new-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.api-key-new-value { display: flex; align-items: center; gap: 10px; }
.api-key-new-value code {
    flex: 1; word-break: break-all; font-size: 12px;
    background: #000; padding: 6px 8px; border-radius: 6px; color: #9effd0;
}
.api-key-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.api-key-row {
    border: 1px solid var(--border, #333); border-radius: 10px; padding: 10px 12px;
    display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.api-key-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.api-key-name { font-weight: 600; }
.api-key-prefix { color: var(--text-muted); font-size: 12px; font-family: monospace; }
.api-key-status { font-size: 11px; padding: 2px 8px; border-radius: 10px; }
.api-key-status.on { background: rgba(16,163,127,0.2); color: #5fe0b0; }
.api-key-status.off { background: rgba(255,80,80,0.18); color: #ff8a8a; }
.api-key-info { font-size: 11px; color: var(--text-muted); width: 100%; }
.api-key-empty { color: var(--text-muted); font-size: 13px; text-align: center; padding: 8px; }
.api-key-doc { font-size: 12px; color: var(--text-muted); }
.api-key-doc pre {
    background: #000; color: #9effd0; padding: 10px; border-radius: 8px;
    overflow-x: auto; font-size: 11px; white-space: pre-wrap; word-break: break-all;
}
.btn-danger { background: #d23b3b; color: #fff; border: none; border-radius: 8px; cursor: pointer; padding: 7px 12px; font-size: 13px; }
.btn-danger:hover { background: #b62f2f; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ========== MIC PERMISSION PANEL ========== */
.mic-permission {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.55); backdrop-filter: blur(2px);
    padding: 20px;
}
.mic-permission-card {
    background: var(--bg-bubble, #2b2b2b);
    border: 1px solid var(--border, #333);
    border-radius: 16px;
    max-width: 380px; width: 100%;
    padding: 26px 24px 22px;
    text-align: center;
    box-shadow: 0 12px 40px rgba(0,0,0,0.45);
    animation: micPop 0.22s ease forwards;
}
@keyframes micPop { from { transform: scale(0.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.mic-permission-icon {
    width: 56px; height: 56px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 14px;
    background: rgba(16,163,127,0.15); color: var(--accent, #10a37f);
}
.mic-permission-card h3 { font-size: 17px; margin-bottom: 8px; color: var(--text-main); }
.mic-permission-card p { font-size: 13.5px; line-height: 1.5; color: var(--text-muted); margin-bottom: 18px; }
.mic-permission-actions { display: flex; gap: 10px; }
.mic-permission-actions button { flex: 1; padding: 11px 0; font-size: 14px; border-radius: 10px; cursor: pointer; border: none; }
.mic-permission-hint {
    font-size: 12px !important; color: #ff9a9a !important; margin: 14px 0 0 !important;
    line-height: 1.45 !important; display: none;
}
.mic-permission-hint.show { display: block; }
.mic-permission-actions .btn-primary {
    background: var(--accent, #10a37f); color: #fff; font-weight: 600;
}
.mic-permission-actions .btn-primary:hover { background: var(--accent-hover, #0d8d6e); }
.mic-permission-actions .btn-secondary {
    background: transparent; color: var(--text-muted); border: 1px solid var(--border, #333) !important;
}
.mic-permission-actions .btn-secondary:hover { background: rgba(255,255,255,0.05); color: var(--text-main); }

/* ========== MIC RECORDING INDICATOR (ChatGPT-style animated waveform) ========== */
.mic-rec-indicator {
    display: none;
    align-items: center; gap: 3px; height: 22px;
    align-self: center; margin-left: 2px;
}
.mic-rec-indicator span {
    width: 3px; height: 100%; border-radius: 2px;
    background: #e04848;
    animation: mic-wave 0.9s ease-in-out infinite;
}
.mic-rec-indicator span:nth-child(2) { animation-delay: 0.15s; }
.mic-rec-indicator span:nth-child(3) { animation-delay: 0.30s; }
.mic-rec-indicator span:nth-child(4) { animation-delay: 0.45s; }
.mic-rec-indicator span:nth-child(5) { animation-delay: 0.60s; }
@keyframes mic-wave {
    0%, 100% { transform: scaleY(0.3); }
    50%      { transform: scaleY(1); }
}

/* ========== MIC RECORDING HINT ========== */
.mic-rec-hint {
    display: none;
    align-items: center; gap: 6px;
    font-size: 12px; font-weight: 600; color: #e04848;
    padding: 4px 10px; border-radius: 999px;
    background: rgba(224,72,72,0.12);
    white-space: nowrap;
    animation: pulse-red 1.2s infinite;
}
.mic-rec-hint.show { display: inline-flex; }

/* Edit/reload dialog styles */
.edit-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 10px 0;
}

.edit-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-bubble);
    color: var(--text-main);
    font-family: inherit;
    font-size: 15px;
    resize: vertical;
    min-height: 60px;
}

.edit-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.25);
}

.edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.edit-cancel, .edit-submit {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    border: none;
    transition: .2s;
}

.edit-cancel {
    background: var(--bg-bubble);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.edit-cancel:hover {
    background: var(--border);
    color: var(--text-main);
}

.edit-submit {
    background: var(--accent);
    color: white;
}

.edit-submit:hover {
    background: var(--accent-hover);
}

/* Modern loading pipe animation */
.loading-pipe {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 12px;
    margin: 6px 0;
}

.loading-pipe .pipe {
    width: 3px;
    height: 18px;
    background: var(--accent);
    border-radius: 2px;
    animation: pipePulse 1.4s ease-in-out infinite;
}

.loading-pipe .pipe:nth-child(1) { animation-delay: 0s; }
.loading-pipe .pipe:nth-child(2) { animation-delay: 0.2s; }
.loading-pipe .pipe:nth-child(3) { animation-delay: 0.4s; }

@keyframes pipePulse {
    0%, 100% { 
        opacity: 0.3;
        transform: scaleY(0.5);
    }
    50% { 
        opacity: 1;
        transform: scaleY(1);
    }
}

/* Chat cursor for streaming */
51%, 100% { opacity: 0; }
}
