/* ===== AE Agent Chat UI - Best in Class Design ===== */

/* Reset & Variables - Light Mode */
:root {
    --bg-main: #ffffff;
    --bg-card: #f8f9fa;
    --bg-input: #f1f3f5;
    --bg-hover: #e9ecef;
    --border: #dee2e6;
    --text: #1a1a2e;
    --text-secondary: #495057;
    --text-muted: #868e96;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --success: #22c55e;
    --error: #ef4444;
    --gold: #d97706;
    --radius: 16px;
    --radius-sm: 12px;
    --font: 'Inter', -apple-system, sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
}

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

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-main);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

body {
    display: flex;
    flex-direction: column;
}

/* ===== AUTH GATE - Premium Login ===== */
.auth-gate {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f8f9ff 0%, #eef1ff 50%, #f5f3ff 100%);
    z-index: 1000;
}

.auth-gate::before {
    content: '';
    position: absolute;
    inset: 0;
    background: 
        radial-gradient(ellipse at 20% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(139, 92, 246, 0.06) 0%, transparent 50%);
    pointer-events: none;
}

.auth-card {
    position: relative;
    background: #ffffff;
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 48px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 
        0 25px 50px -12px rgba(0, 0, 0, 0.1),
        0 0 0 1px rgba(0, 0, 0, 0.02) inset;
}

.auth-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
    border-radius: 20px;
    font-size: 28px;
    font-weight: 700;
    color: white;
    margin-bottom: 24px;
    box-shadow: 0 8px 32px var(--accent-glow);
}

.auth-card h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text);
}

.auth-card p {
    color: var(--text-secondary);
    font-size: 15px;
    margin-bottom: 32px;
}

.auth-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 16px 24px;
    background: var(--text);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.auth-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.auth-btn svg {
    flex-shrink: 0;
}

.auth-error {
    margin-top: 16px;
    padding: 12px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    color: #fca5a5;
    font-size: 13px;
    display: none;
}

.auth-error:not(:empty) {
    display: block;
}

/* ===== TOP BAR ===== */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 64px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    color: white;
}

.logo-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.topbar-nav {
    display: flex;
    gap: 4px;
    background: var(--bg-input);
    padding: 4px;
    border-radius: var(--radius-sm);
}

.nav-item {
    padding: 8px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.nav-item:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.nav-item.active {
    color: var(--text);
    background: var(--bg-card);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.topbar-right {
    display: flex;
    align-items: center;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-input);
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: pulse 2s infinite;
}

.status-badge.connected .status-dot,
.status-badge.live .status-dot {
    background: var(--success);
    animation: none;
}

.status-badge.error .status-dot {
    background: var(--error);
    animation: none;
}

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

/* ===== CHAT CONTAINER ===== */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 0 24px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ===== WELCOME SCREEN ===== */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
}

.welcome-icon {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
    border-radius: 24px;
    margin-bottom: 32px;
    color: white;
    box-shadow: 0 12px 40px var(--accent-glow);
}

/* Stats Tracker */
.stats-tracker {
    display: flex;
    align-items: stretch;
    gap: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    margin-top: 32px;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.stats-group {
    flex: 1;
    padding: 16px 24px;
}

.stats-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.stats-group h3 {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent);
    margin: 0;
}

.stats-count {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-hover);
    padding: 3px 10px;
    border-radius: 20px;
}

.stats-row {
    display: flex;
    gap: 16px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 60px;
}

.stat-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    font-family: var(--font-mono);
    letter-spacing: -0.3px;
}

.stat-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.stats-divider {
    width: 1px;
    background: var(--border);
    margin: 16px 0;
}

.stat-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Upcoming Events */
.upcoming-events {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-top: 20px;
    padding: 14px 18px;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    max-width: 520px;
    width: 100%;
}

.upcoming-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    white-space: nowrap;
}

.upcoming-list {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.upcoming-item {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-hover);
    padding: 5px 10px;
    border-radius: 6px;
    white-space: nowrap;
}

.welcome-screen h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 32px;
    color: var(--text);
    letter-spacing: -0.5px;
}

.welcome-input-wrapper {
    position: relative;
    width: 100%;
    max-width: 640px;
}

