/* Route Plotter v3 — Swatch Picker
   Accessible colour picker using Okabe-Ito palette for map data
   10 swatches (incl. None) in a 5×2 grid; neutral-ink mode uses auto-fit row
   Requires styles/tokens.css to be loaded first
*/

.swatch-picker {
  display: block;
  margin-bottom: var(--row-gap, 0.5rem);
}

/* fieldset created by JS - contains legend + grid in flex row */
.swatch-fieldset {
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
  margin: 0;
  padding: 0;
  border: 0;
  width: 100%;
}

.swatch-legend {
  flex: 0 0 6rem;              /* Match section-content label width */
  font-size: var(--text-xs, 0.75rem);
  line-height: var(--line-tight, 1.2);
  font-weight: 500;            /* Match other labels */
  color: var(--text-02, #2E2E2E);
  text-transform: none;        /* Match other labels */
  letter-spacing: normal;
}

/* Swatch grid: 5×2 CSS Grid fills remaining space after label */
.swatch-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.25rem;
}

/* Swatch option: rectangular cells, 44px min-height for AAA touch targets */
.swatch-option {
  min-height: 2.75rem;         /* 44px AAA touch target */
  display: grid;
  place-items: center;
  border-radius: 0.125rem;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background var(--motion-fast, 120ms) var(--ease-out, ease-out);
}

.swatch-option:hover {
  background: var(--hover-ui, #E9E9E9);
}

.swatch-option:focus-within {
  outline: none;
  /* Focus ring only when keyboard navigating, not when selected */
}

.swatch-radio {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

/* Swatch chip: fills container - CTL-05: consistent border for all swatches */
.swatch-chip {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-1, 0.25rem);
  border: 1px solid rgba(0, 0, 0, 0.18); /* CTL-05: needed for yellow/white contrast */
  box-sizing: border-box;
  transition: box-shadow var(--motion-fast, 120ms) var(--ease-out, ease-out);
}

/* Hover state */
.swatch-option:hover .swatch-chip {
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
}

/* Selected state: black outline for greyscale UI consistency */
.swatch-radio:checked + .swatch-chip {
  outline: 2px solid #161616;
  outline-offset: 2px;
}

/* Focus ring for keyboard navigation - consistent with global focus style per spec §3 */
.swatch-radio:focus-visible + .swatch-chip {
  outline: none;
  box-shadow: 
    0 0 0 2px var(--focus-inner, #FFFFFF),
    0 0 0 5px var(--focus-outer, #0F62FE);
}

/* Light swatches (white, yellow): border already provided by .swatch-chip's
   rgba(0,0,0,0.18) border — sufficient for 3:1 non-text contrast on white */

/* None swatch: red diagonal line (convention for "no colour") */
.swatch-chip.is-none {
  background:
    linear-gradient(
      to top right,
      transparent calc(50% - 1px),
      #DA1E28 calc(50% - 1px),
      #DA1E28 calc(50% + 1px),
      transparent calc(50% + 1px)
    ) !important;
}

/* Disabled */
.swatch-fieldset:disabled .swatch-option {
  cursor: not-allowed;
  opacity: 0.6;
}

.swatch-fieldset:disabled .swatch-option:hover {
  background: transparent;
}

/* Optional actions row */
.swatch-actions {
  display: flex;
  gap: var(--space-2, 8px);
  align-items: center;
  margin-top: var(--space-2, 8px);
}

.swatch-disclosure {
  display: grid;
  gap: var(--space-2, 8px);
  padding: var(--space-3, 12px);
  border: 1px solid var(--ui-03, #CFD4D8);
  border-radius: var(--radius-2, 4px);
  background: var(--ui-02, #fff);
  margin-top: var(--space-2, 8px);
}

.swatch-disclosure input[type="color"] {
  width: 100%;
  height: 40px;
  border: 1px solid var(--border-strong, #707D89);
  border-radius: var(--radius-1, 2px);
  cursor: pointer;
  padding: 2px;
}

/* small buttons */
.btn-sm {
  height: 36px;
  padding: 6px 10px;
  border-radius: var(--radius-2, 4px);
  font-size: var(--type-caption, 12px);
}

/* Neutral ink grid: same auto-fit behaviour */
.swatch-grid.swatch-grid-neutral {
  grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
}
