/* ===========================================
   PRIMORDIA CHAT V2 - Modern AI Chat Interface
   Dark theme with Primordia gold accents
   =========================================== */

/* CSS Variables - Primordia Gold & Black Theme */
:root {
    --chat-bg: #0a0a0a;
    --chat-surface: #111111;
    --chat-surface-hover: #1a1a1a;
    --chat-border: rgba(227, 179, 65, 0.2);
    --chat-accent: #E3B341;
    --chat-accent-hover: #d4af37;
    --chat-accent-glow: rgba(227, 179, 65, 0.3);
    --chat-gold: #E3B341;
    --chat-gold-dark: #c9a03a;
    --chat-gold-glow: rgba(227, 179, 65, 0.25);
    --chat-text: #f5f5f5;
    --chat-text-muted: #a0a0a0;
    --chat-text-dim: #666666;
    --chat-user-bg: linear-gradient(135deg, #E3B341 0%, #c9a03a 100%);
    --chat-ai-bg: linear-gradient(135deg, #1a1a1a 0%, #222222 100%);
    --chat-success: #10b981;
    --chat-warning: #E3B341;
    --chat-error: #ef4444;
    --chat-radius: 12px;
    --chat-radius-lg: 16px;
    --chat-transition: all 0.2s ease;
}

/* Base Reset */
.chat-app * {
    box-sizing: border-box;
}

/* Navigation Header Override */
.chat-nav-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--chat-border);
}

.chat-nav-header .nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-nav-header .nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-nav-header .brand-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--chat-gold);
    text-decoration: none;
}

.chat-nav-header .version-badge {
    font-size: 0.625rem;
    padding: 2px 6px;
    background: var(--chat-gold);
    color: #0a0a0a;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
}

.chat-nav-header .nav-links {
    display: flex;
    gap: 2rem;
}

.chat-nav-header .nav-link {
    color: var(--chat-text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: color 0.2s;
}

.chat-nav-header .nav-link:hover,
.chat-nav-header .nav-link.active {
    color: var(--chat-gold);
}

.chat-nav-header .nav-actions {
    display: flex;
    gap: 0.75rem;
}

.chat-nav-header .btn-secondary {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--chat-border);
    border-radius: 6px;
    color: var(--chat-text);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.chat-nav-header .btn-secondary:hover {
    border-color: var(--chat-gold);
    color: var(--chat-gold);
}

.chat-nav-header .btn-primary {
    padding: 0.5rem 1rem;
    background: var(--chat-gold);
    border: none;
    border-radius: 6px;
    color: #0a0a0a;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 600;
    transition: all 0.2s;
}

.chat-nav-header .btn-primary:hover {
    background: var(--chat-gold-dark);
}

.chat-nav-header .mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--chat-text);
    cursor: pointer;
    padding: 0.5rem;
}

@media (max-width: 900px) {
    .chat-nav-header .nav-links {
        display: none;
    }
    .chat-nav-header .nav-actions {
        display: none;
    }
    .chat-nav-header .mobile-menu-btn {
        display: block;
    }
}

/* Main Container */
.chat-app {
    display: flex;
    height: calc(100vh - 60px);
    margin-top: 60px;
    background: var(--chat-bg);
    color: var(--chat-text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    overflow: hidden;
}

/* ===========================================
   SIDEBAR STYLES
   =========================================== */
.chat-sidebar {
    width: 280px;
    background: var(--chat-surface);
    border-right: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    transition: var(--chat-transition);
}

.chat-sidebar.collapsed {
    width: 0;
    overflow: hidden;
    border-right: none;
}

/* Sidebar Section Header */
.sidebar-section-header {
    padding: 16px;
    border-bottom: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-section-header h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--chat-text);
    margin: 0;
}

.new-chat-btn {
    padding: 6px 12px;
    background: var(--chat-gold);
    border: none;
    border-radius: 6px;
    color: #0a0a0a;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: var(--chat-transition);
}

.new-chat-btn:hover {
    background: var(--chat-gold-dark);
}

/* Conversation List */
.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-item {
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--chat-transition);
    margin-bottom: 4px;
}

.conversation-item:hover {
    background: var(--chat-surface-hover);
}

