/* my-gui combo box (MG3): .m-combo around the field, .m-combo-pop under (or over) it; behaviour in js/combo.js.
   Tokens only, so the light, dark and beige themes come from tokens.css. Spec: docs/spec.md 15. */

.m-combo { position: relative; display: flex; width: 100%; min-width: 0; }
.m-combo > .m-input { flex: 1 1 auto; min-width: 0; padding-inline-end: 32px; text-overflow: ellipsis; }
.m-combo > .m-combo-src { display: none; }

.m-combo-btn {
  position: absolute;
  inset-block: 0;
  inset-inline-end: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--m-r);
  background: none;
  color: var(--m-text-3);
  cursor: pointer;
}
.m-combo-btn .m-i { width: 13px; height: 13px; transition: transform .22s var(--m-ease); }
.m-combo-btn:hover { color: var(--m-text); }
.m-combo.is-open .m-combo-btn .m-i { transform: rotate(180deg); }
.m-combo-btn:disabled { opacity: .5; cursor: not-allowed; }

/* clear button, just before the arrow */
.m-combo.has-clear > .m-input { padding-inline-end: 58px; }
.m-combo-clear {
  position: absolute;
  inset-block: 0;
  inset-inline-end: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--m-r);
  background: none;
  color: var(--m-text-3);
  cursor: pointer;
}
.m-combo-clear[hidden] { display: none; }
.m-combo-clear:hover { color: var(--m-text); }
.m-combo-clear .m-i { width: 12px; height: 12px; }

/* typed text that was not taken */
.m-combo.is-rejected > .m-input { border-color: var(--m-warn); }
.m-combo-msg {
  position: absolute;
  inset-block-start: calc(100% + 4px);
  inset-inline: 0;
  z-index: 2;
  padding: 5px 9px;
  border: 1px solid var(--m-warn);
  border-radius: 8px;
  background: var(--m-modal);
  color: var(--m-text);
  font-size: 11.5px;
  font-weight: 600;
  box-shadow: var(--m-pop-sh);
}
.m-combo-msg[hidden] { display: none; }

/* multiple choice: chips above the field, the arrow stays on the field */
.m-combo--multi { flex-direction: column; gap: 6px; }
.m-combo--multi > .m-input { flex: 0 0 auto; width: 100%; }
.m-combo--multi > .m-combo-btn { inset-block: auto 0; height: 38px; }
.m-combo--multi.m-combo--sm > .m-combo-btn { height: 30px; }
.m-combo-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.m-combo-chips[hidden] { display: none; }
.m-combo-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  min-height: 26px;
  padding-block: 2px;
  padding-inline: 10px 4px;
  border: 1px solid var(--m-line);
  border-radius: 999px;
  background: rgba(var(--m-accent-rgb), .12);
  font-size: 12px;
  font-weight: 700;
}
.m-combo-chip-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-combo-chip-x {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--m-text-3);
  cursor: pointer;
}
.m-combo-chip-x:hover { color: var(--m-text); background: rgba(var(--m-accent-rgb), .18); }
.m-combo-chip-x .m-i { width: 10px; height: 10px; }

/* ---------- the list ---------- */

.m-combo-pop {
  position: fixed;
  z-index: 96;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--m-glass-edge);
  border-radius: 14px;
  background: var(--m-glass);
  box-shadow: var(--m-pop-sh);
  -webkit-backdrop-filter: blur(22px) saturate(1.6);
  backdrop-filter: blur(22px) saturate(1.6);
  color: var(--m-text);
  text-align: start;
  animation: m-combo-in .16s ease;
}
.m-combo-pop[hidden] { display: none; }
@keyframes m-combo-in { from { opacity: 0; } to { opacity: 1; } }

.m-combo-list { position: relative; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 6px; }
.m-combo-list:empty { display: none; }
.m-combo-group { padding: 8px 10px 4px; color: var(--m-text-3); font-size: 10.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }

