/* ═══════════════════════════════════════════════════════════════════════════
   Browser Agent Panel — Modern Dashboard Styles
   Dark production slate with electric accents
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    --slate-950: #0B0E14;
    --slate-900: #0F172A;
    --slate-800: #1E293B;
    --slate-700: #334155;
    --slate-600: #475569;
    --slate-500: #64748B;
    --slate-400: #94A3B8;
    --slate-300: #CBD5E1;
    --slate-200: #E2E8F0;
    --slate-100: #F1F5F9;
    --slate-50: #F8FAFC;

    --accent-blue: #38BDF8;
    --accent-cyan: #22D3EE;
    --accent-teal: #4FD1C5;
    --accent-orange: #F97316;
    --accent-red: #EF4444;
    --accent-green: #10B981;
    --accent-purple: #A855F7;
    --accent-brass: #C9A24B;

    --bg-primary: var(--slate-950);
    --bg-secondary: var(--slate-900);
    --bg-elevated: var(--slate-800);
    --text-primary: var(--slate-50);
    --text-secondary: var(--slate-400);
    --text-muted: var(--slate-500);
    --border-color: var(--slate-700);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */

.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header svg {
    color: var(--accent-cyan);
}

.sidebar-title {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-primary);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.15s ease;
    border-left: 2px solid transparent;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    opacity: 0.7;
}

.nav-item:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.nav-item:hover svg {
    opacity: 1;
}

.nav-item.active {
    background: var(--bg-elevated);
    color: var(--accent-cyan);
    border-left-color: var(--accent-cyan);
}

.nav-item.active svg {
    opacity: 1;
    color: var(--accent-cyan);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-cyan);
    color: var(--slate-900);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.user-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-logout {
    padding: 6px;
    border-radius: 6px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    flex-shrink: 0;
}

.btn-logout svg {
    width: 16px;
    height: 16px;
}

.btn-logout:hover {
    background: var(--bg-elevated);
    color: var(--accent-red);
    border-color: var(--accent-red);
}

/* ── Main Content ───────────────────────────────────────────────────────── */

.main-content {
    flex: 1;
    margin-left: 240px;
    background: var(--bg-primary);
}

.topbar {
    height: 64px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--slate-600);
    animation: pulse 2s ease-in-out infinite;
}

.status-badge.status-online .status-dot {
    background: var(--accent-green);
}

.status-badge.status-offline .status-dot {
    background: var(--accent-red);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.content-area {
    padding: 32px;
    max-width: 1600px;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */

.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.card-wide {
    grid-column: 1 / -1;
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-actions {
    display: flex;
    gap: 8px;
}

.card-body {
    padding: 24px;
}

.card-body.no-padding {
    padding: 0;
}

/* ── Stats Grid ─────────────────────────────────────────────────────────── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--slate-600);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 24px;
    height: 24px;
}

.stat-icon-blue { background: rgba(56, 189, 248, 0.15); color: var(--accent-blue); }
.stat-icon-green { background: rgba(16, 185, 129, 0.15); color: var(--accent-green); }
.stat-icon-orange { background: rgba(249, 115, 22, 0.15); color: var(--accent-orange); }
.stat-icon-purple { background: rgba(168, 85, 247, 0.15); color: var(--accent-purple); }
.stat-icon-red { background: rgba(239, 68, 68, 0.15); color: var(--accent-red); }
.stat-icon-teal { background: rgba(79, 209, 197, 0.15); color: var(--accent-teal); }

.stat-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

/* ── Dashboard Rows ─────────────────────────────────────────────────────── */

.dashboard-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

/* ── Tables ─────────────────────────────────────────────────────────────── */

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: var(--bg-elevated);
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
    color: var(--text-primary);
}

.data-table tbody tr {
    transition: background 0.1s ease;
}

.data-table tbody tr:hover {
    background: var(--bg-elevated);
}

.empty-state {
    text-align: center;
    padding: 48px 24px !important;
    color: var(--text-muted);
    font-style: italic;
}

/* ── Badges ─────────────────────────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-blue { background: rgba(56, 189, 248, 0.15); color: var(--accent-blue); }
.badge-green { background: rgba(16, 185, 129, 0.15); color: var(--accent-green); }
.badge-orange { background: rgba(249, 115, 22, 0.15); color: var(--accent-orange); }
.badge-purple { background: rgba(168, 85, 247, 0.15); color: var(--accent-purple); }
.badge-red { background: rgba(239, 68, 68, 0.15); color: var(--accent-red); }
.badge-gray { background: rgba(148, 163, 184, 0.15); color: var(--slate-400); }
.badge-teal { background: rgba(79, 209, 197, 0.15); color: var(--accent-teal); }

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent-cyan);
    color: var(--slate-900);
}

.btn-primary:hover {
    background: var(--accent-blue);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--slate-500);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
    border: 1px solid transparent;
}

.btn-danger:hover {
    background: var(--accent-red);
    color: white;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
}

.btn-group {
    display: inline-flex;
    gap: 4px;
}

/* ── Forms ──────────────────────────────────────────────────────────────── */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

input[type="text"],
input[type="password"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
}

.select-sm,
.input-sm {
    padding: 6px 10px;
    font-size: 12px;
}

/* ── Login Page ─────────────────────────────────────────────────────────── */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--slate-950) 0%, var(--slate-900) 100%);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 24px;
}

