/**
 * RuleEditor styles
 * @countermeasure/web-components/visualization/rule-editor
 */

/* ============================================================================
   Base
   ============================================================================ */
.cmm-rule-editor {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.8125rem;
  color: hsl(var(--foreground));
}

/* ============================================================================
   Group
   ============================================================================ */
.cmm-rule-editor__group {
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background: hsl(var(--background));
  padding: 0.75rem;
}

.cmm-rule-editor__group--nested {
  margin-top: 0.5rem;
  margin-left: 1rem;
  border-left: 3px solid hsl(var(--primary));
  background: hsl(var(--muted));
}

/* ============================================================================
   Group header
   ============================================================================ */
.cmm-rule-editor__group-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

/* ============================================================================
   Logic toggle (AND/OR)
   ============================================================================ */
.cmm-rule-editor__logic-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast);
}

.cmm-rule-editor__logic-toggle--and {
  background: hsl(221 83% 53% / 0.1);
  color: hsl(221 83% 53%);
  border-color: hsl(221 83% 53% / 0.3);
}

.cmm-rule-editor__logic-toggle--and:hover {
  background: hsl(221 83% 53% / 0.2);
}

.cmm-rule-editor__logic-toggle--or {
  background: hsl(25 95% 53% / 0.1);
  color: hsl(25 95% 53%);
  border-color: hsl(25 95% 53% / 0.3);
}

.cmm-rule-editor__logic-toggle--or:hover {
  background: hsl(25 95% 53% / 0.2);
}

.cmm-rule-editor__logic-toggle:focus-visible {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
}

/* ============================================================================
   Action buttons
   ============================================================================ */
.cmm-rule-editor__btn {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}

.cmm-rule-editor__btn:hover {
  border-color: hsl(var(--primary));
  color: hsl(var(--foreground));
}

.cmm-rule-editor__btn:focus-visible {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
}

.cmm-rule-editor__btn--add-condition {
  color: hsl(142 71% 45%);
  border-color: hsl(142 71% 45% / 0.3);
}

.cmm-rule-editor__btn--add-condition:hover {
  background: hsl(142 71% 45% / 0.08);
  border-color: hsl(142 71% 45%);
}

.cmm-rule-editor__btn--add-group {
  color: hsl(221 83% 53%);
  border-color: hsl(221 83% 53% / 0.3);
}

.cmm-rule-editor__btn--add-group:hover {
  background: hsl(221 83% 53% / 0.08);
  border-color: hsl(221 83% 53%);
}

.cmm-rule-editor__btn--remove {
  color: hsl(0 84% 60%);
  border-color: hsl(0 84% 60% / 0.3);
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  line-height: 1;
}

.cmm-rule-editor__btn--remove:hover {
  background: hsl(0 84% 60% / 0.08);
  border-color: hsl(0 84% 60%);
}

/* ============================================================================
   Conditions list
   ============================================================================ */
.cmm-rule-editor__conditions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 2rem;
  transition: background var(--transition-fast);
}

.cmm-rule-editor__conditions--drag-over {
  background: hsl(var(--primary) / 0.04);
  border-radius: var(--radius-sm);
}

/* ============================================================================
   Condition row
   ============================================================================ */
.cmm-rule-editor__condition {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast), opacity var(--transition-fast);
}

.cmm-rule-editor__condition:hover {
  border-color: hsl(var(--primary) / 0.4);
}

.cmm-rule-editor__condition--dragging {
  opacity: 0.4;
}

/* ============================================================================
   Drag handle
   ============================================================================ */
.cmm-rule-editor__drag-handle {
  display: inline-flex;
  align-items: center;
  cursor: grab;
  color: hsl(var(--muted-foreground));
  font-size: 1.125rem;
  line-height: 1;
  user-select: none;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.cmm-rule-editor__drag-handle:hover {
  color: hsl(var(--foreground));
}

/* ============================================================================
   Form controls (selects and inputs)
   ============================================================================ */
.cmm-rule-editor__select {
  padding: 0.3rem 0.5rem;
  font-size: 0.75rem;
  font-family: inherit;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast);
}

.cmm-rule-editor__select:focus {
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 2px hsl(var(--focus-ring) / 0.3);
}

.cmm-rule-editor__field-select {
  min-width: 120px;
}

.cmm-rule-editor__operator-select {
  min-width: 100px;
}

.cmm-rule-editor__value-select {
  min-width: 80px;
}

.cmm-rule-editor__input {
  flex: 1;
  min-width: 100px;
  padding: 0.3rem 0.5rem;
  font-size: 0.75rem;
  font-family: inherit;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition-fast);
}

.cmm-rule-editor__input:focus {
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 2px hsl(var(--focus-ring) / 0.3);
}

.cmm-rule-editor__input::placeholder {
  color: hsl(var(--muted-foreground));
}

/* ============================================================================
   Responsive
   ============================================================================ */
@media (max-width: 640px) {
  .cmm-rule-editor__condition {
    flex-wrap: wrap;
  }

  .cmm-rule-editor__field-select,
  .cmm-rule-editor__operator-select,
  .cmm-rule-editor__input {
    min-width: 0;
    flex: 1 1 100%;
  }

  .cmm-rule-editor__group--nested {
    margin-left: 0.5rem;
  }
}
