/* 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);
    white-space: nowrap;
}

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

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

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

.selected-user-info {
    color: var(--color-green);
    font-size: 13px;
    font-weight: 500;
    margin-left: 4px;
    white-space: nowrap;
}

.picker-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.picker-actions button {
    padding: 8px 20px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    border: none;
    transition: var(--transition);
}

.picker-actions button:hover:not(:disabled) {
    transform: translateY(-1px);
}

.picker-actions button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.picker-actions .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;
}

/* Grid children must shrink so inner scroll works (default min-height: auto prevents this) */
.main-container > * {
    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 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: var(--spacing);
}

.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 .category,
.history-item .behaviour {
    font-weight: 600;
    color: var(--color-blue);
    margin-bottom: 4px;
}

.history-item .delivery-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.history-item .delivery-tag {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.history-item .delivery-tag-slack {
    background: rgba(137, 180, 250, 0.25);
    color: #89b4fa;
    border: 1px solid rgba(137, 180, 250, 0.5);
}

.history-item .delivery-tag-email {
    background: rgba(166, 227, 161, 0.2);
    color: #a6e3a1;
    border: 1px solid rgba(166, 227, 161, 0.5);
}

.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);
}

.history-item.clickable {
    cursor: pointer;
}
.history-item.clickable:hover {
    background: rgba(64, 64, 88, 0.6);
}
.history-item.clickable:focus {
    outline: 2px solid var(--color-blue);
    outline-offset: 2px;
}

/* 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: 280px;
    min-height: 140px;
}

.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);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
}

.typing-indicator span {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%            { transform: translateY(-6px); opacity: 1; }
}

/* 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;
    align-items: center;
    gap: 8px;
    padding: 10px var(--spacing);
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    flex-shrink: 0;
    min-height: 52px;
}

.chat-input {
    flex: 1;
    min-width: 0;
    height: 40px;
    box-sizing: border-box;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0 14px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 40px;
    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, scheduled runs, and slack workspaces
   ============================================================================= */

/* Initial state (no flash) – set by auth.js from sessionStorage */
#loginModal {
    display: var(--initial-modal-display, flex) !important;
}
#mainContent {
    display: var(--initial-content-display, none) !important;
}

.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;
}

/* Nudge Detail Modal - dark theme to match app */
.nudge-detail-modal .modal-content.nudge-detail-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 24px;
    max-width: 520px;
    width: 92%;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.nudge-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-shrink: 0;
}
.nudge-detail-modal .nudge-detail-header h2 {
    color: var(--text-primary);
    margin: 0;
    font-size: 1.25rem;
}
.nudge-detail-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.nudge-detail-close:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}
.nudge-detail-body {
    overflow-y: auto;
    color: var(--text-secondary);
    font-size: 14px;
}
.nudge-detail-row {
    margin-bottom: 12px;
}
.nudge-detail-label {
    display: inline-block;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 120px;
    margin-right: 8px;
}
.nudge-detail-value {
    margin-top: 4px;
    margin-left: 0;
    word-break: break-word;
    white-space: pre-wrap;
}
.nudge-detail-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}
.nudge-detail-section-title {
    font-weight: 700;
    color: var(--color-blue);
    margin-bottom: 10px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.nudge-detail-feedback {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.nudge-detail-email-body-box {
    margin: 8px 0 0 0;
    padding: 12px;
    font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: auto;
    max-height: 240px;
    overflow-y: auto;
}

/* =============================================================================
   Shared page styles – scheduled-runs, slack workspaces
   (Index uses #mainContent > .header etc.; these apply when using .container)
   ============================================================================= */

.page-container,
.container {
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    padding: var(--spacing);
    box-sizing: border-box;
}

.slack-workspaces .container {
    max-width: 1400px;
    min-width: 800px;
}

.container .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing);
    padding: var(--spacing);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.container .header h1 {
    margin: 0 0 4px 0;
    color: var(--color-blue);
}

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

.nav-links {
    display: flex;
    gap: 6px;
    align-items: center;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 7px 14px;
    border-radius: 6px;
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
    white-space: nowrap;
}

.nav-links a:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.nav-links a.active {
    background: var(--color-blue, #667eea);
    color: var(--bg-primary, #fff);
    font-weight: 600;
    border-color: var(--color-blue, #667eea);
}

/* Stats grid (scheduled-runs) */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing);
    margin-bottom: var(--spacing);
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: var(--spacing);
    box-shadow: var(--shadow);
}

.stat-card h3 {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-card .value {
    font-size: 32px;
    font-weight: 600;
    color: var(--color-blue);
}

.stat-card .label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Filters (scheduled-runs) */
.filters {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: var(--spacing);
    margin-bottom: var(--spacing);
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-group label {
    font-size: 12px;
    color: var(--text-secondary);
}

.filter-group input,
.filter-group select {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
}

/* Buttons – page content (not login modal; .modal-content .btn is in Login Modal section) */
.container .btn,
#mainContent .btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    display: inline-block;
}

.container .btn-primary,
#mainContent .btn-primary {
    background: var(--color-blue);
    color: #1e1e2e;
}

.container .btn-primary:hover,
#mainContent .btn-primary:hover {
    opacity: 0.9;
}

.container .btn-secondary,
#mainContent .btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    font-weight: 600;
}