.login-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header .logo {
    display: inline-flex;
    width: 64px;
    height: 64px;
    align-items: center;
    justify-content: center;
    background: rgba(56, 189, 248, 0.15);
    border-radius: 16px;
    margin-bottom: 16px;
}

.login-header .logo svg {
    color: var(--accent-cyan);
}

.login-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.login-header .subtitle {
    color: var(--text-muted);
    font-size: 14px;
}

.login-form {
    margin-bottom: 24px;
}

.login-footer {
    text-align: center;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.login-footer p {
    font-size: 12px;
    color: var(--text-muted);
}

/* ── Alerts ─────────────────────────────────────────────────────────────── */

.alert {
    padding: 14px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.alert svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.alert-error {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.alert-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-green);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

/* ── Utilities ──────────────────────────────────────────────────────────── */

.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--text-muted); }
.text-green { color: var(--accent-green); }
.text-red { color: var(--accent-red); }

code, .code-sm {
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
    background: var(--bg-elevated);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--accent-cyan);
}

.link {
    color: var(--accent-cyan);
    text-decoration: none;
    transition: color 0.15s ease;
}

.link:hover {
    color: var(--accent-blue);
    text-decoration: underline;
}

.link-more {
    font-size: 12px;
    color: var(--accent-cyan);
    text-decoration: none;
    font-weight: 500;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-description {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

.page-actions {
    display: flex;
    gap: 12px;
}

.filter-group {
    display: flex;
    gap: 8px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.setting-value {
    font-size: 13px;
    color: var(--text-primary);
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 24px;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.info-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.info-value {
    font-size: 16px;
    color: var(--text-primary);
    font-weight: 600;
}

.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    z-index: 100;
}

.dropdown-menu a {
    display: block;
    padding: 10px 16px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 13px;
    transition: background 0.1s ease;
}

.dropdown-menu a:hover {
    background: var(--bg-elevated);
}

.dropdown-menu.hidden {
    display: none;
}

/* ── Projects / Builder / Profile pages ─────────────────────────────────── */

input[type="number"],
input[type="url"] {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
}

.hidden { display: none !important; }
textarea { min-height: 90px; resize: vertical; font-family: inherit; }
textarea.mono, .mono { font-family: 'Monaco', 'Menlo', 'Courier New', monospace; font-size: 12px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px 18px;
}
.form-grid .form-group { margin-bottom: 0; }
.form-grid .span-2 { grid-column: span 2; }
.form-hint { display: block; margin-top: 6px; font-size: 11px; color: var(--text-muted); }
.form-actions { display: flex; gap: 10px; margin-top: 18px; align-items: center; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-primary); }
.check input { width: auto; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border-color); margin-bottom: 20px; flex-wrap: wrap; }
.tab {
    padding: 10px 16px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    background: none;
    border-top: none; border-left: none; border-right: none;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent-cyan); border-bottom-color: var(--accent-cyan); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; color: var(--text-primary); word-break: break-all; }

.timeline { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow: auto; }
.timeline li { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border-color); font-size: 12px; }
.timeline li:last-child { border-bottom: none; }
.timeline time { color: var(--text-muted); white-space: nowrap; min-width: 130px; }
.timeline .lvl-warn { color: var(--accent-orange); }
.timeline .lvl-error { color: var(--accent-red); }

