:root {
  --bg: #0f1117;
  --bg-card: #181a20;
  --bg-elevated: #1e2028;
  --bg-input: #252830;
  --border: #2a2d38;
  --border-hover: #3a3d48;
  --text: #e4e6eb;
  --text-muted: #8b8f9a;
  --text-dim: #5a5e6a;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-bg: rgba(99,102,241,0.12);
  --success: #22c55e;
  --success-bg: rgba(34,197,94,0.12);
  --error: #ef4444;
  --error-bg: rgba(239,68,68,0.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245,158,11,0.12);
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --font: 'Inter', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --sidebar-width: 240px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; overflow: hidden; }

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

/* Sidebar */
#sidebar { width: var(--sidebar-width); background: var(--bg-card); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 20px 16px 12px; display: flex; align-items: center; justify-content: space-between; }
.logo { font-size: 18px; font-weight: 700; color: var(--text); }
.logo-icon { color: var(--primary); }
.version { font-size: 11px; color: var(--text-dim); background: var(--bg-input); padding: 2px 8px; border-radius: 10px; }
nav { flex: 1; padding: 8px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; color: var(--text-muted); text-decoration: none; border-radius: var(--radius); font-size: 14px; font-weight: 500; transition: all 0.15s; }
.nav-item:hover { background: var(--bg-elevated); color: var(--text); }
.nav-item.active { background: var(--primary-bg); color: var(--primary-hover); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }
#status-indicator { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); animation: pulse 2s infinite; }
.status-dot.online { background: var(--success); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* Main Content */
#content { flex: 1; overflow-y: auto; padding: 24px 32px; }
.view { display: none; }
.view.active { display: block; }
.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.view-header h2 { font-size: 24px; font-weight: 700; }
.view-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; margin-top: -16px; }
.header-actions { display: flex; gap: 8px; }

