* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f1117;
    color: #e0e0e0;
    height: 100vh;
    display: flex;
    justify-content: center;
}

.container {
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 1rem;
}

header {
    text-align: center;
    padding: 0.75rem 0;
    flex-shrink: 0;
}

header h1 {
    font-size: 1.6rem;
    background: linear-gradient(135deg, #4A90D9, #9B59B6, #E74C3C);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: #888;
    font-size: 0.85rem;
    margin-top: 0.2rem;
}

.help-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.2rem;
    height: 1.2rem;
    border-radius: 50%;
    background: #222;
    color: #888;
    font-size: 0.7rem;
    font-weight: 700;
    text-decoration: none;
    margin-left: 0.3rem;
    vertical-align: middle;
    transition: background 0.2s, color 0.2s;
}

.help-link:hover {
    background: #4A90D9;
    color: #fff;
}

/* ── Settings Panel ── */
.settings-panel {
    flex-shrink: 0;
}

.settings-toggle {
    width: 100%;
    padding: 0.35rem 0.6rem;
    background: #151821;
    border: 1px solid #222;
    border-radius: 8px;
    color: #888;
    font-size: 0.75rem;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.2s, color 0.2s;
}

.settings-toggle:hover {
    border-color: #4A90D9;
    color: #e0e0e0;
}

.settings-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    background: #151821;
    border: 1px solid #222;
    border-top: none;
    border-radius: 0 0 8px 8px;
    padding: 0 0.6rem;
}

.settings-body.open {
    max-height: 350px;
    padding: 0.6rem;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.settings-row label {
    font-size: 0.72rem;
    color: #aaa;
    white-space: nowrap;
    min-width: 120px;
}

.settings-row input,
.settings-row select {
    flex: 1;
    padding: 0.35rem 0.5rem;
    background: #1a1d27;
    border: 1px solid #333;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.75rem;
    outline: none;
}

.settings-row input {
    font-family: monospace;
}

.settings-row input:focus {
    border-color: #4A90D9;
}

.settings-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.3rem;
}

.settings-btn {
    padding: 0.3rem 0.7rem;
    font-size: 0.7rem;
    border: 1px solid #333;
    border-radius: 6px;
    background: #1a1d27;
    color: #aaa;
    cursor: pointer;
    transition: all 0.15s;
}

.settings-btn:hover {
    border-color: #4A90D9;
    color: #e0e0e0;
}

.settings-btn-danger:hover {
    border-color: #E74C3C;
    color: #E74C3C;
}

.settings-notice {
    font-size: 0.7rem;
    margin-top: 0.35rem;
    min-height: 1em;
}

.settings-notice.warn {
    color: #E67E22;
}

.settings-notice.ok {
    color: #27AE60;
}

/* Usage bar */
.usage-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.8rem;
    padding: 0.25rem 0.6rem;
    background: #151821;
    border: 1px solid #222;
    border-radius: 6px;
    font-size: 0.7rem;
    color: #888;
    flex-shrink: 0;
}

#usage-cost {
    color: #6cb4ee;
    font-weight: 600;
}

/* Search disabled banner */
.search-disabled-banner {
    background: #2d2517;
    border: 1px solid #5c4a20;
    color: #E67E22;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    font-size: 0.72rem;
    text-align: center;
    flex-shrink: 0;
}

/* Agents bar */
.agents-bar {
    display: flex;
    gap: 0.4rem;
    padding: 0.5rem 0;
    overflow-x: auto;
    flex-shrink: 0;
    justify-content: center;
    flex-wrap: wrap;
}

.agent-chip {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 500;
    border: 1px solid #333;
    background: #1a1d27;
    white-space: nowrap;
    transition: all 0.2s;
    cursor: pointer;
    user-select: none;
    opacity: 0.4;
}