.conversation-item.active {
    background: rgba(227, 179, 65, 0.15);
    border-left: 3px solid var(--chat-gold);
}

.conversation-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--chat-text);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-preview {
    font-size: 11px;
    color: var(--chat-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 10px;
    color: var(--chat-text-dim);
    margin-top: 4px;
}

.conversation-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--chat-text-muted);
}

.conversation-empty p {
    margin: 0 0 8px 0;
    font-size: 13px;
}

.conversation-empty .hint {
    font-size: 11px;
    color: var(--chat-text-dim);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--chat-border);
}

.login-prompt {
    text-align: center;
}

.login-prompt p {
    font-size: 12px;
    color: var(--chat-text-muted);
    margin: 0 0 12px 0;
}

.sidebar-login-btn {
    display: inline-block;
    padding: 8px 20px;
    background: var(--chat-gold);
    border-radius: 6px;
    color: #0a0a0a;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: var(--chat-transition);
}

.sidebar-login-btn:hover {
    background: var(--chat-gold-dark);
}

.sidebar-signin-link {
    display: block;
    margin-top: 10px;
    font-size: 11px;
    color: var(--chat-text-muted);
    text-decoration: none;
    transition: var(--chat-transition);
}

.sidebar-signin-link:hover {
    color: var(--chat-gold);
}

/* Simulon Preview Widget */
.simulon-preview {
    margin: 1rem;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(99, 102, 241, 0.1));
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 12px;
    overflow: hidden;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.simulon-preview-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(139, 92, 246, 0.2);
    border-bottom: 1px solid rgba(139, 92, 246, 0.2);
}

.simulon-icon {
    font-size: 1.2rem;
}

.simulon-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: #a78bfa;
}

.preview-badge {
    margin-left: auto;
    font-size: 0.65rem;
    padding: 0.2rem 0.5rem;
    background: rgba(139, 92, 246, 0.3);
    border-radius: 4px;
    color: #c4b5fd;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.simulon-predictions-list {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
}

.simulon-prediction-item {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 0.6rem;
    border-left: 3px solid #8b5cf6;
}

.prediction-question {
    font-size: 0.75rem;
    color: var(--chat-text);
    margin-bottom: 0.5rem;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.probability-bar-container {
    position: relative;
    height: 18px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.25rem;
}

.probability-bar {
    height: 100%;
    background: linear-gradient(90deg, #8b5cf6, #6366f1);
    border-radius: 4px;
    transition: width 0.8s ease-out;
}

.probability-value {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-weight: 700;
    font-size: 0.7rem;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.prediction-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.6rem;
    color: var(--chat-text-muted);
}

.confidence-value {
    color: #10b981;
    font-weight: 600;
}

.simulon-cta {
    text-align: center;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(139, 92, 246, 0.2);
}

.simulon-cta p {
    font-size: 0.7rem;
    color: var(--chat-text-muted);
    margin-bottom: 0.5rem;
}

.simulon-upgrade-btn {
    display: inline-block;
    padding: 0.4rem 1rem;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    transition: all 0.2s;
}

.simulon-upgrade-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--chat-gold);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: #0a0a0a;
}

.user-details {
    flex: 1;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--chat-text);
}

.user-plan {
    font-size: 11px;
    color: var(--chat-text-muted);
}

/* ===========================================
   MAIN CHAT AREA
   =========================================== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Chat Header */
