/* KI Project Hub - Dark Theme */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-tertiary: #252830;
    --bg-hover: #2a2d37;
    --border: #2e3140;
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --sidebar-width: 260px;
    --topbar-height: 52px;
    --radius: 8px;
    --radius-sm: 4px;
}

* { 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);
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
}

/* Sidebar */
#sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

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

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

#sidebar-groups {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.sidebar-group {
    margin-bottom: 4px;
}

.sidebar-group-header {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    cursor: pointer;
    border-radius: var(--radius-sm);
}

.sidebar-group-header:hover {
    background: var(--bg-hover);
}

.sidebar-group-header .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
    flex-shrink: 0;
}

.sidebar-project {
    display: flex;
    align-items: center;
    padding: 8px 8px 8px 24px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}

.sidebar-project:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-project.active {
    background: var(--accent);
    color: white;
}

.sidebar-project .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 8px;
    flex-shrink: 0;
    background: var(--text-muted);
}

.sidebar-project .status-dot.running {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

#stats-mini {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
}

.sidebar-actions {
    padding: 8px;
    border-top: 1px solid var(--border);
}

.sidebar-add-group {
    display: block;
    width: 100%;
    padding: 6px 8px;
    font-size: 12px;
    color: var(--text-muted);
    background: none;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
}

.sidebar-add-group:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Main Content */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#topbar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

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

#breadcrumb span {
    color: var(--text-muted);
    margin: 0 6px;
}

.view {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.view.active {
    display: block;
}

/* Cards */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    text-align: center;
    padding: 24px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s;
    gap: 6px;
}

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

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

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

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

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

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

/* Forms */
label {
    display: block;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--text-secondary);
}

input[type="text"],
input[type="number"],
textarea,
select {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 8px 12px;
    font-size: 13px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    min-width: 400px;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h3 {
    margin-bottom: 16px;
    font-size: 16px;
    color: var(--text-primary);
}

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

/* Agent Cards */
#agent-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.agent-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: border-color 0.15s;
}

.agent-card:hover {
    border-color: var(--accent);
}

.agent-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.agent-card-name {
    font-size: 14px;
    font-weight: 600;
}

.agent-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

.agent-status.queued { background: var(--bg-primary); color: var(--text-muted); }
.agent-status.running { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.agent-status.completed { background: rgba(99, 102, 241, 0.15); color: var(--accent-hover); }
.agent-status.failed { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.agent-status.timeout { background: rgba(245, 158, 11, 0.15); color: var(--warning); }

.agent-status .pulse {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.agent-status.running .pulse {
    animation: pulse 1.5s infinite;
}

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

.agent-card-prompt {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 8px;
}

.agent-card-meta {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
}

/* Phases */
#phases-container {
    margin-bottom: 16px;
}

.phase-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}

.phase-segment {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    transition: background 0.3s;
}

.phase-segment.completed { background: var(--success); }
.phase-segment.running { background: var(--accent); animation: pulse 1.5s infinite; }
.phase-segment.failed { background: var(--danger); }

.phase-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.phase-chip {
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.phase-chip.running {
    border-color: var(--accent);
    color: var(--accent);
}

.phase-chip.completed {
    border-color: var(--success);
    color: var(--success);
}

/* Terminal Panel */
#terminal-panel {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    height: 300px;
    display: flex;
    flex-direction: column;
}

.terminal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#terminal-container {
    flex: 1;
    padding: 4px;
}

/* Task List */
.task-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

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

.task-item:hover { background: var(--bg-hover); }

.task-title {
    font-size: 14px;
    flex: 1;
}

.task-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

.task-status.pending { background: var(--bg-tertiary); color: var(--text-muted); }
.task-status.planning { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.task-status.approved { background: rgba(99, 102, 241, 0.15); color: var(--accent-hover); }
.task-status.running { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.task-status.completed { background: rgba(99, 102, 241, 0.15); color: var(--accent-hover); }
.task-status.failed { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* Task Input */
#task-input-card textarea {
    margin-bottom: 8px;
}

.task-input-actions {
    display: flex;
    justify-content: flex-end;
}

/* CEO Plan */
#ceo-plan-content {
    background: var(--bg-primary);
    padding: 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1.6;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
}

/* SVG Canvas */
#flow-canvas {
    width: 100%;
    min-height: 200px;
    margin-bottom: 16px;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
}

.cost-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.cost-bar-label {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 100px;
}

.cost-bar-fill {
    flex: 1;
    height: 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    overflow: hidden;
}

.cost-bar-fill-inner {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.3s;
}

.cost-bar-value {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 60px;
    text-align: right;
}

/* CEO Activity Panel */
#ceo-activity-card {
    border-color: var(--accent);
    border-width: 1px;
}

.ceo-activity-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.ceo-activity-header h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent-hover);
    margin-bottom: 0;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse 1.5s infinite;
    display: inline-block;
}

#ceo-activity-log {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    max-height: 300px;
    overflow-y: auto;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
}

#ceo-activity-log .ceo-line {
    padding: 1px 0;
}

#ceo-activity-log .ceo-line.tool_use {
    color: var(--warning);
}

#ceo-activity-log .ceo-line.error {
    color: var(--danger);
}

#ceo-activity-log .ceo-line.result {
    color: var(--success);
}

/* Utilities */
.muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.mt-2 { margin-top: 8px; }
.mb-2 { margin-bottom: 8px; }
.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
