/* ── Theme Variables ── */
:root {
    --transition: 0.2s ease;
    --radius: 6px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
    --sidebar-width: 240px;
}

/* ── Light Theme ── */
[data-theme="light"] {
    --bg: #fafafa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f5f5f5;
    --border: #e5e5e5;
    --text: #171717;
    --text-muted: #737373;
    --text-heading: #0a0a0a;
    --primary: #171717;
    --primary-hover: #404040;
    --primary-text: #ffffff;
    --success: #22c55e;
    --warning: #eab308;
    --danger: #ef4444;
    --info: #3b82f6;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
    --focus-ring: rgba(23, 23, 23, 0.15);
    --overlay: rgba(0,0,0,0.4);
    --input-bg: #ffffff;
    --input-border: #d4d4d4;
    --scrollbar-thumb: #d4d4d4;
    --icon-color: #525252;
    --sidebar-bg: #ffffff;
    --sidebar-border: #e5e5e5;
}

/* ── Dark Theme ── */
[data-theme="dark"] {
    --bg: #0a0a0a;
    --bg-secondary: #171717;
    --bg-tertiary: #262626;
    --border: #262626;
    --text: #f5f5f5;
    --text-muted: #737373;
    --text-heading: #fafafa;
    --primary: #f5f5f5;
    --primary-hover: #d4d4d4;
    --primary-text: #0a0a0a;
    --success: #4ade80;
    --warning: #facc15;
    --danger: #f87171;
    --info: #60a5fa;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
    --focus-ring: rgba(245, 245, 245, 0.1);
    --overlay: rgba(0,0,0,0.6);
    --input-bg: #171717;
    --input-border: #404040;
    --scrollbar-thumb: #404040;
    --icon-color: #a3a3a3;
    --sidebar-bg: #111111;
    --sidebar-border: #262626;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background var(--transition), color var(--transition);
}

a { color: var(--info); text-decoration: none; }
a:hover { opacity: 0.8; text-decoration: underline; }

/* ── App Layout (Sidebar + Main) ── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    transition: background var(--transition), border-color var(--transition);
}

.sidebar-brand {
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-brand a {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-heading);
    letter-spacing: -0.01em;
}
.sidebar-brand a:hover { text-decoration: none; opacity: 0.8; }
.sidebar-brand svg {
    width: 22px;
    height: 22px;
    color: var(--text-heading);
}

.sidebar-switcher {
    padding: 12px 16px;
    border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-switcher label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 500;
}
.sidebar-switcher select {
    width: 100%;
    padding: 6px 10px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
}
.sidebar-switcher select:focus {
    outline: none;
    border-color: var(--text-muted);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.sidebar-nav {
    padding: 8px 8px;
    flex: 1;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    transition: color var(--transition), background var(--transition);
    text-decoration: none;
}
.sidebar-link:hover {
    color: var(--text);
    background: var(--bg-tertiary);
    text-decoration: none;
    opacity: 1;
}
.sidebar-link.active {
    color: var(--text-heading);
    background: var(--bg-tertiary);
}
.sidebar-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

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

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-top: 4px;
}
.sidebar-user-name {
    flex: 1;
    font-size: 13px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Main Content ── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    position: relative;
}

.content-container {
    max-width: none;
    padding: 24px;
}

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 40;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--icon-color);
    cursor: pointer;
    align-items: center;
    justify-content: center;
}
.sidebar-toggle svg { width: 20px; height: 20px; }

/* ── Theme Toggle ── */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--icon-color);
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    flex-shrink: 0;
}
.theme-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--text);
}
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-monitor { display: none; }
[data-theme-pref="light"] .theme-toggle .icon-sun { display: block; }
[data-theme-pref="dark"] .theme-toggle .icon-moon { display: block; }
[data-theme-pref="system"] .theme-toggle .icon-monitor { display: block; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition);
    line-height: 1.4;
}
.btn:hover { background: var(--bg-tertiary); text-decoration: none; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-text);
}
.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: var(--primary-text);
}
.btn-secondary { background: var(--bg-tertiary); }
.btn-warning {
    background: rgba(234,179,8,0.15);
    border-color: var(--warning);
    color: var(--warning);
}
.btn-warning:hover { background: rgba(234,179,8,0.25); color: var(--warning); }
.btn-danger {
    background: rgba(239,68,68,0.15);
    border-color: var(--danger);
    color: var(--danger);
}
.btn-danger:hover { background: rgba(239,68,68,0.25); color: var(--danger); }

