/* 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 - two columns keep labels aligned with other controls */
.swatch-fieldset {
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr);
  align-items: center;
  gap: var(--space-2, 8px);
  margin: 0;
  padding: 0;
  border: 0;
  width: 100%;
}

.swatch-legend {
  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 {
  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 - CTL-05: consistent border for all swatches */
.swatch-chip {
  width: 100%;
  height: 2rem; /* lighter visual weight; the 44px .swatch-option stays the tap target (AAA) */
  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;
  /* A11Y-02: the chip IS the value. Forced colours would flatten every swatch
     to one system colour and leave a palette that cannot be read or chosen
     from, so this opts out — the sanctioned treatment for a colour picker.
     The chip's own border and the checked outline keep the swatches apart. */
  forced-color-adjust: none;
  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 {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2, 8px);
  align-items: center;
  margin-top: var(--space-1, 4px);
}

.swatch-disclosure {
  grid-column: 2;
  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[hidden] {
  display: none;
}

.swatch-custom-label {
  display: grid;
  gap: var(--space-1, 4px);
  font-size: var(--type-caption, 12px);
  color: var(--text-02, #2E2E2E);
}

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

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

.swatch-current {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1, 4px);
  min-height: 44px;
  color: var(--text-02, #2E2E2E);
  font-family: var(--font-mono, monospace);
  font-size: var(--type-mono, 11px);
}

.swatch-current-chip {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 1.25rem;
  border: 1px solid rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-1, 2px);
}

.swatch-current-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;
}

.swatch-mixed-state {
  grid-column: 2;
  align-items: center;
  min-height: 2rem;
  color: var(--text-02, #2E2E2E);
  font-size: var(--type-caption, 12px);
  font-weight: 600;
}

.swatch-mixed-state:not([hidden]) {
  display: inline-flex;
}

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