.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--chat-surface);
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle-sidebar-btn {
    width: 36px;
    height: 36px;
    background: var(--chat-surface-hover);
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    color: var(--chat-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
}

.toggle-sidebar-btn:hover {
    background: var(--chat-accent);
    color: white;
    border-color: var(--chat-accent);
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--chat-text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--chat-success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-btn {
    padding: 8px 12px;
    background: var(--chat-surface-hover);
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    color: var(--chat-text-muted);
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: var(--chat-transition);
}

.header-btn:hover {
    background: var(--chat-accent);
    color: white;
    border-color: var(--chat-accent);
}

.header-btn.danger:hover {
    background: var(--chat-error);
    border-color: var(--chat-error);
}

/* Messages Container */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--chat-border);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--chat-text-dim);
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 12px;
    max-width: 80%;
    animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.ai {
    align-self: flex-start;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.message.user .message-avatar {
    background: var(--chat-user-bg);
}

.message.ai .message-avatar {
    background: linear-gradient(135deg, var(--chat-gold), var(--chat-gold-dark));
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-bubble {
    padding: 14px 18px;
    border-radius: var(--chat-radius-lg);
    line-height: 1.6;
    font-size: 14px;
}

.message.user .message-bubble {
    background: var(--chat-user-bg);
    border-bottom-right-radius: 4px;
}

.message.ai .message-bubble {
    background: var(--chat-ai-bg);
    border: 1px solid var(--chat-border);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: var(--chat-text-dim);
    padding: 0 4px;
}

.message.user .message-time {
    text-align: right;
}

/* Code Blocks in Messages */
.message-bubble pre {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
    font-family: 'Fira Code', 'Monaco', monospace;
    font-size: 13px;
}

.message-bubble code {
    font-family: 'Fira Code', 'Monaco', monospace;
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.message-bubble pre code {
    background: none;
    padding: 0;
}

/* Epistemic Confidence Chip */
.epistemic-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 11px;
    font-weight: 500;
    margin-top: 8px;
    margin-bottom: 4px;
}

.epistemic-chip .epistemic-icon {
    font-size: 10px;
}

.epistemic-chip .epistemic-label {
    letter-spacing: 0.3px;
}

.epistemic-chip.confidence-high {
    background-color: rgba(16, 185, 129, 0.15) !important;
    border-color: #10b981 !important;
    color: #10b981 !important;
}

.epistemic-chip.confidence-medium {
    background-color: rgba(245, 158, 11, 0.15) !important;
    border-color: #f59e0b !important;
    color: #f59e0b !important;
}

.epistemic-chip.confidence-low {
    background-color: rgba(239, 68, 68, 0.15) !important;
    border-color: #ef4444 !important;
    color: #ef4444 !important;
}

/* Reasoning Trace */
.reasoning-trace {
    margin-top: 4px;
}

.reasoning-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: rgba(227, 179, 65, 0.1);
    border: 1px solid var(--chat-border);
    border-radius: 6px;
    font-size: 11px;
    color: var(--chat-gold);
    cursor: pointer;
    transition: var(--chat-transition);
}

.reasoning-toggle:hover {
    background: rgba(227, 179, 65, 0.2);
}

.reasoning-toggle .chevron {
    transition: var(--chat-transition);
}

.reasoning-toggle.expanded .chevron {
    transform: rotate(180deg);
}

.reasoning-content {
    display: none;
    margin-top: 8px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    border-left: 3px solid var(--chat-gold);
    font-size: 12px;
    color: var(--chat-text-muted);
    line-height: 1.5;
}

.reasoning-content.visible {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.reasoning-step {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
}

.reasoning-step:last-child {
    margin-bottom: 0;
}

.reasoning-step-icon {
    width: 18px;
    height: 18px;
    background: var(--chat-gold);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    flex-shrink: 0;
    margin-top: 2px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 12px;
    max-width: 80%;
    align-self: flex-start;
}

.typing-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--chat-gold), var(--chat-gold-dark));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.typing-bubble {
    background: var(--chat-ai-bg);
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius-lg);
    border-bottom-left-radius: 4px;
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--chat-text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

.typing-subsystem {
    font-size: 11px;
    color: var(--chat-text-dim);
    display: flex;
    align-items: center;
    gap: 6px;
}

.subsystem-flow {
    display: flex;
    gap: 4px;
}

.subsystem-dot {
    width: 6px;
    height: 6px;
    background: var(--chat-gold);
    border-radius: 50%;
    opacity: 0.3;
    animation: subsystemPulse 1.5s infinite;
}

.subsystem-dot:nth-child(1) { animation-delay: 0s; }
.subsystem-dot:nth-child(2) { animation-delay: 0.2s; }
.subsystem-dot:nth-child(3) { animation-delay: 0.4s; }
.subsystem-dot:nth-child(4) { animation-delay: 0.6s; }
.subsystem-dot:nth-child(5) { animation-delay: 0.8s; }

@keyframes subsystemPulse {
    0%, 100% { opacity: 0.3; background: var(--chat-gold); }
    50% { opacity: 1; background: var(--chat-gold-dark); }
}

