/* controls.css — the low-level UI primitives Prism components are assembled from.
 *
 * A grid toolbar button, a chart legend toggle and a filter popover are the same
 * control wearing different labels. They live here so components inherit them
 * instead of each inventing a slightly different button.
 *
 * SCOPING. Every selector is a `.prism-*` class. Nothing here styles a bare
 * element selector, so dropping this file into an app cannot restyle that app's
 * own buttons and inputs. Requires tokens.css.
 */

/* Box-sizing is applied to Prism's own subtree only — never globally. A library
 * that resets the host page's box model is a library that gets removed. */
[data-prism-component],
[data-prism-component] *,
[data-prism-component] *::before,
[data-prism-component] *::after {
  box-sizing: border-box;
}

[data-prism-component] {
  font-family: var(--prism-font-sans);
  font-size: var(--prism-text-md);
  line-height: var(--prism-leading-normal);
  color: var(--prism-ink-primary);
}

/* ---------------------------------------------------------------- *
 * Focus
 * One ring, everywhere. :focus-visible only, so a mouse click never
 * paints a ring but a keyboard tab always does.
 * ---------------------------------------------------------------- */

.prism-focusable:focus-visible,
[data-prism-component] :focus-visible {
  outline: var(--prism-focus-ring-width) solid var(--prism-focus-ring);
  outline-offset: var(--prism-focus-ring-offset);
  border-radius: var(--prism-radius-sm);
}

/* ---------------------------------------------------------------- *
 * Screen-reader-only text
 * ---------------------------------------------------------------- */

.prism-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------- *
 * Button
 * ---------------------------------------------------------------- */

.prism-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--prism-space-2);
  height: var(--prism-control-height-md);
  padding: 0 var(--prism-control-padding-x);
  border: 1px solid var(--prism-border-strong);
  border-radius: var(--prism-radius-md);
  background: var(--prism-surface-1);
  color: var(--prism-ink-primary);
  font: inherit;
  font-weight: var(--prism-weight-medium);
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color var(--prism-duration-fast) var(--prism-ease),
    border-color var(--prism-duration-fast) var(--prism-ease);
}

.prism-button:hover:not(:disabled) {
  background: var(--prism-surface-2);
}

.prism-button:active:not(:disabled) {
  background: var(--prism-surface-active);
}

.prism-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.prism-button--primary {
  background: var(--prism-accent);
  border-color: var(--prism-accent);
  color: var(--prism-ink-on-accent);
}

.prism-button--primary:hover:not(:disabled) {
  background: var(--prism-accent-hover);
  border-color: var(--prism-accent-hover);
}

/* Toolbar/icon buttons: no chrome until interacted with, so a row of them
 * does not out-shout the data they sit above. */
.prism-button--ghost {
  border-color: transparent;
  background: transparent;
}

.prism-button--ghost:hover:not(:disabled) {
  background: var(--prism-surface-hover);
}

.prism-button--icon {
  width: var(--prism-control-height-md);
  padding: 0;
}

.prism-button--sm {
  height: var(--prism-control-height-sm);
  padding: 0 var(--prism-space-3);
  font-size: var(--prism-text-sm);
}

.prism-button[aria-pressed="true"] {
  background: var(--prism-accent-subtle);
  border-color: var(--prism-accent);
}

/* ---------------------------------------------------------------- *
 * Text input / select
 * ---------------------------------------------------------------- */

.prism-input,
.prism-select {
  height: var(--prism-control-height-md);
  padding: 0 var(--prism-space-3);
  border: 1px solid var(--prism-border-strong);
  border-radius: var(--prism-radius-md);
  background: var(--prism-surface-1);
  color: var(--prism-ink-primary);
  font: inherit;
  min-width: 0;
}

.prism-input::placeholder {
  color: var(--prism-ink-muted);
}

.prism-input:focus,
.prism-select:focus {
  border-color: var(--prism-accent);
}

.prism-input:disabled,
.prism-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.prism-input--sm,
.prism-select--sm {
  height: var(--prism-control-height-sm);
  font-size: var(--prism-text-sm);
}

