/* Command-K overlay (Sprint v5-11.5 foundation)
 * -------------------------------------------------------------------------
 * Locked spec: docs/octopus/v5_11_5_sprint_brief.md §"Part 3 — Command-K"
 *
 * Self-contained overlay component. Drop the assets into any page via:
 *   <link rel="stylesheet" href="/assets/cmdk.css">
 *   <script defer src="/assets/cmdk.js"></script>
 *
 * No HTML markup required — the JS injects the overlay nodes on first
 * activation. Activation: Cmd-K (macOS) / Ctrl-K (Win/Linux) or click
 * any element with `data-cmdk-trigger`.
 *
 * Live-token mapping — uses both legacy team-pages dark tokens (--bg-0,
 * --fg-primary, --accent-primary) and the mockup-bridge tokens. Falls
 * through to hardcoded dark defaults when neither is defined.
 */

/* ---------------------------------------------------------------------
 * Backdrop + scrim
 * --------------------------------------------------------------------- */

.cmdk-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9999;
  display: none;
  animation: cmdk-fade-in 140ms ease-out;
}

.cmdk-backdrop[aria-hidden="false"] {
  display: block;
}

@keyframes cmdk-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------------------------------------------------------------------
 * Dialog
 * --------------------------------------------------------------------- */

.cmdk-dialog {
  position: fixed;
  top: 18vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(620px, calc(100vw - 32px));
  max-height: 64vh;
  background: var(--bg-card, var(--card, #171b24));
  color: var(--fg-primary, var(--foreground, #f5f6fa));
  border: 1px solid var(--stroke-strong, rgba(255, 255, 255, 0.14));
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  z-index: 10000;
  font-family: var(--font-body, "Inter", system-ui, sans-serif);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: cmdk-slide-in 180ms ease-out;
}

.cmdk-dialog[aria-hidden="false"] {
  display: flex;
}

@keyframes cmdk-slide-in {
  from { opacity: 0; transform: translate(-50%, -12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------------------------------------------------------------------
 * Input
 * --------------------------------------------------------------------- */

.cmdk-input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--stroke-default, rgba(255, 255, 255, 0.08));
}

.cmdk-input-icon {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  color: var(--fg-muted, var(--muted-foreground, #8a90a1));
  fill: currentColor;
}

.cmdk-input {
  flex: 1;
  border: 0;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 17px;
  font-weight: 400;
  line-height: 1.3;
  padding: 4px 0;
  outline: none;
}

.cmdk-input::placeholder {
  color: var(--fg-muted, #8a90a1);
}

.cmdk-shortcut {
  flex: 0 0 auto;
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--fg-muted, #8a90a1);
  padding: 3px 7px;
  background: color-mix(in srgb, var(--fg-primary, #f5f6fa) 6%, transparent);
  border: 1px solid var(--stroke-default, rgba(255, 255, 255, 0.12));
  border-radius: 4px;
}

/* ---------------------------------------------------------------------
 * Results
 * --------------------------------------------------------------------- */

.cmdk-results {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}

.cmdk-results:empty::before {
  content: "Start typing to search teams, players, editions…";
  display: block;
  padding: 24px 22px;
  color: var(--fg-muted, #8a90a1);
  font-size: 14px;
  font-style: italic;
}

.cmdk-group {
  padding: 4px 0;
}

.cmdk-group__label {
  padding: 8px 18px 6px;
  font-family: var(--font-body, "Inter", system-ui, sans-serif);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: none;
  color: var(--fg-muted, #8a90a1);
}

.cmdk-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background-color 80ms ease, border-color 80ms ease;
  color: inherit;
  text-decoration: none;
}

.cmdk-item:hover,
.cmdk-item[aria-selected="true"] {
  background: color-mix(
    in srgb,
    var(--accent-primary, var(--gold, #c5b358)) 10%,
    transparent
  );
  border-left-color: var(--accent-primary, var(--gold, #c5b358));
}

.cmdk-item__title {
  flex: 1 1 auto;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--fg-primary, var(--foreground, #f5f6fa));
}

.cmdk-item__subtitle {
  flex: 0 0 auto;
  font-size: 12px;
  font-family: var(--font-body, "Inter", system-ui, sans-serif);
  color: var(--fg-muted, #8a90a1);
  letter-spacing: 0.01em;
  text-align: right;
}

/* Kind badge — small chip on each item */
.cmdk-item__kind {
  flex: 0 0 auto;
  font-family: var(--font-body, "Inter", system-ui, sans-serif);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: none;
  padding: 2px 7px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent-primary, #c5b358) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent-primary, #c5b358) 24%, transparent);
  color: var(--fg-secondary, var(--foreground, #c6cad6));
  margin-right: 4px;
}

/* Kind-specific accents — match the citation badge palette */
.cmdk-item__kind--profile { color: #f0c674; border-color: rgba(240, 198, 116, 0.4); }
.cmdk-item__kind--team    { color: #87b3d4; border-color: rgba(135, 179, 212, 0.4); }
.cmdk-item__kind--player  { color: #b5cea8; border-color: rgba(181, 206, 168, 0.4); }
.cmdk-item__kind--edition { color: #d7ba7d; border-color: rgba(215, 186, 125, 0.4); }
.cmdk-item__kind--mailbag { color: #ce9178; border-color: rgba(206, 145, 120, 0.4); }
.cmdk-item__kind--conference { color: #c586c0; border-color: rgba(197, 134, 192, 0.4); }
.cmdk-item__kind--methodology { color: #9cdcfe; border-color: rgba(156, 220, 254, 0.4); }

/* ---------------------------------------------------------------------
 * Empty state — when search yields zero results
 * --------------------------------------------------------------------- */

.cmdk-empty {
  padding: 32px 22px;
  text-align: center;
  color: var(--fg-muted, #8a90a1);
  font-size: 14px;
}

.cmdk-empty__hint {
  font-size: 12px;
  margin-top: 4px;
  opacity: 0.7;
}

/* ---------------------------------------------------------------------
 * Footer — keyboard hints
 * --------------------------------------------------------------------- */

.cmdk-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  border-top: 1px solid var(--stroke-default, rgba(255, 255, 255, 0.08));
  font-size: 11px;
  color: var(--fg-muted, #8a90a1);
  font-family: var(--font-body, "Inter", system-ui, sans-serif);
}

.cmdk-footer__key {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-weight: 600;
  padding: 2px 6px;
  background: color-mix(in srgb, var(--fg-primary, #f5f6fa) 5%, transparent);
  border: 1px solid var(--stroke-default, rgba(255, 255, 255, 0.1));
  border-radius: 3px;
  margin-right: 6px;
  color: var(--fg-secondary, #c6cad6);
}

/* ---------------------------------------------------------------------
 * Mobile — drop the floating dialog, use a bottom sheet
 * --------------------------------------------------------------------- */

@media (max-width: 640px) {
  .cmdk-dialog {
    top: auto;
    bottom: 0;
    left: 0;
    transform: none;
    width: 100vw;
    max-height: 85vh;
    border-radius: 12px 12px 0 0;
    animation: cmdk-slide-up 200ms ease-out;
  }
  @keyframes cmdk-slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .cmdk-shortcut { display: none; }
}

/* ---------------------------------------------------------------------
 * Trigger button — opt-in for sites that want a visible affordance
 * (mobile/Cmd-K hint). Markup: <button class="cmdk-trigger">⌘K</button>
 * --------------------------------------------------------------------- */

.cmdk-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-card, var(--card, #12151d));
  color: var(--fg-muted, #8a90a1);
  border: 1px solid var(--stroke-default, rgba(255, 255, 255, 0.1));
  border-radius: 6px;
  font-family: var(--font-body, "Inter", system-ui, sans-serif);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease;
}

.cmdk-trigger:hover,
.cmdk-trigger:focus-visible {
  color: var(--fg-primary, #f5f6fa);
  border-color: var(--accent-primary, #c5b358);
  outline: none;
}

.cmdk-trigger__shortcut {
  font-family: var(--font-mono, "JetBrains Mono", monospace);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 5px;
  background: color-mix(in srgb, var(--fg-primary, #f5f6fa) 6%, transparent);
  border: 1px solid var(--stroke-default, rgba(255, 255, 255, 0.1));
  border-radius: 3px;
  color: var(--fg-muted, #8a90a1);
}

/* ---------------------------------------------------------------------
 * Reduced-motion: kill animations
 * --------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .cmdk-backdrop,
  .cmdk-dialog {
    animation: none;
  }
}
