/* Dev Team — Centre de Commande */
:root, [data-theme="dark"] {
    --bg: #161822;
    --bg-card: #1e2130;
    --bg-hover: #2a2e3f;
    --bg-sidebar: #181a24;
    --border: #363b50;
    --text: #eaeaef;
    --text-dim: #9fa2b4;
    --text-muted: #6e7186;
    --primary: #7c7fff;
    --primary-hover: #9b9eff;
    --accent: #a78bfa;
    --success: #34d399;
    --danger: #f87171;
    --warning: #fbbf24;
    --radius: 8px;
    --sidebar-width: 280px;
}

[data-theme="light"] {
    --bg: #f0f0f4;
    --bg-card: #ffffff;
    --bg-hover: #dddde6;
    --bg-sidebar: #e8e8f0;
    --border: #b8b8c8;
    --text: #111114;
    --text-dim: #2d2d42;
    --text-muted: #44445a;
    --primary: #4338ca;
    --primary-hover: #4f46e5;
    --accent: #6d28d9;
    --success: #15803d;
    --danger: #b91c1c;
    --warning: #b45309;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* ── App Layout ── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
}

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

/* ── Global status bar ── */
.global-status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(34, 197, 94, 0.12);
    border-bottom: 1px solid rgba(34, 197, 94, 0.25);
    color: var(--success);
    font-size: 12px;
    font-weight: 600;
    animation: status-glow 3s ease-in-out infinite;
}
.global-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: status-pulse 1.5s ease-in-out infinite;
    flex-shrink: 0;
}
@keyframes status-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
    50% { opacity: 0.6; box-shadow: 0 0 8px 2px rgba(34, 197, 94, 0.3); }
}
@keyframes status-glow {
    0%, 100% { background: rgba(34, 197, 94, 0.12); }
    50% { background: rgba(34, 197, 94, 0.18); }
}

.sidebar-new-btn {
    display: block;
    margin: 12px;
    padding: 10px 16px;
    background: var(--primary);
    color: white;
    border-radius: var(--radius);
    text-decoration: none;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s;
}
.sidebar-new-btn:hover { background: var(--primary-hover); }
/* Nav buttons — secondary style (non-primary background) */
.sidebar-nav-btn {
    background: var(--bg) !important;
    border: 1px solid var(--border) !important;
    color: var(--text) !important;
    margin-top: 4px !important;
}
.sidebar-nav-btn:hover {
    background: var(--bg-hover) !important;
    border-color: var(--primary) !important;
    color: var(--text) !important;
}

.sidebar-section { flex: 1; }
.sidebar-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px 4px;
}
.sidebar-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
}
.sidebar-clear-btn {
    background: none;
    border: none;
    font-size: 12px;
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.2s;
    padding: 2px 4px;
}
.sidebar-clear-btn:hover { opacity: 1; }

/* Sidebar projects */
.sidebar-projects {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 8px;
}

.sidebar-project {
    display: flex;
    align-items: center;
    border-radius: 6px;
    border-left: 2px solid transparent;
    transition: background 0.15s;
}
.sidebar-project:hover { background: var(--bg-hover); }
.sidebar-project.sidebar-project-active {
    background: var(--bg-hover);
    border-left-color: var(--primary);
}

.sidebar-project-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 10px;
    text-decoration: none;
    color: var(--text);
    flex: 1;
    min-width: 0;
}
.sidebar-project-icon { flex-shrink: 0; font-size: 16px; }
.sidebar-project-info { min-width: 0; flex: 1; }
.sidebar-project-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-project-meta {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 1px;
}

.sidebar-delete-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}
.sidebar-project:hover .sidebar-delete-btn { opacity: 0.6; }
.sidebar-delete-btn:hover { opacity: 1; color: var(--danger); }

.sidebar-token-badge {
    margin-left: 6px;
    font-size: 10px;
    color: var(--warning);
    font-family: monospace;
}

.sidebar-empty {
    padding: 12px 16px;
    font-size: 12px;
    color: var(--text-dim);
}

/* Legacy sidebar runs (kept for compatibility) */
.sidebar-runs {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 8px;
}

.sidebar-run-wrapper {
    display: flex;
    align-items: center;
    border-radius: 6px;
    border-left: 2px solid transparent;
    transition: background 0.15s;
    position: relative;
}
.sidebar-run-wrapper:hover { background: var(--bg-hover); }
.sidebar-run-wrapper.sidebar-run-active {
    background: var(--bg-hover);
    border-left-color: var(--primary);
}

.sidebar-run {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 10px;
    text-decoration: none;
    color: var(--text);
    flex: 1;
    min-width: 0;
}
.sidebar-run-running { border-left-color: var(--primary); }
.sidebar-run-completed .sidebar-run-icon { opacity: 0.5; }
.sidebar-run-failed .sidebar-run-icon { color: var(--danger); }

.sidebar-run-icon {
    flex-shrink: 0;
    font-size: 14px;
    margin-top: 2px;
}
.sidebar-run-info { min-width: 0; flex: 1; }
.sidebar-run-task {
    font-size: 13px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.sidebar-run-meta {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

/* ── Main Content ── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 24px 32px;
    min-width: 0;
}

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
}
.card h1 { font-size: 22px; margin-bottom: 16px; }
.card h2 { font-size: 16px; margin-bottom: 12px; color: var(--text); font-weight: 600; }

/* ── Collapsible cards ── */
.card-title-toggle {
    cursor: pointer;
    user-select: none;
}
.card-title-toggle:hover {
    color: var(--text) !important;
}
.card-collapse-body {
    margin-top: 12px;
}

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 6px;
    font-weight: 500;
}
select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}
select:focus {
    outline: none;
    border-color: var(--primary);
}

