/* --- HITL Form Builder --- */

.hitl-builder {
  display: grid;
  grid-template-columns: 220px 1fr 260px;
  gap: 16px;
  min-height: 500px;
}

.hitl-palette {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 12px;
  overflow-y: auto;
  max-height: 600px;
}

.hitl-palette-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin: 12px 0 6px;
}

.hitl-palette-section:first-child { margin-top: 0; }

.hitl-palette-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  margin-bottom: 4px;
  cursor: grab;
  font-size: 13px;
  background: var(--color-bg-light);
  transition: border-color 0.15s, box-shadow 0.15s;
  user-select: none;
}

.hitl-palette-item:hover {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px var(--color-primary);
}

.hitl-palette-item:active { cursor: grabbing; }

.hitl-data-field {
  border-color: color-mix(in srgb, var(--color-primary) 30%, var(--color-border-light));
  background: color-mix(in srgb, var(--color-primary) 5%, var(--color-bg-light));
}

.hitl-palette-edit-data {
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 12px;
  padding: 2px 4px;
  border-radius: var(--radius);
  transition: color 0.15s;
}
.hitl-palette-edit-data:hover {
  color: var(--color-primary);
}

/* Webhook capture box */
.hitl-capture-box {
  background: color-mix(in srgb, var(--color-success) 8%, var(--color-bg));
  border: 1px solid color-mix(in srgb, var(--color-success) 30%, var(--color-border));
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 8px;
}

.hitl-capture-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-success);
  margin-bottom: 8px;
}

.hitl-capture-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success);
  animation: hitl-pulse 1.5s ease-in-out infinite;
}

@keyframes hitl-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.hitl-capture-url {
  display: flex;
  gap: 4px;
}

.hitl-capture-url input {
  flex: 1;
  min-width: 0;
}

.hitl-palette-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--color-primary);
  flex-shrink: 0;
}

.hitl-canvas {
  background: var(--color-bg);
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  min-height: 400px;
  position: relative;
  overflow-y: auto;
  max-height: 600px;
}

.hitl-canvas.drag-over {
  border-color: var(--color-primary);
  background: color-mix(in srgb, var(--color-primary) 5%, var(--color-bg));
}

.hitl-canvas-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-muted);
  font-size: 14px;
  text-align: center;
  padding: 40px;
}

.hitl-canvas-component {
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--color-bg-light);
  cursor: grab;
  position: relative;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.hitl-canvas-component:hover {
  border-color: var(--color-primary);
}

.hitl-canvas-component.selected {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary) 25%, transparent);
}

.hitl-canvas-component.drag-over-above {
  border-top: 2px solid var(--color-primary);
}

.hitl-canvas-component.drag-over-below {
  border-bottom: 2px solid var(--color-primary);
}

.hitl-component-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.hitl-component-type {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.03em;
  color: var(--color-primary);
}

.hitl-component-delete {
  margin-left: auto;
  cursor: pointer;
  opacity: 0;
  color: var(--color-danger);
  font-size: 14px;
  transition: opacity 0.15s;
}

.hitl-canvas-component:hover .hitl-component-delete { opacity: 1; }

.hitl-component-preview {
  font-size: 13px;
  color: var(--color-text);
}

/* Builder columns layout */
.hitl-builder-columns {
  display: grid;
  gap: 8px;
}
.hitl-builder-columns.cols-2 { grid-template-columns: 1fr 1fr; }
.hitl-builder-columns.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

.hitl-builder-column {
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 8px;
  min-height: 60px;
  background: var(--color-bg);
  transition: border-color 0.15s, background 0.15s;
}

.hitl-builder-column.drag-over {
  border-color: var(--color-primary);
  background: color-mix(in srgb, var(--color-primary) 8%, var(--color-bg));
}

.hitl-column-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 44px;
  color: var(--color-text-muted);
  font-size: 12px;
  opacity: 0.6;
}

.hitl-builder-column .hitl-canvas-component {
  margin-bottom: 4px;
  font-size: 12px;
}

.hitl-builder-column .hitl-canvas-component .hitl-component-header {
  font-size: 10px;
  margin-bottom: 2px;
}

.hitl-props {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 12px;
  overflow-y: auto;
  max-height: 600px;
}

.hitl-props-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--color-text-dark);
}

.hitl-props-empty {
  font-size: 13px;
  color: var(--color-text-muted);
  text-align: center;
  padding: 20px;
}

.hitl-prop-group {
  margin-bottom: 10px;
}

.hitl-prop-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.hitl-prop-group input,
.hitl-prop-group select,
.hitl-prop-group textarea {
  width: 100%;
  padding: 6px 8px;
  font-size: 13px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg-light);
  color: var(--color-text);
}

.hitl-prop-group textarea { resize: vertical; min-height: 60px; }

/* --- HITL Status Tabs --- */