/* ── Page Header ── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}
.page-header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-heading);
    letter-spacing: -0.02em;
}

/* ── Cards ── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.card:hover {
    border-color: var(--text-muted);
    box-shadow: var(--shadow);
}
.card h3 { color: var(--text-heading); margin-bottom: 4px; font-size: 16px; font-weight: 600; }
.card-meta { margin-top: 12px; color: var(--text-muted); font-size: 13px; }

/* ── Stats ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    transition: border-color var(--transition);
}
.stat-card h3 { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; font-weight: 500; }
.stat-value { font-size: 32px; font-weight: 600; color: var(--text-heading); letter-spacing: -0.02em; }

/* ── Tables ── */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.table th, .table td {
    padding: 10px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.table th {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}
.table tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--bg-tertiary); }

/* ── Forms ── */
.form { max-width: 560px; }
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-heading);
}
.form-group small { display: block; margin-top: 4px; color: var(--text-muted); font-size: 13px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 8px 12px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--text-muted);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ── Detail List ── */
.detail-list { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; }
.detail-list dt { color: var(--text-muted); font-size: 13px; }
.detail-list dd { color: var(--text); }

/* ── Status Badge ── */
.status-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}
.status-running { background: rgba(34,197,94,0.12); color: var(--success); }
.status-stopped { background: rgba(234,179,8,0.12); color: var(--warning); }
.status-error, .status-terminated { background: rgba(239,68,68,0.12); color: var(--danger); }
.status-provisioning, .status-starting, .status-stopping, .status-deleting { background: rgba(59,130,246,0.12); color: var(--info); }
.status-unhealthy { background: rgba(234,179,8,0.12); color: var(--warning); }

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}
.tab {
    padding: 10px 20px;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    font-size: 14px;
    font-weight: 500;
    transition: color var(--transition), border-color var(--transition);
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text-heading); border-bottom-color: var(--text-heading); }

/* ── Tab Panels ── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Console ── */
.console-container { position: relative; }
.console-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 8px;
}
.console-iframe {
    width: 100%;
    height: 70vh;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
}

/* ── Flash Messages ── */
.flash {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    border: 1px solid;
    font-size: 14px;
}
.flash-success { background: rgba(34,197,94,0.08); border-color: var(--success); color: var(--success); }
.flash-error { background: rgba(239,68,68,0.08); border-color: var(--danger); color: var(--danger); }
.flash-info { background: rgba(59,130,246,0.08); border-color: var(--info); color: var(--info); }

/* ── Modal ── */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    min-width: 400px;
    box-shadow: var(--shadow-lg);
}