.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: rgba(148,163,184,.15); color: var(--slate-400); }
.status-pill.running { background: rgba(56,189,248,.15); color: var(--accent-blue); }
.status-pill.stopping { background: rgba(249,115,22,.15); color: var(--accent-orange); }
.status-pill.finished, .status-pill.completed, .status-pill.ok { background: rgba(16,185,129,.15); color: var(--accent-green); }
.status-pill.exhausted, .status-pill.stopped { background: rgba(249,115,22,.15); color: var(--accent-orange); }
.status-pill.error, .status-pill.dead { background: rgba(239,68,68,.15); color: var(--accent-red); }

.progress { height: 8px; background: var(--bg-elevated); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent-green); transition: width .3s ease; }

/* builder */
.builder-layout { display: grid; grid-template-columns: 290px 1fr; gap: 20px; align-items: start; }
.builder-side .card:first-child { position: sticky; top: 20px; }
.config-list { list-style: none; margin: 0; padding: 0; max-height: 52vh; overflow: auto; }
.config-list li { padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.config-list li:hover { background: var(--bg-elevated); }
.config-list li.active { background: rgba(56,189,248,.12); color: var(--accent-cyan); }
.config-list li small { color: var(--text-muted); font-size: 11px; display: flex; gap: 8px; }
.config-list li .cl-name { display: flex; justify-content: space-between; gap: 6px; word-break: break-all; }
.config-list li .cl-err { color: var(--accent-red); }
.dirty-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-orange); margin-left: 6px; vertical-align: middle; }
.tab-badge { display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: var(--bg-elevated); color: var(--text-secondary); font-size: 10px; line-height: 18px; text-align: center; }
.tab-badge:empty { display: none; }
.help { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; border-radius: 50%; font-size: 10px; font-style: normal; font-weight: 700; color: var(--text-muted); border: 1px solid var(--border-color); cursor: help; margin-left: 4px; vertical-align: middle; }
.help:hover { color: var(--accent-cyan); border-color: var(--accent-cyan); }
details.adv > summary { cursor: pointer; font-size: 13px; color: var(--text-secondary); user-select: none; }
details.adv > summary:hover { color: var(--text-primary); }
.preset-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.preset-row .btn { padding: 4px 10px; font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 36px; padding: 6px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-elevated); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; background: var(--bg-secondary); border: 1px solid var(--border-color); cursor: pointer; color: var(--text-secondary); }
.chip.on { border-color: var(--accent-cyan); color: var(--accent-cyan); background: rgba(56,189,248,.12); }

/* flow strip */
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 12px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--bg-secondary); font-size: 12px; }
.flow .node { padding: 4px 10px; border-radius: 6px; background: var(--bg-elevated); border: 1px solid var(--border-color); cursor: pointer; }
.flow .node.start { border-color: var(--accent-green); color: var(--accent-green); }
.flow .node.orphan { border-style: dashed; color: var(--text-muted); }
.flow .node.bad { border-color: var(--accent-red); color: var(--accent-red); }
.flow .arrow { color: var(--text-muted); }

/* scenario */
.scenario { border: 1px solid var(--border-color); border-radius: 10px; margin-bottom: 14px; background: var(--bg-secondary); }
.scenario-head { display: grid; grid-template-columns: 24px 1fr 1.6fr 1fr auto; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border-color); }
.scenario-head input, .scenario-head select { padding: 6px 10px; font-size: 13px; width: 100%; }
.scenario-head .caret { cursor: pointer; color: var(--text-muted); user-select: none; font-size: 12px; }
.scenario-head .ops { display: flex; gap: 4px; }
.scenario.collapsed .scenario-body { display: none; }
.scenario-body { padding: 6px 12px 10px; }
.scenario-sub { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 6px 0 8px; font-size: 12px; color: var(--text-muted); }
.scenario-sub label { display: inline-flex; align-items: center; gap: 6px; }
.scenario-sub input[type="number"] { width: 80px; padding: 4px 8px; font-size: 12px; }
.scenario-sub input[type="text"] { width: 160px; padding: 4px 8px; font-size: 12px; }