.hitl-status-tabs {
  display: flex;
  gap: 2px;
  background: var(--color-bg-alt, #f3f4f6);
  border-radius: var(--radius);
  padding: 2px;
}

.hitl-tab {
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm, 4px);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.hitl-tab:hover {
  color: var(--color-text);
  background: var(--color-bg-light);
}

.hitl-tab.active {
  background: var(--color-bg-light);
  color: var(--color-text-dark);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.hitl-tab-badge {
  font-size: 10px;
  font-weight: 700;
  background: var(--color-danger);
  color: #fff;
  padding: 0 5px;
  border-radius: 10px;
  margin-left: 2px;
}

.hitl-tab-badge:empty { display: none; }

/* --- HITL Approvals Panel --- */

.hitl-request-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg-light);
  margin-bottom: 12px;
  overflow: hidden;
}

.hitl-request-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-light);
  cursor: pointer;
}

.hitl-request-header:hover { background: var(--color-bg); }

.hitl-request-priority {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.hitl-request-priority.critical { background: #ef4444; }
.hitl-request-priority.high { background: #f59e0b; }
.hitl-request-priority.medium { background: #3b82f6; }
.hitl-request-priority.low { background: #6b7280; }

.hitl-request-title {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hitl-request-time {
  font-size: 11px;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.hitl-request-body {
  padding: 16px;
}

.hitl-request-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}

.hitl-request-status.pending { background: #fef3c7; color: #92400e; }
.hitl-request-status.approved { background: #d1fae5; color: #065f46; }
.hitl-request-status.rejected { background: #fee2e2; color: #991b1b; }
.hitl-request-status.expired { background: #f3f4f6; color: #6b7280; }

/* Rendered form components */
.hitl-rendered-heading { margin: 0 0 8px; }
.hitl-rendered-divider { border: 0; border-top: 1px solid var(--color-border-light); margin: 12px 0; }
.hitl-rendered-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 10px;
}
.hitl-rendered-badge.success { background: #d1fae5; color: #065f46; }
.hitl-rendered-badge.warning { background: #fef3c7; color: #92400e; }
.hitl-rendered-badge.danger { background: #fee2e2; color: #991b1b; }
.hitl-rendered-badge.info { background: #dbeafe; color: #1e40af; }

.hitl-rendered-data {
  padding: 10px 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  margin-bottom: 10px;
}

.hitl-rendered-data-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 4px;
}

.hitl-rendered-json {
  background: var(--color-bg);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: monospace;
  font-size: 12px;
  white-space: pre-wrap;
  overflow-x: auto;
  max-height: 300px;
  overflow-y: auto;
}

.hitl-rendered-columns {
  display: grid;
  gap: 12px;
  margin-bottom: 10px;
}

.hitl-rendered-columns.cols-2 { grid-template-columns: 1fr 1fr; }
.hitl-rendered-columns.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

.hitl-action-buttons {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border-light);
}

/* Form Preview */
.hitl-preview-split {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  min-height: 400px;
}

.hitl-preview-data textarea {
  width: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px;
}

.hitl-preview-render {
  min-width: 0;
}

.hitl-preview-card {
  background: var(--color-bg-light);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  min-height: 300px;
}

@media (max-width: 900px) {
  .hitl-preview-split {
    grid-template-columns: 1fr;
  }
  .hitl-preview-data textarea {
    min-height: 150px !important;
  }
}

/* Builder responsive */
@media (max-width: 900px) {
  .hitl-builder {
    grid-template-columns: 1fr;
  }
  .hitl-palette, .hitl-props {
    max-height: 200px;
  }
}

/* Approval nav badge */
.hitl-nav-badge {
  background: var(--color-danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
  margin-left: auto;
}

/* Template list table */
#hitlTemplateList .users-card { max-width: none; }
.hitl-tpl-table { width: 100%; }
.hitl-tpl-table tr { cursor: default; }
.hitl-tpl-table td { vertical-align: middle; }
.hitl-row-inactive td { opacity: 0.5; }
.hitl-row-inactive td:first-child { opacity: 1; }
.hitl-tpl-name { font-weight: 600; font-size: 13px; }
.hitl-tpl-desc { font-size: 11px; color: var(--color-text-muted); margin-top: 2px; }
.hitl-tpl-slug { font-size: 11px; background: var(--color-bg-alt); padding: 2px 8px; border-radius: var(--radius-xs); color: var(--color-text-muted); }

/* Toggle switch */
.hitl-toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
}
.hitl-toggle input { opacity: 0; width: 0; height: 0; }
.hitl-toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--color-text-xmuted);
  border-radius: 20px;
  transition: background 0.2s;
}
.hitl-toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}
.hitl-toggle input:checked + .hitl-toggle-slider {
  background: var(--color-success);
}
.hitl-toggle input:checked + .hitl-toggle-slider::before {
  transform: translateX(16px);
}

/* Webhook URLs display */
.hitl-webhook-urls {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
}
.hitl-webhook-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.hitl-webhook-hint {
  font-weight: 400;
  font-size: 11px;
  color: var(--color-text-xmuted);
}
.hitl-webhook-hint code {
  background: var(--color-bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
}
.hitl-webhook-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.hitl-webhook-row:last-child { margin-bottom: 0; }
.hitl-webhook-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 3px;
  min-width: 40px;
  text-align: center;
  flex-shrink: 0;
}
.hitl-webhook-tag.prod {
  background: var(--color-success-light, #dcfce7);
  color: var(--color-success);
}
.hitl-webhook-tag.test {
  background: var(--color-warning-light, #fef3c7);
  color: #b45309;
}