/* Buttons */
.btn { padding: 8px 16px; border: none; border-radius: var(--radius); font-family: var(--font); font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.15s; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--border-hover); background: var(--bg-elevated); }
.btn-danger { background: var(--error-bg); color: var(--error); }
.btn-danger:hover { background: var(--error); color: #fff; }
.btn-success { background: var(--success-bg); color: var(--success); }
.btn-success:hover { background: var(--success); color: #fff; }
.btn-ghost { background: none; color: var(--text-muted); padding: 4px 8px; font-size: 18px; }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Cards */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; color: var(--text-muted); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }

/* Automation Cards */
.auto-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; transition: border-color 0.15s; cursor: pointer; }
.auto-card:hover { border-color: var(--primary); }
.auto-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; gap: 8px; }
.auto-card-title { font-size: 16px; font-weight: 600; }
.auto-card-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }
.auto-card-meta { display: flex; gap: 16px; font-size: 12px; color: var(--text-dim); flex-wrap: wrap; }
.auto-card-actions { display: flex; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.tag { background: var(--primary-bg); color: var(--primary-hover); padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; }

/* Status Badges */
.status-badge { padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.status-badge.success { background: var(--success-bg); color: var(--success); }
.status-badge.error { background: var(--error-bg); color: var(--error); }
.status-badge.muted { background: var(--bg-input); color: var(--text-dim); }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
input, select, textarea { width: 100%; padding: 8px 12px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-family: var(--font); font-size: 14px; transition: border-color 0.15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
.mono { font-family: var(--mono); font-size: 12px; }
.form-row { display: flex; gap: 12px; }
.form-row > .form-group { flex: 1; }
.flex-1 { flex: 1 !important; }
.flex-2 { flex: 2 !important; }
.hint { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.hint code { background: var(--bg-input); padding: 2px 6px; border-radius: 3px; font-family: var(--mono); font-size: 11px; }
small.hint { display: block; }

/* Builder */
.builder-layout { display: flex; flex-direction: column; gap: 16px; }
.steps-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.steps-header h3 { font-size: 15px; font-weight: 600; color: var(--text-muted); margin: 0; }
.steps-list { display: flex; flex-direction: column; gap: 8px; }
.step-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; display: flex; align-items: center; gap: 12px; cursor: pointer; transition: border-color 0.15s; }
.step-item:hover { border-color: var(--primary); }
.step-item.active { border-color: var(--primary); background: var(--primary-bg); }
.step-num { width: 28px; height: 28px; border-radius: 50%; background: var(--bg-input); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.step-info { flex: 1; min-width: 0; }
.step-action { font-size: 13px; font-weight: 600; color: var(--primary-hover); text-transform: uppercase; letter-spacing: 0.5px; }
.step-detail { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step-actions { display: flex; gap: 4px; }
.step-actions .btn { padding: 3px 6px; font-size: 14px; }

/* Step Editor */
.step-editor { margin-top: 8px; }
.step-editor-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.step-editor-header h3 { margin: 0; }

/* Test Results */
.test-results { margin-top: 8px; }
.result-item { padding: 10px; border-radius: var(--radius); margin-bottom: 8px; font-size: 13px; }
.result-item.success { background: var(--success-bg); border: 1px solid rgba(34,197,94,0.2); }
.result-item.error { background: var(--error-bg); border: 1px solid rgba(239,68,68,0.2); }
.result-item .result-step { font-weight: 600; margin-bottom: 4px; }
.result-item .result-detail { font-family: var(--mono); font-size: 11px; color: var(--text-muted); word-break: break-all; }
.result-screenshot { max-width: 100%; border-radius: var(--radius); margin-top: 8px; border: 1px solid var(--border); }

/* Dashboard */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.stat-card { text-align: center; padding: 24px; }
.stat-value { font-size: 36px; font-weight: 700; color: var(--primary-hover); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.conn-status-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Tabs list */
.tabs-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.tab-item { background: var(--bg-input); border: 1px solid transparent; border-radius: var(--radius); padding: 10px 14px; display: flex; align-items: center; gap: 12px; cursor: pointer; transition: all 0.15s; }
.tab-item:hover { border-color: var(--primary); background: var(--primary-bg); }
.tab-item-info { flex: 1; min-width: 0; }
.tab-title { font-size: 13px; font-weight: 500; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab-url { font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Recipe grid */
.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.recipe-card { background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; cursor: pointer; transition: all 0.15s; }
.recipe-card:hover { border-color: var(--primary); background: var(--primary-bg); }
.recipe-icon { font-size: 22px; margin-bottom: 6px; }
.recipe-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.recipe-desc { font-size: 11px; color: var(--text-muted); line-height: 1.4; }

/* Inspector */
.inspector-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.insp-tab { padding: 5px 12px; border: 1px solid var(--border); border-radius: 20px; background: var(--bg-input); color: var(--text-muted); font-size: 12px; font-family: var(--font); font-weight: 500; cursor: pointer; transition: all 0.15s; }
.insp-tab:hover { border-color: var(--primary); color: var(--text); }
.insp-tab.active { background: var(--primary-bg); border-color: var(--primary); color: var(--primary-hover); }

.insp-section { display: none; }
.insp-section.active { display: block; }

.insp-item { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; border-radius: var(--radius); cursor: pointer; transition: background 0.1s; border: 1px solid transparent; margin-bottom: 4px; }
.insp-item:hover { background: var(--primary-bg); border-color: var(--primary); }
.insp-item-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; padding-top: 1px; }
.insp-item-body { flex: 1; min-width: 0; }
.insp-item-sel { font-family: var(--mono); font-size: 11px; color: var(--primary-hover); word-break: break-all; }
.insp-item-detail { font-size: 11px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.insp-item-meta { display: flex; gap: 8px; margin-top: 2px; flex-wrap: wrap; }
.insp-item-meta span { font-size: 10px; color: var(--text-dim); background: var(--bg); padding: 1px 6px; border-radius: 3px; }
.insp-item-actions { flex-shrink: 0; display: flex; gap: 3px; }
.insp-empty { padding: 16px; text-align: center; color: var(--text-dim); font-size: 12px; }

/* Action reference */
.action-ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; margin-top: 12px; }
.action-ref-item { background: var(--bg-input); border-radius: var(--radius); padding: 12px; }
.action-ref-item h4 { font-size: 13px; font-weight: 600; color: var(--primary-hover); margin-bottom: 4px; }
.action-ref-item p { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; line-height: 1.4; }
.action-ref-item code { background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 10px; font-family: var(--mono); color: var(--text-dim); }

/* Runs Table */
.runs-table { display: flex; flex-direction: column; gap: 8px; }
.run-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; display: flex; align-items: center; gap: 16px; cursor: pointer; }
.run-item:hover { border-color: var(--border-hover); }
.run-status { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.run-status.success { background: var(--success); }
.run-status.error { background: var(--error); }
.run-status.running { background: var(--warning); animation: pulse 1s infinite; }
.run-status.partial { background: var(--warning); }
.run-name { flex: 1; font-weight: 500; font-size: 14px; }
.run-time { font-size: 12px; color: var(--text-dim); }

/* Settings */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-overlay.hidden { display: none; }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; width: 100%; max-width: 600px; max-height: 80vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal h3 { font-size: 18px; margin-bottom: 16px; }

/* Empty state */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state.small { padding: 24px; }
.empty-state p { font-size: 14px; }

.hidden { display: none !important; }

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

/* Toast */
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 20px; font-size: 13px; box-shadow: var(--shadow); z-index: 2000; animation: slideIn 0.2s; }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--error); }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
