/* ============================================================================
 * WorkstreamSwitcher — CSS Module
 *
 * Maps to the WorkstreamSwitcher component in the PDS v2 prototype.
 * All colour / spacing / radius values use --pds-* CSS variables with
 * oklch fallbacks derived from the prototype's `c` and `t` objects.
 * ============================================================================ */

/* ------------------------------------------------------------------
 * Root wrapper — positions the dropdown relative to the trigger
 * ------------------------------------------------------------------ */
.root {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--pds-spacing-xs, 0.625rem);
  /* A long workstream name shrinks the trigger (ellipsis) instead of widening the header. */
  flex: 0 1 auto;
  min-width: 0;
  max-width: min(28rem, 40vw);
}

/* ------------------------------------------------------------------
 * Trigger button — shows current branch name in code font
 * Height matches --p1-size-lg (same as page selector pill), subtle border.
 * ------------------------------------------------------------------ */
.trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--pds-spacing-2xs, 0.5rem);
  height: var(--p1-size-lg, 2rem);
  padding: var(--pds-spacing-2xs, 0.5rem) 0.64rem;
  background: transparent;
  border: 1px solid var(--pds-color-border-input, oklch(0.8853 0 0));
  border-radius: var(--pds-border-radius-button, 3.5rem);
  font-family: var(--pds-typography-ff-default, 'Inter', sans-serif);
  font-size: var(--pds-typography-size-s, 0.875rem);
  font-weight: var(--pds-typography-fw-medium, 500);
  color: var(--pds-color-foreground-default, oklch(0.2046 0 0));
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  min-width: 0;
  max-width: 100%;
  transition: background 0.2s cubic-bezier(0.2, 0, 0, 1),
              border-color 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.trigger:hover,
.trigger[aria-expanded='true'] {
  background: oklch(0.96 0 0); /* bgSubtle */
  border-color: oklch(0.75 0 0); /* borderStrong */
}

.triggerOpen {
  background: oklch(0.96 0 0); /* bgSubtle */
  border-color: oklch(0.75 0 0); /* borderStrong */
}

.triggerLoading {
  opacity: 0.7;
  cursor: wait;
}

.triggerLoading:hover {
  background: transparent;
  border-color: oklch(0.96 0 0);
}

/* ------------------------------------------------------------------
 * Dropdown panel — portal-rendered, positioned with inline style
 * Width min 400px, elevation-overlay shadow, container border-radius.
 * ------------------------------------------------------------------ */
.dropdown {
  display: flex;
  flex-direction: column;
  background: var(--pds-color-surface-default, oklch(1 0 0));
  border: 1px solid oklch(0.96 0 0); /* borderSubtle */
  border-radius: var(--pds-border-radius-container, 0.375rem);
  box-shadow: var(
    --pds-elevation-overlay,
    0px 0px 0px 1px rgba(0, 0, 0, 0.08),
    0px 1px 1px 0px rgba(0, 0, 0, 0.02),
    0px 8px 16px -4px rgba(0, 0, 0, 0.04),
    0px 24px 32px -8px rgba(0, 0, 0, 0.06)
  );
  overflow: hidden;
  /* z-index and top/left/width are set via inline style from the portal effect */
}

/* ------------------------------------------------------------------
 * Header row — search input + close button
 * ------------------------------------------------------------------ */
.header {
  display: flex;
  align-items: center;
  padding: var(--pds-spacing-xs, 0.625rem);
  border-bottom: 1px solid oklch(0.96 0 0); /* borderSubtle */
  gap: 0.512rem;
  background: var(--pds-color-surface-default-secondary, oklch(0.9702 0 0));
}

/* ------------------------------------------------------------------
 * Search input
 * ------------------------------------------------------------------ */
.search {
  flex: 1;
  border: 1px solid var(--pds-color-border-input, oklch(0.8853 0 0));
  border-radius: var(--pds-border-radius-default, 0.188rem);
  outline: none;
  padding: 0.5rem 0.64rem;
  background: var(--pds-color-surface-default, oklch(1 0 0));
  font-family: var(--pds-typography-ff-default, 'Inter', sans-serif);
  font-size: var(--pds-typography-size-s, 0.875rem);
  color: var(--pds-color-foreground-default, oklch(0.2046 0 0));
  height: 2rem;
  line-height: 1;
  box-sizing: border-box;
  width: 100%;
}

.search::placeholder {
  color: oklch(0.65 0 0); /* fgSubtle */
}

.search:focus {
  border-color: var(--pds-color-interactive-focus, oklch(0.5558 0.2372 267.79));
  box-shadow: 0 0 0 2px oklch(0.5558 0.2372 267.79 / 0.15);
}

/* ------------------------------------------------------------------
 * Close button
 * ------------------------------------------------------------------ */
.closeButton {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--pds-color-foreground-default-secondary, oklch(0.5103 0 0));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  border-radius: var(--pds-border-radius-default, 0.188rem);
  flex-shrink: 0;
}

.closeButton:hover {
  background: oklch(0.96 0 0); /* bgSubtle */
}

/* ------------------------------------------------------------------
 * Scrollable list area
 * ------------------------------------------------------------------ */
.list {
  list-style: none;
  margin: 0;
  padding: 0.41rem;
  overflow-y: auto;
  max-height: 360px;
  flex: 1;
}

.item {
  display: flex;
}

