/* ===========================================================================
   JACRA Backoffice - command palette (Ctrl+K)
   ---------------------------------------------------------------------------
   Built by assets/js/commandbar.js and appended to <body>, so it sits outside
   the app shell and above every screen.

   Load AFTER components.css and mobile.css, with the other screen sheets:
     <link rel="stylesheet" href="assets/css/screens/commandbar.css">

   Two forms, one stylesheet:
     - desktop: a 640px card that drops in from just above the fold
     - phone:   a full sheet from the top edge, so the on screen keyboard has
                the whole viewport to work with and no card floats behind it

   Layer order in this app: bottombar 50, toast 60, palette 90. The palette
   covers the tab bar because it is modal; the floating launcher underneath it
   sits at 45, below the bar it must never hide.

   Colour comes from tokens.css only. The scrim is --navy-900 carried at
   partial opacity on its own element rather than a hand mixed rgba(), which is
   also what lets the blur and the wash fade in together.
   =========================================================================== */


/* ---------------------------------------------------------------------------
   1. Overlay host
   --------------------------------------------------------------------------- */

.cmdk {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding:
    calc(var(--safe-t) + 9vh)
    var(--s-4)
    calc(var(--safe-b) + var(--s-4));
}

/* base.css already hides [hidden], but .cmdk{display:flex} lands later in the
   cascade at the same weight, so the closed palette needs this to stay closed. */
.cmdk[hidden] {
  display: none;
}

.cmdk-scrim {
  position: absolute;
  inset: 0;
  background: var(--veil);
  opacity: 0;
  -webkit-backdrop-filter: blur(0px);
  backdrop-filter: blur(0px);
  transition:
    opacity var(--t-base),
    -webkit-backdrop-filter var(--t-base),
    backdrop-filter var(--t-base);
  cursor: default;
}

/* While the exit transition plays the palette is inert: a row that is fading
   out must not still be clickable, and a stray tap on the way to the screen
   underneath should reach that screen. */
.cmdk.is-closing {
  pointer-events: none;
}

/* The same veil and blur as the modal (components.css): a lighter backdrop
   here read as a second app. */
.cmdk.is-open .cmdk-scrim {
  opacity: 1;
  -webkit-backdrop-filter: blur(var(--blur-veil));
  backdrop-filter: blur(var(--blur-veil));
}


/* ---------------------------------------------------------------------------
   2. Panel

   Entrance and exit run on the same transition, so closing is the opening
   played backwards rather than a second, differently timed animation. The
   panel drops 12px and settles: --ease-out on --t-base, no overshoot, because
   a box that carries text should arrive rather than bounce.
   --------------------------------------------------------------------------- */

.cmdk-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  max-height: 72vh;
  max-height: 72dvh;
  min-height: 0;
  border: 1px solid var(--gray-200);
  border-radius: var(--r-lg);
  background: var(--white);
  box-shadow: var(--sh-lg);
  overflow: hidden;

  opacity: 0;
  transform: translateY(-12px) scale(.985);
  transform-origin: top center;
  transition:
    opacity var(--t-base),
    transform var(--t-base);

  /* Native feel inside the Median WebView: no 300ms tap delay, no blue flash,
     and chrome text that cannot be selected by a long press. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.cmdk.is-open .cmdk-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
}


/* ---------------------------------------------------------------------------
   3. Search head
   --------------------------------------------------------------------------- */

.cmdk-head {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--gray-200);
  background: var(--white);
}

/* The focus ring for the input, drawn as the field's own underline. The input
   has no border of its own to light up, and a rectangle around a borderless
   box inside a bordered card reads as a mistake. */
.cmdk-head::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--gold);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform var(--t-base);
}

.cmdk-head:focus-within::after {
  transform: scaleX(1);
}

.cmdk-hic {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--gray-500);
}

.cmdk-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  padding: var(--s-1) 0;
  background: transparent;
  font-family: var(--f-ui);
  /* 16px is not a style choice: anything smaller makes iOS zoom the page on
     focus, and a zoomed palette inside the Median app cannot be scrolled back. */
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
  -webkit-user-select: text;
  user-select: text;
}

.cmdk-input::placeholder {
  color: var(--muted);
  font-weight: 400;
}

.cmdk-input:focus-visible {
  outline: none;
}

.cmdk-clear,
.cmdk-x {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 34px;
  border-radius: var(--r-sm);
  color: var(--gray-500);
  cursor: pointer;
  transition:
    background var(--t-fast),
    color var(--t-fast),
    transform var(--t-fast);
}

.cmdk-clear {
  width: 34px;
  height: 34px;
}

.cmdk-x {
  padding: 0 var(--s-2);
  font-size: 12px;
  font-weight: 600;
}

