/* Layer panel (lp-*) — search, collapsed groups, focus chips, status line.
   Loaded from partials/layer_panel.html AFTER app.css, so it overrides the
   older lp-* rules there (same specificity, later wins). Tokens come from
   app.css :root. Tailwind is prebuilt: nothing here relies on new utilities. */

.lp-panel {
  width: 320px;
  max-width: calc(100vw - 24px);
  max-height: min(74vh, 660px);
  background: rgba(16,13,9,0.97);
  border-color: rgba(255,255,255,0.09);
}

.lp-header { padding: 11px 14px 9px; }

/* ── Controls block (search, chips, status) — never scrolls away ───────── */
.lp-controls {
  flex-shrink: 0;
  padding: 10px 12px 0;
  border-bottom: 1px solid var(--border);
  background: rgba(16,13,9,0.97);
}

.lp-search { position: relative; }
.lp-search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-2);
  pointer-events: none;
}
.lp-search-input {
  width: 100%;
  height: 36px;
  box-sizing: border-box;
  padding: 0 32px 0 32px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 999px;
  color: var(--text-1);
  font: inherit;
  font-size: 13px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s, background 0.15s;
}
.lp-search-input::placeholder { color: var(--text-2); }
.lp-search-input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
.lp-search-input:focus {
  border-color: rgba(196,120,74,0.65);
  background: rgba(255,255,255,0.07);
}
.lp-search-clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--text-2);
  font-size: 18px;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
}
.lp-search-clear:hover { color: var(--text-1); }

.lp-focus {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
  min-width: 0;
}
.lp-focus-label {
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-2);
}
.lp-chips {
  display: flex;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  padding: 2px 0 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  /* soft right edge: hints that the row scrolls */
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
  padding-right: 18px;
}
.lp-chips::-webkit-scrollbar { display: none; }
.lp-chip {
  flex-shrink: 0;
  height: 26px;
  padding: 0 11px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 999px;
  color: var(--text-1);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.lp-chip:hover { border-color: rgba(196,120,74,0.5); }
.lp-chip { display: inline-flex; align-items: center; gap: 5px; }
.lp-chip-icon { font-size: 13px; line-height: 1; }
/* Active chip: solid fill + check, unmistakable next to the quiet others. */
.lp-chip--on {
  background: var(--col-art);
  border-color: var(--col-art);
  color: #1a0f08;
  box-shadow: 0 0 0 2px rgba(196,120,74,0.3);
}
.lp-chip--on::after {
  content: '';
  width: 4px;
  height: 8px;
  margin: -2px 1px 0 2px;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.lp-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 2px 8px;
  font-size: 11.5px;
  color: var(--text-2);
}
.lp-status-text b { color: var(--text-1); font-weight: 700; font-variant-numeric: tabular-nums; }
.lp-status-actions { display: flex; align-items: center; gap: 2px; }
.lp-status-sep { color: var(--text-3); opacity: 0.5; }
.lp-link-btn {
  background: none;
  border: none;
  padding: 4px 6px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  border-radius: 4px;
  cursor: pointer;
}
.lp-link-btn:hover { color: var(--text-1); }
.lp-link-btn--accent { color: var(--col-art); }
.lp-link-btn--accent:hover { color: #e09468; }
.lp-link-btn:disabled { opacity: 0.35; cursor: default; color: var(--text-2); }

/* ── Groups ──────────────────────────────────────────────────────────── */
.lp-panel {
  overscroll-behavior: contain;
  /* clip, not hidden: focus/tap must not scroll the panel itself and push
     the header + search out of view (only .lp-layer-list scrolls) */
  overflow: hidden;
  overflow: clip;
}
.lp-layer-list { padding: 2px 0 8px; overscroll-behavior: contain; touch-action: pan-y; }

.lp-group + .lp-group { border-top: 1px solid var(--border); }

.lp-group-header {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px 0 0;
  /* undo the old uppercase micro-caption look */
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-1);
}
.lp-group-header--btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 6px 0 14px;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.lp-group-header--btn:hover .lp-group-name { color: #fff; }
.lp-group-header--btn:disabled { cursor: default; }
.lp-group-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; }
.lp-group-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lp-group-count {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.lp-group-count--on {
  color: #f2c9ae;
  background: rgba(196,120,74,0.2);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.lp-chevron {
  flex-shrink: 0;
  width: 10px;
  height: 6px;
  color: var(--text-2);
  transition: transform 0.15s;
}
.lp-chevron--open { transform: rotate(180deg); }

/* In search mode the header is just a small caption above its matches. */
.lp-group--search .lp-group-header { padding-top: 6px; }
.lp-group--search .lp-group-header--btn { min-height: 24px; padding-bottom: 0; }
.lp-group--search .lp-group-name {
  flex: none;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-2);
}
.lp-group--search + .lp-group--search { border-top: none; }

.lp-group-toggle-all { width: 32px; height: 32px; }

/* ── Rows ────────────────────────────────────────────────────────────── */
.lp-item { padding: 0; }
.lp-row {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px 0 14px;
  min-height: 40px;
  cursor: default;
}
.lp-row:hover { background: rgba(255,255,255,0.035); }
/* ON rows: soft tint + a bar in the layer's own map colour. */
.lp-row--on {
  background: rgba(196,120,74,0.08);
  box-shadow: inset 3px 0 0 var(--sw, var(--col-art));
}
.lp-row-label {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.lp-row-icon {
  width: 26px;
  height: 26px;
  font-size: 13px;
  border-radius: 7px;
  /* swatch: the layer's map colour behind its icon */
  background: rgba(255,255,255,0.06);
  background: color-mix(in srgb, var(--sw, #888) 26%, transparent);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--sw, #888) 60%, transparent);
}
.lp-row-name {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--text-2);
  transition: color 0.15s;
}
.lp-row--on .lp-row-name { color: var(--text-1); }

/* The switch: hidden native input + a drawn track (focus ring on the track). */
.lp-sr-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}
.lp-row-label .lp-toggle-slider {
  position: relative;
  inset: auto;
  flex-shrink: 0;
  width: 34px;
  height: 20px;
  border-radius: 10px;
  background: rgba(255,255,255,0.12);
}
.lp-row-label .lp-toggle-slider::before {
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
}
.lp-sr-input:checked + .lp-toggle-slider { background: rgba(196,120,74,0.5); }
.lp-sr-input:checked + .lp-toggle-slider::before {
  transform: translateX(14px);
  background: var(--col-art);
}

.lp-tune-btn {
  flex-shrink: 0;
  margin-left: 10px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-1);
  background: rgba(255,255,255,0.06);
  cursor: pointer;
}
.lp-tune-btn--off { visibility: hidden; }
.lp-tune-btn:hover, .lp-tune-btn--open { color: var(--col-art); background: rgba(196,120,74,0.12); }

.lp-sublayers { padding: 0 14px 4px 52px; }
.lp-sublayer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
}

.lp-slider-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 8px 48px;
}
.lp-slider-label { font-size: 10px; color: var(--text-2); width: 44px; flex-shrink: 0; }
.lp-slider { flex: 1; min-width: 0; height: 20px; }