.agent-chip.selected { opacity: 1; }
.agent-chip:hover { opacity: 0.8; }
.agent-chip.speaking { animation: pulse 1.5s ease-in-out infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.agent-avatar { font-size: 0.9rem; }

/* Main area: chat + queue side by side */
.main-area {
    flex: 1;
    display: flex;
    gap: 0.75rem;
    min-height: 0;
}

/* Chat area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.welcome-message {
    text-align: center;
    color: #666;
    margin: auto;
    font-size: 0.9rem;
}

.welcome-sub {
    font-size: 0.8rem;
    color: #555;
    margin-top: 0.3rem;
}

.round-divider {
    text-align: center;
    color: #555;
    font-size: 0.75rem;
    padding: 0.5rem 0;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.message {
    display: flex;
    gap: 0.6rem;
    padding: 0.6rem;
    border-radius: 10px;
    background: #1a1d27;
    border-left: 3px solid var(--agent-color);
}

.message.user-message {
    background: #1b2333;
    border-left-color: #6cb4ee;
}

.message-avatar { font-size: 1.3rem; flex-shrink: 0; width: 1.8rem; text-align: center; }
.message-body { flex: 1; min-width: 0; }
.message-name { font-weight: 600; font-size: 0.8rem; margin-bottom: 0.2rem; color: var(--agent-color); }

.message-content {
    font-size: 0.85rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Images & links in messages */
.msg-image {
    display: block;
    max-width: 100%;
    max-height: 350px;
    border-radius: 8px;
    margin: 0.5rem 0;
    border: 1px solid #333;
    object-fit: contain;
}

.msg-link {
    color: #6cb4ee;
    text-decoration: none;
    word-break: break-all;
}

.msg-link:hover { text-decoration: underline; }

.cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--agent-color);
    animation: blink 0.8s infinite;
    vertical-align: text-bottom;
    margin-left: 2px;
}

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

/* ── Queue Panel ── */
.queue-panel {
    width: 220px;
    flex-shrink: 0;
    background: #151821;
    border: 1px solid #222;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    padding: 0.6rem;
    gap: 0.5rem;
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.3s;
}

.queue-panel.active {
    opacity: 1;
    pointer-events: auto;
}

.queue-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.queue-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: #aaa;
}

.queue-round {
    font-size: 0.7rem;
    color: #6cb4ee;
    background: #1b2333;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
}

.queue-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-height: 60px;
    max-height: 300px;
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.4rem;
    background: #1a1d27;
    border-radius: 6px;
    border-left: 2px solid var(--q-color);
    font-size: 0.75rem;
    cursor: grab;
    transition: background 0.15s;
}

