/* ===========================
   forms.css
   Reusable form component styles.
   Import alongside style.css on any page that has forms.
=========================== */

/* ===========================
   FORM LAYOUT
=========================== */
.form-section {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 2.75rem;
  box-shadow: var(--shadow-md);
}

.form-title {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.form-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 2rem;
  line-height: 1.6;
}

.form-divider {
  border: none;
  border-top: 2px solid var(--border);
  margin: 2rem 0;
}

/* Grid helpers */
.form-grid {
  display: grid;
  gap: 1.25rem;
}

.form-grid-2 {
  grid-template-columns: 1fr 1fr;
}

.form-grid-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

/* Span full row in a grid */
.form-col-full {
  grid-column: 1 / -1;
}

/* ===========================
   FIELD GROUP
=========================== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

/* ===========================
   LABEL
=========================== */
.form-label {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.form-label .required {
  color: #C0392B;
  font-size: 1rem;
  line-height: 1;
}

.form-hint {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: -0.2rem;
}

/* ===========================
   BASE INPUT STYLES
   (text, email, tel, url, number, date, time, password, search)
=========================== */
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.8rem 1.1rem;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
  line-height: 1.5;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: #A0AFAE;
  font-weight: 600;
}

.form-input:hover,
.form-select:hover,
.form-textarea:hover {
  border-color: #A8CECA;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--teal);
  background: var(--white);
  box-shadow: 0 0 0 4px rgba(26, 123, 116, 0.12);
}

/* ===========================
   TEXTAREA
=========================== */
.form-textarea {
  resize: vertical;
  min-height: 140px;
}

.form-textarea.form-textarea-sm { min-height: 90px; }
.form-textarea.form-textarea-lg { min-height: 220px; }

/* ===========================
   SELECT
=========================== */
.form-select-wrap {
  position: relative;
}

.form-select-wrap::after {
  content: '';
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--text-muted);
  pointer-events: none;
}

.form-select {
  cursor: pointer;
  padding-right: 2.5rem;
}

/* ===========================
   CHECKBOX & RADIO
=========================== */
.form-check {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  cursor: pointer;
}

.form-check-input {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: background var(--transition), border-color var(--transition);
  position: relative;
}

.form-check-input[type="radio"] {
  border-radius: 50%;
}

.form-check-input:hover {
  border-color: var(--teal);
}

.form-check-input:checked {
  background: var(--teal);
  border-color: var(--teal);
}

.form-check-input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 5px;
  width: 6px;
  height: 10px;
  border: 2.5px solid white;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

.form-check-input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 10px;
  height: 10px;
  background: white;
  border-radius: 50%;
}

.form-check-input:focus {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}

.form-check-label {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.5;
  cursor: pointer;
}

.form-check-label a {
  color: var(--teal);
  font-weight: 700;
}

