/**
 * EU Funding Expert Agent - Styles
 * Clean, modern UI without external frameworks
 */

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

:root {
    --primary-color: #003399;
    --secondary-color: #FFCC00;
    --bg-color: #f5f7fa;
    --text-color: #333;
    --border-color: #ddd;
    --user-message-bg: #e3f2fd;
    --agent-message-bg: #ffffff;
    --error-message-bg: #ffebee;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    padding: 20px 0;
    border-bottom: 2px solid var(--primary-color);
    margin-bottom: 20px;
}

header h1 {
    color: var(--primary-color);
    font-size: 2em;
    margin-bottom: 10px;
}

.subtitle {
    color: #666;
    font-size: 1em;
}

.chat-container {
    flex: 1;
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
}

.messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    padding: 15px;
    border-radius: 8px;
    max-width: 85%;
    word-wrap: break-word;
    position: relative;
}

.message-user {
    background: var(--user-message-bg);
    align-self: flex-end;
    border: 1px solid #bbdefb;
}

.message-agent {
    background: var(--agent-message-bg);
    align-self: flex-start;
    border: 1px solid var(--border-color);
}

.message-error {
    background: var(--error-message-bg);
    align-self: center;
    border: 1px solid #ef9a9a;
    color: #c62828;
}

.message-system {
    background: #f9f9f9;
    align-self: center;
    border: 1px solid #e0e0e0;
    width: 90%;
}

.message-content {
    margin-bottom: 5px;
    line-height: 1.6;
}

/* Topic ID highlighting */
.message-content strong {
    font-weight: 600;
}

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

.cache-indicator {
    display: inline-block;
    font-size: 0.85em;
    color: #4caf50;
    font-weight: bold;
    margin-top: 5px;
}

.sources {
    margin-top: 15px;
    padding: 10px 15px;
    background: rgba(102, 126, 234, 0.05);
    border-left: 3px solid rgba(102, 126, 234, 0.3);
    border-radius: 4px;
    font-size: 0.85em;
    color: #666;
}

.sources strong {
    color: #888;
    font-weight: 600;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sources ul {
    margin: 8px 0 0 0;
    padding: 0;
    list-style: none;
}

.sources li {
    margin: 5px 0;
    color: #999;
    padding: 4px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sources li::before {
    content: "📄";
    font-size: 0.9em;
    opacity: 0.7;
}

.sources li:hover {
    color: #667eea;
}

.source-filename {
    font-weight: 500;
    color: #555;
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    gap: 10px;
    color: #666;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* PDF Progress Bar */
.pdf-progress {
    width: 100%;
    max-width: 400px;
    margin-top: 8px;
}

.pdf-progress-bar {
    width: 100%;
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
}

.pdf-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border-radius: 3px;
    transition: width 0.5s ease;
}

.pdf-progress-steps {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 11px;
    color: #999;
}

.pdf-progress-steps .step {
    transition: color 0.3s;
}

.pdf-progress-steps .step.active {
    color: var(--primary-color);
    font-weight: 600;
}

.pdf-progress-steps .step.done {
    color: #28a745;
}

.input-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pdf-icon-button {
    background: white;
    color: var(--secondary-color);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2em;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pdf-icon-button:hover {
    border-color: var(--secondary-color);
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.2);
}

.pdf-icon-button:active {
    transform: scale(0.95);
}

.pdf-icon-button.uploaded {
    border-color: #28a745;
    color: #28a745;
}

.pdf-status-inline {
    font-size: 0.85em;
    color: #28a745;
    font-weight: 500;
    flex-grow: 1;
}


#questionInput {
    flex: 1;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1em;
    font-family: inherit;
    resize: vertical;
    min-height: 60px;
    transition: border-color 0.3s;
}

#questionInput:focus {
    outline: none;
    border-color: var(--primary-color);
}

#questionInput:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}

.send-button {
    padding: 12px 30px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}

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

.send-button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    padding: 10px;
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
    font-size: 0.9em;
    color: #666;
}

.rate-limit-status {
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    background: #f8f9fa;
}

.cache-hit {
    color: #4caf50;
    font-weight: bold;
}

.cache-miss {
    color: #ff9800;
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    header h1 {
        font-size: 1.5em;
    }

    .message {
        max-width: 95%;
    }

    .input-container {
        flex-direction: column;
    }

    .send-button {
        width: 100%;
    }
}

/* Scrollbar styling */
.messages::-webkit-scrollbar {
    width: 8px;
}

.messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

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

/* Stats Button */
/* Header buttons container */
.header-buttons {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
}

.stats-button, .new-chat-button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.stats-button:hover, .new-chat-button:hover {
    background: #002266;
    transform: translateY(-2px);
}

.new-chat-button {
    background: #28a745;
}

.new-chat-button:hover {
    background: #218838;
}

.logout-button {
    background: #dc3545 !important;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.logout-button:hover {
    background: #c82333 !important;
    transform: translateY(-2px);
}

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

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

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    animation: slideIn 0.3s;
}

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

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
}

.close:hover,
.close:focus {
    color: #000;
}

.modal-content h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.stat-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.stat-card.success {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}

.stat-card.warning {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.stat-card.info {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.stat-value {
    font-size: 2.5em;
    font-weight: bold;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 0.9em;
    opacity: 0.9;
}

/* Stats Sections */
.stats-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.stats-section h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
}

.stats-section p {
    margin: 8px 0;
}

/* Popular Questions List */
.popular-list {
    list-style: none;
    padding: 0;
}

.popular-list li {
    display: flex;
    align-items: center;
    padding: 12px;
    margin-bottom: 10px;
    background: white;
    border-radius: 6px;
    border-left: 4px solid var(--primary-color);
}

.hit-count {
    background: var(--secondary-color);
    color: var(--primary-color);
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: bold;
    font-size: 0.9em;
    margin-right: 12px;
    min-width: 40px;
    text-align: center;
}

.question-text {
    flex: 1;
    color: #555;
}

.stats-footer {
    text-align: center;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    color: #999;
}


/* Message Metadata (Model & Duration) */
.message-metadata {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(0, 51, 102, 0.1);
    display: flex;
    gap: 16px;
    font-size: 0.8em;
    color: #666;
}

.metadata-model {
    display: inline-flex;
    align-items: center;
    background: linear-gradient(135deg, #e8f4fd 0%, #d0e8f7 100%);
    padding: 4px 10px;
    border-radius: 12px;
    color: var(--primary-color);
    font-weight: 500;
}

.metadata-duration {
    display: inline-flex;
    align-items: center;
    background: linear-gradient(135deg, #f0f8e8 0%, #e0f0d0 100%);
    padding: 4px 10px;
    border-radius: 12px;
    color: #4a7c23;
    font-weight: 500;
}