/* ── Toast ── */
.cp-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}
.cp-toast.cp-toast-error {
    border-color: var(--danger, #d32f2f);
    color: var(--danger, #d32f2f);
}
.cp-toast.cp-toast-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Confirm Dialog ── */
.cp-confirm { z-index: 150; }
.cp-confirm-body { margin-bottom: 16px; font-size: 14px; line-height: 1.5; }
.cp-confirm-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Login ── */
.login-page {
    background: var(--bg);
    height: 100vh;
    overflow: hidden;
}
.login-layout {
    display: flex;
    height: 100vh;
    position: relative;
    z-index: 1;
}
#login-bg-canvas {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
    pointer-events: none;
    filter: blur(3px);
}
.login-left {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
#login-workflow-canvas {
    width: 100%;
    height: 100%;
    display: block;
}
.login-tagline {
    position: absolute;
    bottom: 40px;
    left: 40px;
    z-index: 2;
}
.login-tagline h2 {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-heading);
    opacity: 0.7;
    letter-spacing: -0.3px;
    margin-bottom: 6px;
}
.login-tagline p {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0;
}
.login-right {
    width: 440px;
    min-width: 380px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 48px 40px;
    background: color-mix(in srgb, var(--bg) 90%, transparent);
    border-left: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
}
.login-inner {
    width: 100%;
    max-width: 320px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    margin-bottom: 48px;
    text-align: center;
}
.login-brand svg {
    width: 44px;
    height: 44px;
    color: var(--text-muted);
    margin-bottom: 16px;
}
.login-brand h1 {
    font-size: 26px;
    font-weight: 600;
    color: var(--text-heading);
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}
.login-brand p {
    font-size: 13px;
    color: var(--text-muted);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 0;
}
.btn-google {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px 24px;
    font-size: 15px;
    font-weight: 500;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
}
.btn-google:hover {
    background: var(--bg-tertiary);
    text-decoration: none;
    opacity: 1;
}
.btn-google svg { width: 20px; height: 20px; flex-shrink: 0; }
.login-terms {
    margin-top: 28px;
}
.login-terms-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
}
.login-terms-label input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px; height: 18px; min-width: 18px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: color-mix(in srgb, var(--bg-secondary) 50%, transparent);
    cursor: pointer;
    margin-top: 1px;
    transition: all 0.2s;
    position: relative;
}
.login-terms-label input[type="checkbox"]:checked {
    background: var(--primary);
    border-color: var(--primary);
}
.login-terms-label input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 5px; top: 2px;
    width: 5px; height: 9px;
    border: solid var(--primary-text);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.login-terms-label span {
    font-size: 12.5px;
    color: var(--text-muted);
    line-height: 1.5;
}
.login-terms-label a {
    color: var(--text);
    text-decoration: underline;
    text-decoration-color: var(--border);
    text-underline-offset: 2px;
}
.login-terms-label a:hover { color: var(--text-heading); }
.login-footer {
    margin-top: auto;
    padding-top: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    width: 100%;
    max-width: 320px;
    color: var(--text-muted);
    font-size: 11px;
}
@media (max-width: 860px) {
    .login-layout { flex-direction: column; }
    .login-left { height: 35vh; min-height: 220px; }
    .login-right {
        width: 100%; min-width: unset;
        border-left: none;
        border-top: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
        flex: 1;
    }
    .login-tagline { bottom: 16px; left: 16px; }
    .login-tagline h2 { font-size: 18px; }
}

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

/* ── Misc ── */
.empty-state { text-align: center; color: var(--text-muted); padding: 40px; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
section { margin-bottom: 32px; }
section h2 { color: var(--text-heading); margin-bottom: 16px; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.admin-nav { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.usage-bar { display: inline-block; width: 100px; height: 8px; background: var(--bg-tertiary); border-radius: 4px; overflow: hidden; vertical-align: middle; }
.usage-fill { height: 100%; background: var(--info); border-radius: 4px; transition: width 0.3s ease; }
.actions-cell { white-space: nowrap; }
.actions { display: flex; gap: 8px; }
.quick-actions { display: flex; gap: 12px; }
code, .mono { font-family: var(--font-mono); font-size: 13px; }

/* ── Provision Progress ── */
.provision-progress {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
}
.provision-progress h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-heading);
    margin-bottom: 16px;
}
.progress-steps {
    display: flex;
    gap: 8px;
}
.step {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    transition: all var(--transition);
}
.step .step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}
.step .step-label {
    font-size: 13px;
    color: var(--text-muted);
}
.step.active .step-number {
    background: var(--success);
    color: #fff;
}
.step.active .step-label {
    color: var(--text);
}
.step.current {
    border-color: var(--info);
    background: rgba(59,130,246,0.06);
}
.step.current .step-number {
    background: var(--info);
    color: #fff;
    animation: pulse-step 1.5s ease-in-out infinite;
}
.step.current .step-label {
    color: var(--info);
    font-weight: 500;
}
@keyframes pulse-step {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ── Dashboard Layout ── */
.dashboard-layout {
    display: flex;
    flex-direction: row;
    gap: 0;
    min-height: calc(100vh - 48px);
}
.dashboard-main {
    flex: 1;
    min-width: 0;
}

/* ── Agent Config Panel (used inside drawer) ── */
.agent-config-panel {
    padding: 12px 16px;
}

/* Config panel header */
.config-panel-title {
    margin: 0 0 4px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-heading);
}
.config-panel-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.config-panel-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 12px;
    color: var(--text-muted);
    padding: 16px 0 8px;
}
.btn-link-muted {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    padding: 4px 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.btn-link-muted:hover {
    color: var(--text);
}

/* Config sections */
.config-section {
    margin-bottom: 12px;
}
.config-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}
.config-section-subtitle {
    display: block;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    font-size: 11px;
    margin-top: 2px;
}

/* Config actions */
.config-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}

