/* Input Field — LittleLives design system
   9 field-type variants × 5 interaction states. Composition:
     .ll-field                       — outer block (label + box + assistive row)
     .ll-field__label                — label row (text + required* / (optional))
     .ll-field__box                  — the input box (min 48px, radius 8, 1.5px border)
     .ll-field__bottom               — flex row: assistive text + counter

   States are driven by:
     - real :hover / :focus-within on .ll-field__box
     - force classes for the storybook matrix:
         .ll-field.is-hover, .ll-field.is-focus, .ll-field.is-readonly, .ll-field.is-error

   The focus ring is rendered as box-shadow so layout does not shift.
*/

:root {
  /* primitives */
  --color-white:        #ffffff;
  --color-neutral-25:   #fafafa;
  --color-neutral-50:   #f0f0f0;
  --color-neutral-100:  #e6e6e6;
  --color-neutral-200:  #d4d4d4;
  --color-neutral-300:  #bbbbbb;
  --color-neutral-600:  #8b8b8b;
  --color-neutral-800:  #545454;
  --color-neutral-950:  #333333;
  --color-brand-500:    #00b8ec;
  --color-brand-800:    #005b82;
  --color-error-500:    #d21e30;
  --color-error-700:    #a01323;

  /* semantics */
  --content-neutral-primary:    var(--color-neutral-950);
  --content-neutral-secondary:  var(--color-neutral-800);
  --content-neutral-tertiary:   var(--color-neutral-600);
  --content-brand-strong:       var(--color-brand-800);
  --content-error-strong:       var(--color-error-700);
  --content-inverse-primary:    var(--color-white);

  --stroke-neutral-soft-primary: var(--color-neutral-200);
  --stroke-brand:                var(--color-brand-500);
  --stroke-brand-strong:         var(--color-brand-800);
  --stroke-error-strong:         var(--color-error-700);

  --surface-default-white:       var(--color-white);
  --surface-default-disabled:    var(--color-neutral-50);
  --surface-overlay-dim-40:      rgba(0, 0, 0, 0.45);
}

/* ===================================================================
   Base wrapper
   =================================================================== */
.ll-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: 'Nunito Sans', system-ui, sans-serif;
  color: var(--content-neutral-primary);
}
.ll-field * { box-sizing: border-box; }

.ll-field__label {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--content-neutral-secondary);
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}
.ll-field__label-text { white-space: nowrap; }
.ll-field__required {
  font-weight: 400;
  color: var(--content-error-strong);
}
.ll-field__optional {
  font-weight: 400;
  color: var(--content-neutral-secondary);
}

/* ---------- Field box ---------- */
.ll-field__box {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--surface-default-white);
  border: 1.5px solid var(--stroke-neutral-soft-primary);
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

/* HOVER ---------------------------------------------------------- */
.ll-field:not(.is-readonly):not(.is-error) .ll-field__box:hover,
.ll-field.is-hover:not(.is-readonly):not(.is-error) .ll-field__box {
  border: 1px solid var(--stroke-brand-strong);
}

/* FOCUS ---------------------------------------------------------- */
.ll-field:not(.is-readonly):not(.is-error) .ll-field__box:focus-within,
.ll-field.is-focus:not(.is-readonly):not(.is-error) .ll-field__box {
  border: 1.5px solid var(--stroke-brand-strong);
  box-shadow: 0 0 0 3px var(--stroke-brand);
}

/* READ-ONLY ------------------------------------------------------
   Strip every interactive affordance: leading / trailing icons, picker
   caret, label-help, blinking caret, textarea resize, file-row trash.
   Text stays visible and selectable. */
.ll-field.is-readonly .ll-field__box {
  background: var(--surface-default-disabled);
  border-color: transparent;
  cursor: default;
}
.ll-field.is-readonly .ll-field__box:hover { border-color: transparent; }
.ll-field.is-readonly .ll-field__icon,
.ll-field.is-readonly .ll-field__caret,
.ll-field.is-readonly .ll-field__upload-label,
.ll-field.is-readonly .ll-field__label-help {
  display: none;
}
.ll-field.is-readonly .ll-field__input,
.ll-field.is-readonly .ll-field__textarea,
.ll-field.is-readonly .ll-field__value {
  pointer-events: none;
  caret-color: transparent;
}
.ll-field.is-readonly .ll-field__textarea { resize: none; }
.ll-field.is-readonly .ll-field__file-row .ll-iconbtn--trash { display: none; }
/* When multi-files has files in read-only, the upload trigger box is
   removed entirely — the rows below are the only content. Single-file
   already hides the box via JS when files are present. */
.ll-field--multi-files.is-readonly[data-has-files="true"] .ll-field__box {
  display: none;
}

