/* Accelerate PRISM - Modern UI Styles */

:root {
    /* Color palette - Dark theme friendly */
    --bg-primary: #1e1e2e;
    --bg-secondary: #2a2a3e;
    --bg-tertiary: #363654;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --text-muted: #707080;
    
    /* Accent colors */
    --color-blue: #89b4fa;
    --color-green: #a6e3a1;
    --color-yellow: #f9e2af;
    --color-red: #f38ba8;
    --color-purple: #cba6f7;
    
    /* UI elements */
    --border-color: #404058;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --spacing: 16px;
    
    /* Transitions */
    --transition: all 0.2s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Constrain height only for main index page (has #mainContent with flex layout) */
body.flex-layout {
    overflow-y: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

html.flex-layout {
    height: 100%;
    overflow: hidden;
}

/* Main content wrapper - must maintain flex layout */
#mainContent {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Header */
.header {
    background: var(--bg-secondary);
    padding: var(--spacing);
    border-bottom: 2px solid var(--border-color);
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

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

.header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--color-blue);
    margin-bottom: 8px;
}

.header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.admin-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-tertiary);
    color: #ffffff;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.admin-btn:hover {
    background: var(--border-color);
    border-color: var(--text-muted);
}

.admin-btn:visited {
    color: #ffffff;
}

.admin-btn {
    background: linear-gradient(135deg, var(--color-purple), var(--color-blue));
    border: 1px solid var(--color-purple);
}

