  /* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(37, 99, 235, 0.06), transparent 55%),
        radial-gradient(900px 500px at 100% 0%, rgba(17, 24, 39, 0.04), transparent 50%),
        #ffffff;
    color: #111827;
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    overflow: hidden;
}

.font-ibm-plex {
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
}

/* App Container — fill viewport; chat column scrolls independently */
.app-container {
    height: 100%;
    max-height: inherit;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(255, 255, 255, 0.92) 100%);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid #e5e7eb;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.header-content {
    max-width: 1024px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-brand {
    min-width: 0;
    flex: 1;
}

.header-lockup {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}

.header-mark {
    flex-shrink: 0;
    border-radius: 10px;
    box-shadow: 0 4px 14px rgba(17, 24, 39, 0.12);
}

.header-mark svg {
    display: block;
}

.header-titles {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.header-title {
    color: #111827;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.02em;
}

.header-tagline {
    color: #6b7280;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.45;
    max-width: 36rem;
}

.clear-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #6b7280;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.clear-btn:hover {
    background: #f3f4f6;
    color: #111827;
}

/* Chat Container */
.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
}

.messages-area {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.messages-content {
    max-width: 1024px;
    margin: 0 auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    text-align: left;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 8px 0 24px;
    gap: 20px;
}

.welcome-intro {
    text-align: center;
}

.welcome-kicker {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #2563eb;
    margin-bottom: 8px;
}

.welcome-title {
    color: #111827;
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 12px;
    line-height: 1.35;
    letter-spacing: -0.02em;
}

.welcome-lead {
    color: #4b5563;
    font-size: 14px;
    line-height: 1.65;
    max-width: 52rem;
    margin: 0 auto;
}

.welcome-lead code {
    font-size: 13px;
    background: #f3f4f6;
    padding: 1px 6px;
    border-radius: 4px;
}

.welcome-badges {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 18px auto 0;
    padding: 0;
    max-width: 52rem;
}

.welcome-badges li {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #1e40af;
    background: linear-gradient(180deg, #eff6ff 0%, #dbeafe 100%);
    border: 1px solid #bfdbfe;
    padding: 6px 12px;
    border-radius: 999px;
}

.welcome-diagram-card {
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
}

.welcome-diagram-inner {
    border-radius: 14px;
    border: 1px solid #e5e7eb;
    background: linear-gradient(165deg, #ffffff 0%, #f9fafb 55%, #f3f4f6 100%);
    box-shadow:
        0 1px 2px rgba(17, 24, 39, 0.04),
        0 12px 40px rgba(17, 24, 39, 0.08);
    padding: 16px 20px;
    overflow: hidden;
}

.welcome-diagram-card img {
    display: block;
    width: 100%;
    height: auto;
    max-height: min(360px, 42vh);
    object-fit: contain;
}

.welcome-diagram-caption {
    margin-top: 10px;
    text-align: center;
    font-size: 12px;
    line-height: 1.5;
    color: #6b7280;
    max-width: 44rem;
    margin-left: auto;
    margin-right: auto;
    padding: 0 8px;
}

.welcome-starters-label {
    margin-top: 18px;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #9ca3af;
}

.welcome-starters {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    max-width: 44rem;
    margin: 0 auto;
}

.starter-chip {
    appearance: none;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: #1e3a8a;
    background: #ffffff;
    border: 1px solid #c7d2fe;
    border-radius: 999px;
    padding: 8px 14px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.starter-chip:hover {
    background: #eef2ff;
    border-color: #a5b4fc;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
}

.starter-chip:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.welcome-modes {
    text-align: center;
}

.welcome-subtitle {
    font-size: 15px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 8px;
}

.welcome-text {
    color: #6b7280;
    max-width: 40rem;
    margin: 0 auto;
    font-size: 14px;
    line-height: 1.6;
}

.welcome-text code {
    font-size: 13px;
    background: #f3f4f6;
    padding: 1px 5px;
    border-radius: 4px;
}

/* Footer */
.site-footer {
    flex-shrink: 0;
    border-top: 1px solid #e5e7eb;
    background: #fafafa;
    padding: 12px 24px;
    text-align: center;
}

.footer-line {
    font-size: 12px;
    color: #6b7280;
    line-height: 1.5;
}

.footer-stack {
    margin-top: 6px;
    font-size: 11px;
    color: #9ca3af;
    letter-spacing: 0.04em;
}

.site-footer a {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
}

.site-footer a:hover {
    text-decoration: underline;
}

/* Messages Container */
.messages-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Message Styles */
.message {
    display: flex;
    width: 100%;
}

.message.user {
    justify-content: flex-end;
}

.message.ai {
    justify-content: flex-start;
}

.message-wrapper {
    max-width: 512px;
    display: flex;
    flex-direction: column;
}

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

.message.ai .message-wrapper {
    align-items: flex-start;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.message.user .message-header {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: #111827;
    border-color: #111827;
    color: #ffffff;
}

.message.ai .message-avatar {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #6b7280;
}

.message-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.message.user .message-info {
    flex-direction: row-reverse;
}

.message-sender {
    color: #6b7280;
    font-size: 14px;
    font-weight: 500;
}

.message-model {
    background: #f3f4f6;
    color: #6b7280;
    border: 1px solid #e5e7eb;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 400;
}

.message-bubble {
    border-radius: 12px;
    padding: 12px 16px;
    word-wrap: break-word;
    max-width: 100%;
}

.message.user .message-bubble {
    background: #111827;
    color: #ffffff;
}

.message.ai .message-bubble {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    color: #111827;
}

.message-text {
    white-space: pre-wrap;
    word-break: break-words;
    font-size: 14px;
    line-height: 1.6;
}

.message-status-chip {
    margin-top: 10px;
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #ffffff;
    color: #4b5563;
    font-size: 12px;
    line-height: 1.4;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.message-status-meta {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: #6b7280;
    font-size: 12px;
    line-height: 1.35;
}

.message-status-chip.status-connected {
    border-color: #86efac;
    background: #f0fdf4;
    color: #166534;
}

.message-status-meta.status-connected {
    color: #166534;
}

.message-status-chip.status-warning {
    border-color: #fcd34d;
    background: #fffbeb;
    color: #92400e;
}

.message-status-meta.status-warning {
    color: #92400e;
}

.message-status-chip.status-disconnected {
    border-color: #fca5a5;
    background: #fef2f2;
    color: #991b1b;
}

.message-status-meta.status-disconnected {
    color: #991b1b;
}

.message-status-chip.status-unknown {
    border-color: #d1d5db;
    background: #f9fafb;
    color: #4b5563;
}

.message-status-meta.status-unknown {
    color: #6b7280;
}

.message-footer {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 4px;
    font-size: 12px;
    color: #9ca3af;
}

.message.user .message-footer {
    justify-content: flex-end;
}

.message.ai .message-footer {
    justify-content: flex-start;
}

/* Loading Indicator */
.loading-indicator {
    display: flex;
    justify-content: flex-start;
}

.loading-bubble {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 32px;
    padding: 24px;
    max-width: 320px;
}

.loading-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.dot {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

.dot:nth-child(2) {
    animation-delay: 0.2s;
}

.dot:nth-child(3) {
    animation-delay: 0.4s;
}

.loading-text {
    color: #6b7280;
    font-size: 14px;
}

@keyframes pulse {
    0%, 80%, 100% {
        opacity: 0.3;
    }
    40% {
        opacity: 1;
    }
}

/* Input Area */
.input-area {
    border-top: 1px solid #e5e7eb;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(16px);
}

.input-content {
    max-width: 1024px;
    margin: 0 auto;
    padding: 16px 24px;
}

.chat-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.model-section {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.model-label {
    color: #6b7280;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.mode-segmented {
    display: inline-flex;
    border-radius: 10px;
    padding: 3px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    gap: 2px;
}

.mode-segment {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 108px;
    padding: 8px 14px 6px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #6b7280;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.mode-segment-hint {
    display: block;
    margin-top: 2px;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: #9ca3af;
}

.mode-segment-active {
    background: #ffffff;
    color: #111827;
    box-shadow: 0 1px 3px rgba(17, 24, 39, 0.08);
}

.mode-segment-active .mode-segment-hint {
    color: #6b7280;
}

.mode-segment:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.mode-segment:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.live-disabled-hint {
    padding: 0 0 4px;
    margin: 0;
    font-size: 13px;
    color: #6b7280;
    line-height: 1.5;
}

.live-disabled-hint code {
    font-size: 12px;
    background: #f3f4f6;
    padding: 1px 5px;
    border-radius: 4px;
}

.input-section {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.textarea-container {
    flex: 1;
    position: relative;
}

.message-textarea {
    width: 100%;
    min-height: 44px;
    max-height: 128px;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 12px 16px;
    color: #111827;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    resize: vertical;
    outline: none;
    transition: all 0.2s ease;
}

.message-textarea::placeholder {
    color: #9ca3af;
}

.message-textarea:focus {
    border-color: #9ca3af;
    box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.1);
}

.message-textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #f9fafb;
}

.send-button {
    height: 44px;
    width: 44px;
    background: #111827;
    border: none;
    border-radius: 8px;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    position: relative;
}

.send-button:hover:not(:disabled) {
    background: #1f2937;
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.loading-spinner {
    position: absolute;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Scrollbar Styling */
.messages-area::-webkit-scrollbar {
    width: 6px;
}

.messages-area::-webkit-scrollbar-track {
    background: transparent;
}

.messages-area::-webkit-scrollbar-thumb {
    background: #e5e7eb;
    border-radius: 3px;
}

.messages-area::-webkit-scrollbar-thumb:hover {
    background: #d1d5db;
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-content {
        padding: 16px;
    }
    
    .messages-content {
        padding: 16px;
        gap: 20px;
    }
    
    .message-wrapper {
        max-width: 85%;
    }
    
    .input-content {
        padding: 16px;
    }
    
    .chat-form {
        gap: 10px;
    }
    
    .model-section {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .mode-segmented {
        width: 100%;
    }

    .mode-segment {
        flex: 1;
        min-width: 0;
    }
}

@media (max-width: 480px) {
    .header-lockup {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-title {
        font-size: 16px;
    }
    
    .welcome-title {
        font-size: 18px;
    }
    
    .message-wrapper {
        max-width: 90%;
    }
    
    .message-bubble {
        padding: 10px 12px;
    }
    
    .header-content {
        padding: 12px;
    }
    
    .messages-content {
        padding: 12px;
    }
    
    .input-content {
        padding: 12px;
    }
}