/* action row */
.action { display: grid; grid-template-columns: 22px 210px 1fr auto; gap: 10px; align-items: start; padding: 8px 0; border-bottom: 1px dashed var(--border-color); position: relative; }
.action:last-child { border-bottom: none; }
.action .grip { color: var(--text-muted); cursor: grab; font-size: 14px; line-height: 1; padding-top: 8px; text-align: center; user-select: none; }
.action .grip small { display: block; font-size: 10px; }
.action.dragging { opacity: .4; }
.action.drop-before { box-shadow: inset 0 2px 0 var(--accent-cyan); }
.action.drop-after { box-shadow: inset 0 -2px 0 var(--accent-cyan); }
.action select, .action input, .action textarea { padding: 6px 10px; font-size: 12px; }
.action .cmdcol { display: flex; flex-direction: column; gap: 6px; }
.action .cmdcol .cmd-desc { font-size: 11px; color: var(--text-muted); line-height: 1.35; }
.action .fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.action .fields .f-wide { grid-column: 1 / -1; }
.action .fields label { font-size: 11px; color: var(--text-muted); display: block; margin-bottom: 2px; }
.action .fields textarea { min-height: 44px; }
.action .fields .range { display: flex; gap: 4px; align-items: center; }
.action .fields .range input { width: 50%; }
.action .flags { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--text-muted); grid-column: 1 / -1; }
.action .flags label { display: inline-flex; align-items: center; gap: 4px; margin: 0; }
.action .flags input[type="number"] { width: 64px; padding: 3px 6px; }
.action .ops { display: flex; flex-direction: column; gap: 3px; }
.action .ops .btn { padding: 3px 7px; font-size: 11px; line-height: 1.2; }
.action.nested-wrap { grid-template-columns: 1fr; }
.nested-list { margin-left: 24px; border-left: 2px solid var(--border-color); padding-left: 10px; margin-top: 4px; }
.nested-list .action { grid-template-columns: 22px 190px 1fr auto; }
.action.collapsed .fields, .action.collapsed .cmd-desc, .action.collapsed .nested-list { display: none; }
.action.collapsed { padding: 4px 0; }
.action .summary { font-size: 12px; color: var(--text-secondary); padding-top: 7px; word-break: break-all; }
.action.err { background: rgba(239,68,68,.06); }
.add-action { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.problems { margin: 12px 0; padding: 10px 14px; border-radius: 8px; background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); font-size: 12px; color: var(--accent-red); white-space: pre-wrap; }
.problems.warn { background: rgba(249,115,22,.1); border-color: rgba(249,115,22,.3); color: var(--accent-orange); }
.problems.ok { background: rgba(16,185,129,.1); border-color: rgba(16,185,129,.3); color: var(--accent-green); }
.editor { width: 100%; min-height: 60vh; }

/* command palette */
.palette { position: fixed; z-index: 500; width: 420px; max-height: 60vh; overflow: hidden; display: flex; flex-direction: column; background: var(--bg-elevated); border: 1px solid var(--border-color); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 8px; }
.palette input { margin-bottom: 6px; }
.palette #paletteList { overflow: auto; }
.palette .pgroup { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); padding: 8px 8px 4px; }
.palette .pitem { padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 12px; display: grid; grid-template-columns: 140px 1fr; gap: 8px; }
.palette .pitem:hover, .palette .pitem.sel { background: rgba(56,189,248,.12); }
.palette .pitem b { font-family: 'Monaco','Menlo','Courier New',monospace; font-weight: 600; color: var(--text-primary); }
.palette .pitem span { color: var(--text-muted); }

/* modal */
.modal { position: fixed; inset: 0; z-index: 900; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-box { width: min(640px, 100%); max-height: 90vh; overflow: auto; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 12px; box-shadow: var(--shadow-lg); }
.modal-box select[size] { height: auto; }
.kw-row input { padding: 6px 10px; font-size: 13px; }

/* filter bars + stat sub-captions (project / profiles / runs) */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; border-bottom: 1px solid var(--border-color); }
.filters .input-sm, .filters .select-sm { width: auto; }
.filters input[type="date"] { color-scheme: dark; }
.stat-sub { display: block; margin-top: 2px; }