.config-actions-bottom {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.config-action-btn {
    flex: 1;
    min-width: 0;
    text-align: center;
    white-space: nowrap;
}

/* Config alerts */
.config-alert {
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 12px;
    border: 1px solid;
}
.config-alert-warning {
    border-color: var(--warning);
    background: rgba(234,179,8,0.08);
    color: var(--warning);
}
.config-alert-error {
    border-color: var(--danger);
    background: rgba(239,68,68,0.08);
    color: var(--danger);
}
.config-alert-actions {
    margin-top: 6px;
    display: flex;
    gap: 6px;
}

/* Config details (collapsible sections within config-section) */
.config-details {
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.config-details-summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-tertiary);
}
.config-details-summary:hover {
    background: var(--bg-tertiary);
    opacity: 0.9;
}
.config-details-status {
    font-weight: 400;
    font-size: 12px;
}
.config-details-body {
    padding: 12px;
}
.config-details-action {
    margin-bottom: 12px;
}

/* Config service toggles */
.config-service-label {
    font-size: 13px;
    font-weight: 600;
    display: block;
    margin-bottom: 6px;
}
.config-service-toggles {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.config-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
}
.config-checkbox-mb {
    margin-bottom: 8px;
}

/* Config inline group (API key row) */
.config-inline-group {
    display: flex;
    gap: 6px;
    align-items: center;
}
.config-inline-group input {
    flex: 1;
}
.config-inline-status {
    font-size: 12px;
    white-space: nowrap;
}

/* Config hidden utility */
.config-hidden {
    display: none;
}

/* Channel cards */
.channel-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 10px;
}
.channel-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.channel-card-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
}

/* Config save section */
.config-save-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.config-save-btn {
    width: 100%;
    justify-content: center;
}
.config-save-status {
    font-size: 12px;
    text-align: center;
}

/* Activity timeline (replaces audit log table) */
.activity-timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.activity-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}
.activity-item:last-child {
    border-bottom: none;
}
.activity-action {
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
}
.activity-meta {
    color: var(--text-muted);
    white-space: nowrap;
}
.activity-user {
    color: var(--text-muted);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Agent View ── */
#agent-view {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 48px);
}

.agent-view-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.agent-view-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-heading);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agent-view-domain {
    font-size: 12px;
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
}
.agent-view-domain:hover {
    color: var(--primary);
    text-decoration: underline;
}

.agent-view-toolbar .status-badge {
    margin-right: auto;
}