textarea, input[type="text"], input[type="password"] {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 12px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
}
textarea:focus, input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.8; }
.btn-block { width: 100%; padding: 14px; font-size: 16px; }

/* ── Utility classes ── */
.form-row { display: flex; gap: 10px; align-items: flex-end; }
.form-row .form-group { flex: 1; margin-bottom: 0; }
.form-row select { flex: 1; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-dim { color: var(--text-dim); }
.text-muted { color: var(--text-muted); }
.hidden { display: none; }

/* Inline button — matches existing tab/filter style */
.inline-btn {
    padding: 4px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}
.inline-btn:hover {
    border-color: var(--primary);
    color: var(--text);
}
.inline-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Command bar ── */
.command-bar { padding: 12px 16px; }
.command-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.command-form textarea {
    flex: 1;
    resize: vertical;
    padding: 10px 14px;
    font-size: 13px;
    min-height: 52px;
    max-height: 50vh;
}
.btn-send {
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    font-size: 16px;
    flex-shrink: 0;
}
.btn-send:hover { background: var(--primary-hover); }
.btn-stop {
    padding: 8px 12px;
    font-size: 14px;
    flex-shrink: 0;
}

/* ── OAuth banner ── */
.oauth-banner {
    background: var(--bg-card);
    border: 2px solid #f59e0b;
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 16px;
    animation: oauth-pulse 2s ease-in-out infinite;
}
.oauth-badge {
    font-size: 13px;
    font-weight: 700;
    color: #fbbf24;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}
.oauth-text {
    font-size: 14px;
    color: var(--text);
    line-height: 1.5;
    margin-bottom: 12px;
}
.oauth-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.oauth-open-btn {
    display: inline-block;
    padding: 10px 20px;
    background: #f59e0b;
    color: #000;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
    white-space: nowrap;
}
.oauth-open-btn:hover {
    background: #d97706;
    color: #000;
}
.oauth-dismiss-btn {
    padding: 10px 16px;
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.oauth-dismiss-btn:hover {
    background: var(--bg);
    color: var(--text);
}
@keyframes oauth-pulse {
    0%, 100% { border-color: #f59e0b; }
    50% { border-color: #fbbf24; box-shadow: 0 0 12px rgba(245, 158, 11, 0.3); }
}
[data-theme="light"] .oauth-banner {
    background: #fffbeb;
    border-color: #f59e0b;
}
[data-theme="light"] .oauth-badge {
    color: #b45309;
}
[data-theme="light"] .oauth-open-btn {
    background: #f59e0b;
    color: #000;
}

/* ── Question banner ── */
.question-banner {
    background: var(--bg-card);
    border: 2px solid #7c3aed;
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 16px;
    animation: question-pulse 2s ease-in-out infinite;
}
.question-badge {
    font-size: 13px;
    font-weight: 700;
    color: #a78bfa;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}
.question-text {
    font-size: 15px;
    color: var(--text);
    line-height: 1.5;
    white-space: pre-wrap;
    margin-bottom: 8px;
}
/* Question answer form */
.question-answer-form {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
.question-answer-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg);
    border: 2px solid #7c3aed;
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.question-answer-input:focus {
    border-color: #a78bfa;
    box-shadow: 0 0 8px rgba(124, 58, 237, 0.4);
}
.question-answer-input::placeholder {
    color: var(--text-dim);
}
.question-answer-btn {
    padding: 10px 20px;
    background: #7c3aed;
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}
.question-answer-btn:hover {
    background: #6d28d9;
}
.question-answer-btn:disabled {
    background: #4c1d95;
    cursor: wait;
}
@keyframes question-pulse {
    0%, 100% { border-color: #7c3aed; }
    50% { border-color: #a78bfa; box-shadow: 0 0 12px rgba(124, 58, 237, 0.3); }
}

/* Question in log */
.log-line.log-question {
    background: rgba(124, 58, 237, 0.1);
    border-left: 2px solid #7c3aed;
    padding-left: 8px;
    margin: 4px 0;
    border-radius: 2px;
}
.log-question-text { color: var(--accent); font-weight: 600; }

[data-theme="light"] .question-banner {
    background: #f0edf8;
    border-color: #7c3aed;
}
[data-theme="light"] .question-badge {
    color: #6d28d9;
}
[data-theme="light"] .question-answer-input {
    background: #ffffff;
    border-color: #a78bfa;
}
[data-theme="light"] .log-question-text {
    color: #6d28d9;
}

/* ── Progress + stats ── */
.progress-stats {
    display: flex;
    align-items: center;
    gap: 16px;
}
.progress-left { flex: 1; }
.progress-right {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}
.stat {
    font-size: 13px;
    color: var(--text-dim);
    font-family: monospace;
    white-space: nowrap;
}

.progress-bar-container {
    width: 100%;
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 4px;
}
.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.5s ease;
}

/* ── Agents grid ── */
.agents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}
.agent-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: 3px solid;
    border-radius: var(--radius);
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.agent-card:hover { border-color: var(--primary); }
.agent-card.agent-working {
    border-color: var(--primary);
    animation: pulse 2s ease-in-out infinite;
}
.agent-card.agent-idle { opacity: 0.5; }
.agent-card.agent-failed { border-left-color: var(--danger); }
.agent-card.agent-selected {
    border: 1px solid var(--primary);
    background: var(--bg-hover);
}
.agent-name { font-weight: 600; font-size: 14px; }
.agent-status {
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-top: 4px;
}
.agent-task {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.agent-tool {
    font-size: 11px;
    color: var(--primary);
    font-family: monospace;
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

/* ── Tasks ── */
.tasks-list { display: flex; flex-direction: column; gap: 6px; }
.task-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: monospace;
}
.task-item.task-completed { opacity: 0.6; }
.task-item.task-in_progress { border-left: 2px solid var(--primary); }
.task-item.task-failed { border-left: 2px solid var(--danger); }
.task-icon { flex-shrink: 0; }
.task-id { font-weight: 600; min-width: 180px; }
.task-agent { font-size: 12px; min-width: 100px; }
.task-deps { font-size: 11px; color: var(--text-dim); }
.task-duration { font-size: 11px; color: var(--text-dim); }

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.tab {
    padding: 6px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}
.tab:hover { border-color: var(--primary); color: var(--text); }
.tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ── Output panel ── */
.output-panel {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 12px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: var(--text);
}

/* ── Log ── */
.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.log-header h2 { margin-bottom: 0; }
.log-filters {
    display: flex;
    gap: 4px;
    align-items: center;
}
.filter-btn {
    padding: 4px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.filter-btn:hover { border-color: var(--primary); }
.filter-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}
#agent-filter-buttons { display: contents; }

.log-container {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    height: 480px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 12px;
    line-height: 1.8;
}
.log-line { color: var(--text-dim); margin-bottom: 2px; }
.log-line .log-time { color: var(--text-muted); margin-right: 6px; }
.log-line .log-agent { font-weight: 600; margin-right: 4px; }
.log-line .log-text-output { color: var(--text); }
.log-line.log-error { color: var(--danger); }

/* ── Runs list (history page) ── */
.runs-list { display: flex; flex-direction: column; gap: 8px; }
.run-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.2s;
}
.run-item:hover { border-color: var(--primary); }
.run-item.run-running { border-left: 3px solid var(--primary); }
.run-item.run-completed { border-left: 3px solid var(--success); }
.run-item.run-failed { border-left: 3px solid var(--danger); }
.run-status { font-size: 18px; flex-shrink: 0; }
.run-task { flex: 1; font-size: 14px; }
.run-meta { font-size: 12px; color: var(--text-dim); text-align: right; }
.run-id { display: block; }
.run-cwd { display: block; font-size: 11px; }

/* ── Dashboard layout (main + context sidebar) ── */
.dashboard-layout {
    display: flex;
    gap: 16px;
}
.dashboard-main { flex: 1; min-width: 0; }
.dashboard-context {
    width: 240px;
    flex-shrink: 0;
    position: sticky;
    top: 24px;
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
}
.dashboard-context h3 {
    font-size: 14px;
    margin-bottom: 4px;
}
.context-runs {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
}
.context-run {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 8px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.4;
    transition: background 0.15s;
    border-left: 2px solid transparent;
    flex-wrap: wrap;
}
.context-run:hover { background: var(--bg-hover); color: var(--text); }
.context-run-active {
    background: var(--bg-hover);
    color: var(--text);
    border-left-color: var(--primary);
    font-weight: 500;
}
.context-run-icon { flex-shrink: 0; font-size: 12px; }
.context-run-task {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1;
}
.context-run-tokens {
    font-size: 10px;
    color: var(--warning);
    font-family: monospace;
    white-space: nowrap;
    width: 100%;
    padding-left: 18px;
}

/* ── Project page ── */
.project-runs { display: flex; flex-direction: column; gap: 6px; }
.project-run-wrapper { display: flex; flex-direction: column; }
.project-run-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.2s;
}
.project-run-item:hover { border-color: var(--primary); }
.project-run-item.project-run-running { border-left: 3px solid var(--primary); }
.project-run-item.project-run-completed { border-left: 3px solid var(--success); }
.project-run-item.project-run-failed { border-left: 3px solid var(--danger); }
.project-run-item.project-run-stopped { border-left: 3px solid var(--text-dim); }
.project-run-left { display: flex; align-items: flex-start; gap: 10px; flex: 1; min-width: 0; }
.project-run-icon { font-size: 18px; flex-shrink: 0; margin-top: 2px; }
.project-run-content { min-width: 0; flex: 1; }
.project-run-task { font-size: 14px; line-height: 1.4; }
.project-run-meta { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.project-run-prompt-btn {
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}
.project-run-item:hover .project-run-prompt-btn { opacity: 1; }

.project-run-delete {
    background: none; border: none; color: var(--text-dim);
    font-size: 18px; cursor: pointer; opacity: 0; transition: opacity 0.15s;
    padding: 4px 8px; flex-shrink: 0;
}
.project-run-item:hover .project-run-delete { opacity: 0.6; }
.project-run-delete:hover { opacity: 1; color: var(--danger); }

.token-badge {
    color: var(--warning);
    font-family: monospace;
    font-size: 11px;
}

/* ── Prompt viewing ── */
.prompt-preview {
    display: flex;
    align-items: center;
    gap: 10px;
}
.full-prompt {
    margin-top: 10px;
}
.full-prompt .output-panel {
    max-height: 300px;
}
.run-prompt-expand {
    padding: 8px 16px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    margin-top: -1px;
}
.run-prompt-text {
    max-height: 200px;
    margin: 0;
    border: none;
}

/* ── Final Summary ── */
.final-summary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.final-summary-header h2 { margin-bottom: 0; }

/* ── Mode Toggle (Local / SSH) ── */
.mode-toggle {
    display: inline-flex;
    gap: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 3px;
}
.mode-btn {
    padding: 8px 20px;
    background: transparent;
    border: none;
    border-radius: 20px;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
}
.mode-btn:hover { color: var(--text); }
.mode-btn-active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

/* ── SSH Form ── */
.ssh-form { margin-bottom: 16px; }
.ssh-row {
    display: flex;
    gap: 12px;
    margin-bottom: 0;
}
.ssh-field { flex: 1; }
.ssh-field-sm { flex: 0 0 100px; }

.btn-ssh-connect {
    background: linear-gradient(135deg, var(--success), #16a34a);
    color: white;
    border: none;
    padding: 11px 20px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: 4px;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.2);
}
.btn-ssh-connect:hover { box-shadow: 0 4px 16px rgba(34, 197, 94, 0.35); transform: translateY(-1px); }
.btn-ssh-connect:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ── SSH Browser ── */
.ssh-browser-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.ssh-connected-badge {
    font-size: 13px;
    font-weight: 600;
    color: var(--success);
    font-family: monospace;
}
.btn-ssh-disconnect {
    background: none;
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-ssh-disconnect:hover { background: var(--danger); color: white; }

.ssh-path-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.ssh-path-label {
    font-size: 12px;
    color: var(--text-dim);
    flex-shrink: 0;
}
.ssh-path-input {
    flex: 1;
    font-family: monospace;
    font-size: 13px;
}
.btn-ssh-go {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
}
.btn-ssh-go:hover { border-color: var(--primary); }

.ssh-file-list {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 360px;
    overflow-y: auto;
}
.ssh-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}
.ssh-entry:last-child { border-bottom: none; }
.ssh-entry-dir { cursor: pointer; }
.ssh-entry-dir:hover { background: var(--bg-hover); }
.ssh-entry-file { color: var(--text-dim); }
.ssh-entry-icon { flex-shrink: 0; font-size: 14px; }
.ssh-entry-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ssh-entry-size {
    font-size: 11px;
    color: var(--text-dim);
    font-family: monospace;
    flex-shrink: 0;
}
.ssh-select-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}
.ssh-entry-dir:hover .ssh-select-btn { opacity: 1; }

.ssh-selected-path {
    font-family: monospace;
    background: var(--bg) !important;
    color: var(--success) !important;
    font-weight: 600;
}

/* ── Image Drop Zone ── */
.image-drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}
.image-drop-zone:hover {
    border-color: var(--primary);
    color: var(--text);
}
.image-drop-zone.dragover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.08);
    color: var(--text);
}
.image-drop-zone input[type="file"] { display: none; }

.image-previews {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}
.image-preview {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.image-preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 11px;
    line-height: 18px;
    text-align: center;
    cursor: pointer;
    padding: 0;
    opacity: 0;
    transition: opacity 0.15s;
}
.image-preview:hover .image-preview-remove { opacity: 1; }

/* ── Theme toggle ── */
.theme-toggle {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    opacity: 0.6;
    transition: opacity 0.2s;
}
.theme-toggle:hover { opacity: 1; }

/* ── Stack quick select (chips in command bar) ── */
.stack-quick-select {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    align-items: center;
}
.stack-chip {
    padding: 5px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.stack-chip:hover { border-color: var(--primary); color: var(--text); }
.stack-chip-active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ── Stack badge ── */
.stack-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--primary);
    color: white;
    margin-right: 4px;
}
.sidebar-agents-active {
    display: flex;
    gap: 2px;
    margin-top: 2px;
    flex-wrap: wrap;
}
.sidebar-agent-icon {
    font-size: 12px;
    animation: pulse 2s ease-in-out infinite;
}

/* ── Project rename ── */
.sidebar-rename-btn {
    background: none;
    border: none;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    padding: 0 2px;
    vertical-align: middle;
}
.sidebar-project-name:hover .sidebar-rename-btn { opacity: 0.6; }
.sidebar-rename-btn:hover { opacity: 1 !important; }

.sidebar-project-name-input {
    background: var(--bg);
    border: 1px solid var(--primary);
    border-radius: 4px;
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    padding: 2px 6px;
    width: 100%;
    outline: none;
}

/* ── File Explorer ── */
.file-explorer {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
}
.file-explorer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.file-explorer-header h3 {
    font-size: 13px;
    margin: 0;
    color: var(--text-dim);
}
.file-explorer-body {
    max-height: 350px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
}
.context-section-title {
    font-size: 14px;
    margin-bottom: 6px;
}
.file-tree-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-tree-item:hover { background: var(--bg-hover); }
.file-tree-item.active { background: var(--bg-hover); color: var(--primary); }
.file-tree-icon { flex-shrink: 0; font-size: 14px; }
.file-tree-name { overflow: hidden; text-overflow: ellipsis; }
.file-tree-indent { display: inline-block; width: 16px; flex-shrink: 0; }
.file-viewer-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.file-viewer {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    max-height: 500px;
    overflow: auto;
    font-family: monospace;
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ── Markdown rendered content ── */
.md-content {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.7;
    white-space: normal;
    word-wrap: break-word;
}
.md-content h1 { font-size: 22px; font-weight: 700; margin: 16px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.md-content h2 { font-size: 18px; font-weight: 600; margin: 14px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.md-content h3 { font-size: 15px; font-weight: 600; margin: 12px 0 4px; }
.md-content h4 { font-size: 14px; font-weight: 600; margin: 10px 0 4px; color: var(--text-dim); }
.md-content p { margin: 6px 0; }
.md-content strong { font-weight: 700; }
.md-content em { font-style: italic; }
.md-content code {
    background: var(--bg-hover);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 13px;
}
.md-content .md-code-block {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin: 8px 0;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
}
.md-content .md-code-block code {
    background: none;
    padding: 0;
}
.md-content ul { margin: 6px 0; padding-left: 24px; }
.md-content li { margin: 3px 0; }
.md-content hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.md-content a { color: var(--primary); text-decoration: none; }
.md-content a:hover { text-decoration: underline; }
.md-content table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 13px; }
.md-content td, .md-content th { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md-content tr:nth-child(even) { background: var(--bg-hover); }

/* ── Local file browser ── */
.local-browser { margin-top: 8px; }
.local-browser .ssh-file-list { max-height: 280px; }

/* ── Connection Profiles ── */
.conn-profiles-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
}
.conn-profile-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    transition: border-color 0.2s;
}
.conn-profile-card:hover {
    border-color: var(--primary);
}
.conn-profile-info {
    flex: 1;
    min-width: 0;
}
.conn-profile-name {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conn-profile-details {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 2px;
}
.conn-profile-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}
.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    color: var(--text);
}
.btn-sm:hover {
    background: var(--bg-hover);
}

/* ── Auth Type Toggle (SSH Key vs Password) ── */
.auth-type-toggle {
    display: inline-flex;
    gap: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 3px;
    margin-top: 4px;
}
.auth-type-option {
    display: flex;
    align-items: center;
    cursor: pointer;
}
.auth-type-option input[type="radio"] {
    display: none;
}
.auth-type-option span {
    padding: 7px 16px;
    border-radius: 20px;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
    user-select: none;
    white-space: nowrap;
}
.auth-type-option input[type="radio"]:checked + span {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}
.auth-type-option:hover span {
    color: var(--text);
}

/* ── Edit Profile Form ── */
.edit-profile-form {
    margin-top: 12px;
    padding: 14px;
    border: 1px solid var(--primary);
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.04);
}
.edit-profile-form h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
}
[data-theme="light"] .edit-profile-form {
    background: rgba(99, 102, 241, 0.03);
}