/* docs */
.docs-layout { display: grid; grid-template-columns: 260px 1fr; gap: 20px; align-items: start; }
.docs-nav { position: sticky; top: 20px; }
.docs-nav a { display: block; padding: 6px 8px; border-radius: 6px; font-size: 13px; color: var(--text-secondary); text-decoration: none; }
.docs-nav a:hover { background: var(--bg-elevated); color: var(--text-primary); }
.docs-nav a.active { color: var(--accent-cyan); background: rgba(56,189,248,.1); }
.docs { line-height: 1.6; font-size: 14px; }
.docs h1 { font-size: 26px; margin: 0 0 8px; }
.docs h2 { font-size: 20px; margin: 36px 0 12px; padding-top: 12px; border-top: 1px solid var(--border-color); }
.docs h3 { font-size: 15px; margin: 20px 0 8px; color: var(--text-primary); }
.docs .lead { color: var(--text-secondary); font-size: 15px; }
.docs p { margin: 8px 0; color: var(--text-secondary); }
.docs ul, .docs ol { margin: 8px 0 8px 22px; color: var(--text-secondary); }
.docs li { margin: 4px 0; }
.docs ol.steps li { margin: 8px 0; }
.docs code { background: var(--bg-elevated); padding: 1px 6px; border-radius: 4px; font-size: 12.5px; color: var(--accent-cyan); }
.docs pre.mono { background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 8px; padding: 12px 14px; overflow: auto; font-size: 12px; line-height: 1.5; color: var(--text-primary); }
.docs .callout { margin: 14px 0; padding: 12px 14px; border-radius: 8px; background: rgba(56,189,248,.08); border: 1px solid rgba(56,189,248,.3); color: var(--text-primary); }
.docs .callout.warn { background: rgba(249,115,22,.08); border-color: rgba(249,115,22,.35); }
.docs dl.defs dt { font-weight: 600; margin-top: 12px; color: var(--text-primary); }
.docs dl.defs dd { margin: 2px 0 0; color: var(--text-secondary); }
.docs .docs-table td { font-size: 13px; vertical-align: top; }
.docs .docs-table td:first-child { white-space: nowrap; width: 240px; }
.docs .cmd-group { margin-top: 26px; color: var(--accent-cyan); text-transform: uppercase; letter-spacing: .06em; font-size: 12px; }
.docs .cmd { border: 1px solid var(--border-color); border-radius: 10px; padding: 12px 14px; margin: 10px 0; background: var(--bg-secondary); }
.docs .cmd-head { display: flex; gap: 12px; align-items: baseline; }
.docs .cmd-head code { font-size: 14px; }
.docs .cmd-head span { color: var(--text-primary); font-weight: 600; }
.docs .cmd details summary { cursor: pointer; font-size: 12px; color: var(--text-muted); margin-top: 6px; }
@media (max-width: 1100px) { .docs-layout { grid-template-columns: 1fr; } .docs-nav { position: static; } }
.stat-body .text-xs { display: block; margin-top: 2px; }
.badge-engine { text-transform: uppercase; letter-spacing: .04em; }

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 1100px) {
    .builder-layout { grid-template-columns: 1fr; }
    .builder-side .card { position: static; }
    .action { grid-template-columns: 28px 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        width: 200px;
    }
    .main-content {
        margin-left: 200px;
    }
    .content-area {
        padding: 16px;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .dashboard-row {
        grid-template-columns: 1fr;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Form controls v2 — every input/select/textarea/checkbox/date/file is styled,
   regardless of where it is rendered (templates or JS). Declared last so it
   wins over the older per-type rules above.
   ═══════════════════════════════════════════════════════════════════════════ */

:root { color-scheme: dark; }

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]),
select,
textarea {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 13.5px;
    font-family: inherit;
    line-height: 1.4;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
    -webkit-appearance: none;
    appearance: none;
}
input::placeholder, textarea::placeholder { color: var(--slate-500); opacity: 1; }
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: var(--slate-600); }
input:focus, select:focus, textarea:focus, .chips:focus-within {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, .14);
    background: var(--slate-900);
}
input:disabled, select:disabled, textarea:disabled, button:disabled { opacity: .55; cursor: not-allowed; }
input:invalid:not(:placeholder-shown):not(:focus) { border-color: rgba(239,68,68,.6); }
input[readonly] { color: var(--text-secondary); background: var(--bg-secondary); }

/* select: custom chevron, dark options */
select:not([multiple]):not([size]) {
    padding-right: 34px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    cursor: pointer;
}
select[multiple], select[size] { padding: 6px; height: auto; overflow: auto; }
select option { background: var(--slate-800); color: var(--text-primary); padding: 6px 10px; }
select option:checked { background: rgba(34,211,238,.18) linear-gradient(0deg, rgba(34,211,238,.18), rgba(34,211,238,.18)); color: var(--text-primary); }
select option:disabled { color: var(--slate-500); }
select:focus option:checked { background: rgba(34,211,238,.25); }