.welcome-input-wrapper textarea {
    width: 100%;
    padding: 20px 60px 20px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 16px;
    font-family: var(--font);
    resize: none;
    outline: none;
    transition: all 0.2s ease;
}

.welcome-input-wrapper textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

.welcome-input-wrapper textarea::placeholder {
    color: var(--text-muted);
}

.welcome-input-wrapper textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.welcome-input-wrapper .send-btn {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.welcome-input-wrapper .send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.welcome-input-wrapper .send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.welcome-footer {
    margin-top: 32px;
    font-size: 12px;
    color: var(--text-muted);
    opacity: 0.7;
}

.welcome-footer strong {
    color: var(--text-secondary);
}

/* ===== MESSAGES LIST ===== */
.messages-list {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.messages-list:empty {
    display: none;
}

.message {
    display: flex;
    gap: 16px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
    color: white;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message.user .message-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
}

.message.user .message-content p {
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
}

.message.assistant .message-content {
    padding: 4px 0;
}

.message.assistant .message-content p {
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.7;
    margin-bottom: 16px;
}

.message.assistant .message-content p:last-child {
    margin-bottom: 0;
}

.message.assistant .message-content strong {
    color: var(--text);
    font-weight: 600;
}

.message.assistant .message-content ul,
.message.assistant .message-content ol {
    margin: 12px 0;
    padding-left: 24px;
    color: var(--text-secondary);
}

.message.assistant .message-content li {
    margin-bottom: 8px;
}

.message.assistant .message-content code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--gold);
}

/* Tables */
.message.assistant .message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 14px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

.message.assistant .message-content th {
    background: var(--bg-input);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

.message.assistant .message-content td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}

.message.assistant .message-content tr:last-child td {
    border-bottom: none;
}

.message.assistant .message-content tr:hover td {
    background: var(--bg-hover);
}

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

.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: loadingDot 1.4s infinite;
}

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

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

/* ===== CHAT INPUT AREA (bottom fixed) ===== */
.chat-input-area {
    padding: 16px 0 24px;
    background: linear-gradient(to top, #ffffff 80%, transparent);
    position: sticky;
    bottom: 0;
}

.input-wrapper {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.2s ease;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

.chat-input-area textarea {
    width: 100%;
    padding: 18px 60px 18px 20px;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 15px;
    font-family: var(--font);
    resize: none;
    outline: none;
    max-height: 200px;
}

.chat-input-area textarea::placeholder {
    color: var(--text-muted);
}

.chat-input-area .send-btn {
    position: absolute;
    right: 10px;
    bottom: 10px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-input-area .send-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.chat-input-area .send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* ===== ERROR BANNER ===== */
.error-banner {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-sm);
    color: #fca5a5;
    font-size: 14px;
    backdrop-filter: blur(12px);
    z-index: 200;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translate(-50%, 20px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.error-close {
    background: none;
    border: none;
    color: #fca5a5;
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.error-close:hover {
    opacity: 1;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .topbar {
        padding: 0 16px;
    }
    
    .topbar-nav {
        display: none;
    }
    
    .chat-container {
        padding: 0 16px;
    }
    
    .welcome-screen h1 {
        font-size: 24px;
    }
    
    .welcome-input-wrapper textarea {
        padding: 16px 56px 16px 16px;
        font-size: 15px;
    }
    
    /* Stats Tracker Mobile */
    .stats-tracker {
        flex-direction: column;
        max-width: 100%;
        margin-top: 32px;
    }
    
    .stats-group {
        padding: 16px 20px;
    }
    
    .stats-header {
        margin-bottom: 12px;
    }
    
    .stats-divider {
        width: 100%;
        height: 1px;
        margin: 0;
    }
    
    .stats-row {
        gap: 16px;
    }
    
    .stat-value {
        font-size: 18px;
    }
    
    .stat-item {
        min-width: auto;
    }
    
    .auth-card {
        padding: 32px 24px;
    }
    
    .auth-logo {
        width: 60px;
        height: 60px;
        font-size: 24px;
    }
    
    .auth-card h1 {
        font-size: 24px;
    }
    
    .message {
        gap: 12px;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }
}
