:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a25;
    --accent-primary: #00d4ff;
    --accent-secondary: #ff006e;
    --accent-success: #00ff88;
    --accent-warning: #ffaa00;
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --border: #2a2a3a;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Header */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header h1 {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.status-indicator {
    color: var(--accent-success);
    font-size: 12px;
    animation: pulse 2s infinite;
}

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

.header-right {
    display: flex;
    gap: 8px;
}

/* Buttons */
.btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.btn:hover {
    background: var(--accent-primary);
    color: var(--bg-primary);
}

.btn-primary {
    background: var(--accent-primary);
    color: var(--bg-primary);
    border: none;
}

.btn-emergency {
    background: var(--accent-secondary);
    color: white;
    border: none;
}

.btn-small {
    padding: 4px 12px;
    font-size: 12px;
}

/* Main Grid */
.main-grid {
    padding: 76px 16px 24px;
    max-width: 1400px;
    margin: 0 auto;
    display: grid;
    gap: 16px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

@media (min-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-primary);
}

.stat-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent-primary);
}

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

/* Sections */
section {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 16px;
    font-weight: 600;
}

/* VNC Section */
.vnc-container {
    background: var(--bg-primary);
    border-radius: 8px;
    height: 400px;
    overflow: hidden;
    position: relative;
}

.vnc-container iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.vnc-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
}

.vnc-url {
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-secondary);
    word-break: break-all;
}

/* Quick Actions */
.quick-actions {
    padding: 16px;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

@media (min-width: 768px) {
    .action-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.action-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
    font-size: 14px;
}

.action-btn:hover {
    background: var(--accent-primary);
    color: var(--bg-primary);
    border-color: var(--accent-primary);
}

.action-icon {
    font-size: 28px;
}

/* Jobs & Agents Lists */
.jobs-list, .agents-tree {
    max-height: 300px;
    overflow-y: auto;
}

.job-item, .agent-item {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    border-left: 4px solid var(--accent-primary);
}

.job-item.pending { border-left-color: var(--accent-warning); }
.job-item.running { border-left-color: var(--accent-primary); animation: pulse-border 2s infinite; }
.job-item.completed { border-left-color: var(--accent-success); }
.job-item.failed { border-left-color: var(--accent-secondary); }

@keyframes pulse-border {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.job-title, .agent-name {
    font-weight: 600;
    margin-bottom: 4px;
}

.job-meta, .agent-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 600;
}

.status-badge.pending { background: var(--accent-warning); color: #000; }
.status-badge.running { background: var(--accent-primary); color: #000; }
.status-badge.completed { background: var(--accent-success); color: #000; }
.status-badge.failed { background: var(--accent-secondary); color: #fff; }

/* Logs */
.logs-container {
    max-height: 250px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

.log-entry {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 12px;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-entry .timestamp {
    color: var(--text-secondary);
    min-width: 70px;
}

.log-entry .level {
    min-width: 50px;
    font-weight: 600;
}

.log-entry.info .level { color: var(--accent-primary); }
.log-entry.warn .level { color: var(--accent-warning); }
.log-entry.error .level { color: var(--accent-secondary); }

.log-entry .message {
    flex: 1;
    color: var(--text-primary);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
}

.modal-content h3 {
    margin-bottom: 16px;
}

.modal-content input,
.modal-content textarea,
.modal-content select {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    color: var(--text-primary);
    margin-bottom: 12px;
    font-size: 14px;
}

.modal-content textarea {
    min-height: 100px;
    resize: vertical;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 16px;
}

/* Empty State */
.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* Mobile Optimizations */
@media (max-width: 480px) {
    .header h1 {
        font-size: 16px;
    }
    
    .stat-value {
        font-size: 22px;
    }
    
    .vnc-container {
        height: 250px;
    }
    
    .action-btn {
        padding: 16px 12px;
        font-size: 12px;
    }
    
    .action-icon {
        font-size: 24px;
    }
}

/* Desktop optimizations */
@media (min-width: 1200px) {
    .main-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .vnc-section {
        grid-column: 1 / -1;
    }
    
    .vnc-container {
        height: 600px;
    }
}

/* Chat Interface */
.left-column, .right-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

@media (min-width: 1024px) {
    .main-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 400px;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    position: relative;
}

.message.user {
    align-self: flex-end;
    background: var(--accent-primary);
    color: #000;
}

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

.message.system {
    align-self: center;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
}

.message.typing {
    align-self: flex-start;
    background: var(--bg-tertiary);
    animation: pulse 1.5s infinite;
}

.message-content {
    line-height: 1.5;
    word-break: break-word;
}

.model-badge {
    font-size: 10px;
    background: rgba(0,0,0,0.3);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    opacity: 0.7;
}

.message-time {
    font-size: 10px;
    opacity: 0.5;
    margin-top: 4px;
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border);
}

#chat-input {
    flex: 1;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    color: var(--text-primary);
    resize: none;
    min-height: 44px;
    max-height: 120px;
}

.btn-attach, .btn-send {
    padding: 12px;
    min-width: 44px;
}

/* Agent Selector */
.agent-selector {
    padding: 12px;
}

.agent-selector select {
    width: 100%;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
}

/* Spawner Section */
.spawner-section {
    background: var(--bg-tertiary);
    border: 1px solid var(--accent-primary);
    border-radius: 12px;
    padding: 16px;
}

.spawner-section input,
.spawner-section select {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
}

.spawner-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Cost Bar */
.cost-bar {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    height: 40px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 16px;
    z-index: 999;
    font-size: 12px;
}

.cost-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.cost-value {
    color: var(--accent-success);
    font-weight: 600;
}

.cost-limit {
    color: var(--text-secondary);
}

#model-selector {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px;
    color: var(--text-primary);
    font-size: 11px;
}

/* VNC Enhancements */
.vnc-container {
    position: relative;
}

.vnc-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 8px;
}

.vnc-reload {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
    opacity: 0.8;
}

.vnc-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    cursor: pointer;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.vnc-placeholder:hover {
    background: var(--bg-secondary);
}

.vnc-password {
    color: var(--accent-primary);
    font-family: monospace;
    margin-top: 8px;
}

.vnc-quick-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

/* Status Badge */
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.pending { background: var(--accent-warning); color: #000; }
.status-badge.running { background: var(--accent-primary); color: #000; }
.status-badge.completed { background: var(--accent-success); color: #000; }
.status-badge.failed { background: var(--accent-secondary); color: #fff; }

/* Adjust main grid for cost bar */
.main-grid {
    padding-top: 116px;
}

.header {
    height: 60px;
}

/* File upload preview */
#upload-preview {
    padding: 0 12px 12px;
    font-size: 12px;
    color: var(--accent-primary);
}

/* Log entries */
.log-entry {
    padding: 4px 0;
    font-size: 11px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.log-time {
    color: var(--text-secondary);
    margin-right: 8px;
}

.log-level {
    font-weight: 600;
    margin-right: 8px;
}

.log-source {
    color: var(--accent-primary);
    margin-right: 4px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .main-grid {
        grid-template-columns: 1fr;
    }
    
    .cost-bar {
        font-size: 10px;
        flex-wrap: wrap;
        height: auto;
        padding: 8px;
    }
    
    .chat-section {
        min-height: 300px;
    }
}
