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

/* Dark theme (default) */
:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #64748b;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-dark: #0f172a;
    --bg-darker: #020617;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border: #334155;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

/* Light theme */
[data-theme="light"] {
    --bg-dark: #f8fafc;
    --bg-darker: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border: #e2e8f0;
}

[data-theme="light"] .modal-overlay {
    background: rgba(0, 0, 0, 0.3);
}

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

/* Auth View */
.auth-container {
    max-width: 400px;
    margin: 100px auto;
    padding: 40px;
    background: var(--bg-card);
    border-radius: 12px;
    text-align: center;
}

.auth-container h1 {
    font-size: 28px;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.auth-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
}

.auth-tabs .tab {
    flex: 1;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.auth-tabs .tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.form-group {
    margin-bottom: 16px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    color: var(--text-secondary);
}

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

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.error-message {
    color: var(--danger);
    font-size: 14px;
    margin-top: 16px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
}

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

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

.btn-success:hover {
    background: #16a34a;
}

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

.btn-block {
    width: 100%;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-darker);
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 18px;
    font-weight: 600;
}

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

.header-center select {
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    min-width: 200px;
}

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

#user-name {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Main Layout */
.main-content {
    display: flex;
    height: calc(100vh - 57px);
}

.sidebar {
    width: 260px;
    background: var(--bg-darker);
    border-right: 1px solid var(--border);
    padding: 20px;
    overflow-y: auto;
}

.sidebar-section {
    margin-bottom: 32px;
}

.sidebar-section h3 {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.item-list {
    list-style: none;
    margin-bottom: 12px;
}

.item-list li {
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.item-list li:hover {
    background: var(--bg-card);
}

.item-list li.active {
    background: var(--primary);
}

.item-list .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
}

.item-list .status-dot.active {
    background: var(--success);
}

.item-list .status-dot.running {
    background: var(--warning);
    animation: pulse 1.5s infinite;
}

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

/* Content Area */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 20px;
    overflow-y: auto;
}

.panel {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
}

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

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

.panel-header-left h2 {
    cursor: pointer;
    transition: color 0.2s;
}

.panel-header-left h2:hover {
    color: var(--primary);
}

/* Status Badge */
.status-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
}

.status-pending {
    background: var(--secondary);
    color: white;
}

.status-running {
    background: var(--warning);
    color: #1a1a1a;
    animation: pulse 1.5s infinite;
}

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

.status-completed {
    background: var(--success);
    color: white;
}

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

.mission-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

.progress-bar {
    width: 200px;
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s;
}

/* Token Info */
.token-info {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

.token-info .token-usage {
    font-family: var(--font-mono);
}

.token-info .cost-usage {
    color: var(--warning);
    font-weight: 500;
}

/* Theme Toggle */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
}

.theme-toggle:hover {
    background: var(--bg-input);
}

/* Language Toggle */
.lang-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    transition: all 0.2s;
}

.lang-toggle:hover {
    background: var(--bg-input);
}

/* Question Panel */
.question-panel {
    background: var(--bg-input);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 16px;
    text-align: center;
}

.question-icon {
    width: 40px;
    height: 40px;
    background: var(--warning);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    margin: 0 auto 12px;
}

.question-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin: 16px 0;
}

.question-options button {
    padding: 8px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
}

.question-options button:hover {
    background: var(--primary);
    border-color: var(--primary);
}

.custom-answer {
    display: flex;
    gap: 8px;
    max-width: 400px;
    margin: 0 auto;
}

.custom-answer input {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
}

/* Chat Messages */
.chat-messages {
    max-height: 400px;
    overflow-y: auto;
    padding: 12px;
    background: var(--bg-darker);
    border-radius: 8px;
}

.message {
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 8px;
    max-width: 80%;
}

.message.user {
    background: var(--primary);
    margin-left: auto;
}

.message.assistant {
    background: var(--bg-card);
}

.message.tool {
    background: var(--bg-input);
    font-size: 12px;
    color: var(--text-secondary);
}

.message.tool .tool-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-family: inherit;
}

.message.tool .tool-icon {
    font-size: 16px;
}

.message.tool pre {
    margin: 0;
    padding: 8px;
    background: var(--bg-darker);
    border-radius: 4px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 11px;
}

/* Message Content (Markdown) */
.message-content {
    line-height: 1.6;
}

.message-content p {
    margin: 0 0 12px 0;
}

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

.message-content h2,
.message-content h3,
.message-content h4 {
    margin: 16px 0 8px 0;
    font-weight: 600;
}

.message-content h2 {
    font-size: 18px;
}

.message-content h3 {
    font-size: 16px;
}

.message-content h4 {
    font-size: 14px;
}

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

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

.message-content code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
}

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

.message-content pre code {
    background: none;
    padding: 0;
    font-size: 12px;
    line-height: 1.5;
}

.message-content blockquote {
    margin: 12px 0;
    padding: 8px 16px;
    border-left: 3px solid var(--primary);
    background: var(--bg-input);
    font-style: italic;
}

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

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

.message-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

.message-content strong {
    font-weight: 600;
}

.message-content em {
    font-style: italic;
}

/* Tables */
.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
}

.message-content table th,
.message-content table td {
    padding: 10px 12px;
    text-align: left;
    border: 1px solid var(--border);
}

.message-content table th {
    background: var(--bg-input);
    font-weight: 600;
    white-space: nowrap;
}

.message-content table tr:nth-child(even) {
    background: var(--bg-darker);
}

.message-content table tr:hover {
    background: var(--bg-input);
}

/* Responsive table */
@media (max-width: 600px) {
    .message-content table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* Activity Feed */
.activity-panel {
    max-height: 300px;
}

.activity-panel h3 {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.activity-feed {
    max-height: 240px;
    overflow-y: auto;
}

.activity-item {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-time {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
    min-width: 50px;
}

.activity-icon {
    font-size: 14px;
}

.activity-text {
    flex: 1;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    min-width: 400px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    z-index: 101;
}

/* Prevent accidental close on mobile */
@media (max-width: 768px) {
    .modal-content {
        min-width: 90vw;
        max-width: 95vw;
        margin: 20px;
    }
}

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

.modal-header h2 {
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
}

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

/* Share Modal */
.share-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.input-with-copy {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.input-with-copy input,
.input-with-copy textarea {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 13px;
}

.input-with-copy textarea {
    resize: vertical;
    min-height: 70px;
}

.input-with-copy .btn {
    white-space: nowrap;
    min-width: 70px;
}

/* Tools Grid */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
}

.tool-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px;
    background: var(--bg-input);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.tool-checkbox:hover {
    background: var(--bg-darker);
}

.tool-checkbox input[type="checkbox"] {
    margin-top: 4px;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.tool-checkbox .tool-icon {
    font-size: 20px;
}

.tool-checkbox .tool-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tool-checkbox .tool-name {
    font-weight: 500;
    font-size: 14px;
}

.tool-checkbox .tool-desc {
    font-size: 11px;
    color: var(--text-secondary);
}

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

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

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

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

/* Responsive */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .header-center {
        display: none;
    }
}