/* ── Profile Auth Badge ── */
.profile-auth-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    flex-shrink: 0;
    line-height: 1.6;
}
.profile-auth-badge-key {
    background: rgba(251, 191, 36, 0.12);
    color: var(--warning);
    border: 1px solid rgba(251, 191, 36, 0.25);
}
.profile-auth-badge-password {
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary);
    border: 1px solid rgba(99, 102, 241, 0.25);
}
[data-theme="light"] .profile-auth-badge-key {
    background: rgba(180, 83, 9, 0.1);
    color: var(--warning);
    border-color: rgba(180, 83, 9, 0.2);
}
[data-theme="light"] .profile-auth-badge-password {
    background: rgba(67, 56, 202, 0.08);
    color: var(--primary);
    border-color: rgba(67, 56, 202, 0.2);
}

/* ── Responsive ── */
@media (max-width: 1200px) {
    .dashboard-context { display: none; }
    .dashboard-main { max-width: 100%; }
}

/* ── Utils ── */
.dim { color: var(--text-dim); font-size: 13px; }
code {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

/* ── Login Page ── */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
    padding: 24px;
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 400px;
}
.login-brand { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 8px; }
.login-title { font-size: 18px; text-align: center; margin-bottom: 24px; color: var(--text-dim); }
.login-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 13px;
    color: var(--danger);
    margin-bottom: 16px;
}
.login-card .btn-primary {
    width: 100%;
    padding: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

/* ── Sidebar User Bar ── */
.sidebar-user-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    flex-wrap: wrap;
}
.sidebar-user-name { font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 6px;
    border-radius: 4px;
}
.role-badge-superadmin { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.role-badge-admin { background: rgba(99, 102, 241, 0.15); color: var(--primary); }
.role-badge-viewer { background: rgba(113, 113, 122, 0.15); color: var(--text-dim); }
[data-theme="light"] .role-badge-viewer { background: rgba(113,113,122,0.25); }
.sidebar-user-actions { display: flex; gap: 4px; }
.sidebar-admin-link, .sidebar-logout-btn {
    background: none; border: none; font-size: 14px; cursor: pointer;
    padding: 2px 4px; text-decoration: none; opacity: 0.6; transition: opacity 0.2s;
    color: var(--text);
}
.sidebar-admin-link:hover, .sidebar-logout-btn:hover { opacity: 1; }

/* ── Admin Panel ── */
.admin-form-row { display: flex; gap: 12px; align-items: flex-end; }
.admin-create-btn { margin-bottom: 16px; white-space: nowrap; }
.admin-users-list { display: flex; flex-direction: column; gap: 8px; }
.admin-user-row {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; background: var(--bg);
    border: 1px solid var(--border); border-radius: var(--radius);
}
.admin-user-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.admin-user-name { font-weight: 600; font-size: 14px; }
.admin-role-badge {
    font-size: 10px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.05em; padding: 2px 8px; border-radius: 4px;
}
.admin-role-superadmin { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.admin-role-admin { background: rgba(99, 102, 241, 0.15); color: var(--primary); }
.admin-role-viewer { background: rgba(113, 113, 122, 0.15); color: var(--text-dim); }
[data-theme="light"] .admin-role-viewer { background: rgba(113,113,122,0.25); }
.admin-user-meta { font-size: 12px; flex-shrink: 0; }
.admin-user-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ══════════════════════════════════════════════════════════
   UNIFIED DESIGN SYSTEM — Component Extensions
   Appended to support settings.html and future pages
   ══════════════════════════════════════════════════════════ */

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.page-header h1 { font-size: 22px; font-weight: 700; margin: 0; }
.page-header-right { display: flex; gap: 8px; align-items: center; }

/* ── Tab Navigation (underline style) ── */
.tab-nav {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}
.tab-btn {
    padding: 9px 18px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: color .15s, border-color .15s;
    margin-bottom: -1px;
    font-family: inherit;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Section Header ── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.section-header h2 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}
.section-header p {
    font-size: 13px;
    color: var(--text-dim);
    margin-top: 2px;
}

/* ── Icon Header ── */
.icon-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}
.icon-header-icon {
    font-size: 22px;
    flex-shrink: 0;
}
.icon-header h2 {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
}
.icon-header p {
    font-size: 12px;
    color: var(--text-dim);
    margin: 0;
}

/* ── Enhanced Card ── */
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card-body { }
.card-footer {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ── Account/Item Card ── */
.item-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: border-color .15s;
}
.item-card:hover { border-color: var(--primary); }
.item-card.disabled { opacity: 0.55; }
.item-card-icon {
    width: 40px; height: 40px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.item-card-content { min-width: 0; flex: 1; }
.item-card-title { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.item-card-title span:first-child { font-weight: 600; font-size: 14px; }
.item-card-meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.item-card-actions {
    display: flex; gap: 6px; margin-left: auto; flex-shrink: 0;
    flex-wrap: wrap; justify-content: flex-end;
}

/* ── Badge ── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.6;
}
.badge-default { background: rgba(99,102,241,0.2); color: var(--primary); }
.badge-ok, .badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-warn, .badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-off, .badge-muted { background: rgba(113,113,122,0.15); color: var(--text-dim); }
[data-theme="light"] .badge-off, [data-theme="light"] .badge-muted { background: rgba(113,113,122,0.25); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }

/* ── Button Icon ── */
.btn-icon {
    padding: 5px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: var(--radius);
    font-size: 12px;
    cursor: pointer;
    transition: background .15s, color .15s;
    font-family: inherit;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }
.btn-icon.danger:hover { background: rgba(239,68,68,0.1); color: var(--danger); border-color: var(--danger); }
.btn-icon.primary:hover { background: rgba(99,102,241,0.15); color: var(--primary); border-color: var(--primary); }

/* ── Secondary Button ── */
.btn-secondary {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-dim);
}
.btn-secondary:hover {
    border-color: var(--primary);
    color: var(--text);
}

/* ── Toggle Switch ── */
.toggle-switch {
    position: relative; width: 40px; height: 22px; cursor: pointer; flex-shrink: 0;
    display: inline-block;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
    position: absolute; inset: 0;
    background: var(--border);
    border-radius: 11px;
    transition: background .2s;
}
.toggle-switch input:checked + .toggle-track { background: var(--success); }
.toggle-thumb {
    position: absolute;
    top: 3px; left: 3px;
    width: 16px; height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform .2s;
    pointer-events: none;
}
.toggle-switch input:checked ~ .toggle-thumb { transform: translateX(18px); }

/* ── Type/Selection Card ── */
.type-card {
    padding: 16px 12px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
    display: flex; flex-direction: column; align-items: center;
    font-family: inherit;
}
.type-card:hover:not([disabled]):not(.disabled) { border-color: var(--primary); background: var(--bg-hover); }
.type-card.selected { border-color: var(--primary); background: rgba(99,102,241,0.08); }
.type-card.disabled { opacity: 0.45; cursor: not-allowed; }
.type-card-icon { font-size: 28px; }
.type-card-title { font-weight: 600; font-size: 13px; margin-top: 6px; }
.type-card-desc { font-size: 11px; color: var(--text-dim); }

/* ── Modal System ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 560px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
    position: relative;
}
.modal-close {
    position: absolute;
    top: 12px; right: 12px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 4px;
}
.modal-subtitle {
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 20px;
}
.modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-dim);
}
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.empty-state-text { font-size: 13px; }

/* ── Status Message ── */
.status-msg {
    padding: 10px;
    border-radius: var(--radius);
    font-size: 13px;
    display: none;
    margin-top: 10px;
}
.status-msg.success { display: block; background: rgba(34,197,94,0.12); color: var(--success); }
.status-msg.error { display: block; background: rgba(239,68,68,0.12); color: var(--danger); }

/* ── Toast ── */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    animation: toast-in 0.3s ease;
    max-width: 400px;
}
.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-info { background: var(--primary); color: white; }
@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ── Data Table ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid var(--border);
    color: var(--text-dim);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
.data-table tr:hover td { background: var(--bg-hover); }
.data-table code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

/* ── Service Row ── */
.service-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.service-row:last-child { border-bottom: none; }
.service-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
.service-icon { font-size: 18px; width: 24px; text-align: center; }
.service-label { font-size: 13px; font-weight: 600; }
.service-desc { font-size: 12px; color: var(--text-dim); }

/* ── Scope Tag ── */
.scope-tag {
    display: inline-block;
    padding: 2px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 11px;
    color: var(--text-dim);
    font-family: monospace;
}

/* ── Info Box ── */
.info-box {
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 12px;
}
.info-box a { color: var(--primary); }
.info-box ul { margin: 6px 0 0 16px; padding: 0; }

/* ── Content Wrapper ── */
.content-narrow { max-width: 900px; }
.content-wide { max-width: 1200px; }

/* ── Pill Status ── */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-dim);
}
.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-dot-success { background: var(--success); }
.status-dot-warning { background: var(--warning); }
.status-dot-danger { background: var(--danger); }
.status-dot-muted { background: var(--border); }