.queue-item:hover { background: #222638; }
.queue-item.dragging { opacity: 0.4; }
.queue-item.drag-over { background: #2a2f45; box-shadow: 0 0 0 1px #4A90D9; }

.q-handle {
    color: #555;
    font-size: 0.75rem;
    cursor: grab;
}

.q-avatar { font-size: 0.85rem; }
.q-name { flex: 1; color: #ccc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.q-arrows {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.q-arrow {
    background: none;
    border: none;
    color: #555;
    font-size: 0.65rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.q-arrow:hover { color: #4A90D9; }

.q-remove {
    background: none;
    border: none;
    color: #555;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0 0.15rem;
    line-height: 1;
}

.q-remove:hover { color: #E74C3C; }

.queue-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem;
}

.q-btn {
    padding: 0.35rem 0.3rem;
    font-size: 0.7rem;
    border: 1px solid #333;
    border-radius: 6px;
    background: #1a1d27;
    color: #aaa;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}

.q-btn:hover:not(:disabled) { border-color: #4A90D9; color: #e0e0e0; }
.q-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.q-play { color: #27AE60; border-color: #27AE60; }
.q-play:hover:not(:disabled) { background: #1a2e1f; border-color: #27AE60; color: #2ECC71; }

.q-next { color: #4A90D9; border-color: #4A90D9; }
.q-next:hover:not(:disabled) { background: #1a2333; }

.q-end { color: #E74C3C; border-color: #444; }
.q-end:hover:not(:disabled) { border-color: #E74C3C; background: #2d1b1b; }

.queue-add {
    display: flex;
    gap: 0.3rem;
}

.queue-add select {
    flex: 1;
    background: #1a1d27;
    color: #aaa;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 0.2rem;
    font-size: 0.7rem;
}

.q-btn-sm {
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
    border: 1px solid #333;
    border-radius: 4px;
    background: #1a1d27;
    color: #aaa;
    cursor: pointer;
}

.q-btn-sm:hover:not(:disabled) { border-color: #4A90D9; color: #e0e0e0; }
.q-btn-sm:disabled { opacity: 0.3; cursor: not-allowed; }

/* Input area */
.input-area {
    flex-shrink: 0;
    padding: 0.75rem 0;
    border-top: 1px solid #222;
}

.controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
    font-size: 0.8rem;
    color: #888;
    flex-wrap: wrap;
}

.file-upload-btn {
    padding: 0.2rem 0.5rem;
    background: #1a1d27;
    border: 1px solid #333;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    color: #aaa;
    transition: border-color 0.2s;
}

.file-upload-btn:hover { border-color: #4A90D9; color: #e0e0e0; }

.file-status { font-size: 0.75rem; color: #6cb4ee; }

.icon-btn {
    padding: 0.2rem 0.5rem;
    background: #1a1d27;
    border: 1px solid #333;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    color: #aaa;
    transition: border-color 0.2s;
}

.icon-btn:hover:not(:disabled) { border-color: #4A90D9; color: #e0e0e0; }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.input-row {
    display: flex;
    gap: 0.5rem;
}

#topic-input {
    flex: 1;
    padding: 0.6rem 0.8rem;
    border: 1px solid #333;
    border-radius: 8px;
    background: #1a1d27;
    color: #e0e0e0;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

#topic-input:focus { border-color: #4A90D9; }

#submit-btn {
    padding: 0.6rem 1.2rem;
    background: linear-gradient(135deg, #4A90D9, #9B59B6);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    min-width: 80px;
}

#submit-btn:hover { opacity: 0.9; }
#submit-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Error */
.error-message {
    background: #2d1b1b;
    border: 1px solid #5c2020;
    color: #f08080;
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    font-size: 0.85rem;
    text-align: center;
}

/* Scrollbar */
.chat-area::-webkit-scrollbar, .queue-list::-webkit-scrollbar { width: 5px; }
.chat-area::-webkit-scrollbar-track, .queue-list::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb, .queue-list::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

/* ── Queue toggle button (mobile only) ── */
.queue-toggle {
    display: none;
}

/* ── Responsive: mobile layout ── */
@media (max-width: 700px) {
    .container {
        padding: 0.5rem;
    }

    header { padding: 0.4rem 0; }
    header h1 { font-size: 1.2rem; }
    .subtitle { font-size: 0.75rem; }

    /* Settings panel: stack labels above inputs on mobile */
    .settings-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.2rem;
    }
    .settings-row label { min-width: unset; }
    .settings-row input,
    .settings-row select { font-size: 16px; min-height: 40px; }

    /* Agents bar: horizontal scroll, larger tap targets */
    .agents-bar {
        flex-wrap: nowrap;
        justify-content: flex-start;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0.4rem 0;
        gap: 0.35rem;
        scrollbar-width: none;
    }
    .agents-bar::-webkit-scrollbar { display: none; }

    .agent-chip {
        padding: 0.4rem 0.7rem;
        font-size: 0.7rem;
        min-height: 36px;
        flex-shrink: 0;
    }

    /* Main area: stack vertically */
    .main-area {
        flex-direction: column;
        gap: 0;
    }

    /* Chat area fills available space */
    .chat-area {
        flex: 1;
        padding: 0.5rem 0;
        min-height: 0;
    }

    .message {
        padding: 0.5rem;
        gap: 0.4rem;
    }
    .message-avatar { font-size: 1.1rem; width: 1.5rem; }
    .message-content { font-size: 0.82rem; }

    /* Queue toggle: visible on mobile */
    .queue-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.3rem;
        width: 100%;
        padding: 0.5rem;
        background: #151821;
        border: 1px solid #222;
        border-radius: 8px;
        color: #aaa;
        font-size: 0.75rem;
        font-weight: 600;
        cursor: pointer;
        min-height: 40px;
        flex-shrink: 0;
        order: -1;
    }
    .queue-toggle:hover { border-color: #4A90D9; color: #e0e0e0; }

    /* Queue panel: normal-flow collapsible (not absolute) */
    .queue-panel {
        width: 100%;
        position: static;
        max-height: 0;
        overflow: hidden;
        border-radius: 0 0 10px 10px;
        padding: 0 0.6rem;
        opacity: 1;
        pointer-events: none;
        transition: max-height 0.3s ease, padding 0.3s ease;
        flex-shrink: 0;
        order: -1;
    }

    .queue-panel.active {
        pointer-events: auto;
    }

    .queue-panel.mobile-open {
        max-height: 300px;
        padding: 0.6rem;
        pointer-events: auto;
        margin-bottom: 0.4rem;
    }

    .queue-list { max-height: 100px; }

    .queue-actions {
        grid-template-columns: repeat(3, 1fr);
    }

    .q-btn {
        min-height: 38px;
        font-size: 0.72rem;
    }

    /* Input area: mobile-friendly */
    .input-area {
        padding: 0.5rem 0;
    }

    .controls {
        gap: 0.35rem;
        margin-bottom: 0.35rem;
    }

    .file-upload-btn, .icon-btn {
        min-height: 36px;
        display: flex;
        align-items: center;
        padding: 0.3rem 0.5rem;
        font-size: 0.72rem;
    }

    .input-row {
        gap: 0.4rem;
    }

    #topic-input {
        font-size: 16px; /* prevents iOS zoom on focus */
        padding: 0.55rem 0.7rem;
        min-height: 44px;
    }

    #submit-btn {
        min-height: 44px;
        min-width: 70px;
        padding: 0.55rem 0.8rem;
        font-size: 0.85rem;
    }
}
