/* =========================================================================
   JNC Holdings — Form controls (selection + text input)
   Requires colors_and_type.css + semantic-roles.css.
   인지·접근성 근거:
   · 선택 컨트롤은 색만으로 상태를 전달하지 않는다 — 체크/선택은 형태(체크표시·
     점·노브 위치)로도 구분(규칙 1.7, WCAG 1.4.1 non-color).
   · 모든 컨트롤은 동일한 상태 머신(hover/focus-visible/checked/disabled/invalid)을
     공유해 학습 전이를 돕는다(규칙 1.5 Jakob, 1.6 게슈탈트 유사성).
   · 터치 환경 타깃 ≥44px는 coarse-pointer에서만 키워 데스크톱 밀도를 보존
     (Fitts 법칙, 규칙 1.7 / Apple HIG / WCAG 2.5.5).
   ========================================================================= */

/* ---------- Form layout helpers ---------- */
.jform        { display: flex; flex-direction: column; gap: var(--sp-5); }
.jform-row    { display: flex; gap: var(--sp-4); flex-wrap: wrap; }
.jform-row > .jfield { flex: 1 1 0; min-width: 180px; }
.jfieldset    { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.jfieldset > legend {
  font: var(--w-semibold) var(--fs-body-sm)/1.3 var(--font-sans);
  color: var(--fg1); padding: 0; margin-bottom: var(--sp-1);
}
/* Required marker + optional hint */
.jfield .req  { color: var(--error); margin-left: 2px; }
.jfield .opt  { color: var(--fg3); font-weight: 400; margin-left: 6px; }

/* =========================================================================
   CHECKBOX  —  .jcheck  (wrap a native input for accessibility)
   <label class="jcheck"><input type="checkbox"><span class="box"></span>라벨</label>
   ========================================================================= */
.jcheck, .jradio {
  display: inline-flex; align-items: flex-start; gap: var(--sp-2);
  font: var(--w-regular) var(--fs-body-sm)/1.45 var(--font-sans);
  color: var(--fg1); cursor: pointer; user-select: none;
  position: relative; min-height: 20px;
}
.jcheck > input, .jradio > input {
  position: absolute; opacity: 0; width: 18px; height: 18px; margin: 0; cursor: pointer;
}
.jcheck .box {
  flex: none; width: 18px; height: 18px; margin-top: 1px;
  border: var(--bw-strong) solid var(--border-field); border-radius: var(--r-xs);
  background: var(--surface); display: grid; place-items: center;
  transition: background var(--transition-base), border-color var(--transition-base);
}
.jcheck .box::after {           /* the checkmark — drawn, not glyph */
  content: ""; width: 10px; height: 6px; margin-top: -2px;
  border-left: 2px solid var(--on-brand); border-bottom: 2px solid var(--on-brand);
  transform: rotate(-45deg) scale(0); transform-origin: center;
  transition: transform var(--dur-fast) var(--ease-out);
}
.jcheck > input:checked ~ .box           { background: var(--brand); border-color: var(--brand); }
.jcheck > input:checked ~ .box::after    { transform: rotate(-45deg) scale(1); }
.jcheck > input:indeterminate ~ .box     { background: var(--brand); border-color: var(--brand); }
.jcheck > input:indeterminate ~ .box::after {
  content: ""; width: 10px; height: 0; border: 0; border-top: 2px solid var(--on-brand);
  transform: none; margin: 0;
}
.jcheck:hover .box, .jradio:hover .dot   { border-color: var(--brand); }
.jcheck > input:focus-visible ~ .box,
.jradio > input:focus-visible ~ .dot     { outline: none; box-shadow: var(--sh-focus); }
.jcheck > input:disabled ~ .box,
.jradio > input:disabled ~ .dot          { background: var(--state-disabled-surface); border-color: var(--state-disabled-outline); }
.jcheck:has(> input:disabled),
.jradio:has(> input:disabled)            { color: var(--state-disabled-content); cursor: not-allowed; }
/* invalid (group-level required) */
.jcheck.invalid .box, .jradio.invalid .dot { border-color: var(--error); }
/* helper text under a control group */
.jcontrol-help { font-size: var(--fs-label); color: var(--fg3); margin-top: 2px; }
.jcontrol-help.err { color: var(--error); }

/* =========================================================================
   RADIO  —  .jradio
   ========================================================================= */
.jradio .dot {
  flex: none; width: 18px; height: 18px; margin-top: 1px;
  border: var(--bw-strong) solid var(--border-field); border-radius: var(--r-pill);
  background: var(--surface); display: grid; place-items: center;
  transition: border-color var(--transition-base);
}
.jradio .dot::after {
  content: ""; width: 9px; height: 9px; border-radius: var(--r-pill);
  background: var(--brand); transform: scale(0);
  transition: transform var(--dur-fast) var(--ease-out);
}
.jradio > input:checked ~ .dot         { border-color: var(--brand); }
.jradio > input:checked ~ .dot::after  { transform: scale(1); }

/* =========================================================================
   SWITCH  —  .jswitch  (on/off only; use for immediate settings, not form submit)
   ========================================================================= */
.jswitch {
  display: inline-flex; align-items: center; gap: var(--sp-3);
  font: var(--w-regular) var(--fs-body-sm)/1.4 var(--font-sans);
  color: var(--fg1); cursor: pointer; user-select: none;
}
.jswitch > input { position: absolute; opacity: 0; width: 0; height: 0; }
.jswitch .track {
  flex: none; width: 40px; height: 22px; border-radius: var(--r-pill);
  background: var(--control-track); position: relative;
  transition: background var(--transition-base);
}
.jswitch .track::after {        /* knob */
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: var(--r-pill);
  background: var(--white); box-shadow: var(--sh-xs);
  transition: transform var(--dur-base) var(--ease-standard);
}
.jswitch > input:checked ~ .track          { background: var(--brand); }
.jswitch > input:checked ~ .track::after    { transform: translateX(18px); }
.jswitch > input:focus-visible ~ .track     { outline: none; box-shadow: var(--sh-focus); }
.jswitch:has(> input:disabled)              { color: var(--state-disabled-content); cursor: not-allowed; }
.jswitch > input:disabled ~ .track          { background: var(--state-disabled-surface); }
/* small size */
.jswitch.sm .track { width: 32px; height: 18px; }
.jswitch.sm .track::after { width: 14px; height: 14px; }
.jswitch.sm > input:checked ~ .track::after { transform: translateX(14px); }

/* =========================================================================
   TEXTAREA  —  shares .jinput filled-field language
   ========================================================================= */
.jtextarea {
  font: var(--w-regular) var(--fs-body-sm)/1.55 var(--font-sans); color: var(--fg1);
  width: 100%; min-height: 88px; padding: 10px 12px; resize: vertical;
  background: var(--field-bg); border: 1px solid transparent;
  border-bottom: 1px solid var(--field-border);
  border-radius: var(--field-radius) var(--field-radius) 0 0;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
.jtextarea::placeholder { color: var(--fg3); }
.jtextarea:focus { outline: none; border-bottom-color: var(--field-border-focus); box-shadow: 0 1px 0 0 var(--field-border-focus); }
.jtextarea.invalid { border-bottom-color: var(--error); box-shadow: 0 1px 0 0 var(--error); }
.jtextarea:disabled { background: var(--state-disabled-surface); color: var(--state-disabled-content); cursor: not-allowed; }

/* =========================================================================
   SELECT  —  .jselect  (native <select> styled to match filled fields)
   ========================================================================= */
.jselect {
  position: relative; display: inline-flex; align-items: center; width: 100%;
}
.jselect > select {
  appearance: none; -webkit-appearance: none; font-family: var(--font-sans);
  font-size: var(--fs-body-sm); color: var(--fg1);
  height: var(--control-height); width: 100%; padding: 0 36px 0 12px;
  background: var(--field-bg); border: 1px solid transparent;
  border-bottom: 1px solid var(--field-border);
  border-radius: var(--field-radius) var(--field-radius) 0 0; cursor: pointer;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
.jselect > select:focus { outline: none; border-bottom-color: var(--field-border-focus); box-shadow: 0 1px 0 0 var(--field-border-focus); }
.jselect > select:disabled { background: var(--state-disabled-surface); color: var(--state-disabled-content); cursor: not-allowed; }
.jselect::after {                /* chevron — drawn caret */
  content: ""; position: absolute; right: 14px; top: 50%; width: 8px; height: 8px;
  border-right: 1.5px solid var(--fg2); border-bottom: 1.5px solid var(--fg2);
  transform: translateY(-70%) rotate(45deg); pointer-events: none;
}
.jselect.invalid > select { border-bottom-color: var(--error); box-shadow: 0 1px 0 0 var(--error); }
.jselect.sm > select { height: var(--control-h-sm); }
.jselect.lg > select { height: var(--control-h-lg); }

/* =========================================================================
   SEARCH FIELD  —  .jsearch  (icon-leading text input)
   ========================================================================= */
.jsearch {
  display: inline-flex; align-items: center; gap: var(--sp-2); width: 100%;
  height: var(--control-height); padding: 0 12px;
  background: var(--field-bg); border: 1px solid transparent;
  border-bottom: 1px solid var(--field-border);
  border-radius: var(--field-radius) var(--field-radius) 0 0;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
.jsearch:focus-within { border-bottom-color: var(--field-border-focus); box-shadow: 0 1px 0 0 var(--field-border-focus); }
.jsearch .ico { display: inline-flex; color: var(--fg3); flex: none; }
.jsearch .ico svg { width: var(--icon-sm); height: var(--icon-sm); }
.jsearch > input {
  border: 0; background: transparent; outline: none; flex: 1; min-width: 0;
  font-family: var(--font-sans); font-size: var(--fs-body-sm); color: var(--fg1);
}
.jsearch > input::placeholder { color: var(--fg3); }
.jsearch .clear {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border: 0; background: transparent; color: var(--fg3);
  border-radius: var(--r-pill); cursor: pointer; flex: none;
}
.jsearch .clear:hover { background: var(--state-hover-surface); color: var(--fg1); }

/* =========================================================================
   RANGE SLIDER  —  .jrange  (native input[type=range], brand track)
   ========================================================================= */
.jrange { width: 100%; height: 24px; -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer; }
.jrange::-webkit-slider-runnable-track { height: 4px; border-radius: var(--r-pill); background: var(--surface-inset); }
.jrange::-moz-range-track { height: 4px; border-radius: var(--r-pill); background: var(--surface-inset); }
.jrange::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; margin-top: -7px;
  width: 18px; height: 18px; border-radius: var(--r-pill);
  background: var(--brand); border: 2px solid var(--white); box-shadow: var(--sh-sm);
}
.jrange::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: var(--r-pill); border: 2px solid var(--white);
  background: var(--brand); box-shadow: var(--sh-sm);
}
.jrange:focus-visible::-webkit-slider-thumb { box-shadow: var(--sh-focus); }
.jrange:focus-visible::-moz-range-thumb { box-shadow: var(--sh-focus); }

/* =========================================================================
   COARSE-POINTER touch sizing — non-destructive, Fitts 법칙 (규칙 1.7)
   ========================================================================= */
@media (pointer: coarse) {
  .jcheck, .jradio { min-height: var(--touch-min); align-items: center; }
  .jselect > select, .jsearch { height: var(--touch-min); }
}
