/* ==========================================
   Chat Switchboard — Preact ChatPane Kit CSS
   ==========================================
   v0.37.8: Styles for the composable ChatPane kit.
   sw- prefixed, no conflicts with legacy chat-pane.css.
   ========================================== */

/* ── Container ─────────────────────────────── */

.sw-chat-pane {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: var(--bg, #0e0e10);
}

/* ── Header Bar (standalone mode) ──────────── */

.sw-chat-pane__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border, #2a2a2e);
    background: var(--bg-secondary, #151517);
    flex-shrink: 0;
    min-height: 36px;
}

.sw-chat-pane__header-left {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.sw-chat-pane__header-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* ── Chat History Select ──────────────────── */

.sw-chat-history__select {
    flex: 1;
    min-width: 0;
    background: var(--bg, #0e0e10);
    border: 1px solid var(--border, #2a2a2e);
    border-radius: 4px;
    color: var(--text, #eee);
    font-size: 11px;
    font-family: inherit;
    padding: 4px 6px;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sw-chat-history__select:focus {
    border-color: var(--accent, #b38a4e);
    outline: none;
}

.sw-chat-history__new-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: none;
    border: 1px solid var(--border, #2a2a2e);
    border-radius: 4px;
    color: var(--text-2, #999);
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.sw-chat-history__new-btn:hover {
    color: var(--accent, #b38a4e);
    border-color: var(--accent, #b38a4e);
    background: var(--accent-dim, rgba(179, 138, 78, 0.1));
}

/* ── Model Selector ───────────────────────── */

.sw-model-selector__select {
    background: var(--bg, #0e0e10);
    border: 1px solid var(--border, #2a2a2e);
    border-radius: 4px;
    color: var(--text-2, #999);
    font-size: 11px;
    font-family: inherit;
    padding: 4px 6px;
    cursor: pointer;
    min-width: 100px;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sw-model-selector__select:disabled {
    opacity: 0.5;
    cursor: default;
}

.sw-model-selector__select:focus {
    border-color: var(--accent, #b38a4e);
    outline: none;
    color: var(--text, #eee);
}

/* ── Messages Area ─────────────────────────── */

.sw-chat-pane__messages {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    padding: 12px 0;
    min-height: 0;
}

/* ── Message Bubbles ───────────────────────── */

.sw-chat-msg {
    padding: 8px 16px;
    font-size: var(--msg-font, 14px);
    line-height: 1.65;
    color: var(--text, #eee);
}

.sw-chat-msg + .sw-chat-msg {
    margin-top: 2px;
}

/* User messages — right-aligned bubble */
.sw-chat-msg--user {
    display: flex;
    justify-content: flex-end;
    padding: 8px 16px;
}

.sw-chat-msg--user .sw-chat-msg__content {
    background: var(--accent-dim, rgba(179, 138, 78, 0.15));
    color: var(--text, #eee);
    padding: 8px 14px;
    border-radius: 12px 12px 2px 12px;
    max-width: 85%;
    word-wrap: break-word;
}

/* Other user messages — left-aligned bubble */
.sw-chat-msg--other {
    padding: 8px 16px;
}

.sw-chat-msg--other .sw-chat-msg__content {
    background: var(--bg-2, #1a1a1e);
    color: var(--text, #eee);
    padding: 8px 14px;
    border-radius: 12px 12px 12px 2px;
    max-width: 85%;
    word-wrap: break-word;
}

.sw-chat-msg__sender {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3, #555);
    margin-bottom: 2px;
    padding-left: 2px;
}

/* ── @Mention highlights in rendered messages ─ */

.sw-mention {
    color: var(--accent, #6366f1);
    background: rgba(var(--accent-rgb, 99, 102, 241), 0.1);
    border-radius: 3px;
    padding: 0 3px;
    font-weight: 500;
}

/* ── Typing Indicator ─────────────────────── */

.sw-typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 16px;
    font-size: 12px;
    color: var(--text-3, #888);
    min-height: 22px;
}

.sw-typing-indicator__dots {
    display: flex;
    gap: 3px;
}

.sw-typing-indicator__dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text-3, #888);
    animation: sw-typing-bounce 1.4s infinite ease-in-out both;
}

.sw-typing-indicator__dot:nth-child(1) { animation-delay: 0s; }
.sw-typing-indicator__dot:nth-child(2) { animation-delay: 0.16s; }
.sw-typing-indicator__dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes sw-typing-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Assistant messages — left-aligned */
.sw-chat-msg--assistant {
    padding: 8px 16px;
}

.sw-chat-msg--assistant .sw-chat-msg__content {
    max-width: 100%;
    word-wrap: break-word;
}

/* System/error messages */
.sw-chat-msg--system {
    padding: 6px 16px;
    font-size: 12px;
}

.sw-chat-msg--system .sw-chat-msg__content {
    color: var(--danger, #f44336);
    font-size: 12px;
}

/* ── Streaming indicator ───────────────────── */

.sw-chat-msg--streaming .sw-chat-msg__content::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 14px;
    background: var(--accent, #b38a4e);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: sw-cursor-blink 0.8s step-end infinite;
}

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

/* ── Typing dots ───────────────────────────── */

.sw-chat-msg--typing {
    padding: 8px 16px;
}

.sw-chat-msg--typing .sw-typing-dots {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.sw-chat-msg--typing .sw-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-3, #555);
    animation: sw-dot-bounce 1.2s ease-in-out infinite;
}

.sw-chat-msg--typing .sw-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.sw-chat-msg--typing .sw-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

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

/* ── Markdown content ──────────────────────── */

.sw-chat-msg__content p { margin: 0 0 0.5em; }
.sw-chat-msg__content p:last-child { margin-bottom: 0; }

.sw-chat-msg__content pre {
    background: var(--bg-secondary, #151517);
    border: 1px solid var(--border, #2a2a2e);
    border-radius: 6px;
    padding: 10px 12px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 12px;
    line-height: 1.5;
    font-family: var(--mono, 'SF Mono', monospace);
}

.sw-chat-msg__content code {
    background: var(--bg-secondary, #151517);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.88em;
    font-family: var(--mono, 'SF Mono', monospace);
}

.sw-chat-msg__content pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

.sw-chat-msg__content ul, .sw-chat-msg__content ol {
    margin: 4px 0;
    padding-left: 1.5em;
}

.sw-chat-msg__content blockquote {
    border-left: 3px solid var(--accent, #b38a4e);
    padding: 4px 12px;
    margin: 8px 0;
    color: var(--text-2, #999);
}

.sw-chat-msg__content a {
    color: var(--accent, #b38a4e);
    text-decoration: none;
}

.sw-chat-msg__content a:hover {
    text-decoration: underline;
}

.sw-chat-msg__content table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 13px;
}

.sw-chat-msg__content th,
.sw-chat-msg__content td {
    border: 1px solid var(--border, #2a2a2e);
    padding: 4px 8px;
}

.sw-chat-msg__content th {
    background: var(--bg-secondary, #151517);
    font-weight: 600;
}

/* ── Welcome / Empty State ─────────────────── */

.sw-chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px 20px;
    opacity: 0.6;
}

.sw-chat-welcome__title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text, #eee);
    margin: 0 0 6px;
}

.sw-chat-welcome__hint {
    font-size: 13px;
    color: var(--text-3, #555);
    margin: 0;
}

/* ── Input Bar ─────────────────────────────── */

.sw-chat-pane__input-bar {
    flex-shrink: 0;
    border-top: 1px solid var(--border, #2a2a2e);
    background: var(--bg-secondary, #151517);
    padding: 8px 12px;
}

.sw-msg-input__wrap {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    background: var(--bg, #0e0e10);
    border: 1px solid var(--border, #2a2a2e);
    border-radius: 8px;
    padding: 6px 8px;
    transition: border-color 0.15s;
}

.sw-msg-input__wrap:focus-within {
    border-color: var(--accent, #b38a4e);
}

.sw-msg-input__textarea {
    flex: 1;
    min-height: 20px;
    max-height: 160px;
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text, #eee);
    font-size: 13px;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    outline: none;
    padding: 0;
}

/* ── Send Button ───────────────────────────── */

.sw-msg-input__send {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--accent, #b38a4e);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.sw-msg-input__send:hover {
    background: var(--accent-dim, rgba(179, 138, 78, 0.15));
    color: var(--accent-hover, #c9a05e);
}

.sw-msg-input__send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ── Stop Button ──────────────────────────── */

.sw-msg-input__stop {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--danger, #f44336);
    cursor: pointer;
    transition: background 0.15s;
}

.sw-msg-input__stop:hover {
    background: rgba(244, 67, 54, 0.1);
}

/* ── Input Buttons Row ────────────────────── */

.sw-msg-input__buttons {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

/* ── Emoji Button + Picker ────────────────── */

.sw-msg-input__emoji-wrap {
    position: relative;
}

.sw-msg-input__emoji-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--text-3, #555);
    cursor: pointer;
    transition: color 0.15s;
}

.sw-msg-input__emoji-btn:hover {
    color: var(--text-2, #999);
}

.sw-emoji-picker {
    position: absolute;
    bottom: 40px;
    right: 0;
    width: 320px;
    max-height: 360px;
    background: var(--bg-secondary, #151517);
    border: 1px solid var(--border, #2a2a2e);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sw-emoji-picker__tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border, #2a2a2e);
    padding: 4px 4px 0;
    flex-shrink: 0;
}

.sw-emoji-picker__tab {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 6px 4px;
    font-size: 16px;
    cursor: pointer;
    transition: border-color 0.15s;
    line-height: 1;
}

.sw-emoji-picker__tab--active {
    border-bottom-color: var(--accent, #b38a4e);
}

.sw-emoji-picker__search {
    margin: 6px 8px;
    padding: 6px 10px;
    background: var(--bg, #0e0e10);
    border: 1px solid var(--border, #2a2a2e);
    border-radius: 6px;
    color: var(--text, #eee);
    font-size: 12px;
    font-family: inherit;
    outline: none;
    flex-shrink: 0;
}

.sw-emoji-picker__search:focus {
    border-color: var(--accent, #b38a4e);
}

.sw-emoji-picker__grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 6px 8px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.sw-emoji-picker__emoji {
    width: 100%;
    aspect-ratio: 1;
    background: none;
    border: none;
    border-radius: 6px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s;
    line-height: 1;
    padding: 0;
}

.sw-emoji-picker__emoji:hover {
    background: var(--bg, #0e0e10);
}

.sw-emoji-picker__empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 20px;
    color: var(--text-3, #555);
    font-size: 12px;
}

/* ── CM6 Chat Input ──────────────────────── */

.sw-msg-input__cm-container {
    flex: 1;
    min-width: 0;
}

.sw-msg-input__cm-container .cm-editor {
    font-size: 14px;
    line-height: 1.5;
    max-height: 160px;
    overflow-y: auto;
}

.sw-msg-input__cm-container .cm-editor.cm-focused {
    outline: none;
}

/* ── Error Banner ─────────────────────────── */

.sw-chat-pane__error {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(244, 67, 54, 0.1);
    border-bottom: 1px solid rgba(244, 67, 54, 0.2);
    color: var(--danger, #f44336);
    font-size: 12px;
    flex-shrink: 0;
}

.sw-chat-pane__error-text {
    flex: 1;
    min-width: 0;
}

.sw-chat-pane__error-dismiss {
    background: none;
    border: none;
    color: var(--danger, #f44336);
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.7;
}

.sw-chat-pane__error-dismiss:hover {
    opacity: 1;
}

/* ── Load More ────────────────────────────── */

.sw-chat-pane__load-more {
    text-align: center;
    padding: 8px;
}

.sw-chat-pane__load-more-btn {
    background: none;
    border: 1px solid var(--border, #2a2a2e);
    border-radius: 6px;
    color: var(--text-2, #999);
    font-size: 12px;
    padding: 6px 16px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.sw-chat-pane__load-more-btn:hover {
    border-color: var(--accent, #b38a4e);
    color: var(--text, #eee);
}

.sw-chat-pane__load-more-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Message Footer (time + actions) ──────── */

.sw-chat-msg__footer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}

.sw-chat-msg:hover .sw-chat-msg__footer {
    opacity: 1;
}

.sw-chat-msg__time {
    font-size: 10px;
    color: var(--text-3, #555);
}

/* ── Message Actions Toolbar ──────────────── */

.sw-chat-msg__actions {
    display: flex;
    gap: 2px;
}

.sw-chat-msg__action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: none;
    border: none;
    border-radius: 4px;
    color: var(--text-3, #555);
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    padding: 0;
}

.sw-chat-msg__action-btn:hover {
    color: var(--text, #eee);
    background: var(--bg-secondary, #151517);
}

.sw-chat-msg__action-btn--danger:hover {
    color: var(--danger, #f44336);
}

/* ── Code Block ───────────────────────────── */

.sw-code-block {
    position: relative;
    margin: 8px 0;
    border: 1px solid var(--border, #2a2a2e);
    border-radius: 6px;
    overflow: hidden;
}

.sw-code-block__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    background: var(--bg, #0e0e10);
    border-bottom: 1px solid var(--border, #2a2a2e);
    min-height: 28px;
}

.sw-code-block__lang {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3, #555);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: var(--mono, 'SF Mono', monospace);
}

.sw-code-block__copy {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text-3, #555);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
    margin-left: auto;
}

.sw-code-block__copy:hover {
    color: var(--text, #eee);
    background: var(--bg-secondary, #151517);
}

.sw-code-block__copy-text {
    font-family: inherit;
}

.sw-code-block__pre {
    background: var(--bg-secondary, #151517);
    padding: 10px 12px;
    overflow-x: auto;
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
    font-family: var(--mono, 'SF Mono', monospace);
}

.sw-code-block__pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
    font-family: inherit;
}

/* ── Task List Checkboxes ─────────────────── */

.sw-task-item {
    list-style: none;
    margin-left: -1.5em;
}

.sw-task-checkbox {
    margin-right: 6px;
    vertical-align: middle;
    accent-color: var(--accent, #b38a4e);
}

/* ── Thinking / Reasoning Blocks ────────── */

.sw-chat-msg__thinking {
    margin-bottom: 8px;
    border-left: 3px solid var(--border, rgba(255,255,255,0.1));
    border-radius: 4px;
    font-size: 0.85em;
    color: var(--text-muted, #888);
}

.sw-chat-msg__thinking-toggle {
    cursor: pointer;
    padding: 6px 10px;
    user-select: none;
    font-weight: 500;
    opacity: 0.7;
}

.sw-chat-msg__thinking-toggle:hover { opacity: 1; }

.sw-chat-msg__thinking[open] .sw-chat-msg__thinking-toggle {
    border-bottom: 1px solid var(--border, rgba(255,255,255,0.06));
    margin-bottom: 4px;
}

.sw-chat-msg__thinking-content {
    padding: 6px 10px 10px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}
