/* ==========================================================================
   FORMS MODULE - Input Group Primitive
   ==========================================================================
   Phase 1.1 Hotfix: Token-driven Input Group component
   ADR-004 Compliant: No inline styles, no hard-coded hex
   
   Patterns supported:
   1. .input-group + .input-group-text (Bootstrap-style leading addon)
   2. .input-group + .input-prefix (Currency/symbol prefix)
   ========================================================================== */

/* -----------------------------------------------------------------------------
   INPUT GROUP - Base Container
   Horizontal flex row, full width, aligned items
----------------------------------------------------------------------------- */
.input-group {
  display: flex;
  width: 100%;
  align-items: stretch;
  position: relative;
}

/* -----------------------------------------------------------------------------
   INPUT GROUP TEXT - Leading/Trailing Addon (icon container)
   Bootstrap-compatible pattern: <span class="input-group-text">...</span>
----------------------------------------------------------------------------- */
.input-group-text {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3, 0.5rem) var(--space-4, 0.75rem);
  font-size: var(--text-sm, 0.875rem);
  font-weight: 400;
  line-height: 1.5;
  color: var(--color-text-3, var(--text-secondary));
  background: var(--color-surface-2, var(--bg-secondary));
  border: 1px solid var(--color-border-1, var(--border));
  border-radius: var(--radius-md, 0.375rem) 0 0 var(--radius-md, 0.375rem);
  white-space: nowrap;
}

.input-group-text svg {
  width: 1rem;
  height: 1rem;
  color: inherit;
}

/* Input following input-group-text: remove left border-radius, prevent double border */
.input-group .input-group-text + .form-control,
.input-group .input-group-text + input {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  margin-left: -1px;
}

/* Input preceding input-group-text (trailing addon) */
.input-group .form-control:first-child,
.input-group input:first-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.input-group .input-group-text:last-child {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-top-right-radius: var(--radius-md, 0.375rem);
  border-bottom-right-radius: var(--radius-md, 0.375rem);
}

/* -----------------------------------------------------------------------------
   INPUT PREFIX - Currency/Symbol Prefix Pattern
   Pattern: <span class="input-prefix">$</span><input class="form-control">
----------------------------------------------------------------------------- */
.input-prefix {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-4, 0.75rem);
  font-size: var(--text-sm, 0.875rem);
  font-weight: 500;
  color: var(--color-text-3, var(--text-secondary));
  background: var(--color-surface-2, var(--bg-secondary));
  border: 1px solid var(--color-border-1, var(--border));
  border-right: none;
  border-radius: var(--radius-md, 0.375rem) 0 0 var(--radius-md, 0.375rem);
  min-width: 2.5rem;
}

.input-group .input-prefix + .form-control,
.input-group .input-prefix + input {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  flex: 1 1 auto;
  width: 1%;
}

/* -----------------------------------------------------------------------------
   FORM CONTROL INSIDE INPUT GROUP
   Ensure proper flex behavior and border radius
----------------------------------------------------------------------------- */
.input-group .form-control,
.input-group input[type="text"],
.input-group input[type="number"],
.input-group input[type="email"],
.input-group input[type="password"],
.input-group input[type="search"],
.input-group input[type="tel"],
.input-group input[type="url"] {
  flex: 1 1 auto;
  width: 1%;
  min-width: 0;
}

/* When input is the only child (no addons), keep default border-radius */
.input-group .form-control:only-child {
  border-radius: var(--radius-md, 0.375rem);
}

/* -----------------------------------------------------------------------------
   INPUT GROUP BUTTONS
   Style buttons inside input groups for search/action patterns
----------------------------------------------------------------------------- */
.input-group .btn {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  margin-left: -1px;
}

.input-group .btn:first-child {
  border-top-left-radius: var(--radius-md, 0.375rem);
  border-bottom-left-radius: var(--radius-md, 0.375rem);
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  margin-left: 0;
  margin-right: -1px;
}

/* -----------------------------------------------------------------------------
   FOCUS STATES
   Maintain focus ring consistency with existing form-control focus styles
----------------------------------------------------------------------------- */
.input-group .form-control:focus,
.input-group input:focus {
  z-index: 1;
  position: relative;
}