/* ERROR ---------------------------------------------------------- */
.ll-field.is-error .ll-field__label,
.ll-field.is-error .ll-field__required {
  color: var(--content-error-strong);
}
.ll-field.is-error .ll-field__box {
  border-color: var(--stroke-error-strong);
}
.ll-field.is-error .ll-field__box:hover {
  border: 1.5px solid var(--stroke-error-strong);
}

/* ---------- Native control inside the box ---------- */
.ll-field__input,
.ll-field__textarea,
.ll-field__select {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--content-neutral-primary);
  padding: 12px 0;
}
.ll-field__input::placeholder,
.ll-field__textarea::placeholder {
  color: var(--content-neutral-tertiary);
}
.ll-field__input:disabled,
.ll-field__textarea:disabled,
.ll-field__select:disabled { cursor: default; color: var(--content-neutral-primary); }

/* ---------- Icons (leading / trailing) ---------- */
.ll-field__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--content-neutral-secondary);
  flex-shrink: 0;
}
.ll-field__icon--lead { margin-right: 4px; }
.ll-field__icon--trail { margin-left: 4px; }
.ll-field__icon svg { display: block; }

.ll-field:not(.is-readonly):not(.is-error) .ll-field__box:hover .ll-field__icon,
.ll-field.is-hover:not(.is-readonly):not(.is-error) .ll-field__icon,
.ll-field:not(.is-readonly):not(.is-error) .ll-field__box:focus-within .ll-field__icon,
.ll-field.is-focus:not(.is-readonly):not(.is-error) .ll-field__icon {
  color: var(--content-brand-strong);
}

/* Dropdown caret rotation when open */
.ll-field__caret { transition: transform 120ms ease; }
.ll-field[data-open="true"] .ll-field__caret { transform: rotate(180deg); }

/* ---------- Bottom row: assistive text + counter ---------- */
.ll-field__bottom {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--content-neutral-secondary);
}
.ll-field__bottom:empty { display: none; }
.ll-field__assistive { flex: 1 1 auto; }
.ll-field__counter { flex-shrink: 0; font-variant-numeric: tabular-nums; }
.ll-field.is-error .ll-field__assistive,
.ll-field.is-error .ll-field__counter {
  color: var(--content-error-strong);
}

/* ===================================================================
   Type: short-text
   =================================================================== */
.ll-field--short-text .ll-field__input { padding: 12px 0; }

/* ===================================================================
   Type: long-text
   =================================================================== */
.ll-field--long-text .ll-field__box {
  align-items: stretch;
  padding: 12px;
  min-height: 144px;
}
.ll-field--long-text .ll-field__textarea {
  width: 100%;
  min-height: 120px;
  padding: 0;
  resize: vertical;
  line-height: 1.5;
}

/* ===================================================================
   Type: single-select / multi-select
   =================================================================== */
.ll-field--single-select .ll-field__box,
.ll-field--multi-select .ll-field__box {
  cursor: pointer;
  padding-right: 12px;
}
.ll-field--single-select .ll-field__value {
  flex: 1 1 auto;
  padding: 12px 0;
  font-size: 16px;
  color: var(--content-neutral-primary);
}
.ll-field--single-select .ll-field__value:empty::before {
  content: '';
}

/* multi-select chip area */
.ll-field--multi-select .ll-field__box {
  align-items: center;
  padding: 6px 12px 6px 8px;
  min-height: 48px;
  flex-wrap: wrap;
}
.ll-field--multi-select .ll-field__chips {
  flex: 1 1 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 4px 0;
}

/* Multi-select renders real LLChip components — see chip.css for styling.
   This rule only handles read-only stripping of the chip's close button. */
.ll-field.is-readonly .ll-chip__close { display: none; }

/* ===================================================================
   Type: date / time — native input + OS picker
   The native browser indicator at the right edge is hidden; the leading
   icon (Calendar / Clock) is the only icon shown. Clicking anywhere on
   the box calls input.showPicker() (see input-field.js).
   =================================================================== */
.ll-field--date .ll-field__box,
.ll-field--time .ll-field__box {
  position: relative;
  cursor: pointer;
}
.ll-field--date .ll-field__input,
.ll-field--time .ll-field__input {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  color: var(--content-neutral-primary);
}
.ll-field--date .ll-field__input::placeholder,
.ll-field--time .ll-field__input::placeholder {
  color: var(--content-neutral-tertiary);
}
/* Native <input type="date|time"> sibling — owns the OS picker.
   The visible masked text input owns the value display (dd/mm/yyyy or
   hh:mmam). input-field.js calls native.showPicker() on every box click.
   The native sits at 1x1 in the bottom-left corner with opacity 0 — it
   must have a non-zero box and not be `display:none` for showPicker to
   succeed, but it stays out of the user's pointer path. */
