/* ================================================================
   DataHints DS — Forms Component
   Requires: tokens.css
   ================================================================ */

  /* ============================================================
     FORM FIELD WRAPPER
  ============================================================ */
  .dh-field {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
  }

  /* ============================================================
     LABEL
  ============================================================ */
  .dh-label {
    font-family: var(--font-sans);
    font-size: 0.875rem;       /* 14px */
    font-weight: 500;
    color: var(--fg);
    line-height: 1.35;
    display: flex;
    align-items: center;
    gap: var(--sp-1);
  }

  .dh-label-required {
    color: var(--micro-coral-text);
    font-size: 0.8125rem;
    line-height: 1;
    flex-shrink: 0;
  }

  .dh-label-optional {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--fg-3);
    font-weight: 400;
    letter-spacing: 0.04em;
  }

  /* ============================================================
     HELP & ERROR TEXT
  ============================================================ */
  .dh-help {
    font-family: var(--font-mono);
    font-size: 0.75rem;        /* 12px */
    color: var(--fg-3);
    line-height: 1.55;
    margin: 0;
  }

  .dh-error {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--micro-coral-text);
    line-height: 1.55;
    margin: 0;
    display: flex;
    align-items: flex-start;
    gap: var(--sp-1);
  }
  .dh-error-icon {
    width: 13px; height: 13px; flex-shrink: 0;
    margin-top: 1px;
    display: inline-flex; align-items: center;
  }
  .dh-error-icon svg { width: 100%; height: 100%; }

  /* ============================================================
     BASE CONTROL — shared by input, textarea, select
  ============================================================ */
  .dh-input,
  .dh-textarea,
  .dh-select {
    font-family: var(--font-sans);
    font-size: 0.9375rem;      /* 15px */
    color: var(--fg);
    background: var(--bg-elevated);
    border: 1px solid var(--border-s);
    border-radius: var(--r-xs);
    width: 100%;
    box-sizing: border-box;
    outline: none;
    transition:
      border-color var(--ease-fast),
      box-shadow var(--ease-fast),
      background var(--ease-fast);
    -webkit-appearance: none;
    appearance: none;
  }

  /* Placeholder */
  .dh-input::placeholder,
  .dh-textarea::placeholder { color: var(--fg-3); opacity: 1; }

  /* Hover */
  .dh-input:hover:not(:disabled):not(.is-error),
  .dh-textarea:hover:not(:disabled):not(.is-error),
  .dh-select:hover:not(:disabled):not(.is-error) {
    border-color: var(--border-a);
  }

  /* Focus */
  .dh-input:focus,
  .dh-textarea:focus,
  .dh-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-sub);
  }

  /* Error state */
  .dh-input.is-error,
  .dh-textarea.is-error,
  .dh-select.is-error {
    border-color: var(--micro-coral);
    box-shadow: 0 0 0 3px var(--micro-coral-sub);
  }
  .dh-input.is-error:focus,
  .dh-textarea.is-error:focus,
  .dh-select.is-error:focus {
    border-color: var(--micro-coral);
    box-shadow: 0 0 0 3px var(--micro-coral-sub);
  }

  /* Disabled */
  .dh-input:disabled,
  .dh-textarea:disabled,
  .dh-select:disabled {
    opacity: 0.45;
    cursor: not-allowed;
  }

  /* ============================================================
     INPUT
  ============================================================ */
  .dh-input {
    height: 40px;
    padding: 0 var(--sp-4);
    line-height: 1;
  }

  /* SM size */
  .dh-input-sm {
    height: 34px;
    font-size: 0.875rem;
    padding: 0 var(--sp-3);
  }

  /* Input with leading icon */
  .dh-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
  }
  .dh-input-wrap .dh-input {
    padding-left: var(--sp-10);
  }
  .dh-input-wrap .dh-input-icon {
    position: absolute;
    left: var(--sp-3);
    color: var(--fg-3);
    display: flex; align-items: center;
    pointer-events: none;
    transition: color var(--ease-fast);
  }
  .dh-input-wrap .dh-input-icon svg { width: 16px; height: 16px; }
  .dh-input-wrap:focus-within .dh-input-icon { color: var(--accent-text); }

  /* Input with trailing action (clear / show-password) */
  .dh-input-wrap .dh-input-action {
    position: absolute;
    right: var(--sp-3);
    color: var(--fg-3);
    display: flex; align-items: center;
    background: none; border: none; padding: 0; cursor: pointer;
    transition: color var(--ease-fast);
    border-radius: var(--r-xs);
  }
  .dh-input-wrap .dh-input-action svg { width: 16px; height: 16px; }
  .dh-input-wrap .dh-input-action:hover { color: var(--fg); }
  .dh-input-wrap .dh-input-action:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
  }
  .dh-input-wrap .dh-input.has-action { padding-right: var(--sp-10); }

  /* ============================================================
     TEXTAREA
  ============================================================ */
  .dh-textarea {
    padding: var(--sp-3) var(--sp-4);
    line-height: 1.6;
    resize: vertical;
    min-height: 96px;
  }

  .dh-textarea-noresize { resize: none; }

  /* ============================================================
     SELECT
  ============================================================ */
  .dh-select {
    height: 40px;
    padding: 0 var(--sp-10) 0 var(--sp-4);
    cursor: pointer;
    /* Custom chevron — theme-adaptive via CSS variable trick */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--sp-3) center;
    background-size: 16px;
  }
  .dh-select:focus {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a865e1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  }

  /* SM size */
  .dh-select-sm {
    height: 34px;
    font-size: 0.875rem;
    padding: 0 var(--sp-10) 0 var(--sp-3);
  }

  /* Select option theming (browser-native, limited) */
  .dh-select option {
    background: var(--bg-card);
    color: var(--fg);
  }

  /* ============================================================
     CHECKBOX
  ============================================================ */
  .dh-check-wrap {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    cursor: pointer;
    user-select: none;
    position: relative;
  }
  .dh-check-wrap.is-disabled { cursor: not-allowed; opacity: 0.45; }

  .dh-checkbox {
    -webkit-appearance: none;
    appearance: none;
    width: 18px; height: 18px;
    flex-shrink: 0;
    margin: 1px 0 0;             /* optical alignment with label cap-height */
    border: 1.5px solid var(--border-s);
    border-radius: 4px;
    background: var(--bg-elevated);
    cursor: pointer;
    transition:
      background var(--ease-fast),
      border-color var(--ease-fast),
      box-shadow var(--ease-fast);
    position: relative;
    display: grid;
    place-content: center;
  }

  /* Checkmark via ::before + SVG mask */
  .dh-checkbox::before {
    content: '';
    width: 10px; height: 10px;
    background: white;
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
    transform: scale(0);
    transition: transform 0.1s ease;
  }

  /* Hover */
  .dh-checkbox:hover:not(:disabled):not(:checked) {
    border-color: var(--border-a);
  }

  /* Checked */
  .dh-checkbox:checked {
    background: var(--accent-fill);
    border-color: var(--accent-fill);
  }
  .dh-checkbox:checked::before { transform: scale(1); }

  /* Indeterminate */
  .dh-checkbox:indeterminate {
    background: var(--accent-fill);
    border-color: var(--accent-fill);
  }
  .dh-checkbox:indeterminate::before {
    clip-path: none;
    width: 10px; height: 2px;
    border-radius: 1px;
    transform: scale(1);
  }

  /* Focus */
  .dh-checkbox:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-sub);
    border-color: var(--accent);
  }

  /* Disabled */
  .dh-checkbox:disabled { cursor: not-allowed; }

  /* Error */
  .dh-checkbox.is-error {
    border-color: var(--micro-coral);
    box-shadow: 0 0 0 3px var(--micro-coral-sub);
  }

  .dh-check-label {
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    color: var(--fg-2);
    line-height: 1.45;
    cursor: pointer;
  }
  .dh-check-wrap.is-disabled .dh-check-label { cursor: not-allowed; }
  .dh-check-sublabel {
    display: block;
    font-size: 0.8125rem;
    color: var(--fg-3);
    margin-top: 2px;
    line-height: 1.4;
  }

  /* ============================================================
     RADIO
  ============================================================ */
  .dh-radio-wrap {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    cursor: pointer;
    user-select: none;
  }
  .dh-radio-wrap.is-disabled { cursor: not-allowed; opacity: 0.45; }

  .dh-radio {
    -webkit-appearance: none;
    appearance: none;
    width: 18px; height: 18px;
    flex-shrink: 0;
    margin: 1px 0 0;
    border: 1.5px solid var(--border-s);
    border-radius: 50%;
    background: var(--bg-elevated);
    cursor: pointer;
    transition:
      background var(--ease-fast),
      border-color var(--ease-fast),
      box-shadow var(--ease-fast);
    display: grid;
    place-content: center;
  }

  /* Inner dot */
  .dh-radio::before {
    content: '';
    width: 8px; height: 8px;
    border-radius: 50%;
    background: white;
    transform: scale(0);
    transition: transform 0.1s ease;
  }

  /* Hover */
  .dh-radio:hover:not(:disabled):not(:checked) {
    border-color: var(--border-a);
  }

  /* Checked */
  .dh-radio:checked {
    background: var(--accent-fill);
    border-color: var(--accent-fill);
  }
  .dh-radio:checked::before { transform: scale(1); }

  /* Focus */
  .dh-radio:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-sub);
    border-color: var(--accent);
  }

  /* Disabled */
  .dh-radio:disabled { cursor: not-allowed; }

  .dh-radio-label {
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    color: var(--fg-2);
    line-height: 1.45;
    cursor: pointer;
  }
  .dh-radio-wrap.is-disabled .dh-radio-label { cursor: not-allowed; }
  .dh-radio-sublabel {
    display: block;
    font-size: 0.8125rem;
    color: var(--fg-3);
    margin-top: 2px;
    line-height: 1.4;
  }

  /* Radio card variant — bordered selectable card */
  .dh-radio-card {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border: 1px solid var(--border-s);
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: border-color var(--ease-fast), background var(--ease-fast);
    user-select: none;
  }
  .dh-radio-card:hover:not(.is-disabled) { border-color: var(--border-a); background: var(--bg-card); }
  .dh-radio-card:has(.dh-radio:checked) {
    border-color: var(--accent);
    background: var(--accent-sub);
  }
  .dh-radio-card.is-disabled { opacity: 0.45; cursor: not-allowed; }
  .dh-radio-card .dh-radio { margin-top: 2px; }
  .dh-radio-card .dh-radio-label { cursor: pointer; }

  /* Group spacing */
  .dh-check-group,
  .dh-radio-group {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
  }
  .dh-radio-group.is-cards { gap: var(--sp-2); }

  /* ============================================================
     COMPOSED FORM EXAMPLE
  ============================================================ */
  .dh-form {
    display: flex;
    flex-direction: column;
    gap: var(--sp-5);
  }
  .dh-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-4);
  }
  .dh-form-divider {
    border: none;
    border-top: 1px solid var(--border-s);
    margin: var(--sp-2) 0;
  }
  @media (max-width: 560px) {
    .dh-form-row { grid-template-columns: 1fr; }
  }
