/* ============================================
   DST Statistik Agent - Clean CSS
   Med afdæmpet farvepalet
   ============================================ */

:root {
    /* Brand colors */
    --color-primary: #0f78c8;
    --color-primary-hover: #0c5fa0;
    
    /* Text colors */
    --color-text-main: #333333;
    --color-text-secondary: #555555;
    --color-text-light: #999999;
    
    /* Backgrounds */
    --color-background: #fafafa;
    --color-surface: #ffffff;
    
    /* Borders */
    --color-border: #e0e0e0;
    --color-border-light: #f0f0f0;

    /* Font */
    --font-family-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --font-size-main: 1rem;
    --font-size-h1: 1.6rem;
    --font-weight-main: 400;
    --font-weight-bold: 600;
}

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

body {
    font-family: var(--font-family-main);
    font-size: var(--font-size-main);
    font-weight: var(--font-weight-main);
    background: var(--color-background);
    color: var(--color-text-main);
    line-height: 1.6;
    min-height: 100vh;
}

/* ============================================
   Layout
   ============================================ */

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

/* Header */
header {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 1.5rem 2rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--color-border);
    text-align: center;
}

header h1 {
    font-size: var(--font-size-h1);
    color: var(--color-text-main);
    margin-bottom: 0.3rem;
    font-weight: 600;
}

header p {
    color: var(--color-text-secondary);
    font-size: 0.95rem;
}

/* Main */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ============================================
   Chat Container
   ============================================ */

.chat-container {
    background: var(--color-surface);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 500px;
    overflow: hidden;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    scroll-behavior: smooth;
}

/* ============================================
   Messages - User & Assistant
   ============================================ */

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

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

.message.user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.message.assistant {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

/* Chat bubble - bruger */
.message.user .message-content {
    max-width: 85%;
    padding: 0.875rem 1.125rem;
    background: var(--color-primary);
    color: white;
    border-radius: 12px;
    border-bottom-right-radius: 4px;
}

/* Chat bubble - assistent */
.message.assistant .message-content {
    max-width: 85%;
    padding: 0.875rem 1.125rem;
    background: var(--color-surface);
    color: var(--color-text-main);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

/* ============================================
   Thought Steps (Agent tankeproces)
   ============================================ */

.thought-container {
    max-width: 85%;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    margin-bottom: 0.75rem;
}

.thought-container:empty {
    display: none;
}

.thought-step {
    padding: 0.875rem 1.125rem;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-primary);
    border-radius: 8px;
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    animation: fadeInThought 0.4s ease-out;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
    position: relative;
}

/* Ikon før tekst */
.thought-step::before {
    content: '🔍';
    font-size: 1rem;
    flex-shrink: 0;
}

/* Forskellige ikoner baseret på indhold */
.thought-step.thought-thinker::before {
    content: '🧠';
}

.thought-step.thought-search::before {
    content: '🔍';
}

.thought-step.thought-found::before {
    content: '✅';
}

.thought-step.thought-loading::before {
    content: '📊';
}

.thought-step.thought-nothing::before {
    content: '❌';
}

.thought-step-done {
    animation: none;
    opacity: 0.9;
}

/* Checkmark kun på søge-steps der er færdige */
.thought-step.thought-search.thought-step-done::after,
.thought-step.thought-thinker.thought-step-done::after {
    content: '✓';
    position: absolute;
    right: 0.75rem;
    color: #4caf50;
    font-weight: bold;
    font-size: 0.85rem;
}

/* Ingen checkmark på found, loading, nothing - de har allerede ikoner */
.thought-step.thought-found::after,
.thought-step.thought-loading::after,
.thought-step.thought-nothing::after {
    content: none;
}

/* Aktiv thought step (med animation) */
.thought-step:not(.thought-step-done) {
    background: linear-gradient(135deg, #e3f2fd 0%, #f8f9fa 100%);
    border-left-color: var(--color-primary);
}

@keyframes fadeInThought {
    from { 
        opacity: 0; 
        transform: translateX(-15px); 
    }
    to { 
        opacity: 1; 
        transform: translateX(0); 
    }
}

/* Pulserende effekt på aktiv thought */
.thought-step:not(.thought-step-done)::before {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.thought-step a {
    color: var(--color-primary);
    text-decoration: none;
}

.thought-step a:hover {
    text-decoration: underline;
}

/* ============================================
   Standalone Spinner - Under thought bubbles
   ============================================ */

.standalone-spinner {
    padding: 0.5rem 0 0.5rem 1rem;
    display: flex;
    align-items: center;
}

.spinner-circle {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid #e0e0e0;
    border-top-color: #0f78c8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   Message Meta (iterations, tokens, pris)
   ============================================ */

.message-meta {
    font-size: 0.75rem;
    color: var(--color-text-light);
    margin-top: 0.5rem;
    padding: 0.25rem 0.75rem;
    background: var(--color-border-light);
    border-radius: 10px;
    display: inline-block;
}

/* ============================================
   Markdown Content Styling
   ============================================ */

.message-content p {
    margin: 0.5em 0;
}

.message-content p:first-child {
    margin-top: 0;
}

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

.message-content ul,
.message-content ol {
    margin: 0.5rem 0 0.5rem 1.5rem;
}

.message-content li {
    margin: 0.25rem 0;
}

.message-content strong {
    font-weight: var(--font-weight-bold);
}

.message-content code {
    background: var(--color-border-light);
    padding: 0.1em 0.4em;
    border-radius: 4px;
    font-size: 0.9em;
}

.message-content pre {
    background: #2d3748;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.message-content a {
    color: var(--color-primary);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

/* ============================================
   Error Messages
   ============================================ */

.api-error {
    background: #fef3c7;
    border-left: 4px solid #d97706;
    padding: 1rem 1.125rem;
    border-radius: 0 8px 8px 0;
    color: #92400e;
}

.api-error .error-icon {
    font-size: 1.1rem;
    margin-right: 0.5rem;
}

/* ============================================
   Chat Form
   ============================================ */

.chat-form {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
    border-radius: 0 0 12px 12px;
}

.chat-form input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: all 0.2s;
    background: var(--color-surface);
    color: var(--color-text-main);
}

.chat-form input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(15, 120, 200, 0.1);
}

.chat-form input:disabled {
    background: var(--color-background);
}

.chat-form input::placeholder {
    color: var(--color-text-light);
}

.chat-form button {
    padding: 0.75rem 1.5rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 90px;
}

.chat-form button:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.chat-form button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Button spinner */
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.btn-loading {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   Footer
   ============================================ */

footer {
    text-align: center;
    padding: 1rem;
    color: var(--color-text-light);
    font-size: 0.85rem;
}

footer a {
    color: var(--color-primary);
    text-decoration: none;
}

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

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 640px) {
    .container {
        padding: 0.5rem;
    }
    
    header {
        padding: 1rem;
        border-radius: 8px;
    }
    
    header h1 {
        font-size: 1.3rem;
    }
    
    .chat-container {
        border-radius: 8px;
    }
    
    .message.user .message-content,
    .message.assistant .message-content {
        max-width: 90%;
    }
    
    .thought-container {
        max-width: 90%;
    }
    
    .chat-form {
        padding: 0.75rem 1rem;
    }
    
    .chat-form button {
        padding: 0.75rem 1rem;
        min-width: auto;
    }
}