.cmdk-clear:hover,
.cmdk-x:hover {
  background: var(--gray-100);
  color: var(--ink);
}

.cmdk-clear:active,
.cmdk-x:active {
  transform: scale(.94);
}

/* The sprite carries no cross. A plus turned a quarter of the way round is the
   same eight lines, so the clear button reuses #i-plus instead of shipping a
   34th symbol that means the same thing. */
.cmdk-xic {
  width: 16px;
  height: 16px;
  transform: rotate(45deg);
}

.cmdk-x-t {
  display: none;
}

.cmdk-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  padding: 2px var(--s-2);
  border: 1px solid var(--gray-300);
  border-radius: var(--r-sm);
  background: var(--gray-50);
  font-family: var(--f-mono);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--gray-600);
  white-space: nowrap;
}


/* ---------------------------------------------------------------------------
   4. Progress hairline

   Shown while a request is in flight. It replaces a spinner: the results
   already on screen stay readable, and the only thing that moves is a 2px
   line, which is the quietest way to say "still working".
   --------------------------------------------------------------------------- */

.cmdk-bar {
  flex: none;
  position: relative;
  height: 2px;
  overflow: hidden;
  opacity: 0;
  transition: opacity var(--t-fast);
}

.cmdk-panel.is-busy .cmdk-bar {
  opacity: 1;
}

.cmdk-bar::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 38%;
  background: var(--gold);
  transform: translateX(-110%);
}

.cmdk-panel.is-busy .cmdk-bar::after {
  animation: cmdk-sweep var(--t-loop) var(--ease-in-out) infinite;
}

@keyframes cmdk-sweep {
  0%   { transform: translateX(-110%); }
  100% { transform: translateX(370%); }
}


/* ---------------------------------------------------------------------------
   5. Results scroller
   --------------------------------------------------------------------------- */

.cmdk-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  padding: var(--s-2) var(--s-2) var(--s-3);
}

.cmdk-group + .cmdk-group {
  margin-top: var(--s-2);
}

.cmdk-ghead {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-3) var(--s-1);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--gray-500);
}

.cmdk-gt {
  min-width: 0;
}

.cmdk-gn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  padding: 0 var(--s-1);
  border-radius: 999px;
  background: var(--gray-100);
  font-family: var(--f-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--gray-600);
}

.cmdk-gact {
  margin-left: auto;
  padding: var(--s-1) var(--s-2);
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--gold-700);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}

.cmdk-gact:hover {
  background: var(--gold-100);
}


/* ---------------------------------------------------------------------------
   6. Result row

   44px minimum at every width, not only on the phone: the same rule that makes
   a target reachable with a thumb makes it comfortable with a mouse.

   The highlight is a gold wash plus a rail down the left edge, so which row
   Enter will run stays obvious in a photograph, on a projector, and to anyone
   who cannot separate the wash from white.
   --------------------------------------------------------------------------- */

.cmdk-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: 44px;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background var(--t-fast),
    box-shadow var(--t-fast),
    transform var(--t-fast);
}

.cmdk-row:hover {
  background: var(--gray-50);
}

.cmdk-row.is-selected {
  background: var(--gold-a14);
  box-shadow: inset 3px 0 0 var(--gold-600);
}

.cmdk-row:active {
  transform: scale(.99);
}

.cmdk-row:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.cmdk-rico {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  background: var(--gray-100);
  color: var(--navy);
  transition: background var(--t-fast), color var(--t-fast);
}

.cmdk-rico .ic {
  width: 16px;
  height: 16px;
}

.cmdk-row.is-selected .cmdk-rico {
  background: var(--white);
  color: var(--gold-600);
}

.cmdk-row--alert .cmdk-rico {
  background: var(--red-100);
  color: var(--red-700);
}

.cmdk-rtxt {
  flex: 1 1 auto;
  min-width: 0;
}

.cmdk-rt {
  display: block;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cmdk-rs {
  display: block;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cmdk-rcode {
  flex: none;
  font-family: var(--f-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-600);
}

.cmdk-rhint {
  flex: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-500);
}

.cmdk-row.is-selected .cmdk-rcode,
.cmdk-row.is-selected .cmdk-rhint {
  color: var(--gold-700);
}


/* ---------------------------------------------------------------------------
   7. Empty and note states
   --------------------------------------------------------------------------- */

.cmdk-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-7) var(--s-5);
  text-align: center;
}

.cmdk-empty b {
  font-family: var(--f-disp);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.cmdk-eic {
  width: 24px;
  height: 24px;
  color: var(--gray-400);
}

.cmdk-enote {
  max-width: 34ch;
  font-size: 13px;
  color: var(--muted);
}

.cmdk-note {
  padding: var(--s-3) var(--s-3) var(--s-2);
  font-size: 12px;
  color: var(--muted);
}


/* ---------------------------------------------------------------------------
   8. Key legend
   --------------------------------------------------------------------------- */

.cmdk-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-2) var(--s-4);
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
  font-size: 12px;
  color: var(--muted);
}