.m-combo-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 5px 10px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.m-combo-opt.is-active { background: rgba(var(--m-accent-rgb), .14); }
.m-combo-opt.is-current { font-weight: 800; }
.m-combo-opt[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.m-combo-opt > .m-i { flex: 0 0 auto; width: 14px; height: 14px; color: var(--m-accent); }
.m-combo-text { display: flex; flex: 1 1 auto; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.m-combo-hint { color: var(--m-text-3); font-size: 11.5px; font-weight: 400; }

/* the matched part: a wash and an underline, so it does not rest on colour alone */
.m-combo-opt mark {
  border-radius: 3px;
  background: rgba(var(--m-accent-rgb), .2);
  color: inherit;
  font-weight: 800;
  text-decoration: underline;
  text-decoration-color: var(--m-accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

.m-combo-note { padding: 12px; color: var(--m-text-3); font-size: 12px; font-weight: 600; text-align: center; }
.m-combo-note[hidden] { display: none; }
.m-combo-rest { padding: 7px 12px; border-block-start: 1px solid var(--m-line); font-size: 11px; }
.m-combo-list.is-stale { opacity: .55; }
.m-combo-retry { align-self: center; margin-block-end: 10px; }
.m-combo-retry[hidden] { display: none; }
.m-combo-create { color: var(--m-accent); }

/* ---------- bottom sheet (small touch screens) ---------- */

.m-combo-scrim { position: fixed; inset: 0; z-index: 95; background: rgba(0, 0, 0, .45); touch-action: none; }
.m-combo-head { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; padding: 10px 12px 6px; }
.m-combo-head[hidden] { display: none; }
.m-combo-title { overflow: hidden; font-size: 14px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.m-combo-search { grid-column: 1 / -1; width: 100%; height: 44px; font-size: 16px; }
.m-combo-done { min-height: 40px; }
.m-combo-pop.is-sheet {
  inset-inline: 0;
  width: auto;
  padding-block-end: env(safe-area-inset-bottom, 0px);
  border-radius: 18px 18px 0 0;
  background: var(--m-modal);
  animation: m-combo-sheet .22s var(--m-ease);
}
.m-combo-pop.is-sheet .m-combo-opt { min-height: 48px; font-size: 15px; }
@keyframes m-combo-sheet { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- touch ---------- */

@media (pointer: coarse) {
  .m-combo > .m-input { height: 44px; padding-inline-end: 46px; font-size: 16px; }   /* 16px: iOS does not zoom in */
  .m-combo-btn { width: 44px; }
  .m-combo.has-clear > .m-input { padding-inline-end: 88px; }
  .m-combo-clear { inset-inline-end: 44px; width: 40px; }
  .m-combo--multi > .m-combo-btn { height: 44px; }
  .m-combo-chip { min-height: 36px; font-size: 13px; }
  .m-combo-chip-x { width: 32px; height: 32px; }
  .m-combo-opt { min-height: 44px; font-size: 14px; }
  .m-combo-hint { font-size: 12.5px; }
}

/* ---------- looks, shapes, modes ---------- */

:root[data-m-look="glass"] .m-combo-pop {
  background: var(--m-look-pop);
  border-color: var(--m-look-edge);
  box-shadow: var(--m-pop-sh), inset 0 1px 0 var(--m-look-hi);
  -webkit-backdrop-filter: blur(var(--m-look-blur-strong)) saturate(var(--m-look-sat));
  backdrop-filter: blur(var(--m-look-blur-strong)) saturate(var(--m-look-sat));
}
:root[data-m-shape] .m-combo-pop { border-radius: calc(14px * var(--m-r-k)); }
:root[data-m-shape] .m-combo-opt { border-radius: calc(9px * var(--m-r-k)); }
:root[data-m-shape] .m-combo-pop.is-sheet { border-radius: calc(18px * var(--m-r-k)) calc(18px * var(--m-r-k)) 0 0; }
:root[data-m-look="glass"] .m-combo-pop.is-sheet { background: var(--m-modal); }

@media (prefers-reduced-motion: reduce) {
  .m-combo-pop { animation: none; }
}

@media (forced-colors: active) {
  .m-combo-pop { border: 1px solid CanvasText; box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
  .m-combo-opt.is-active { forced-color-adjust: none; background: Highlight; color: HighlightText; }
  .m-combo-opt.is-active .m-combo-hint, .m-combo-opt.is-active > .m-i { color: HighlightText; }
  .m-combo-opt[aria-disabled="true"] { color: GrayText; }
  .m-combo-opt mark { background: none; text-decoration-color: currentColor; }
  .m-combo-chip, .m-combo-msg { border: 1px solid CanvasText; }
}

@media print {
  .m-combo-pop, .m-combo-btn, .m-combo-clear, .m-combo-chip-x, .m-combo-msg, .m-combo-scrim { display: none; }
}