.container .btn-secondary:hover,
#mainContent .btn-secondary:hover {
    background: var(--border-color);
}

.container .btn-danger,
#mainContent .btn-danger,
.modal-content .btn-danger {
    background: var(--color-red);
    color: var(--text-primary);
    font-weight: 600;
}

.container .btn-danger:hover,
#mainContent .btn-danger:hover,
.modal-content .btn-danger:hover {
    opacity: 0.9;
}

.container .btn-sm,
#mainContent .btn-sm {
    background: transparent;
    color: var(--text-primary);
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 600;
}

/* Card (admin) */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: var(--spacing);
    margin-bottom: var(--spacing);
    box-shadow: var(--shadow);
    min-width: 0;
    overflow-x: auto;
}

.card h2 {
    margin-top: 0;
    margin-bottom: var(--spacing);
    color: var(--color-blue);
    font-size: 20px;
}

/* Form groups – page content only (login modal uses .modal-content .form-group) */
.container .form-group,
#mainContent .form-group,
.card .form-group {
    margin-bottom: 16px;
}

.container .form-group label,
#mainContent .form-group label,
.card .form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 14px;
}

.container .form-group input,
.container .form-group textarea,
.container .form-group select,
#mainContent .form-group input,
#mainContent .form-group textarea,
#mainContent .form-group select,
.card .form-group input,
.card .form-group textarea,
.card .form-group select {
    width: 100%;
    padding: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
}

.container .form-group input:focus,
#mainContent .form-group input:focus,
.card .form-group input:focus,
.container .form-group textarea:focus,
#mainContent .form-group textarea:focus,
.card .form-group textarea:focus,
.container .form-group select:focus,
#mainContent .form-group select:focus,
.card .form-group select:focus {
    outline: none;
    border-color: var(--color-blue);
}

.help-text {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.action-buttons {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

/* Tables – inside container / runs-table / card */
.runs-table {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.container table,
.runs-table table,
.card table {
    width: 100%;
    min-width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
    table-layout: auto;
}

.container thead,
.runs-table thead,
.card thead,
.container table thead,
.runs-table table thead,
.card table thead {
    background: var(--bg-tertiary);
}

.container th,
.runs-table th,
.card th,
.container table th,
.runs-table table th,
.card table th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.container td,
.runs-table td,
.card td,
.container table td,
.runs-table table td,
.card table td {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 14px;
}

.container tbody tr:hover,
.runs-table tbody tr:hover,
.card tbody tr:hover {
    background: var(--bg-tertiary);
}

.runs-table th {
    font-size: 12px;
    color: var(--text-secondary);
}

.runs-table td {
    border-top: 1px solid var(--border-color);
}

/* Status badges and run link */
.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.status-success {
    background: rgba(166, 227, 161, 0.2);
    color: var(--color-green);
}

.status-failed,
.status-error {
    background: rgba(243, 139, 168, 0.2);
    color: var(--color-red);
}

.status-partial {
    background: rgba(249, 226, 175, 0.2);
    color: var(--color-yellow);
}

.status-in_progress {
    background: rgba(147, 197, 253, 0.2);
    color: var(--color-blue, #2563eb);
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success {
    background: rgba(166, 227, 161, 0.2);
    color: var(--color-green);
}

.badge-warning {
    background: rgba(249, 226, 175, 0.2);
    color: var(--color-yellow);
}

.run-link {
    color: var(--color-blue);
    cursor: pointer;
    text-decoration: underline;
}

.run-link:hover {
    opacity: 0.8;
}

/* Run detail modal (scheduled-runs) */
.run-detail-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    overflow-y: auto;
}

.run-detail-modal-content {
    background: var(--bg-primary);
    margin: 40px auto;
    padding: var(--spacing);
    border-radius: var(--radius);
    max-width: 1200px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing);
    padding-bottom: var(--spacing);
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    margin: 0;
    color: var(--color-blue);
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
}

.detail-section {
    margin-bottom: var(--spacing);
}

.detail-section h3 {
    color: var(--color-blue);
    margin-bottom: 12px;
    font-size: 16px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 12px;
}

.detail-item {
    background: var(--bg-secondary);
    padding: 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.detail-item label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.detail-item .value {
    font-size: 14px;
    color: var(--text-primary);
}

/* User decisions table inside run detail modal */
.decisions-table {
    margin-top: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    overflow: hidden;
    max-height: 360px;
    overflow-y: auto;
}

.decisions-table table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

.decisions-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-tertiary);
    box-shadow: 0 1px 0 var(--border-color);
}

.decisions-table th {
    padding: 10px 12px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.decisions-table td {
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
}

.decisions-table tbody tr:last-child td {
    border-bottom: none;
}

.decisions-table tbody tr:hover {
    background: var(--bg-tertiary);
}

/* Long text (reason, error) wraps instead of stretching */
.decisions-table td:nth-child(3),
.decisions-table td:nth-child(6) {
    word-break: break-word;
    min-width: 0;
}

.decisions-table .run-link,
.decisions-table .log-id-link {
    cursor: pointer;
    color: var(--color-blue);
    text-decoration: none;
}

.decisions-table .run-link:hover,
.decisions-table .log-id-link:hover {
    text-decoration: underline;
}

/* Truncate very long reason/error in cell with title for full text */
.decisions-table td:nth-child(3),
.decisions-table td:nth-child(6) {
    max-width: 180px;
}

.decisions-table .status-badge {
    white-space: nowrap;
}

/* Shared loading, error, empty, message */
.loading {
    text-align: center;
    padding: var(--spacing);
    color: var(--text-secondary);
}

.card .loading,
.empty-state {
    padding: 40px;
    color: var(--text-muted);
}

.error {
    background: rgba(243, 139, 168, 0.2);
    color: var(--color-red);
    padding: var(--spacing);
    border-radius: var(--radius);
    margin-bottom: var(--spacing);
}

.empty {
    text-align: center;
    padding: var(--spacing);
    color: var(--text-muted);
}

.container .message,
#mainContent .message {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
}

.container .message.success,
#mainContent .message.success {
    background: rgba(166, 227, 161, 0.2);
    color: var(--color-green);
    border: 1px solid rgba(166, 227, 161, 0.3);
}

.container .message.error,
#mainContent .message.error {
    background: rgba(243, 139, 168, 0.2);
    color: var(--color-red);
    border: 1px solid rgba(243, 139, 168, 0.3);
}