.cmdk-fhints {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  min-width: 0;
  overflow: hidden;
}

.cmdk-fhint {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  white-space: nowrap;
}

.cmdk-ftxt {
  margin-left: var(--s-1);
}

.cmdk-fbrand {
  flex: none;
  font-family: var(--f-disp);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--gray-400);
}


/* ---------------------------------------------------------------------------
   9. Launchers

   .cmdk-launch rides on .icon-btn, so it inherits the shell's button look and
   only overrides what differs. The doubled class keeps it winning whatever
   order the sheets end up in.
   --------------------------------------------------------------------------- */

.cmdk-launch.icon-btn {
  gap: var(--s-2);
  color: var(--gray-600);
}

.cmdk-launch.icon-btn:hover {
  color: var(--ink);
}

.cmdk-launch-k {
  display: none;
  font-family: var(--f-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-500);
  white-space: nowrap;
}

/* Last resort entry point: shown only when no screen offered a home for the
   launcher, and only at phone widths, where Ctrl+K does not exist. Bottom
   left, clear of the bottom bar and of the screens that park a FAB bottom
   right. */
.cmdk-fab {
  position: fixed;
  left: var(--s-4);
  bottom: calc(var(--bottombar-h) + var(--safe-b) + var(--s-4));
  z-index: 45;
  display: none;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: var(--navy);
  color: var(--white);
  box-shadow: var(--sh-lg);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform var(--t-base), background var(--t-fast);
}

.cmdk-fab .ic {
  width: 20px;
  height: 20px;
}

.cmdk-fab:hover {
  background: var(--navy-800);
}

.cmdk-fab:active {
  transform: scale(.94);
}


/* ---------------------------------------------------------------------------
   10. Desktop only additions
   --------------------------------------------------------------------------- */

@media (min-width: 861px) {

  /* The shortcut chip turns the launcher from "another search box" into the
     one that opens the palette. */
  .cmdk-launch.icon-btn {
    width: auto;
    padding: 0 var(--s-3);
  }

  .cmdk-launch-k {
    display: inline-flex;
  }

  .cmdk-x-k {
    display: inline-flex;
  }

  /* The sidebar's own "Search Ctrl K" entry is always on screen here, so a
     second launcher in every topbar was a duplicate. Phones keep theirs. */
  .tb-tools .cmdk-launch.icon-btn {
    display: none;
  }

}


/* ---------------------------------------------------------------------------
   11. Phone: a full sheet from the top

   No floating card and no rounded corners: the sheet owns the viewport, the
   keyboard takes the bottom half, and the results scroll between them. The top
   padding is the notch, the bottom padding is the home indicator.
   --------------------------------------------------------------------------- */

@media (max-width: 860px) {

  .cmdk {
    align-items: stretch;
    padding: 0;
  }

  .cmdk-panel {
    max-width: none;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    transform: translateY(-16px);
    padding-top: var(--safe-t);
  }

  .cmdk.is-open .cmdk-panel {
    transform: translateY(0);
  }

  .cmdk-head {
    padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
  }

  /* Thumb sized: 44px of hit area for both head buttons. */
  .cmdk-clear {
    width: 44px;
    height: 44px;
  }

  .cmdk-input {
    min-height: 44px;
  }

  .cmdk-x {
    min-height: 44px;
    padding: 0 var(--s-3);
    color: var(--ink);
  }

  .cmdk-x-t {
    display: inline-flex;
  }

  .cmdk-x-k {
    display: none;
  }

  .cmdk-body {
    padding-bottom: calc(var(--s-6) + var(--safe-b));
  }

  .cmdk-row {
    min-height: 52px;
  }

  .cmdk-rt {
    font-size: 15px;
  }

  .cmdk-foot {
    display: none;
  }

  .cmdk-launch.icon-btn {
    width: 44px;
    height: 44px;
  }

  .cmdk-fab {
    display: inline-flex;
  }

}


/* ---------------------------------------------------------------------------
   12. Reduced motion

   base.css collapses the shared duration tokens and every animation, which
   already neutralises the panel and the scrim. Two things live outside that
   reach: the smooth scroller, which is a scroll behaviour rather than a
   transition, and the sweeping progress line, whose looping animation would
   otherwise be flattened into a stationary gold block.
   --------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {

  .cmdk-body {
    scroll-behavior: auto;
  }

  .cmdk-panel.is-busy .cmdk-bar::after {
    animation: none;
    width: 100%;
    transform: translateX(0);
    opacity: .35;
  }

}