/* small variants */
.input-sm, .select-sm, .filters input, .filters select { padding: 6px 10px; font-size: 12.5px; border-radius: 7px; }
.select-sm:not([multiple]), .filters select:not([multiple]) { padding-right: 30px; background-position: right 9px center; }
.filters input[type="date"], .filters input[type="number"] { width: auto; }

/* number: no spinners jumping the layout */
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* date/time: dark calendar icon */
input[type="date"], input[type="datetime-local"], input[type="time"] { color-scheme: dark; min-width: 140px; }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(.7); cursor: pointer; }

/* checkbox / radio */
input[type="checkbox"], input[type="radio"] {
    width: 16px; height: 16px; margin: 0; flex: none;
    accent-color: var(--accent-cyan);
    cursor: pointer;
    vertical-align: middle;
    border-radius: 4px;
}
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; }
.form-group > label.check { margin-bottom: 0; padding: 8px 0; }

/* file input: render like a button */
input[type="file"] { width: 100%; font-size: 12.5px; color: var(--text-secondary); }
input[type="file"]::file-selector-button {
    padding: 6px 12px; margin-right: 10px; border-radius: 7px;
    border: 1px solid var(--border-color); background: var(--bg-elevated); color: var(--text-primary); cursor: pointer;
    font: inherit; font-size: 12.5px;
}
input[type="file"]::file-selector-button:hover { border-color: var(--slate-500); }

/* range */
input[type="range"] { width: 100%; accent-color: var(--accent-cyan); }

/* textarea */
textarea { min-height: 84px; resize: vertical; }
textarea.mono, .mono { font-family: 'JetBrains Mono', 'Fira Code', Monaco, Menlo, 'Courier New', monospace; font-size: 12px; }
textarea.editor { min-height: 480px; line-height: 1.5; tab-size: 2; }

/* labels & hints */
.form-group label { display: flex; align-items: center; gap: 4px; margin-bottom: 7px; font-size: 12.5px; font-weight: 500; color: var(--text-secondary); }
.form-group label .help { margin-left: 2px; }
.form-hint { display: block; margin-top: 6px; font-size: 11.5px; color: var(--text-muted); line-height: 1.4; }
.form-hint a { color: var(--accent-cyan); }

/* buttons: consistent focus + disabled */
.btn:focus-visible { outline: 2px solid var(--accent-cyan); outline-offset: 2px; }
.btn:disabled { transform: none !important; box-shadow: none !important; }
.btn-outline.active { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--accent-cyan); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-elevated); }

/* ── "?" help icon + hover tooltip ─────────────────────────────────────── */

.help {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border-radius: 50%;
    font-size: 10px; font-style: normal; font-weight: 700; line-height: 1;
    color: var(--slate-400); background: rgba(148,163,184,.12); border: 1px solid transparent;
    cursor: help; margin-left: 4px; vertical-align: middle; flex: none;
    transition: all .15s ease;
}
.help:hover { color: var(--slate-900); background: var(--accent-cyan); }
th .help { margin-left: 2px; }