.lp-empty { padding: 22px 14px; }

/* ── Keyboard focus ──────────────────────────────────────────────────── */
.lp-panel button:focus-visible,
.lp-search-input:focus-visible,
.lp-slider:focus-visible,
.lp-sublayer-row input:focus-visible {
  outline: 2px solid var(--col-art);
  outline-offset: 1px;
}
.lp-sr-input:focus-visible + .lp-toggle-slider {
  outline: 2px solid var(--col-art);
  outline-offset: 2px;
}

/* ── Phone sheet ─────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .lp-panel {
    width: 100%;
    max-width: none;
    max-height: 82vh;
    max-height: 82dvh;
    /* keyboard-aware: the wrapper's --lp-kb / --lp-vh come from visualViewport
       (layer-store.js lpPanel), so results stay above the on-screen keyboard */
    bottom: var(--lp-kb, 0px);
    max-height: min(82dvh, calc(var(--lp-vh, 100dvh) - 16px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .lp-layer-list { padding-bottom: 12px; }
  /* the sheet has its own close button; the trigger would show through it */
  .lp-trigger-btn--active { opacity: 0; pointer-events: none; }
  .lp-controls { padding: 8px 12px 0; }
  /* 16px: iOS zooms the page on focus of anything smaller */
  .lp-search-input { height: 42px; font-size: 16px; }
  .lp-chip { height: 36px; padding: 0 14px; font-size: 13px; }
  .lp-status { font-size: 12.5px; padding: 6px 2px 8px; }
  .lp-link-btn { font-size: 12.5px; min-height: 36px; padding: 0 10px; }
  .lp-group-header--btn { min-height: 48px; }
  .lp-group-toggle-all { width: 44px; height: 44px; }
  .lp-row { min-height: 48px; }
  .lp-row-label { min-height: 48px; }
  .lp-row-name { font-size: 14px; }
  .lp-row-icon { width: 28px; height: 28px; font-size: 14px; }
  .lp-row-label .lp-toggle-slider { width: 42px; height: 24px; border-radius: 12px; }
  .lp-row-label .lp-toggle-slider::before { width: 18px; height: 18px; left: 3px; top: 3px; }
  .lp-sr-input:checked + .lp-toggle-slider::before { transform: translateX(18px); }
  .lp-tune-btn { width: 44px; height: 44px; margin-left: 10px; }
  .lp-slider-wrap { padding-left: 52px; }
  .lp-slider { height: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  .lp-panel, .lp-panel *, .lp-chevron, .lp-chip, .lp-row-name, .lp-toggle-slider, .lp-toggle-slider::before {
    transition: none !important;
    animation: none !important;
  }
}