/* ── Grid Layouts ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-gap-sm { display: flex; gap: 8px; align-items: center; }
.flex-gap { display: flex; gap: 12px; align-items: center; }

/* ══════════════════════════════════════════════════════════
   TERMINAL PANEL — Persistent bottom panel for questions
   ══════════════════════════════════════════════════════════ */

/* Container: fixed bottom, full width */
.terminal-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1050;
    background: var(--bg-card);
    border-top: 2px solid var(--border);
    transition: transform 0.3s ease, height 0.2s ease;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.25);
}

/* Hidden state: slide down */
.terminal-panel.tp-hidden {
    transform: translateY(100%);
    pointer-events: none;
}

/* Minimized state: only header visible */
.terminal-panel.tp-minimized {
    height: auto !important;
}
.terminal-panel.tp-minimized .tp-body { display: none; }

/* Has question: purple border + glow */
.terminal-panel.tp-has-question {
    border-top-color: #7c3aed;
    box-shadow: 0 -4px 24px rgba(124, 58, 237, 0.35);
}

/* ── Drag handle (resize) ── */
.tp-drag-handle {
    height: 6px;
    cursor: ns-resize;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.tp-drag-handle::after {
    content: '';
    width: 40px;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
}
.tp-drag-handle:hover::after,
.tp-drag-handle:active::after {
    background: var(--text-dim);
}

/* ── Header bar ── */
.tp-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 16px 6px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 38px;
}
.tp-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--border);
    transition: background 0.3s;
}
.tp-status-dot.tp-dot-idle { background: var(--text-muted); }
.tp-status-dot.tp-dot-question {
    background: #7c3aed;
    animation: tp-dot-pulse 1.5s ease-in-out infinite;
}
@keyframes tp-dot-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(124, 58, 237, 0.5); }
    50% { box-shadow: 0 0 0 6px rgba(124, 58, 237, 0); }
}
.tp-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tp-badge {
    background: #7c3aed;
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    animation: tp-badge-bounce 0.5s ease;
}
@keyframes tp-badge-bounce {
    0% { transform: scale(0.5); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}
.tp-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}
.tp-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}
.tp-btn:hover { color: var(--text); background: var(--bg-hover); }
.tp-btn.tp-sound-on { color: #7c3aed; }
.tp-kbd {
    font-size: 10px;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 4px;
    font-family: monospace;
}

/* ── Body: question display + history ── */
.tp-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    min-height: 0;
}