.tip {
    position: fixed; z-index: 2000; max-width: 340px;
    padding: 10px 12px; border-radius: 8px;
    background: var(--slate-800); color: var(--slate-100);
    border: 1px solid var(--slate-600); box-shadow: var(--shadow-lg);
    font-size: 12.5px; line-height: 1.45; font-weight: 400; white-space: pre-line;
    pointer-events: none;
    animation: tipIn .12s ease;
}
@keyframes tipIn { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
[data-tip] { cursor: help; }
.btn[data-tip], a[data-tip], .status-pill[data-tip] { cursor: pointer; }

/* ── Sidebar extras (two panels) ───────────────────────────────────────── */

.sidebar-header { position: relative; }
.sidebar-mode {
    position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
    padding: 2px 7px; border-radius: 999px; font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
    background: rgba(201,162,75,.15); color: var(--accent-brass); border: 1px solid rgba(201,162,75,.35);
}
.nav-sep { height: 1px; margin: 10px 14px; background: var(--border-color); }
.nav-item-admin { color: var(--accent-brass); }
.nav-item-admin:hover { color: var(--accent-brass); background: rgba(201,162,75,.08); }

/* ── Modals ────────────────────────────────────────────────────────────── */

.modal { position: fixed; inset: 0; z-index: 900; background: rgba(2,6,23,.7); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fadeIn .15s ease; }
.modal-box { width: min(680px, 100%); max-height: 90vh; overflow: auto; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 14px; box-shadow: var(--shadow-lg); animation: popIn .15s ease; }
.modal-box .card-header { padding: 16px 20px; }
.modal-box .card-body { padding: 20px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* ── Client portal: overview / guide / settings ────────────────────────── */

.chart-wrap { position: relative; height: 240px; }
.steps { margin: 6px 0 0 0; padding-left: 0; list-style: none; counter-reset: step; }
.steps li { position: relative; padding: 6px 0 6px 38px; color: var(--text-secondary); font-size: 13.5px; line-height: 1.5; }
.steps li b { color: var(--text-primary); }
.steps li::before {
    counter-increment: step; content: counter(step);
    position: absolute; left: 0; top: 6px; width: 26px; height: 26px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: rgba(34,211,238,.12); color: var(--accent-cyan); font-weight: 700; font-size: 12px;
}
.getting-started { border-color: rgba(34,211,238,.3); }
.docs-toc .card { position: sticky; top: 20px; }
.docs-toc a { display: block; padding: 7px 10px; border-radius: 7px; font-size: 13px; color: var(--text-secondary); text-decoration: none; }
.docs-toc a:hover { background: var(--bg-elevated); color: var(--text-primary); }
.docs-body { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.docs-body .card { scroll-margin-top: 20px; }
.docs-text { font-size: 14px; line-height: 1.65; color: var(--text-secondary); }
.docs-text p { margin: 8px 0; }
.docs-text ul { margin: 8px 0 8px 20px; }
.docs-text li { margin: 5px 0; }
.docs-text b { color: var(--text-primary); }
.docs-text h4 { margin: 14px 0 6px; font-size: 13.5px; color: var(--text-primary); }
.docs-text code { background: var(--bg-elevated); padding: 1px 6px; border-radius: 4px; font-size: 12.5px; color: var(--accent-cyan); }
.docs-text .docs-table td { font-size: 13px; vertical-align: top; }
.docs-text .docs-table td:first-child { white-space: nowrap; width: 200px; color: var(--text-primary); font-weight: 500; }
@media (max-width: 1100px) { .docs-toc .card { position: static; } }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; align-items: start; }
.setting-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border-color); }
.setting-item:last-child { border-bottom: none; }
.setting-label { font-size: 13px; color: var(--text-secondary); }
.setting-value { font-size: 13px; color: var(--text-primary); text-align: right; }
.key-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.key-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--slate-600); }
.key-status.on .dot { background: var(--accent-green); box-shadow: 0 0 8px rgba(16,185,129,.6); }
.key-status.server .dot { background: var(--accent-blue); }
.input-with-btn { display: flex; gap: 6px; }
.input-with-btn input { flex: 1; }
.input-with-btn .btn { padding: 6px 10px; flex: none; }

/* ── Builder polish ────────────────────────────────────────────────────── */

.tab-pane .form-grid + h3, .tab-pane h3.text-sm { color: var(--text-primary); font-weight: 600; }
.section-title { display: flex; align-items: center; gap: 6px; margin: 18px 0 10px; font-size: 13px; font-weight: 600; color: var(--text-primary); text-transform: uppercase; letter-spacing: .05em; }
.section-title:first-child { margin-top: 0; }
.section-title .help { text-transform: none; letter-spacing: 0; }
.intro { padding: 12px 14px; margin-bottom: 14px; border-radius: 10px; background: rgba(34,211,238,.06); border: 1px solid rgba(34,211,238,.2); font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.intro b { color: var(--text-primary); }
.config-list li { border-radius: 8px; }
.config-list li.active { background: rgba(34,211,238,.1); border-left: 3px solid var(--accent-cyan); }
.action .cmd-name { font-weight: 600; color: var(--text-primary); }
.action .cmd-title { color: var(--text-muted); font-size: 12px; }
.empty-hint { padding: 26px; text-align: center; color: var(--text-muted); border: 1px dashed var(--border-color); border-radius: 10px; font-size: 13px; }
.empty-hint .btn { margin-top: 10px; }
.kbd { display: inline-block; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border-color); background: var(--bg-elevated); font-size: 11px; font-family: inherit; color: var(--text-secondary); }

/* tables: subtle row hover, muted mono */
.data-table tbody tr:hover td { background: rgba(148,163,184,.04); }
.data-table code { font-size: 11.5px; color: var(--slate-300); }
.empty-state a { color: var(--accent-cyan); }