/* Check/radio group */
.form-check-group {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.form-check-group.inline {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 1.25rem;
}

/* ===========================
   FILE INPUT
=========================== */
.form-file-wrap {
  position: relative;
}

.form-file {
  width: 100%;
  padding: 0.8rem 1.1rem;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.form-file:hover { border-color: var(--teal); background: var(--teal-light); }
.form-file:focus { border-color: var(--teal); outline: none; box-shadow: 0 0 0 4px rgba(26,123,116,0.12); }

/* ===========================
   STATES: DISABLED, READONLY, ERROR, SUCCESS
=========================== */

/* Disabled */
.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
  background: #EEF0EF;
  border-color: #D1D8D7;
  color: #8A9E9D;
  cursor: not-allowed;
}

/* Read-only */
.form-input[readonly],
.form-textarea[readonly] {
  background: var(--teal-light);
  border-color: var(--border);
  cursor: default;
}

/* Error state */
.form-group.error .form-input,
.form-group.error .form-select,
.form-group.error .form-textarea {
  border-color: #C0392B;
  background: #FEF5F5;
}

.form-group.error .form-input:focus,
.form-group.error .form-select:focus,
.form-group.error .form-textarea:focus {
  box-shadow: 0 0 0 4px rgba(192, 57, 43, 0.12);
}

.form-error-msg {
  display: none;
  font-size: 0.8rem;
  font-weight: 700;
  color: #C0392B;
  align-items: center;
  gap: 0.35rem;
}

.form-group.error .form-error-msg {
  display: flex;
}

.form-error-msg::before {
  content: '!';
  width: 16px;
  height: 16px;
  background: #C0392B;
  color: white;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Success state */
.form-group.success .form-input,
.form-group.success .form-select,
.form-group.success .form-textarea {
  border-color: #27AE60;
  background: #F4FBF7;
}

.form-group.success .form-input:focus,
.form-group.success .form-select:focus,
.form-group.success .form-textarea:focus {
  box-shadow: 0 0 0 4px rgba(39, 174, 96, 0.12);
}

.form-success-msg {
  display: none;
  font-size: 0.8rem;
  font-weight: 700;
  color: #27AE60;
  align-items: center;
  gap: 0.35rem;
}

.form-group.success .form-success-msg {
  display: flex;
}

.form-success-msg::before {
  content: '✓';
  width: 16px;
  height: 16px;
  background: #27AE60;
  color: white;
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ===========================
   CHARACTER COUNTER
=========================== */
.form-count {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
  margin-top: -0.2rem;
}

.form-count.over { color: #C0392B; }

/* ===========================
   FORM ACTIONS
=========================== */
.form-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  padding-top: 0.5rem;
}

.form-actions.right { justify-content: flex-end; }
.form-actions.center { justify-content: center; }
.form-actions.spread { justify-content: space-between; }

/* ===========================
   SUBMIT FEEDBACK
=========================== */
.form-alert {
  display: none;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 700;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.form-alert.show { display: flex; }

.form-alert-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 900;
  flex-shrink: 0;
  margin-top: 1px;
}

.form-alert.success {
  background: #F0FBF4;
  border: 2px solid #27AE60;
  color: #1E8449;
}

.form-alert.success .form-alert-icon {
  background: #27AE60;
  color: white;
}

.form-alert.error {
  background: #FEF5F5;
  border: 2px solid #C0392B;
  color: #922B21;
}

.form-alert.error .form-alert-icon {
  background: #C0392B;
  color: white;
}

.form-alert.info {
  background: var(--teal-light);
  border: 2px solid var(--teal);
  color: var(--teal-dark);
}

.form-alert.info .form-alert-icon {
  background: var(--teal);
  color: white;
}

/* ===========================
   FIELDSET / SECTION GROUPING
=========================== */
.form-fieldset {
  border: none;
  padding: 0;
  margin: 0;
}

.form-legend {
  font-size: 1rem;
  font-weight: 900;
  color: var(--teal);
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
}

.form-legend::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--teal-light);
  border-radius: 2px;
}

/* ===========================
   INPUT WITH ICON / PREFIX / SUFFIX
=========================== */
.form-input-wrap {
  position: relative;
  display: flex;
  align-items: stretch;
}

.form-input-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  display: flex;
  align-items: center;
}

.form-input-wrap .form-input.has-icon-left { padding-left: 2.75rem; }
.form-input-wrap .form-input.has-icon-right { padding-right: 2.75rem; }

.form-input-icon.right {
  left: auto;
  right: 1rem;
}

.form-input-prefix,
.form-input-suffix {
  display: flex;
  align-items: center;
  padding: 0 1rem;
  background: var(--teal-light);
  border: 2px solid var(--border);
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--teal);
  white-space: nowrap;
}

.form-input-prefix {
  border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.form-input-suffix {
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.form-input-wrap .form-input.with-prefix {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.form-input-wrap .form-input.with-suffix {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

/* ===========================
   CONSENT / GDPR BLOCK
=========================== */
.form-consent {
  background: var(--teal-light);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
}

.form-consent .form-check-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===========================
   RESPONSIVE
=========================== */
@media (max-width: 640px) {
  .form-section { padding: 1.75rem 1.25rem; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .btn { justify-content: center; }
  .form-check-group.inline { flex-direction: column; }
}