/* Question card */
.tp-question {
    background: rgba(124, 58, 237, 0.08);
    border: 1px solid rgba(124, 58, 237, 0.3);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 10px;
}
.tp-question-meta {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 6px;
    display: flex;
    gap: 8px;
    align-items: center;
}
.tp-question-agent {
    font-weight: 600;
    color: #a78bfa;
}
.tp-question-text {
    font-size: 14px;
    color: var(--text);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

/* History items */
.tp-history-item {
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-dim);
    display: flex;
    gap: 8px;
}
.tp-history-item:last-child { border-bottom: none; }
.tp-history-q { color: var(--accent); }
.tp-history-a { color: var(--success); }

/* ── Footer: answer input ── */
.tp-footer {
    display: flex;
    gap: 8px;
    padding: 8px 16px 10px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    align-items: center;
}
.tp-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}
.tp-input:focus {
    border-color: #7c3aed;
    box-shadow: 0 0 8px rgba(124, 58, 237, 0.3);
}
.tp-input::placeholder { color: var(--text-dim); }
.tp-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.tp-submit {
    padding: 10px 20px;
    background: #7c3aed;
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}
.tp-submit:hover { background: #6d28d9; }
.tp-submit:disabled { background: #4c1d95; cursor: not-allowed; }

/* ── Light theme overrides ── */
[data-theme="light"] .terminal-panel {
    box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
}
[data-theme="light"] .terminal-panel.tp-has-question {
    box-shadow: 0 -4px 24px rgba(124, 58, 237, 0.2);
}
[data-theme="light"] .tp-question {
    background: rgba(124, 58, 237, 0.06);
}
[data-theme="light"] .tp-input {
    background: #ffffff;
}

/* ══════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
   ══════════════════════════════════════════════════════════ */

/* ── Sidebar Toggle Button (always visible when sidebar is collapsed) ── */
.sidebar-toggle-btn {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1100;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    display: none; /* hidden when sidebar is visible */
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: background 0.2s, opacity 0.2s;
    line-height: 1;
    padding: 0;
}
.sidebar-toggle-btn:hover { background: var(--bg-hover); }

/* Show toggle button when sidebar is collapsed */
.sidebar-collapsed .sidebar-toggle-btn { display: flex; }

/* ── Sidebar Collapse Button (inside sidebar header) ── */
.sidebar-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}
.sidebar-collapse-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius);
    transition: color 0.2s, background 0.2s;
    line-height: 1;
}
.sidebar-collapse-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}