#messageContainer {
    margin-bottom: var(--spacing);
}

#installationsContainer,
#workspacesContainer {
    min-height: 100px;
}

@media (max-width: 900px) {
    .container {
        min-width: 100%;
        padding: 12px;
    }
}

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

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

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

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

/* =========================================================================
   Tool call cards (collapsible) in chat panel
   ========================================================================= */

.tool-card {
    margin: 4px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-tertiary);
    font-size: 12px;
    overflow: hidden;
}

.tool-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    cursor: pointer;
    user-select: none;
    color: var(--text-secondary);
    transition: background 0.15s;
}

.tool-card-header:hover {
    background: var(--bg-secondary);
}

.tool-card-icon {
    font-size: 13px;
}

.tool-card-name {
    font-family: monospace;
    font-weight: 600;
    color: var(--color-blue);
}

.tool-card-toggle {
    margin-left: auto;
    font-size: 10px;
    transition: transform 0.15s;
}

.tool-card.expanded .tool-card-toggle {
    transform: rotate(90deg);
}

.tool-card-body {
    display: none;
    padding: 8px 10px;
    border-top: 1px solid var(--border-color);
}

.tool-card.expanded .tool-card-body {
    display: block;
}

.tool-card-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    margin-top: 8px;
}

.tool-card-label:first-child {
    margin-top: 0;
}

.tool-card-code {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 6px 8px;
    font-family: monospace;
    font-size: 11px;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
    margin: 0;
}

/* =========================================================================
   Memory & Context panel
   ========================================================================= */

.memory-section {
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.memory-container {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 12px;
    font-size: 13px;
}

.memory-meta {
    padding: 8px 0;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.6;
}

.memory-meta-label {
    font-weight: 600;
    color: var(--text-secondary);
}

.memory-section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--color-purple);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 12px;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
}

.memory-chat-history {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 8px;
}

.memory-chat-user,
.memory-chat-agent {
    padding: 4px 0;
    font-size: 12px;
    line-height: 1.5;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    word-break: break-word;
}

.memory-chat-user {
    color: var(--text-primary);
}

.memory-chat-agent {
    color: var(--text-secondary);
}

.memory-field {
    margin-bottom: 8px;
}

.memory-field-key {
    font-size: 11px;
    font-weight: 600;
    color: var(--color-blue);
    font-family: monospace;
    margin-bottom: 2px;
}

.memory-field-value {
    font-size: 12px;
    color: var(--text-primary);
    line-height: 1.5;
}

.memory-json {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 6px 8px;
    font-family: monospace;
    font-size: 11px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
    margin: 2px 0 0;
}