/* Gold Subsystem Thinking Animation (matching dashboard) */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.thinking-brain {
    color: var(--chat-gold);
    animation: brainPulse 1.5s ease-in-out infinite;
}

.thinking-text {
    color: var(--chat-gold);
    font-size: 13px;
    font-weight: 500;
}

.thinking-dots {
    display: flex;
    gap: 2px;
}

.thinking-dots span {
    color: var(--chat-gold);
    animation: dotFade 1.5s infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.3s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.6s; }

@keyframes brainPulse {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.1); }
}

@keyframes dotFade {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.subsystem-chip {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(212, 175, 55, 0.15);
    border: 1px solid var(--chat-gold);
    border-radius: 12px;
    font-size: 11px;
    color: var(--chat-gold);
    opacity: 0;
    animation: chipAppear 0.5s ease forwards;
}

@keyframes chipAppear {
    0% { opacity: 0; transform: translateX(-10px); }
    100% { opacity: 1; transform: translateX(0); }
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 40px 20px;
    max-width: 600px;
    margin: 0 auto;
}

.welcome-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--chat-gold), var(--chat-gold-dark));
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin: 0 auto 20px;
    box-shadow: 0 8px 32px var(--chat-gold-glow);
}

.welcome-title {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--chat-text), var(--chat-gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-subtitle {
    color: var(--chat-text-muted);
    font-size: 14px;
    margin-bottom: 24px;
    line-height: 1.6;
}

.welcome-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.prompt-chip {
    padding: 10px 16px;
    background: var(--chat-surface-hover);
    border: 1px solid var(--chat-border);
    border-radius: 20px;
    font-size: 13px;
    color: var(--chat-text-muted);
    cursor: pointer;
    transition: var(--chat-transition);
}

.prompt-chip:hover {
    background: var(--chat-accent);
    color: white;
    border-color: var(--chat-accent);
    transform: translateY(-2px);
}

/* ===========================================
   INPUT AREA
   =========================================== */
.chat-input-area {
    padding: 16px 24px 24px;
    border-top: 1px solid var(--chat-border);
    background: var(--chat-surface);
}

.input-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    max-width: 900px;
    margin: 0 auto;
}

.input-wrapper {
    flex: 1;
    position: relative;
}

.chat-input {
    width: 100%;
    padding: 14px 18px;
    padding-right: 50px;
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius);
    color: var(--chat-text);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    min-height: 50px;
    max-height: 150px;
    line-height: 1.5;
    transition: var(--chat-transition);
}

.chat-input:focus {
    outline: none;
    border-color: var(--chat-accent);
    box-shadow: 0 0 0 3px var(--chat-accent-glow);
}

.chat-input::placeholder {
    color: var(--chat-text-dim);
}

.char-counter {
    position: absolute;
    right: 14px;
    bottom: 14px;
    font-size: 11px;
    color: var(--chat-text-dim);
}

.char-counter.warning {
    color: var(--chat-warning);
}

.char-counter.error {
    color: var(--chat-error);
}

.send-button {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--chat-gold), var(--chat-gold-dark));
    border: none;
    border-radius: var(--chat-radius);
    color: #0a0a0a;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: var(--chat-transition);
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 8px 20px var(--chat-gold-glow);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.send-button.sending {
    animation: sendPulse 1s infinite;
}

@keyframes sendPulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--chat-gold-glow); }
    50% { box-shadow: 0 0 0 10px transparent; }
}

.input-hint {
    text-align: center;
    margin-top: 8px;
    font-size: 11px;
    color: var(--chat-text-dim);
}

.input-hint kbd {
    background: var(--chat-surface-hover);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: inherit;
}

/* Rate Limit Warning */
.rate-limit-warning {
    display: none;
    padding: 12px 16px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--chat-warning);
    text-align: center;
}

.rate-limit-warning.visible {
    display: block;
}

/* ===========================================
   SIGNUP MODAL
   =========================================== */
.signup-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--chat-transition);
}

.signup-modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.signup-modal {
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius-lg);
    max-width: 480px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.9) translateY(20px);
    transition: var(--chat-transition);
}

.signup-modal-overlay.visible .signup-modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 24px 24px 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.modal-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: linear-gradient(135deg, var(--chat-gold), var(--chat-gold-dark));
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: #0a0a0a;
}