/* Individual branch row button */
.branchButton {
  display: flex;
  align-items: center;
  gap: 0.64rem;
  width: 100%;
  text-align: left;
  padding: 0.512rem 0.64rem;
  background: transparent;
  border: none;
  border-radius: var(--pds-border-radius-default, 0.188rem);
  font-family: var(--pds-typography-ff-default, 'Inter', sans-serif);
  font-size: var(--pds-typography-size-s, 0.875rem);
  color: var(--pds-color-foreground-default, oklch(0.2046 0 0));
  cursor: pointer;
  transition: background 0.15s;
}

.branchButton:hover {
  background: var(--pds-color-surface-default-secondary, oklch(0.9702 0 0));
}

.branchButton[aria-selected='true'] {
  background: var(
    --pds-color-status-discovery-background,
    oklch(0.9635 0.022 312.19)
  );
}

/* "Live" StatusIndicator on the main branch row */
.liveIndicator :global(.pds-status-indicator__label) {
  font-weight: var(--pds-typography-fw-semibold, 600);
}

/* ------------------------------------------------------------------
 * Footer — New workstream / create form
 * ------------------------------------------------------------------ */
.footer {
  padding: 0.512rem 0.64rem;
  border-top: 1px solid oklch(0.96 0 0); /* borderSubtle */
  background: var(--pds-color-surface-default-secondary, oklch(0.9702 0 0));
  display: flex;
  align-items: center;
}

/* "New workstream" button — matches PageNavigator's .newButton style */
.newButton {
  display: inline-flex;
  align-items: center;
  gap: 0.41rem;
  cursor: pointer;
  background: transparent;
  border: 1px solid oklch(0.8853 0 0); /* btnSecondaryBorder */
  border-radius: var(--pds-border-radius-button, 3.5rem);
  padding: 0.5rem 0.625rem;
  font-family: var(--pds-typography-ff-default, 'Inter', sans-serif);
  font-size: var(--pds-typography-size-s, 0.875rem);
  font-weight: var(--pds-typography-fw-semibold, 600);
  color: var(--pds-color-foreground-default, oklch(0.2046 0 0));
  height: 2rem;
  line-height: 1;
  letter-spacing: 0.025em;
  transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.newButton:hover {
  background: var(--pds-color-surface-default-secondary, oklch(0.9702 0 0));
}

/* ------------------------------------------------------------------
 * Inline create form (replaces footer content when isCreating)
 * ------------------------------------------------------------------ */
.createForm {
  display: flex;
  flex-direction: column;
  gap: 0.41rem;
  width: 100%;
}

.createInput {
  flex: 1;
  border: 1px solid var(--pds-color-border-input, oklch(0.8853 0 0));
  border-radius: var(--pds-border-radius-default, 0.188rem);
  outline: none;
  padding: 0.375rem 0.5rem;
  background: var(--pds-color-surface-default, oklch(1 0 0));
  font-family: var(--pds-typography-ff-default, 'Inter', sans-serif);
  font-size: var(--pds-typography-size-s, 0.875rem);
  color: var(--pds-color-foreground-default, oklch(0.2046 0 0));
  width: 100%;
  box-sizing: border-box;
}

.createInput:focus {
  border-color: var(--pds-color-interactive-focus, oklch(0.5558 0.2372 267.79));
  box-shadow: 0 0 0 2px oklch(0.5558 0.2372 267.79 / 0.15);
}

.createActions {
  display: flex;
  gap: 0.41rem;
}

.createSubmit {
  flex: 1;
  padding: 0.375rem 0.5rem;
  background: var(--pds-color-interactive-default, oklch(0.5558 0.2372 267.79));
  color: oklch(1 0 0);
  border: none;
  border-radius: var(--pds-border-radius-button, 3.5rem);
  font-family: var(--pds-typography-ff-default, 'Inter', sans-serif);
  font-size: var(--pds-typography-size-s, 0.875rem);
  font-weight: var(--pds-typography-fw-semibold, 600);
  cursor: pointer;
}

.createSubmit:hover {
  background: var(--pds-color-interactive-hover, oklch(0.4558 0.2372 267.79));
}

.createCancel {
  padding: 0.375rem 0.5rem;
  background: transparent;
  border: 1px solid oklch(0.8853 0 0);
  border-radius: var(--pds-border-radius-button, 3.5rem);
  font-family: var(--pds-typography-ff-default, 'Inter', sans-serif);
  font-size: var(--pds-typography-size-s, 0.875rem);
  color: var(--pds-color-foreground-default, oklch(0.2046 0 0));
  cursor: pointer;
}

.createCancel:hover {
  background: var(--pds-color-surface-default-secondary, oklch(0.9702 0 0));
}

.createError {
  font-size: var(--pds-typography-size-xs, 0.75rem);
  color: var(--pds-color-status-critical-foreground, oklch(0.5274 0.2069 27.33));
}

/* ── Responsive label text ──────────────────────────────────────────── */
/* Wraps branch name + chevron in trigger; hidden on mobile for icon-only mode */

.labelText {
  display: inline-flex;
  align-items: center;
  gap: var(--pds-spacing-2xs, 0.5rem);
  min-width: 0;
}

/* The name gives way to the chevron, which stays visible. */
.labelName {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 767px) {
  .labelText {
    display: none;
  }

  .dropdown {
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .list {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .branchButton {
    width: max-content;
    min-width: 100%;
  }
}