/* ── Sidebar Collapse Transition ── */
.sidebar {
    transition: transform 0.3s ease, opacity 0.2s ease;
}
.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
    pointer-events: none;
    opacity: 0;
}
.sidebar-collapsed .main-content {
    margin-left: 0 !important;
    padding-left: 60px; /* room for the toggle button */
}

/* ── Sidebar Overlay (mobile only) ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
}
.sidebar-overlay.active { display: block; opacity: 1; }

/* ── Responsive (component extensions) ── */

/* Tablet */
@media (max-width: 1024px) {
    .main-content { padding: 20px 20px; }
    .card { padding: 18px; }
}

/* Mobile landscape / small tablets */
@media (max-width: 768px) {
    /* On mobile, sidebar overlays content instead of pushing it */
    .sidebar {
        z-index: 1000;
    }
    /* When sidebar is visible on mobile (not collapsed), show overlay */
    .app-layout:not(.sidebar-collapsed) .sidebar {
        transform: translateX(0);
    }
    .sidebar-collapsed .sidebar {
        transform: translateX(-100%);
    }

    .main-content {
        margin-left: 0 !important;
        padding: 68px 16px 24px;
    }
    .sidebar-collapsed .main-content {
        padding-left: 16px;
    }

    /* Grids */
    .grid-3 { grid-template-columns: 1fr 1fr; }
    .agents-grid { grid-template-columns: 1fr 1fr !important; }

    /* Tabs: scrollable */
    .tab-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0;
        flex-wrap: nowrap;
    }
    .tab-btn { padding: 8px 12px; font-size: 12px; white-space: nowrap; flex-shrink: 0; }

    /* Modal */
    .modal-content { width: 100%; margin: 12px; padding: 18px; }

    /* Forms */
    .form-row { flex-direction: column; }
    .command-form { flex-direction: column; }
    .command-form textarea { min-height: 48px; }
    .command-form .btn-send,
    .command-form .btn-stop { width: 100%; }

    /* Cards */
    .item-card { flex-direction: column; align-items: flex-start; }
    .item-card-actions { margin-left: 0; margin-top: 10px; width: 100%; }
    .item-card-actions .btn-icon { flex: 1; }

    /* Page header */
    .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .page-header-right { width: 100%; justify-content: flex-start; }

    /* Service rows */
    .service-row { flex-direction: column; align-items: flex-start; gap: 8px; }

    /* Admin */
    .admin-form-row { flex-direction: column; }
    .admin-user-row { flex-direction: column; align-items: flex-start; gap: 8px; }
    .admin-user-actions { width: 100%; }

    /* Toast */
    .toast-container { right: 12px; left: 12px; top: 12px; }
    .toast { max-width: 100%; }

    /* Data table: horizontal scroll */
    .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Question banner */
    .question-answer-form { flex-direction: column; }
    .question-answer-btn { width: 100%; }

    /* Terminal panel mobile */
    .terminal-panel { max-height: 60vh; }
    .tp-footer { flex-direction: column; }
    .tp-submit { width: 100%; }
    .tp-kbd { display: none; }
    .tp-header { padding: 6px 12px; }
    .tp-body { padding: 10px 12px; }
    .tp-footer { padding: 8px 12px; }

    /* Card padding */
    .card { padding: 16px; }
    .card h1 { font-size: 18px; }

    /* Section header */
    .section-header { flex-direction: column; align-items: flex-start; gap: 8px; }

    /* Flex layouts */
    .flex-between { flex-wrap: wrap; gap: 8px; }

    /* Content wrappers */
    .content-narrow, .content-wide { max-width: 100%; }

    /* Type cards grid */
    .grid-2 { grid-template-columns: 1fr 1fr; }

    /* Login */
    .login-card { padding: 24px; }
}

