/*
================================================================================
  ML Software, LLC
  Copyright 2026. All rights reserved.

  IQ Platform - _app/assets/css/forms.css

  Platform: 0.1.1
  Version: 0.1.2
  Created: 2026-04-27
  Updated: 2026-04-27

  Description: Form controls. Inputs, textareas, selects, labels,
  fieldsets, error states, help text. Every IQ product builds forms;
  the platform owns the look so every product feels like the same
  family.

  Class vocabulary:
    .form-group     -- wraps a label + input pair
    .form-row       -- horizontal flex row of .form-group blocks
    .form-label     -- field label (uppercase display font, small)
    .form-input     -- text-like inputs (text, email, password, number, date)
    .form-select    -- select dropdowns (with custom chevron)
    .form-textarea  -- multi-line textareas
    .form-help      -- helper text below an input
    .form-error     -- error state block (used both per-field and as a
                      page-level error banner)
    .form-checkbox  -- styled checkbox + label combo

  Load order: tokens.css -> base.css -> shell.css -> components.css
              -> forms.css.

  Version History:
    0.1.2 - 2026-04-27 - Burgundy color migration. .form-error,
                         .form-error-text, .form-input.is-error,
                         and .form-label-required all updated to
                         consume the new red token set
                         (tokens.css 0.1.2). Hardcoded
                         rgba(255, 100, 80, ...) coral references
                         removed. `color: var(--red)` corrected to
                         `var(--red-text)` for legibility -- burgundy
                         is unreadable as foreground text on dark
                         surfaces.
    0.1.1 - 2026-04-27 - Session 3 cont'd. Readability floor pass:
                         - .form-help 12px -> 13px
                         - .form-error 13px -> 14px (banner-level body)
                         - .form-error-text 12px -> 13px (per-field)
                         - .form-checkbox-label small 12px -> 13px
                         - .form-label stays 12px (display small caps)
                         - .form-legend stays 12px (display small caps)
                         Touch override already covered the input
                         font-size at 16px (prevents iOS auto-zoom).
    0.1.0 - 2026-04-27 - Session 3 initial. Form patterns extracted
                         from JQiq lines 636-724 (the most complete
                         and modern form treatment in the source apps,
                         including the autofill kill rule and the
                         Firefox password-reveal fix). iOS date input
                         width fix from RIQ 2.26.0 carried forward.
                         Custom select chevron SVG inlined as data-uri
                         (one of the few places the platform
                         hardcodes a color -- the chevron color
                         matches --text-primary at 85% opacity).
================================================================================
*/

/* ============================================================================
   Form layout
   ============================================================================ */

.form-group {
  margin-bottom: 16px;
}

.form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.form-row .form-group {
  flex: 1;
  margin-bottom: 0;
}

@media (max-width: 480px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .form-row .form-group {
    margin-bottom: 16px;
  }
  .form-row .form-group:last-child {
    margin-bottom: 0;
  }
}


/* ============================================================================
   Labels
   ============================================================================ */

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-family: var(--font-display);
}

.form-label-required::after {
  content: ' *';
  color: var(--red-text);
}


/* ============================================================================
   Text inputs, selects, textareas
   ============================================================================ */

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-ui);
  padding: 8px 12px;
  outline: none !important;
  box-shadow: none !important;
  transition: border-color var(--t-fast);
  -webkit-appearance: none;
  appearance: none;
  color-scheme: dark;
}

.form-input:focus,
.form-input:focus-visible,
.form-select:focus,
.form-select:focus-visible,
.form-textarea:focus,
.form-textarea:focus-visible {
  outline: none !important;
  box-shadow: none !important;
  border-color: var(--accent);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-dim);
}

.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}


/* ============================================================================
   Custom select chevron
   The data-uri chevron uses #f0f0f4 at 85% alpha (matches
   --text-primary). It is intentionally hardcoded; theming the
   chevron would require generating one SVG per theme. The cost of
   the inconsistency is low (a chevron color is barely noticeable).
   ============================================================================ */

.form-select,
select.form-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='10' viewBox='0 0 16 10'%3E%3Cpath d='M2 2l6 6 6-6' stroke='rgba(240,240,244,0.85)' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
  cursor: pointer;
}


/* ============================================================================
   Textarea
   ============================================================================ */

.form-textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}


/* ============================================================================
   Date / time inputs (iOS fix)
   Without these rules, iOS Safari can't size date/time inputs
   correctly inside flex containers -- they overflow their parent.
   ============================================================================ */

input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"],
input[type="week"] {
  -webkit-appearance: none;
  max-width: 100%;
  box-sizing: border-box;
}


/* ============================================================================
   Browser autofill cleanup

   Kill the yellow autofill background that browsers apply by
   default. Force the autofilled state to use the platform's
   raised-surface color and primary text color.
   ============================================================================ */

.form-input:-webkit-autofill,
.form-input:-webkit-autofill:hover,
.form-input:-webkit-autofill:focus,
.form-select:-webkit-autofill,
.form-textarea:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--bg-raised) inset !important;
  -webkit-text-fill-color: var(--text-primary) !important;
  caret-color: var(--text-primary);
}

/* Hide the Firefox / Edge password reveal/lock icon -- conflicts
   with the platform's input styling. */
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear {
  display: none;
}
input[type="password"]::-moz-password-reveal {
  display: none;
}
input[type="password"] {
  -moz-appearance: none;
}


/* ============================================================================
   Helper text and inline errors
   ============================================================================ */

.form-help {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.4;
}

.form-error {
  background: var(--red-dim);
  border: 1px solid var(--red-bord);
  border-radius: var(--radius);
  color: var(--red-text);
  font-size: 14px;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-weight: 500;
}

/* Per-field error: input border red + helper text red */
.form-input.is-error,
.form-select.is-error,
.form-textarea.is-error {
  border-color: var(--red-text);
}

.form-error-text {
  display: block;
  font-size: 13px;
  color: var(--red-text);
  margin-top: 4px;
  line-height: 1.4;
}


/* ============================================================================
   Checkbox / radio
   ============================================================================ */

.form-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
}

.form-checkbox input[type="checkbox"],
.form-checkbox input[type="radio"] {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
}

.form-checkbox-label {
  flex: 1;
  line-height: 1.45;
}

.form-checkbox-label small {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}


/* ============================================================================
   Fieldsets
   ============================================================================ */

fieldset.form-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 20px;
}

legend.form-legend {
  padding: 0 8px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}


/* ============================================================================
   Touch-target enlargement (coarse pointers)
   iOS / Android need at least 44px tap targets. Apply across all
   form controls when the device is touch-driven.
   ============================================================================ */

@media (pointer: coarse) {

  .form-input,
  .form-select,
  .form-textarea {
    min-height: 44px;
    font-size: 16px;  /* prevents iOS auto-zoom on focus */
    padding: 10px 14px;
  }

  .form-textarea {
    min-height: 100px;
  }

  .form-checkbox input[type="checkbox"],
  .form-checkbox input[type="radio"] {
    width: 20px;
    height: 20px;
  }
}