/* CM001 kit — select.css (@layer cm.components). The searchable combobox that replaces every native
 * <select>. The native element is hidden but kept for form submit; .cm-select-btn mirrors input chrome. */
@layer cm.components {
  .cm-select { position: relative; display: block; }
  .cm-select-native { display: none; }

  .cm-select-btn {
    /* padding-block 7 (not 8) so a single-select lands exactly on --control-h like every native
       input/select next to it; multi-select still grows past it for tag rows. */
    width: 100%; min-height: var(--control-h, 38px); display: flex; align-items: center; gap: 6px;
    padding: 7px 11px; border: 1px solid var(--line-2, #cbd5e1); border-radius: var(--radius-md, 10px);
    background: var(--surface); color: var(--text); font: inherit; font-size: 13.5px; cursor: pointer; text-align: start;
  }
  .cm-select-btn:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--line-2)); }
  .cm-select.is-open .cm-select-btn { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
  .cm-select.is-disabled { opacity: .6; }
  .cm-select-ph { color: var(--text-3); }
  .cm-select-val { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .cm-select-ph { flex: 1; }
  .cm-select-caret { margin-inline-start: auto; color: var(--text-3); display: inline-flex; transition: transform var(--dur-fast, 120ms) var(--ease-std, ease); }
  .cm-select.is-open .cm-select-caret { transform: rotate(180deg); }
  .cm-select--multi .cm-select-btn { flex-wrap: wrap; gap: 4px; }
  .cm-tag { background: var(--brand-50, #eff6ff); color: var(--brand); border-radius: var(--radius-pill, 999px); padding: 2px 9px; font-size: 12px; font-weight: 600; }

  .cm-select-pop {
    position: fixed; z-index: var(--z-dropdown, 800); background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-md, 10px); box-shadow: var(--shadow-md); padding: 6px; min-width: 160px; overflow: hidden;
  }
  .cm-select-pop[hidden] { display: none; }
  .cm-select-search { width: 100%; margin-bottom: 6px; }
  .cm-select-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
  .cm-select-opt {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; color: var(--text);
  }
  .cm-select-opt .cm-select-tick { width: 14px; flex: none; }
  .cm-select-opt .ic { color: var(--brand); flex: none; }
  .cm-select-opt:hover, .cm-select-opt.is-active { background: var(--surface-2); }
  .cm-select-opt.is-selected { color: var(--brand); font-weight: 600; }
  .cm-select-opt.is-disabled { opacity: .5; cursor: not-allowed; }
  .cm-select-empty { padding: 14px 10px; text-align: center; color: var(--text-3); font-size: 13px; }

  /* ---- hierarchy mode -------------------------------------------------------
     A parent picker used to say "— — — Basement (Floor)", which asks the reader to count dashes to
     work out where a room sits. These rules draw the real thing: continuation rails for ancestors
     that still have siblings below, an elbow into each node, and the kind as a quiet badge instead of
     being glued into the name. Rails are borders on empty <i>s, so they take the theme's line colour
     and need no images. All logical properties, so the tree mirrors correctly in Arabic. */
  /* tighter gap so the elbow stub visibly meets the name instead of floating away from it */
  .cm-select-list--tree .cm-select-opt { align-items: flex-start; padding-block: 6px; gap: 6px; }
  .cm-select-list--tree .cm-select-opt .cm-select-tick,
  .cm-select-list--tree .cm-select-opt > .ic { margin-block-start: 2px; }

  .cm-tree-guide { display: flex; flex: none; align-self: stretch; }
  /* one 14px column per ancestor level; the rail only paints when that ancestor has more children */
  .cm-tree-seg { display: block; width: 16px; flex: none; border-inline-start: 1px solid transparent; }
  .cm-tree-seg.is-on { border-inline-start-color: var(--line-2, #cbd5e1); }
  /* the elbow: a rail down to the row's middle, then a stub across to the name */
  .cm-tree-elbow {
    display: block; width: 16px; flex: none; position: relative;
    border-inline-start: 1px solid var(--line-2, #cbd5e1);
  }
  .cm-tree-elbow::after {
    content: ""; position: absolute; inset-inline-start: 0; top: 9px; width: 12px;
    border-block-start: 1px solid var(--line-2, #cbd5e1);
  }
  /* a last child stops its rail at the elbow instead of running past it */
  .cm-tree-elbow.is-last { border-inline-start-color: transparent; }
  .cm-tree-elbow.is-last::before {
    content: ""; position: absolute; inset-inline-start: 0; top: 0; height: 10px;
    border-inline-start: 1px solid var(--line-2, #cbd5e1);
  }

  /* nowrap: the kind badge must stay beside the name. Letting it wrap put a lone badge on its own
     line under long names like "Back of House and Plant", which read as a broken row. */
  .cm-tree-main { display: flex; align-items: baseline; gap: 7px; flex-wrap: nowrap; min-width: 0; }
  .cm-tree-name { min-width: 0; overflow-wrap: anywhere; }
  .cm-tree-kind {
    flex: none; font-size: 11px; line-height: 1.5; padding: 1px 7px; border-radius: 999px;
    background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line);
    font-weight: 500; white-space: nowrap;
  }
  .cm-select-opt.is-selected .cm-tree-kind { color: var(--text-2); font-weight: 500; }

  /* Searching: the tree is replaced by each match's ancestor path, because a filtered tree would draw
     branches hanging off parents that are no longer in the list. */
  .cm-tree-path {
    flex-basis: 100%; font-size: 11.5px; color: var(--text-3); line-height: 1.4;
    display: flex; gap: 5px; flex-wrap: wrap; align-items: baseline;
  }
  .cm-tree-path i { font-style: normal; opacity: .65; }
  .cm-select-opt--node.is-flat { padding-block: 7px; }
  /* Search mode is the one case that DOES wrap: the ancestor path takes its own line above the name. */
  .cm-select-opt--node.is-flat .cm-tree-main { flex-wrap: wrap; }

  @media (prefers-reduced-motion: reduce) { .cm-select-list--tree * { transition: none !important; } }
  /* A tree popup is sized by its content, not by the control it hangs off, so the rails and the names
     both fit. Capped so it never runs off a phone. */
  .cm-select-pop--tree { max-width: min(560px, calc(100vw - 24px)); }
  .cm-select-pop--tree .cm-select-list { overflow-x: hidden; }
}