/* Mobile portrait */
@media (max-width: 480px) {
    .main-content { padding: 60px 12px 20px; }

    .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .agents-grid { grid-template-columns: 1fr !important; }

    /* Sidebar narrower on very small screens */
    :root { --sidebar-width: 260px; }

    .tab-btn { padding: 7px 10px; font-size: 11px; }

    .btn { padding: 8px 14px; font-size: 13px; }
    .btn-block { padding: 12px; font-size: 14px; }

    .card { padding: 14px; margin-bottom: 12px; }
    .card h1 { font-size: 17px; }
    .card h2 { font-size: 14px; }

    /* Toggle switch */
    .item-card-title { font-size: 13px; }

    /* Status pill */
    .status-pill { font-size: 11px; padding: 3px 8px; }

    /* Scope tags: wrap */
    .scope-tag { font-size: 10px; }

    /* Modal full screen on tiny devices */
    .modal-content { margin: 8px; padding: 14px; }
}

/* Very small devices (iPhone SE, etc.) */
@media (max-width: 360px) {
    :root { --sidebar-width: 240px; }
    .main-content { padding: 56px 8px 16px; }
    .sidebar-new-btn { margin: 8px; padding: 8px 12px; font-size: 13px; }
    .sidebar-toggle-btn { width: 36px; height: 36px; font-size: 17px; top: 10px; left: 8px; }
}

/* ── Safe areas (notch devices) ── */
@supports (padding: max(0px)) {
    .sidebar { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
    .main-content { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
}

/* ── Touch improvements ── */
@media (hover: none) and (pointer: coarse) {
    .btn, .btn-icon, .btn-primary, .btn-danger, .btn-secondary,
    .sidebar-new-btn, .tab-btn, .type-card, .toggle-switch {
        min-height: 44px;
    }
    .sidebar-project { min-height: 48px; }
    .sidebar-delete-btn { opacity: 0.6; min-width: 44px; min-height: 44px; }
    .sidebar-rename-btn { min-width: 36px; min-height: 36px; }
}
