/* ============================================================================
   Global Styles
   ============================================================================ */

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

:root {
    --color-primary: #4f46e5;
    --color-primary-dark: #4338ca;
    --color-secondary: #8b5cf6;
    --color-success: #10b981;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;
    --color-bg: #ffffff;
    --color-bg-alt: #f9fafb;
    --color-bg-hover: #f3f4f6;
    --color-border: #e5e7eb;
    --color-text: #1f2937;
    --color-text-light: #6b7280;
    --color-text-lighter: #9ca3af;

    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --font-mono: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Courier New', monospace;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

    --border-radius: 8px;
    --transition: all 0.3s ease;
}

body {
    font-family: var(--font-family);
    background: var(--color-bg-alt);
    color: var(--color-text);
    line-height: 1.6;
}

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

.container {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
    color: white;
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    z-index: 100;
}

.header-content h1 {
    font-size: 1.875rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.subtitle {
    font-size: 0.875rem;
    opacity: 0.9;
}

.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    width: 300px;
    background: var(--color-bg);
    border-right: 1px solid var(--color-border);
    overflow-y: auto;
    padding: 1.5rem;
    gap: 1.5rem;
    display: flex;
    flex-direction: column;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 1.5rem;
    gap: 1rem;
}

.status-bar {
    background: var(--color-bg);
    border-top: 1px solid var(--color-border);
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
    color: var(--color-text-light);
}

/* ============================================================================
   Sidebar Components
   ============================================================================ */

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.sidebar-section h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.schema-select,
.format-select {
    padding: 0.625rem;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    font-family: var(--font-family);
    font-size: 0.875rem;
    background: var(--color-bg);
    color: var(--color-text);
    cursor: pointer;
    transition: var(--transition);
}

.schema-select:hover,
.format-select:hover {
    border-color: var(--color-primary);
}

.schema-select:focus,
.format-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.conversation-id {
    padding: 0.75rem;
    background: var(--color-bg-alt);
    border-radius: var(--border-radius);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    word-break: break-all;
    color: var(--color-text-light);
}

.fields-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.fields-list li {
    padding: 0.5rem;
    background: var(--color-bg-alt);
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    color: var(--color-text);
}

.fields-list li.placeholder {
    color: var(--color-text-light);
    font-style: italic;
}

.fields-list li.required::before {
    content: '● ';
    color: var(--color-danger);
}

/* ============================================================================
   Buttons
   ============================================================================ */

.btn {
    padding: 0.625rem 1rem;
    border: none;
    border-radius: var(--border-radius);
    font-family: var(--font-family);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
    text-align: center;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-dark);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--color-bg-alt);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-bg-hover);
    border-color: var(--color-primary);
}

.btn-danger {
    background: var(--color-danger);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    box-shadow: var(--shadow-md);
}

/* ============================================================================
   Chat Section
   ============================================================================ */

.chat-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
    min-height: 0;
}

.chat-section h2 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
}

.chat-container {
    flex: 1;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.welcome-message {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
    color: var(--color-text-light);
    padding: 2rem;
    justify-content: center;
}

.welcome-message p:first-child {
    font-size: 1.5rem;
}

.message {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    word-wrap: break-word;
    line-height: 1.5;
}

.message.user .message-bubble {
    background: var(--color-primary);
    color: white;
}

.message.assistant .message-bubble {
    background: var(--color-bg-alt);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.message-time {
    font-size: 0.75rem;
    color: var(--color-text-lighter);
    padding: 0 0.5rem;
    align-self: flex-end;
}

.streaming {
    display: flex;
    gap: 0.25rem;
}

.streaming span {
    width: 0.5rem;
    height: 0.5rem;
    background: var(--color-text-light);
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}

.streaming span:nth-child(2) {
    animation-delay: 0.2s;
}

.streaming span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-0.5rem);
    }
}

.input-area {
    display: flex;
    gap: 0.75rem;
}

.message-input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    font-family: var(--font-family);
    font-size: 0.875rem;
    resize: none;
    max-height: 120px;
    color: var(--color-text);
}

.message-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.message-input:disabled {
    background: var(--color-bg-alt);
    color: var(--color-text-light);
}

/* ============================================================================
   Suggestions Section
   ============================================================================ */

.suggestions-section {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-top: 1rem;
}

.suggestions-section h3 {
    margin-bottom: 0.75rem;
}

.suggestions-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.suggestion-card {
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 1rem;
    cursor: pointer;
    transition: var(--transition);
}

.suggestion-card:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.suggestion-field {
    font-weight: 600;
    color: var(--color-primary);
    font-size: 0.875rem;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.suggestion-value {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    padding: 0.5rem;
    background: var(--color-bg);
    border-radius: 4px;
    margin-bottom: 0.5rem;
    word-break: break-all;
}

.suggestion-reasoning {
    font-size: 0.75rem;
    color: var(--color-text-light);
    margin-bottom: 0.5rem;
}

.suggestion-confidence {
    display: flex;
    align-items: center;
    font-size: 0.75rem;
    color: var(--color-text-light);
    gap: 0.5rem;
}

.confidence-bar {
    flex: 1;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    background: var(--color-success);
    border-radius: 2px;
}

/* ============================================================================
   Configuration Section
   ============================================================================ */

.config-section {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-top: 1rem;
}

.config-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.config-header h3 {
    margin: 0;
}

.format-select {
    padding: 0.5rem;
    width: 150px;
}

.config-preview {
    background: var(--color-text);
    color: #e0e0e0;
    padding: 1rem;
    border-radius: var(--border-radius);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.5;
    max-height: 300px;
    margin-bottom: 1rem;
}

.config-preview code {
    font-family: var(--font-mono);
}

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

.config-actions .btn {
    flex: 1;
}

/* ============================================================================
   Status & Connection
   ============================================================================ */

.status-text {
    flex: 1;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    background: var(--color-bg-alt);
    font-size: 0.875rem;
}

.connection-status.connected {
    color: var(--color-success);
}

.connection-status.disconnected {
    color: var(--color-danger);
}

/* ============================================================================
   Loading Overlay
   ============================================================================ */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    gap: 1rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-overlay p {
    color: white;
    font-weight: 500;
}

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

@media (max-width: 1024px) {
    .main-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 300px;
        flex-direction: row;
        padding: 1rem;
        overflow-x: auto;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }

    .sidebar-section {
        min-width: 250px;
    }

    .main-content {
        padding: 1rem;
    }

    .suggestions-container {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .message-bubble {
        max-width: 85%;
    }
}

@media (max-width: 640px) {
    .header-content h1 {
        font-size: 1.5rem;
    }

    .sidebar {
        flex-direction: column;
        overflow-x: visible;
        max-height: none;
        border-bottom: 1px solid var(--color-border);
    }

    .sidebar-section {
        min-width: unset;
    }

    .suggestions-container {
        grid-template-columns: 1fr;
    }

    .message-bubble {
        max-width: 95%;
    }

    .btn {
        font-size: 0.875rem;
        padding: 0.5rem;
    }
}

/* ============================================================================
   Scrollbar Styling
   ============================================================================ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-bg-alt);
}

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

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