.admin-btn:hover {
    background: linear-gradient(135deg, #b895e6, #6c9fe8);
    border-color: var(--color-purple);
}

.admin-icon {
    flex-shrink: 0;
}

/* Trigger Panel */
.trigger-panel {
    background: var(--bg-secondary);
    padding: var(--spacing);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.trigger-panel label {
    font-weight: 500;
    color: var(--text-secondary);
}

.trigger-panel input {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 14px;
    width: 120px;
    transition: var(--transition);
}

.trigger-panel input:focus {
    outline: none;
    border-color: var(--color-blue);
    box-shadow: 0 0 0 3px rgba(137, 180, 250, 0.1);
}

.trigger-panel button {
    background: var(--color-blue);
    color: var(--bg-primary);
    border: none;
    padding: 8px 20px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
}

.trigger-panel button:hover:not(:disabled) {
    background: #6c9fe8;
    transform: translateY(-1px);
}

.trigger-panel button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.trigger-panel .secondary-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.trigger-panel .secondary-btn:hover:not(:disabled) {
    background: var(--border-color);
    border-color: var(--text-muted);
}

.trigger-panel .danger-btn {
    background: var(--bg-tertiary);
    color: var(--color-red);
    border: 1px solid var(--color-red);
}

.trigger-panel .danger-btn:hover:not(:disabled) {
    background: var(--color-red);
    color: var(--bg-primary);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    font-size: 14px;
    font-weight: 500;
}

.status-indicator .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-indicator.idle .dot {
    background: var(--text-muted);
    animation: none;
}

.status-indicator.running .dot {
    background: var(--color-yellow);
}

.status-indicator.completed .dot {
    background: var(--color-green);
    animation: none;
}

.status-indicator.failed .dot {
    background: var(--color-red);
    animation: none;
}

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

/* Main Layout */
.main-container {
    display: grid;
    grid-template-columns: 1fr 300px;
    grid-template-rows: minmax(0, 1fr);
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Logs Section */
.logs-section {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    min-height: 0;
    overflow: hidden;
}

.section-header {
    background: var(--bg-secondary);
    padding: 12px var(--spacing);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    margin-left: auto;
    padding: 0 8px;
    line-height: 1;
    transition: var(--transition);
}

.toggle-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.logs-container {
    flex: 1 1 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--spacing);
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.8;
    min-height: 0;
}

.log-entry {
    padding: 6px 0;
    display: flex;
    gap: 8px;
}

.log-entry .timestamp {
    color: var(--text-muted);
    font-size: 11px;
    min-width: 60px;
}

.log-entry .message {
    flex: 1;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Log level colors */
.log-entry.info .message { color: var(--text-primary); }
.log-entry.success .message { color: var(--color-green); }
.log-entry.warning .message { color: var(--color-yellow); }
.log-entry.error .message { color: var(--color-red); }
.log-entry.tool .message { color: var(--color-purple); }

/* History Sidebar */
.history-section {
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.history-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--spacing);
    min-height: 0;
}

.history-empty {
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
    padding: 40px 20px;
}

.history-item {
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    border-left: 3px solid var(--color-blue);
}

.history-item .behaviour {
    font-weight: 600;
    color: var(--color-blue);
    margin-bottom: 4px;
}

.history-item .message {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.history-item .timestamp {
    font-size: 11px;
    color: var(--text-muted);
}

/* Chat Section */
.chat-section {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    max-height: 400px;
    min-height: 250px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--spacing);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

.chat-message {
    display: flex;
    width: 100%;
}

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

.chat-message.agent-message {
    justify-content: flex-start;
}

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

.user-message .message-bubble {
    background: var(--color-blue);
    color: var(--bg-primary);
    border-bottom-right-radius: 4px;
}

.agent-message .message-bubble {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border-left: 3px solid var(--color-purple);
}

/* Markdown styling in chat bubbles */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4 {
    margin: 16px 0 8px 0;
    font-weight: 600;
}

.message-bubble h1 { font-size: 18px; }
.message-bubble h2 { font-size: 16px; }
.message-bubble h3 { font-size: 15px; }
.message-bubble h4 { font-size: 14px; }

.message-bubble p {
    margin: 8px 0;
}

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

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

.message-bubble ul,
.message-bubble ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-bubble li {
    margin: 4px 0;
}

.message-bubble strong,
.message-bubble b {
    font-weight: 600;
    color: var(--color-blue);
}

.message-bubble em,
.message-bubble i {
    font-style: italic;
}

.message-bubble code {
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 12px;
}

.message-bubble pre {
    background: var(--bg-primary);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.message-bubble pre code {
    background: none;
    padding: 0;
}

.message-bubble a {
    color: var(--color-blue);
    text-decoration: underline;
}

.message-bubble a:hover {
    color: #6c9fe8;
}

.message-bubble blockquote {
    border-left: 3px solid var(--color-blue);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
}

.chat-input-container {
    display: flex;
    gap: 8px;
    padding: var(--spacing);
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    transition: var(--transition);
}

.chat-input:focus {
    outline: none;
    border-color: var(--color-blue);
    box-shadow: 0 0 0 3px rgba(137, 180, 250, 0.1);
}

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

.send-btn {
    background: var(--color-blue);
    color: var(--bg-primary);
    border: none;
    padding: 10px 24px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.send-btn:hover:not(:disabled) {
    background: #6c9fe8;
    transform: translateY(-1px);
}

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

.message-timestamp {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: #505068;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border-color);
    border-top-color: var(--color-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Responsive */
@media (max-width: 1024px) {
    .main-container {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
    }
    
    .logs-section {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        min-height: 300px;
    }
    
    .history-section {
        max-height: 300px;
    }
}

/* =============================================================================
   Login Modal - Shared between main page and admin dashboard
   ============================================================================= */

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 40px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
    margin-bottom: 10px;
    color: #333;
}

.modal-content p {
    color: #666;
    margin-bottom: 20px;
}

.modal-content .form-group {
    margin-bottom: 20px;
}

.modal-content input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s;
    font-family: inherit;
}

.modal-content input:focus {
    outline: none;
    border-color: #667eea;
}

.modal-content .message.error {
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid #ef4444;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: 500;
}

.modal-content .btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.modal-content .btn-primary {
    background: #667eea;
    color: white;
    width: 100%;
}

.modal-content .btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.modal-content .btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Utility classes */
.hidden {
    display: none !important;
}

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

.mt-2 {
    margin-top: 8px;
}

.mb-2 {
    margin-bottom: 8px;
}

