/*
 * form-contrast.css — TRUE Platform Form Contrast Override
 * Deployment: /public/form-contrast.css → index.html <link>
 * Architecture: isolated override layer, zero JSX touch, hot-removable
 * Rationale: form contrast = data quality issue, not cosmetic
 *   poor contrast → skipped fields → incomplete captures
 *   → lower scores → worse ledger density
 * OBS-UX-001 compliant
 */

/* ── Base form elements ──────────────────────────────────── */
input,
select,
textarea {
  /* Contrast */
  background-color: #2A1810 !important;
  color: #F0ECE2 !important;
  border: 1px solid #7A5C4E !important;
  border-radius: 2px !important;

  /* Apple HIG 44px touch target */
  min-height: 44px !important;

  /* Font — prevents iOS zoom on focus (must be ≥16px) */
  font-size: 16px !important;
  font-family: 'IBM Plex Mono', monospace !important;

  /* Padding */
  padding: 10px 12px !important;

  /* Box model */
  box-sizing: border-box !important;
  width: 100% !important;
}

/* ── Focus state — must be clearly visible ───────────────── */
input:focus,
select:focus,
textarea:focus {
  outline: none !important;
  border-color: #C44A1A !important;
  box-shadow: 0 0 0 2px rgba(196, 74, 26, 0.25) !important;
  background-color: #2E1C12 !important;
}

/* ── Placeholder contrast ────────────────────────────────── */
input::placeholder,
textarea::placeholder {
  color: #7A5C4E !important;
  opacity: 1 !important; /* Firefox normalisation */
  font-style: italic !important;
}

/* ── Select — arrow visibility on dark bg ────────────────── */
select {
  appearance: none !important;
  -webkit-appearance: none !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23C44A1A' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 12px center !important;
  padding-right: 36px !important;
  cursor: pointer !important;
}

select option {
  background-color: #2A1810 !important;
  color: #F0ECE2 !important;
}

/* ── Textarea — multi-line fields ────────────────────────── */
textarea {
  min-height: 88px !important; /* 2× 44px base */
  resize: vertical !important;
  line-height: 1.6 !important;
}

/* ── Disabled / readonly states ──────────────────────────── */
input:disabled,
select:disabled,
textarea:disabled {
  background-color: #1A0F0A !important;
  color: #7A5C4E !important;
  border-color: #2E1E16 !important;
  cursor: not-allowed !important;
  opacity: 0.7 !important;
}

input[readonly],
textarea[readonly] {
  background-color: #1F120C !important;
  color: #7A5C4E !important;
  cursor: default !important;
}

/* ── Checkbox and radio — touch targets ──────────────────── */
input[type="checkbox"],
input[type="radio"] {
  min-height: 20px !important;
  width: 20px !important;
  height: 20px !important;
  min-width: 20px !important;
  accent-color: #C44A1A !important;
  cursor: pointer !important;
  padding: 0 !important;
}

/* ── Labels — legibility ─────────────────────────────────── */
label {
  color: #F0ECE2 !important;
  font-family: 'IBM Plex Mono', monospace !important;
  font-size: 11px !important;
  letter-spacing: 0.08em !important;
  display: block !important;
  margin-bottom: 4px !important;
}

/* ── Field populated state — trust signal ────────────────── */
input:not(:placeholder-shown),
textarea:not(:placeholder-shown) {
  border-color: #C44A1A !important;
  background-color: #2A1810 !important;
}

/* ── Error state ─────────────────────────────────────────── */
input[data-error="true"],
select[data-error="true"],
textarea[data-error="true"] {
  border-color: #f87171 !important;
  box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.20) !important;
}

/* ── Sidebar contrast guard ──────────────────────────────── */
/* Prevent sidebar from appearing dim against brighter field inputs.
 * The sidebar uses C.dimmer (#1F120C) background.
 * Ensure score bars and rings read as active, not washed out. */
[class*="sidebar"],
[class*="Sidebar"],
[data-sidebar] {
  background-color: #1F120C !important;
}

/* ── ScorePill — iOS keyboard clearance ──────────────────── */
/* Floating pill: ensure it stays above the iOS keyboard.
 * iOS keyboard is ~260px. env(safe-area-inset-bottom) adds notch offset. */
[class*="ScorePill"],
[class*="score-pill"],
[data-score-pill] {
  bottom: max(80px, calc(16px + env(safe-area-inset-bottom))) !important;
  z-index: 600 !important; /* above form content, below modals */
}

/* ── Mobile: form field full-width on small screens ─────── */
@media (max-width: 640px) {
  input,
  select,
  textarea {
    font-size: 16px !important; /* critical — prevents iOS zoom */
    width: 100% !important;
  }

  /* Tighten sidebar on mobile — don't let it crowd form fields */
  [class*="sidebar"],
  [class*="Sidebar"] {
    max-width: 160px !important;
  }
}

/* ── High contrast media query respect ───────────────────── */
@media (prefers-contrast: high) {
  input,
  select,
  textarea {
    border-color: #F0ECE2 !important;
    border-width: 2px !important;
  }

  input:focus,
  select:focus,
  textarea:focus {
    outline: 3px solid #C44A1A !important;
    outline-offset: 2px !important;
  }
}
