/* ==========================================================================
   Phase 1 ERP — forms.css
   Field structure, validation states, fieldsets, chips/multi-select.
   ========================================================================== */

.form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form__row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form__row--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form__row--1 { grid-template-columns: minmax(0, 1fr); }

/* Fieldset grouping inside the sliding panel */
.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  margin: 0;
  background: var(--surface-1);
}

.fieldset + .fieldset { margin-top: 4px; }

.fieldset__legend {
  padding: 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--primary);
}

.fieldset__hint {
  font-size: 12.5px;
  color: var(--muted);
  margin: -4px 0 14px;
  line-height: 1.5;
}

/* Field */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.field__required {
  color: #d92d20;
  font-weight: 800;
  line-height: 1;
}

.field__optional {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.field__hint {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

.field__error {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--danger);
}

.field__error::before {
  content: '!';
  display: inline-grid;
  place-items: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  flex: none;
}

/* Inputs */
.input,
.select,
.textarea,
.in {
  width: 100%;
  padding: calc(var(--py, 6px) + 3px) var(--px, 12px);
  border: 1px solid var(--line, var(--border));
  border-radius: var(--r, var(--radius));
  background: var(--panel2, var(--surface-1));
  color: var(--text);
  font: 400 var(--fs, 13.5px)/1.4 var(--font);
  transition: border-color 120ms ease, box-shadow 120ms ease;
  letter-spacing: var(--track, 0);
  box-sizing: border-box;
}

.textarea { min-height: 80px; resize: vertical; }

.input::placeholder,
.textarea::placeholder,
.in::placeholder { color: var(--placeholder, #9aa4b2); }

.input:focus,
.select:focus,
.textarea:focus,
.in:focus {
  outline: none;
  border-color: var(--accent, var(--primary));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent, var(--primary)) 30%, transparent);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  background: var(--surface-3);
  color: var(--muted);
  cursor: not-allowed;
}

.input--mono { font-family: var(--mono); letter-spacing: 0.02em; }

/* Native select chevron */
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

/* Invalid / valid states */
.field.is-invalid .input,
.field.is-invalid .select,
.field.is-invalid .textarea,
.input.is-invalid,
.select.is-invalid,
.textarea.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(217, 45, 32, 0.12);
}

.field.is-valid .input,
.field.is-valid .select,
.field.is-valid .textarea {
  border-color: #12b76a;
}

/* Read-only display value inside forms */
.field__static {
  min-height: 40px;
  display: flex;
  align-items: center;
  padding: 9px 12px;
  background: var(--surface-3);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-size: 14.5px;
  color: var(--text-2);
}

/* Password strength meter */
.strength { display: flex; flex-direction: column; gap: 5px; }
.strength__bars { display: flex; gap: 4px; }
.strength__bar {
  height: 5px;
  flex: 1;
  background: var(--surface-4);
  border-radius: 999px;
}
.strength__bar.is-on--weak { background: #f04438; }
.strength__bar.is-on--fair { background: #f79009; }
.strength__bar.is-on--good { background: #2e90fa; }
.strength__bar.is-on--strong { background: #12b76a; }
.strength__text { font-size: 12px; font-weight: 600; color: var(--muted); }

/* Toggle switch */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 40px;
  height: 22px;
  margin: 0;
  cursor: pointer;
}

.switch__track {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-4);
  border: 1px solid var(--border);
  position: relative;
  transition: background 140ms ease;
  flex: none;
}

.switch__track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.3);
  transition: transform 140ms ease;
}

.switch input:checked + .switch__track { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--primary-400); outline-offset: 2px; }
.switch input:disabled + .switch__track { opacity: 0.5; cursor: not-allowed; }

.switch__label { font-size: 14px; font-weight: 500; }

/* Checkbox group (permissions matrix, actions) */
.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
  font-size: 13.5px;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}

.check:hover { border-color: var(--primary-400, var(--primary)); background: var(--surface-2); }
.check input { accent-color: var(--primary); width: 15px; height: 15px; cursor: pointer; flex: none; }
.check.is-disabled { opacity: 0.6; cursor: not-allowed; }
.check.is-checked { border-color: var(--primary); background: var(--primary-50, #f2f7ff); }

.check__meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.check__code { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

/* Chip list (multi-select entity assignment) */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 9px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
}

.chips:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  font-size: 13.5px;
  padding: 4px 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 7px 4px 10px;
  border-radius: 999px;
  background: var(--primary-50, #eaf1fd);
  border: 1px solid var(--primary-100, #c9dcfb);
  color: var(--primary-700);
  font-size: 13px;
  font-weight: 600;
}

.chip__remove {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border: 0;
  border-radius: 50%;
  background: rgba(43, 96, 196, 0.14);
  color: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.chip__remove:hover { background: rgba(43, 96, 196, 0.3); }

/* Entity picker list used by assignments */
.picker {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface-1);
}

.picker__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-soft, var(--border));
  font-size: 13.5px;
  cursor: pointer;
}
.picker__item:last-child { border-bottom: 0; }
.picker__item:hover { background: var(--surface-2); }
.picker__item input { accent-color: var(--primary); }
.picker__meta { color: var(--muted); font-size: 12px; }

/* Inline "row of value + action" (temporary password, sequences) */
.secret-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  border: 1px dashed var(--primary);
  background: var(--primary-50, #f1f6fe);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  word-break: break-all;
}

.copy-btn {
  margin-left: auto;
  flex: none;
}

/* Filter bar inside list views */
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.filters .select { min-width: 150px; width: auto; }

/* Searchable permission role cards */
.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