.modal-close {
    width: 32px;
    height: 32px;
    background: var(--chat-surface-hover);
    border: none;
    border-radius: 8px;
    color: var(--chat-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
}

.modal-close:hover {
    background: var(--chat-error);
    color: white;
}

.modal-content {
    padding: 24px;
}

.modal-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
    line-height: 1.3;
}

.modal-subtitle {
    color: var(--chat-text-muted);
    font-size: 14px;
    margin-bottom: 24px;
    line-height: 1.6;
}

.modal-benefits {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.benefit-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background: var(--chat-surface-hover);
    border-radius: 8px;
}

.benefit-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--chat-gold), var(--chat-gold-dark));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.benefit-text h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
}

.benefit-text p {
    font-size: 12px;
    color: var(--chat-text-muted);
    line-height: 1.4;
}

.modal-cta {
    width: 100%;
    padding: 14px 20px;
    background: linear-gradient(135deg, var(--chat-gold), var(--chat-gold-dark));
    border: none;
    border-radius: var(--chat-radius);
    color: #0a0a0a;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: var(--chat-transition);
    margin-bottom: 12px;
}

.modal-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px var(--chat-gold-glow);
}

.modal-dismiss {
    width: 100%;
    padding: 12px;
    background: transparent;
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius);
    color: var(--chat-text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: var(--chat-transition);
}

.modal-dismiss:hover {
    background: var(--chat-surface-hover);
}

/* ===========================================
   PERSISTENT BANNER
   =========================================== */
.upgrade-banner {
    display: none;
    padding: 12px 24px;
    background: linear-gradient(90deg, rgba(227, 179, 65, 0.05), rgba(227, 179, 65, 0.1));
    border-bottom: 1px solid var(--chat-border);
    text-align: center;
}

.upgrade-banner.visible {
    display: block;
}

.banner-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.banner-text {
    font-size: 13px;
    color: var(--chat-text);
}

.banner-text strong {
    color: var(--chat-accent);
}

.banner-cta {
    padding: 8px 16px;
    background: linear-gradient(135deg, var(--chat-gold), var(--chat-gold-dark));
    border: none;
    border-radius: 6px;
    color: #0a0a0a;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    transition: var(--chat-transition);
}

.banner-cta:hover {
    transform: scale(1.05);
}

/* ===========================================
   RESPONSIVE DESIGN
   =========================================== */
@media (max-width: 768px) {
    .chat-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        width: 280px;
        transform: translateX(-100%);
    }

    .chat-sidebar.open {
        transform: translateX(0);
    }

    .chat-sidebar.collapsed {
        transform: translateX(-100%);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
    }

    .sidebar-overlay.visible {
        display: block;
    }

    .message {
        max-width: 90%;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-input-area {
        padding: 12px 16px 16px;
    }

    .welcome-prompts {
        flex-direction: column;
    }

    .prompt-chip {
        width: 100%;
        text-align: center;
    }

    .chat-header {
        padding: 12px 16px;
    }

    .header-btn span {
        display: none;
    }
}

/* Dark/Light Mode Toggle (respects system preference) */
@media (prefers-color-scheme: light) {
    .chat-app.auto-theme {
        --chat-bg: #f8fafc;
        --chat-surface: #ffffff;
        --chat-surface-hover: #f1f5f9;
        --chat-border: rgba(99, 102, 241, 0.2);
        --chat-text: #1e293b;
        --chat-text-muted: #64748b;
        --chat-text-dim: #94a3b8;
        --chat-ai-bg: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .chat-app * {
        animation: none !important;
        transition: none !important;
    }
}

/* Focus Visible */
.chat-app button:focus-visible,
.chat-app input:focus-visible,
.chat-app textarea:focus-visible {
    outline: 2px solid var(--chat-accent);
    outline-offset: 2px;
}

/* Screen Reader Only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ===========================================
   STREAMING MESSAGE STYLES
   =========================================== */

.message.streaming .message-bubble {
    min-height: 24px;
}

.streaming-cursor {
    display: inline-block;
    color: var(--chat-accent);
    animation: blink 1s step-end infinite;
    margin-left: 2px;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.message.streaming .message-time {
    color: var(--chat-accent);
    font-style: italic;
}