/* ---------------------------------------------------------------- *
 * Checkbox
 * The native control, resized and tinted. Custom checkboxes lose
 * indeterminate state and forced-colors support for no real gain.
 * ---------------------------------------------------------------- */

.prism-checkbox {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--prism-accent);
  cursor: pointer;
  flex: none;
}

/* ---------------------------------------------------------------- *
 * Menu / popover
 * ---------------------------------------------------------------- */

.prism-menu {
  position: absolute;
  z-index: var(--prism-z-dropdown);
  min-width: 180px;
  padding: var(--prism-space-2);
  border: 1px solid var(--prism-border);
  border-radius: var(--prism-radius-lg);
  background: var(--prism-surface-1);
  box-shadow: var(--prism-shadow-2);
}

.prism-menu__item {
  display: flex;
  align-items: center;
  gap: var(--prism-space-3);
  width: 100%;
  padding: var(--prism-space-2) var(--prism-space-3);
  border: 0;
  border-radius: var(--prism-radius-sm);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.prism-menu__item:hover,
.prism-menu__item:focus-visible {
  background: var(--prism-surface-hover);
}

.prism-menu__item[aria-disabled="true"] {
  color: var(--prism-ink-muted);
  cursor: not-allowed;
}

.prism-menu__separator {
  height: 1px;
  margin: var(--prism-space-2) 0;
  background: var(--prism-border-hairline);
  border: 0;
}

/* ---------------------------------------------------------------- *
 * Badge / tag
 * ---------------------------------------------------------------- */

.prism-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--prism-space-2);
  padding: 1px var(--prism-space-3);
  border-radius: var(--prism-radius-pill);
  background: var(--prism-surface-2);
  color: var(--prism-ink-secondary);
  font-size: var(--prism-text-sm);
  font-weight: var(--prism-weight-medium);
  white-space: nowrap;
}

/* Status badges pair a colour with a dot AND keep their label — colour never
 * carries the meaning on its own. */
.prism-badge--good { color: var(--prism-status-good); }
.prism-badge--warning { color: var(--prism-status-warning); }
.prism-badge--serious { color: var(--prism-status-serious); }
.prism-badge--critical { color: var(--prism-status-critical); }

.prism-badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

/* ---------------------------------------------------------------- *
 * Toolbar — the strip a component puts its controls in
 * ---------------------------------------------------------------- */

.prism-toolbar {
  display: flex;
  align-items: center;
  gap: var(--prism-space-3);
  padding: var(--prism-space-3);
  background: var(--prism-surface-2);
  border-bottom: 1px solid var(--prism-border);
}

.prism-toolbar__spacer {
  flex: 1 1 auto;
}

/* ---------------------------------------------------------------- *
 * States — empty, loading, error
 * Every component that loads data shows all three. Defining them once
 * is what stops each component inventing its own empty state.
 * ---------------------------------------------------------------- */

.prism-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--prism-space-3);
  padding: var(--prism-space-8) var(--prism-space-5);
  text-align: center;
  color: var(--prism-ink-secondary);
}

.prism-state__title {
  font-size: var(--prism-text-lg);
  font-weight: var(--prism-weight-medium);
  color: var(--prism-ink-primary);
}

.prism-state__detail {
  max-width: 42ch;
  color: var(--prism-ink-muted);
}

.prism-state--error .prism-state__title {
  color: var(--prism-status-critical);
}

.prism-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--prism-border-strong);
  border-top-color: var(--prism-accent);
  border-radius: 50%;
  animation: prism-spin 700ms linear infinite;
}

@keyframes prism-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .prism-spinner {
    animation-duration: 2s;
  }
}

/* ---------------------------------------------------------------- *
 * Forced colours (Windows high contrast)
 * Token colours are dropped by the OS here, so the pieces that were
 * carrying meaning through colour need a system colour instead.
 * ---------------------------------------------------------------- */

@media (forced-colors: active) {
  .prism-button,
  .prism-input,
  .prism-select,
  .prism-menu {
    border-color: ButtonBorder;
  }
  .prism-button[aria-pressed="true"] {
    background: Highlight;
    color: HighlightText;
  }
  .prism-badge__dot {
    outline: 1px solid CanvasText;
  }
}