/* When input is focused, slightly elevate to show focus ring above addon borders */
.input-group:focus-within .input-group-text,
.input-group:focus-within .input-prefix {
  border-color: var(--color-focus, var(--border-focus));
}

/* -----------------------------------------------------------------------------
   RESPONSIVE BEHAVIOR
   Ensure input groups don't break on narrow widths
----------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .input-group-text,
  .input-prefix {
    padding-left: var(--space-2, 0.5rem);
    padding-right: var(--space-2, 0.5rem);
    min-width: 2rem;
  }
}

/* ==========================================================================
   PREMIUM FORM SYSTEM - ADR-007 Companion
   ==========================================================================
   Canonical form field, section, and layout components
   ========================================================================== */

/* -----------------------------------------------------------------------------
   FORM SECTION (Card Container)
----------------------------------------------------------------------------- */
.form-section {
  background: var(--surface-primary, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px;
  margin-bottom: 1.5rem;
}

.form-section__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary, #1e293b);
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border, #e2e8f0);
  margin: 0;
}

.form-section__body {
  padding: 1.5rem;
}

/* -----------------------------------------------------------------------------
   FORM GRID (2-col responsive)
----------------------------------------------------------------------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem 1.5rem;
}

@media (max-width: 767px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* -----------------------------------------------------------------------------
   FORM FIELD - Base
----------------------------------------------------------------------------- */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-field--full {
  grid-column: 1 / -1;
}

.form-field--error .form-field__input {
  border-color: var(--color-danger, #ef4444);
  background-color: rgba(239, 68, 68, 0.02);
}

.form-field--error .form-field__input:focus {
  border-color: var(--color-danger, #ef4444);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* -----------------------------------------------------------------------------
   FORM FIELD - Label
----------------------------------------------------------------------------- */
.form-field__label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary, #475569);
  line-height: 1.4;
}

.form-field__required {
  color: var(--color-danger, #ef4444);
  margin-left: 0.125rem;
}

/* -----------------------------------------------------------------------------
   FORM FIELD - Input
----------------------------------------------------------------------------- */
.form-field__input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-primary, #1e293b);
  background: var(--surface-primary, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-field__input::placeholder {
  color: var(--text-muted, #94a3b8);
}

.form-field__input:hover {
  border-color: var(--border-hover, #cbd5e1);
}

.form-field__input:focus {
  outline: none;
  border-color: var(--color-primary, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-field__input:disabled,
.form-field__input[readonly] {
  background: var(--surface-secondary, #f8fafc);
  color: var(--text-muted, #94a3b8);
  cursor: not-allowed;
}

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

select.form-field__input {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.75rem center;
  background-repeat: no-repeat;
  background-size: 1rem;
  padding-right: 2.5rem;
}

/* -----------------------------------------------------------------------------
   FORM FIELD - Help Text
----------------------------------------------------------------------------- */
.form-field__help {
  font-size: 0.75rem;
  color: var(--text-muted, #94a3b8);
  line-height: 1.4;
}

/* -----------------------------------------------------------------------------
   FORM FIELD - Error
----------------------------------------------------------------------------- */
.form-field__error {
  font-size: 0.75rem;
  color: var(--color-danger, #ef4444);
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.form-field__error::before {
  content: "";
  width: 0.875rem;
  height: 0.875rem;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23ef4444'%3e%3cpath fill-rule='evenodd' d='M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z' clip-rule='evenodd'/%3e%3c/svg%3e");
  background-size: contain;
  flex-shrink: 0;
}

/* -----------------------------------------------------------------------------
   FORM ACTIONS (Button Bar)
----------------------------------------------------------------------------- */
.form-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border, #e2e8f0);
  margin-top: 1.5rem;
}

.form-actions--end {
  justify-content: flex-end;
}

.form-actions--between {
  justify-content: space-between;
}

.form-actions .btn-danger {
  margin-left: auto;
}

@media (max-width: 767px) {
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .form-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .form-actions .btn-danger {
    margin-left: 0;
    margin-top: 0.5rem;
  }
}