.agent-view-content {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* ── Config Dropdown ── */
.agent-config-toggle-wrap {
    position: relative;
}

.agent-config-drawer {
    position: absolute;
    top: 100%;
    right: 0;
    width: 360px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    z-index: 100;
    opacity: 1;
    transform: translateY(4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.agent-config-drawer.drawer-hidden {
    display: none;
    opacity: 0;
    transform: translateY(0);
}

/* ── Agent iframe container ── */
.agent-iframe-container {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.agent-iframe {
    flex: 1;
    width: 100%;
    border: none;
    background: var(--bg);
}

.agent-no-iframe {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 14px;
    padding: 24px;
    text-align: center;
}

/* ── Expanded mode — hide main sidebar, keep config drawer ── */
#agent-view.agent-view-expanded {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    height: auto;
    background: var(--bg);
}

/* ── Quick Create Form ── */
.quick-create-form {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.quick-create-form select,
.quick-create-form input {
    padding: 6px 10px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
}
.quick-create-form select { max-width: 200px; }
.quick-create-form input { flex: 1; }
.quick-create-form select:focus,
.quick-create-form input:focus {
    outline: none;
    border-color: var(--text-muted);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ── Danger Zone ── */
.danger-zone {
    margin-top: 32px;
    padding: 20px;
    background: rgba(239,68,68,0.04);
    border: 1px solid rgba(239,68,68,0.2);
    border-radius: var(--radius);
}
.danger-zone h3 {
    color: var(--danger);
    font-size: 16px;
    margin-bottom: 8px;
}
.danger-zone p {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 16px;
}

/* ── Provision Cards (Dashboard) ── */
.provision-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}
.provision-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    min-width: 260px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.provision-card:hover {
    border-color: var(--text-muted);
    box-shadow: var(--shadow);
}
.provision-card-inner {
    display: flex;
    align-items: center;
    gap: 16px;
}
.provision-card-info {
    flex: 1;
    min-width: 0;
}
.provision-card-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-heading);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.provision-card-step {
    font-size: 13px;
    color: var(--info);
    font-weight: 500;
}
.provision-card-spinner {
    position: relative;
    width: 64px;
    height: 64px;
    flex-shrink: 0;
}
.spinner-ring {
    display: block;
    animation: spinner-rotate 1.2s linear infinite;
}
@keyframes spinner-rotate {
    to { transform: rotate(360deg); }
}
.spinner-ring-bg {
    stroke: var(--border);
}
.spinner-ring-arc {
    stroke: var(--info);
}
.provision-elapsed {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-heading);
    font-variant-numeric: tabular-nums;
}
.provision-card-error {
    display: flex;
    align-items: center;
    gap: 12px;
}
.provision-card-error-icon {
    flex-shrink: 0;
    color: var(--danger);
}
.provision-card-error-msg {
    font-size: 13px;
    color: var(--danger);
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-toggle {
        display: flex;
    }
    .main-content {
        margin-left: 0;
    }
    .content-container { padding: 16px; padding-top: 60px; }
    .card-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .detail-list { grid-template-columns: 1fr; }
    .modal-content { min-width: auto; margin: 16px; }
    .progress-steps { flex-direction: column; }
    .dashboard-layout { flex-direction: column; }
    .agent-config-drawer {
        width: calc(100vw - 24px);
        right: -8px;
    }
    .quick-create-form { flex-wrap: wrap; }
    .quick-create-form select { max-width: none; flex: 1; }
}

/* ── Requests & Markdown ── */
.status-badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.status-open { background: var(--success); color: #fff; }
.status-in_progress { background: var(--info); color: #fff; }
.status-closed { background: var(--text-muted); color: #fff; }

.request-filter-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.filter-tab { padding: 8px 16px; text-decoration: none; color: var(--text-muted); border-bottom: 2px solid transparent; font-size: 14px; }
.filter-tab:hover { color: var(--text); }
.filter-tab.active { color: var(--text); border-bottom-color: var(--primary); }
.filter-count { background: var(--bg-tertiary); border-radius: 10px; padding: 1px 7px; font-size: 12px; margin-left: 4px; }

.request-body-card, .comment-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}
.request-meta, .comment-meta { margin-bottom: 12px; }
.comment-meta { display: flex; align-items: center; gap: 8px; }

.markdown-editor { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.markdown-editor-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}
.tab-btn {
    background: none;
    border: none;
    padding: 4px 10px;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
}
.tab-btn.active { background: var(--bg-secondary); color: var(--text); }
.markdown-write {
    width: 100%;
    min-height: 120px;
    border: none;
    padding: 12px;
    background: var(--bg-secondary);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 14px;
    resize: vertical;
}
.markdown-preview {
    padding: 12px;
    min-height: 120px;
    background: var(--bg-secondary);
}

.markdown-body { line-height: 1.6; word-wrap: break-word; margin-top: 12px; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 16px 0 8px; color: var(--text-heading); }
.markdown-body h1 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.markdown-body h2 { font-size: 1.3em; }
.markdown-body h3 { font-size: 1.1em; }
.markdown-body p { margin: 8px 0; }
.markdown-body code { background: var(--bg-tertiary); padding: 2px 5px; border-radius: 3px; font-family: var(--font-mono); font-size: 0.9em; }
.markdown-body pre { background: var(--bg-tertiary); padding: 12px; border-radius: var(--radius); overflow-x: auto; margin: 12px 0; }
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote { border-left: 3px solid var(--border); margin: 12px 0; padding: 4px 16px; color: var(--text-muted); }
.markdown-body ul, .markdown-body ol { padding-left: 24px; margin: 8px 0; }
.markdown-body li { margin: 4px 0; }
.markdown-body img { max-width: 100%; border-radius: var(--radius); margin: 8px 0; }
.markdown-body a { color: var(--info); text-decoration: underline; }
.markdown-body table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.markdown-body th { background: var(--bg-tertiary); font-weight: 600; }

.form-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; max-width: 800px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 14px; }
.form-input {
    width: 100%;
    padding: 8px 12px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
}
.form-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--focus-ring); }
.form-textarea {
    width: 100%;
    padding: 8px 12px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 14px;
    resize: vertical;
}
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.drop-zone { position: relative; }
.drop-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: var(--overlay);
    border: 3px dashed var(--info);
    border-radius: var(--radius);
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
}
.drop-zone.drop-active .drop-overlay { display: flex; }

