:root {
  --bg: #060d17;
  --surface: #0d1929;
  --surface2: #122236;
  --border: #1a3350;
  --accent: #0ea5e9;
  --accent-hover: #38bdf8;
  --success: #25d366;
  --error: #ef4444;
  --warning: #f97316;
  --text: #e2e8f0;
  --text-muted: #7ea6c4;
  --node-trigger: #7c3aed;
  --node-http: #0ea5e9;
  --node-transform: #10b981;
  --node-condition: #f97316;
  --node-response: #ec4899;
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Top Bar ── */
#topbar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  z-index: 100;
}

#topbar .logo {
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
  margin-right: 8px;
  white-space: nowrap;
}

#topbar .flow-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  min-width: 120px;
}

.spacer { flex: 1; }

.btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #16a34a; }

/* ── Layout ── */
#app {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Left Sidebar (flow list) ── */
#sidebar {
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

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

#sidebar-header h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#flow-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.flow-item {
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s;
}

.flow-item:hover { background: var(--surface2); }

.flow-item.active {
  background: var(--surface2);
  border-left-color: var(--accent);
}

.flow-item-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.flow-item-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
}
.badge-active { background: #052e16; color: var(--success); }
.badge-inactive { background: #0d1929; color: var(--text-muted); }
.badge-running { background: #073859; color: #38bdf8; }
.badge-success { background: #052e16; color: var(--success); }
.badge-error { background: #450a0a; color: var(--error); }

/* ── Canvas Area ── */
#canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── Node Palette ── */
#palette {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

#palette span {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 4px;
}

.palette-node {
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: grab;
  user-select: none;
  border: 1px solid transparent;
  transition: opacity 0.15s, transform 0.1s;
}
.palette-node:hover { opacity: 0.85; transform: translateY(-1px); }
.palette-node:active { cursor: grabbing; }

.pn-trigger_webhook { background: #2d1b69; color: #c4b5fd; border-color: #6d28d9; }
.pn-trigger_cron    { background: #2d1b69; color: #c4b5fd; border-color: #6d28d9; }
.pn-http_request    { background: #073859; color: #7dd3fc; border-color: #0ea5e9; }
.pn-transform       { background: #053728; color: #6ee7b7; border-color: #059669; }
.pn-condition       { background: #431407; color: #fdba74; border-color: #f97316; }
.pn-response        { background: #500724; color: #f9a8d4; border-color: #be185d; }
.pn-ai_agent        { background: #1e1b4b; color: #a5b4fc; border-color: #4f46e5; }

/* ── Drawflow Canvas ── */
#drawflow {
  flex: 1;
  background: var(--bg);
  background-image: radial-gradient(circle, #2e3150 1px, transparent 1px);
  background-size: 24px 24px;
  overflow: hidden;
  position: relative;
}

/* Drawflow overrides */
.drawflow .drawflow-node {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
  min-width: 180px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.drawflow .drawflow-node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(99,102,241,0.3), 0 4px 16px rgba(0,0,0,0.4);
}

.drawflow .drawflow-node .drawflow_content_node {
  padding: 0;
}

.df-node-header {
  padding: 8px 12px;
  border-radius: 8px 8px 0 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
}

.df-node-body {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.node-type-trigger_webhook .df-node-header { background: #2d1b69; color: #c4b5fd; }
.node-type-trigger_cron    .df-node-header { background: #2d1b69; color: #c4b5fd; }
.node-type-http_request    .df-node-header { background: #073859; color: #7dd3fc; }
.node-type-transform       .df-node-header { background: #053728; color: #6ee7b7; }
.node-type-condition       .df-node-header { background: #431407; color: #fdba74; }
.node-type-response        .df-node-header { background: #500724; color: #f9a8d4; }
.node-type-ai_agent        .df-node-header { background: #1e1b4b; color: #a5b4fc; }

.drawflow .connection .main-path {
  stroke: var(--accent);
  stroke-width: 2;
}

.drawflow .connection .main-path:hover {
  stroke: var(--accent-hover);
  stroke-width: 3;
}

/* Port dots */
.drawflow .drawflow-node .input, .drawflow .drawflow-node .output {
  background: var(--border);
  border: 2px solid var(--surface);
  width: 12px;
  height: 12px;
}
.drawflow .drawflow-node .input:hover, .drawflow .drawflow-node .output:hover {
  background: var(--accent);
}

/* ── Right Panel ── */
#right-panel {
  width: 320px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

#panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.panel-tab {
  flex: 1;
  padding: 10px;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: color 0.15s;
}
.panel-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

#panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* Node config form */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--accent);
}
.form-group textarea {
  min-height: 80px;
  resize: vertical;
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  font-size: 12px;
}
.form-group select option { background: var(--surface2); }

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.mapping-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}
.mapping-row input {
  flex: 1;
  min-width: 0;
}
.btn-icon {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--border); color: var(--text); }

/* Execution list */
.exec-item {
  padding: 10px;
  border-radius: 8px;
  background: var(--surface2);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.1s;
}
.exec-item:hover { background: var(--border); }
.exec-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.exec-item-id {
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
}
.exec-item-time {
  font-size: 11px;
  color: var(--text-muted);
}

.step-item {
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 6px;
  font-size: 12px;
}
.step-item-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}
.step-detail {
  font-family: monospace;
  font-size: 11px;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 100px;
  overflow-y: auto;
  margin-top: 4px;
  background: var(--bg);
  padding: 4px 6px;
  border-radius: 4px;
}

/* ── Modal ── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}
#modal-overlay.open { display: flex; }

#modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 440px;
  max-width: 90vw;
}
#modal h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
}
#modal .modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ── Notification ── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  z-index: 2000;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  max-width: 320px;
}
#toast.show {
  opacity: 1;
  transform: translateY(0);
}
#toast.toast-success { border-color: var(--success); color: var(--success); }
#toast.toast-error { border-color: var(--error); color: var(--error); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state h3 { font-size: 14px; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 12px; line-height: 1.6; }

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

/* ── Login Screen ── */
#login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  width: 360px;
  max-width: 90vw;
}

.login-logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
  text-align: center;
}

.login-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 24px;
  text-align: center;
  color: var(--text-muted);
}

.login-error {
  background: #450a0a;
  border: 1px solid var(--error);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--error);
  margin-bottom: 12px;
}

/* User badge in topbar */
.user-badge {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
}

/* ── Settings & Users Tab ── */
.settings-section {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child {
  border-bottom: none;
}
.settings-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.cred-row, .user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  border-radius: 6px;
  background: var(--surface2);
  margin-bottom: 6px;
}

/* Status indicator */
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.active { background: var(--success); }
.status-dot.inactive { background: var(--text-muted); }

/* Loading */
.loading {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* No flow selected */
#no-flow {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
}
