/* ============================================================
   FORMS — Inputs, Selects, Checkboxes, Validation
   ============================================================ */

/* ── Form group ────────────────────────────────── */
.form-group { margin-bottom: var(--sp-5); }
.form-row { display: grid; gap: var(--sp-4); }
.form-row-2 { grid-template-columns: repeat(2, 1fr); }
.form-row-3 { grid-template-columns: repeat(3, 1fr); }
.form-row-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 767px) {
  .form-row-2, .form-row-3, .form-row-4 { grid-template-columns: 1fr; }
}
@media (min-width: 768px) and (max-width: 991px) {
  .form-row-3, .form-row-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ── Labels ────────────────────────────────────── */
.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: var(--sp-2);
}

.form-help {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  margin-top: var(--sp-1);
}

/* ── Text inputs ───────────────────────────────── */
.form-control {
  display: block;
  width: 100%;
  padding: 8px var(--sp-3);
  font-size: var(--font-size-sm);
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  line-height: 1.5;
  appearance: none;
  -webkit-appearance: none;
}

.form-control::placeholder { color: var(--color-text-disabled); }

.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, .12);
}

.form-control:disabled,
.form-control[readonly] {
  background: var(--color-page-bg);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.form-control-sm { padding: 5px var(--sp-3); font-size: var(--font-size-xs); }
.form-control-lg { padding: 10px var(--sp-4); font-size: var(--font-size-base); }

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

/* ── Select ────────────────────────────────────── */
select.form-control {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
  background-size: 14px;
  padding-right: calc(var(--sp-3) + 20px);
  cursor: pointer;
}

html[dir="rtl"] select.form-control {
  background-position: left var(--sp-3) center;
  padding-right: var(--sp-3);
  padding-left: calc(var(--sp-3) + 20px);
}

/* ── Input group (prefix / suffix) ────────────── */
.input-group {
  display: flex;
  align-items: stretch;
}

.input-group-text {
  display: flex;
  align-items: center;
  padding: 8px var(--sp-3);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  background: var(--color-page-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  border-right: none;
  white-space: nowrap;
}

html[dir="rtl"] .input-group-text {
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  border-right: 1px solid var(--color-border);
  border-left: none;
}

.input-group .form-control {
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
html[dir="rtl"] .input-group .form-control {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

/* Input with icon */
.input-icon-wrapper { position: relative; }
.input-icon-wrapper .form-control { padding-left: 36px; }
.input-icon-wrapper .input-icon {
  position: absolute;
  left: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  font-size: 16px;
  pointer-events: none;
}
html[dir="rtl"] .input-icon-wrapper .form-control { padding-left: var(--sp-3); padding-right: 36px; }
html[dir="rtl"] .input-icon-wrapper .input-icon { left: auto; right: var(--sp-3); }

/* Password visibility toggle */
.password-wrapper,
.input-icon-wrap { position: relative; }
.password-wrapper .form-control,
.input-icon-wrap .form-control { padding-right: 40px; }
.password-toggle {
  position: absolute;
  right: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}
.password-toggle:hover { color: var(--color-text); }
html[dir="rtl"] .password-wrapper .form-control,
html[dir="rtl"] .input-icon-wrap .form-control { padding-right: var(--sp-3); padding-left: 40px; }
html[dir="rtl"] .password-toggle { right: auto; left: var(--sp-3); }

/* ── Checkbox / Radio ──────────────────────────── */
.form-check { display: flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.form-check-input {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  cursor: pointer;
  flex-shrink: 0;
  appearance: none;
  -webkit-appearance: none;
  transition: all var(--transition-fast);
  position: relative;
}
.form-check-input:checked {
  background: var(--color-primary);
  border-color: var(--color-primary);
}
.form-check-input:checked::after {
  content: '';
  position: absolute;
  inset: 2px;
  background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round' d='M2 8l4 4 8-8'/%3e%3c/svg%3e") no-repeat center;
}
.form-check-input[type="radio"] { border-radius: var(--radius-full); }
.form-check-input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  inset: 3px;
  background: white;
  border-radius: var(--radius-full);
}
.form-check-label { font-size: var(--font-size-sm); color: var(--color-text); cursor: pointer; }

/* ── Validation states ─────────────────────────── */
.form-control.is-invalid {
  border-color: var(--color-danger);
  box-shadow: none;
}
.form-control.is-invalid:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .12);
}
.form-control.is-valid {
  border-color: var(--color-success);
}
.form-control.is-valid:focus {
  box-shadow: 0 0 0 3px rgba(22, 163, 74, .12);
}

.field-error {
  display: none;
  font-size: var(--font-size-xs);
  color: var(--color-danger);
  margin-top: var(--sp-1);
  align-items: center;
  gap: 4px;
}
.field-error.show { display: flex; }
.form-group:has(.form-control.is-invalid) .field-error { display: flex; }

/* Validation summary */
.validation-summary {
  padding: var(--sp-4);
  background: var(--color-danger-light);
  border: 1px solid #fca5a5;
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-5);
  font-size: var(--font-size-sm);
}
.validation-summary ul { margin: var(--sp-2) 0 0; padding-left: var(--sp-5); }
.validation-summary li { color: #7f1d1d; }

/* ── Form actions bar ──────────────────────────────────────────── */
.form-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.125rem 1.75rem;
  border-top: 1px solid #f1f5f9;
  background: #fff;
  border-radius: 0 0 16px 16px;
  flex-wrap: wrap;
  position: relative;
}

/* Subtle top accent line */
.form-actions::before {
  content: '';
  position: absolute;
  top: 0;
  left: 1.75rem;
  right: 1.75rem;
  height: 1px;
  background: linear-gradient(90deg, transparent, #e2e8f0 20%, #e2e8f0 80%, transparent);
}

/* Save button — primary filled */
.form-actions .btn-primary {
  background: linear-gradient(135deg, var(--color-primary, #1e3a8a), #1d4ed8);
  border: none;
  color: #fff;
  font-weight: 600;
  padding: .55rem 1.75rem;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(30, 64, 175, .25);
  transition: transform .15s, box-shadow .15s, background .15s;
  letter-spacing: .01em;
}
.form-actions .btn-primary:hover {
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
  box-shadow: 0 6px 18px rgba(30, 64, 175, .35);
  transform: translateY(-1px);
  color: #fff;
}
.form-actions .btn-primary:active { transform: translateY(0); }

/* Back / Cancel button — ghost style */
.form-actions .btn-ghost,
.form-actions .btn-secondary,
.form-actions .btn-outline-secondary {
  background: transparent;
  border: 1.5px solid #e2e8f0;
  color: #64748b;
  font-weight: 500;
  padding: .5rem 1.5rem;
  border-radius: 10px;
  transition: background .15s, border-color .15s, color .15s;
  text-decoration: none;
}
.form-actions .btn-ghost:hover,
.form-actions .btn-secondary:hover,
.form-actions .btn-outline-secondary:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #0f172a;
}

.form-actions .ms-auto { margin-left: auto; }
html[dir="rtl"] .form-actions .ms-auto { margin-left: 0; margin-right: auto; }

/* RTL border-radius flip */
html[dir="rtl"] .form-actions {
  border-radius: 0 0 16px 16px;
}

/* ── Form card wrapper ─────────────────────────────────────────── */
/* Utility alias — same as global card, for forms specifically */
.form-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 16px rgba(0, 0, 0, .06);
  border: 1px solid #f1f5f9;
  margin-bottom: 1.5rem;
  overflow: hidden;
}

/* Card body inside any card used for a form */
.card .card-body,
.form-card .card-body {
  padding: 1.75rem;
}

/* Section dividers inside multi-section forms */
.form-section {
  padding-bottom: 1.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid #f1f5f9;
}
.form-section:last-of-type { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.form-section-title {
  font-size: .8rem;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 1rem;
}
