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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    overflow-x: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

/* Header Styles */
.header {
    background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
    color: white;
    padding: 1rem 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-actions .btn-primary:active,
.header-actions .btn-secondary:active {
    transform: translateY(0);
    filter: brightness(0.98);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo i {
    font-size: 2rem;
    color: #f39c12;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.observability-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.obs-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.92);
}

.obs-item {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    padding: 0.15rem 0.5rem;
    white-space: nowrap;
}

.btn-primary, .btn-secondary {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 50px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.btn-primary {
    background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(243, 156, 18, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    position: relative;
    min-height: 0; /* allow chat area to shrink within viewport */
    overflow-y: auto; /* prevent footer/input overlap on shorter viewports */
}

/* Welcome Section */
.welcome-section {
    text-align: center;
    padding: 2rem 2rem;
    animation: fadeInUp 0.8s ease-out;
}

.welcome-content {
    max-width: 600px;
    margin: 0 auto;
}

.welcome-icon {
    font-size: 3.25rem;
    color: #3498db;
    margin-bottom: 1.5rem;
    animation: bounce 2s infinite;
}

.welcome-section h2 {
    font-size: 2.5rem;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 1rem;
}

.welcome-section p {
    font-size: 1.2rem;
    color: #7f8c8d;
    margin-bottom: 2rem;
    line-height: 1.6;
}

.features {
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.feature {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background: rgba(52, 152, 219, 0.1);
    border-radius: 15px;
    min-width: 120px;
    transition: transform 0.3s ease;
}

.feature:hover {
    transform: translateY(-5px);
}

.feature i {
    font-size: 1.5rem;
    color: #3498db;
}

.feature span {
    font-weight: 600;
    color: #2c3e50;
}

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-bottom: 1rem;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    animation: slideInUp 0.5s ease-out;
    min-height: 0; /* allow messages to control height */
}

.chat-messages {
    flex: 1;
    padding: 2rem;
    background: #f8f9fa;
    overflow-y: auto;
    max-height: none;
    min-height: 0;
    scroll-behavior: smooth;
}

.message {
    margin-bottom: 1.5rem;
    animation: fadeInUp 0.3s ease-out;
}

.message.user {
    text-align: right;
}

.message.assistant {
    text-align: left;
}

.message-content {
    display: inline-block;
    max-width: 80%;
    padding: 1rem 1.5rem;
    border-radius: 20px;
    position: relative;
    word-wrap: break-word;
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.message.user:hover .message-content,
.message.assistant:hover .message-content {
    transform: translateY(-1px);
}

.message.user .message-content {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: white;
    border-bottom-right-radius: 5px;
}

.message.assistant .message-content {
    background: white;
    color: #2c3e50;
    border: 1px solid #e1e8ed;
    border-bottom-left-radius: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    line-height: 1.6;
}

.message.assistant .message-content br {
    margin-bottom: 0.5rem;
}

.message.assistant .message-content {
    white-space: pre-line;
}

.message-time {
    font-size: 0.8rem;
    color: #95a5a6;
    margin-top: 0.5rem;
}

.token-usage {
    margin-top: 0.4rem;
    font-size: 0.75rem;
    color: #6b7280;
    user-select: text;
    word-break: break-word;
}

.citations {
    margin-top: 0.6rem;
    padding: 0.75rem;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
}

.citations-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #374151;
    margin-bottom: 0.5rem;
}

.citation-item {
    padding: 0.5rem 0;
    border-top: 1px dashed #e5e7eb;
}

.citation-item:first-of-type {
    border-top: none;
    padding-top: 0;
}

.citation-head {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.citation-ref {
    font-size: 0.75rem;
    font-weight: 700;
    color: #111827;
    background: #e0f2fe;
    border: 1px solid #bae6fd;
    border-radius: 6px;
    padding: 0.1rem 0.35rem;
}

.citation-meta {
    font-size: 0.75rem;
    color: #4b5563;
}

.citation-evidence {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: #6b7280;
    line-height: 1.35;
    word-break: break-word;
}

.message-sources {
    margin-top: 1rem;
    padding: 1rem;
    background: #f1f2f6;
    border-radius: 10px;
    border-left: 4px solid #3498db;
}

.sources-title {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.source-item {
    font-size: 0.8rem;
    color: #7f8c8d;
    margin-bottom: 0.25rem;
}

.confidence-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: #27ae60;
    color: white;
    border-radius: 15px;
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

/* Input Section */
.input-section {
    background: white;
    padding: 0.9rem 1.25rem;
    border-top: 1px solid #e1e8ed;
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.1);
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
}

.input-wrapper {
    display: flex;
    background: #f8f9fa;
    border-radius: 50px;
    padding: 0.35rem;
    border: 2px solid transparent;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.input-wrapper:focus-within {
    border-color: #3498db;
    box-shadow: 0 4px 20px rgba(52, 152, 219, 0.3);
}

#messageInput {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.65rem 1rem;
    font-size: 1rem;
    outline: none;
    color: #2c3e50;
}

#messageInput::placeholder {
    color: #95a5a6;
}

.send-btn {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    border: none;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.4);
}

.send-btn:active {
    transform: scale(0.98);
}

.send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.input-footer {
    margin-top: 0.5rem;
    text-align: center;
}

.typing-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: #7f8c8d;
    font-size: 0.9rem;
}

.typing-indicator i {
    animation: pulse 1.5s infinite;
    animation-delay: calc(var(--i) * 0.2s);
}

.typing-indicator i:nth-child(1) { --i: 0; }
.typing-indicator i:nth-child(2) { --i: 1; }
.typing-indicator i:nth-child(3) { --i: 2; }

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    animation: fadeIn 0.3s ease-out;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 20px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: slideInUp 0.3s ease-out;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
    color: white;
}

.modal-header h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.modal-body {
    padding: 2rem;
    max-height: 60vh;
    overflow-y: auto;
}

.sample-questions {
    display: grid;
    gap: 1rem;
}

.sample-question {
    padding: 1rem 1.5rem;
    background: #f8f9fa;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    text-align: left;
}

.sample-question:hover {
    background: #e3f2fd;
    border-color: #3498db;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.2);
}

.sample-question i {
    margin-right: 0.5rem;
    color: #3498db;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease-out;
}

.loading-spinner {
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

.loading-spinner p {
    color: #7f8c8d;
    font-size: 1.1rem;
    font-weight: 500;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

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

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

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        margin: 0;
        border-radius: 0;
    }
    
    .header {
        padding: 1rem;
    }
    
    .header-content {
        flex-direction: column;
        text-align: center;
        align-items: stretch;
    }

    .observability-bar {
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .header-actions {
        width: 100%;
        justify-content: center;
    }
    
    .logo h1 {
        font-size: 1.25rem;
    }
    
    .main-content {
        padding: 1rem;
    }
    
    .welcome-section {
        padding: 2rem 1rem;
    }
    
    .welcome-section h2 {
        font-size: 2rem;
    }
    
    .features {
        gap: 1rem;
    }
    
    .message-content {
        max-width: 95%;
    }
    
    .input-section {
        padding: 1rem;
    }

    .chat-messages {
        padding: 1rem;
        max-height: calc(100vh - 260px);
        min-height: 260px;
    }
    
    .modal-content {
        width: 95%;
        margin: 1rem;
    }
    
    .modal-header, .modal-body {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .welcome-section h2 {
        font-size: 1.5rem;
    }
    
    .welcome-section p {
        font-size: 1rem;
    }
    
    .features {
        flex-direction: column;
        align-items: center;
    }
    
    .btn-primary, .btn-secondary {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
}