.upload-status { margin-top: 4px; }
.upload-status-entry { font-size: 13px; color: var(--text-muted); padding: 2px 0; }
.upload-status-entry.upload-done { color: var(--success); }
.upload-status-entry.upload-error { color: var(--danger); }

/* ── Team Map ── */
.team-map-container {
    position: relative;
    width: 100%;
    height: calc(100vh - 140px);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.team-map-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ── Skills Marketplace ── */
.skill-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}
.skill-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.skill-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
}
.skill-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
}
.skill-card-name {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-heading);
}
.skill-card-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.4;
}
.skill-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
    font-size: 12px;
}
.skill-verified-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(74, 222, 128, 0.15);
    color: var(--success);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.inject-count {
    color: var(--info);
    font-size: 12px;
    font-weight: 500;
}
.contributor-list {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}
.contributor-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
}

/* ── Skill Filter Bar ── */
.skill-filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.skill-filter-tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.skill-filter-tabs::-webkit-scrollbar { display: none; }
.skill-filter-bar .btn {
    flex-shrink: 0;
    margin-bottom: -1px;
}

/* ── Skill Editor ── */
.skill-editor-form {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 200px);
}
.skill-editor-textarea {
    flex: 1;
    min-height: calc(100vh - 380px);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
}
.skill-editor-preview {
    height: calc(100vh - 380px);
    overflow-y: auto;
    padding: 16px;
    background: var(--bg-secondary);
}

/* ── Skill Content Preview ── */
.skill-content-preview {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    max-height: 600px;
    overflow-y: auto;
    margin: 0;
}
.skill-content-preview.markdown-body {
    margin-top: 0;
    white-space: normal;
}
.skill-content-preview.markdown-body > :first-child { margin-top: 0; }
pre.skill-content-preview {
    font-family: var(--font-mono);
    font-size: 13px;
    background: var(--bg-secondary);
    white-space: pre-wrap;
}
.content-view-tabs {
    display: inline-flex;
    gap: 0;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 2px;
}
.content-view-tabs .tab-btn {
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 4px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}
.content-view-tabs .tab-btn.active {
    background: var(--bg-secondary);
    color: var(--text);
    box-shadow: var(--shadow);
}

/* ── Diff View ── */
.diff-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: auto;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
}
.diff-line {
    display: flex;
    padding: 1px 12px;
    white-space: pre-wrap;
    word-break: break-all;
}
.diff-prefix {
    flex-shrink: 0;
    width: 20px;
    color: var(--text-muted);
    user-select: none;
}
.diff-text {
    flex: 1;
}
.diff-add {
    background: rgba(74, 222, 128, 0.12);
    color: var(--success);
}
.diff-remove {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
}
.diff-unchanged {
    color: var(--text-muted);
}

/* ── Agent Card Grid ── */
.agent-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.agent-section-header h2 {
    margin-bottom: 0;
}
.agent-header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}
.agent-search-input {
    padding: 6px 12px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    width: 200px;
}
.agent-search-input:focus {
    outline: none;
    border-color: var(--text-muted);
    box-shadow: 0 0 0 3px var(--focus-ring);
}
.agent-search-input::placeholder {
    color: var(--text-muted);
}
.view-toggle {
    display: inline-flex;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 2px;
    gap: 2px;
}
.view-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}
.view-toggle-btn:hover {
    color: var(--text);
}
.view-toggle-btn.active {
    background: var(--bg-secondary);
    color: var(--text);
    box-shadow: var(--shadow);
}
.agent-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}
.agent-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.agent-card:hover {
    border-color: var(--text-muted);
    box-shadow: var(--shadow);
}
.agent-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
}
.agent-card-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-heading);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.agent-card-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.agent-card-field {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}
.agent-card-label {
    color: var(--text-muted);
    min-width: 80px;
    font-size: 12px;
}

@media (max-width: 768px) {
    .agent-card-grid { grid-template-columns: 1fr; }
    .agent-section-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .agent-search-input { width: 100%; }
}

/* ── Skill Status Badges ── */
.status-active { background: rgba(74, 222, 128, 0.15); color: var(--success); }
.status-failed { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.status-removed { background: var(--bg-tertiary); color: var(--text-muted); }