.ll-field--date .ll-field__box,
.ll-field--time .ll-field__box {
  position: relative;
}
.ll-field__native {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  opacity: 0;
  color: transparent;
  font: inherit;
}
.ll-field--date.is-readonly .ll-field__native,
.ll-field--time.is-readonly .ll-field__native {
  display: none;
}

/* ===================================================================
   Type: single-file / multi-files
   =================================================================== */
.ll-field--single-file .ll-field__box,
.ll-field--multi-files .ll-field__box {
  cursor: pointer;
}
.ll-field--single-file .ll-field__upload-label,
.ll-field--multi-files .ll-field__upload-label {
  flex: 1 1 auto;
  padding: 12px 0;
  font-size: 16px;
  color: var(--content-neutral-tertiary);
}

.ll-field__file-rows {
  display: flex;
  flex-direction: column;
  margin-top: 8px;
}
.ll-field__file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  font-size: 14px;
  border-bottom: 1px solid var(--color-neutral-100);
}
.ll-field__file-row:last-child { border-bottom: 0; }
.ll-field__file-link {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--content-brand-strong);
  text-decoration: underline;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ll-field__file-time {
  color: var(--content-neutral-secondary);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.ll-field__file-row .ll-iconbtn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--content-neutral-secondary);
  cursor: pointer;
  border-radius: 4px;
}
.ll-field__file-row .ll-iconbtn:hover { color: var(--content-neutral-primary); background: var(--color-neutral-25); }
.ll-field__file-row .ll-iconbtn svg { width: 18px; height: 18px; display: block; }

.ll-field.is-readonly .ll-field__file-row .ll-iconbtn--trash { display: none; }

/* In read-only single/multi-file the upload box itself is hidden (read-only
   files are listed bare per the visual reference). Toggle via data-attr. */
.ll-field.is-readonly[data-hide-upload="true"] .ll-field__box { display: none; }

/* ===================================================================
   Type: single-image
   =================================================================== */
.ll-field--single-image .ll-field__box {
  display: block;
  min-height: 160px;
  height: var(--ll-image-h, 160px);
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  border-style: dashed;
  border-width: 1.5px;
}
.ll-field--single-image .ll-field__dropzone {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--content-neutral-secondary);
  font-size: 16px;
  font-weight: 600;
}
.ll-field--single-image .ll-field__dropzone svg { color: inherit; }

.ll-field--single-image:not(.is-readonly):not(.is-error) .ll-field__box:hover,
.ll-field--single-image.is-hover .ll-field__box,
.ll-field--single-image:not(.is-readonly):not(.is-error) .ll-field__box:focus-within,
.ll-field--single-image.is-focus .ll-field__box {
  border-style: solid;
}
.ll-field--single-image:not(.is-readonly):not(.is-error) .ll-field__box:hover .ll-field__dropzone,
.ll-field--single-image.is-hover .ll-field__dropzone,
.ll-field--single-image:not(.is-readonly):not(.is-error) .ll-field__box:focus-within .ll-field__dropzone,
.ll-field--single-image.is-focus .ll-field__dropzone {
  color: var(--content-brand-strong);
}

.ll-field--single-image.is-readonly .ll-field__box {
  border-style: solid;
  border-color: transparent;
}
.ll-field--single-image.is-error .ll-field__box { border-style: solid; }

/* Filled preview */
.ll-field--single-image[data-has-value="true"] .ll-field__box {
  border-style: solid;
}
.ll-field--single-image[data-has-value="true"] .ll-field__dropzone {
  display: none;
}
.ll-field__preview {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  position: relative;
  display: none;
}
.ll-field--single-image[data-has-value="true"] .ll-field__preview { display: block; }
.ll-field__preview-overlay {
  position: absolute;
  inset: 0;
  background: var(--surface-overlay-dim-40);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--content-inverse-primary);
  font-size: 16px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 120ms ease;
}
.ll-field--single-image:not(.is-readonly):not(.is-error) .ll-field__box:hover .ll-field__preview-overlay,
.ll-field--single-image.is-hover .ll-field__preview-overlay,
.ll-field--single-image:not(.is-readonly):not(.is-error) .ll-field__box:focus-within .ll-field__preview-overlay,
.ll-field--single-image.is-focus .ll-field__preview-overlay {
  opacity: 1;
}

/* Label help-tooltip dot (image upload) */
.ll-field__label-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  color: var(--content-neutral-secondary);
}
.ll-field__label-help svg { width: 16px; height: 16px; display: block; }

/* ===================================================================
   Reduced motion
   =================================================================== */
@media (prefers-reduced-motion: reduce) {
  .ll-field__box,
  .ll-field__caret,
  .ll-field__preview-overlay { transition: none !important; }
}
