/* ==========================================================================
   Covio JSR — UI primitives.

   Every value here is a token from tokens.css. Each component carries a header
   naming the states it supports; if a state is not listed, it is not styled,
   and adding one means adding it here rather than in a view.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Base — reset and document defaults.
   -------------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--covio-light);
  color: var(--covio-ink);
  font-family: var(--ff-ui);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 {
  margin: 0;
  font-family: var(--ff-display);
  font-weight: 600;
  letter-spacing: -.015em;
}

h1 {
  font-size: var(--fs-page-title);
  line-height: var(--lh-page-title);
}

h2 {
  font-size: var(--fs-section-title);
  line-height: var(--lh-section-title);
}

p {
  margin: 0;
}

a {
  color: var(--covio-teal-link);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--motion-micro) var(--ease);
}

a:hover {
  color: var(--covio-ink);
}

img,
svg {
  max-width: 100%;
}

/* One focus treatment for the whole app. Keyboard users must always be able to
   see where they are; :focus-visible keeps it off mouse clicks. */
:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-radius: var(--radius-input);
}

.is-on-dark :focus-visible {
  outline: var(--focus-ring-dark);
}

/* Visible only to screen readers, and to keyboard users when focused. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  border-radius: var(--radius-input);
  transform: translateY(-200%);
  transition: transform var(--motion-micro) var(--ease);
}

.skip-link:focus {
  transform: translateY(0);
}

/* --------------------------------------------------------------------------
   .eyebrow — a mono label above a title.
   States: default · on dark (.eyebrow--dark, teal) · with a leading pip.
   -------------------------------------------------------------------------- */

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0;
  font-family: var(--ff-mono);
  font-size: var(--fs-mono);
  line-height: var(--lh-mono);
  font-weight: 500;
  letter-spacing: var(--ls-mono);
  text-transform: uppercase;
  color: var(--muted-ink);
}

.eyebrow--dark {
  color: var(--covio-teal);
}

.eyebrow .pip {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* Mono, wide-tracked and upper — for eyebrows, table headers and short codes,
   where the letterforms are the label. */
.mono {
  font-family: var(--ff-mono);
  font-size: var(--fs-mono);
  line-height: var(--lh-mono);
  letter-spacing: var(--ls-mono);
  text-transform: uppercase;
}

/* Mono for a value that is data rather than a label: an email address, a
   username, a panel key, a timestamp. Tight tracking so a long string still
   fits a dense row, and no uppercasing — an address shown in capitals is a
   different string from the one the person types. */
.mono-value {
  font-family: var(--ff-mono);
  font-size: var(--fs-mono);
  line-height: var(--lh-mono);
  letter-spacing: .02em;
}

.text-secondary {
  font-size: var(--fs-secondary);
  line-height: var(--lh-secondary);
  color: var(--muted-ink);
}

.text-caption {
  font-size: var(--fs-caption);
  line-height: var(--lh-caption);
  color: var(--muted-ink);
}

/* --------------------------------------------------------------------------
   .btn — primary · secondary · ghost · danger.
   States: idle · hover · active · focus · pending (spinner keeps the label) ·
   disabled. Every variant is at least 44px tall.
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--hit);
  padding: var(--space-3) var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-input);
  font-family: var(--ff-ui);
  font-size: var(--fs-body);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color var(--motion-micro) var(--ease),
    border-color var(--motion-micro) var(--ease),
    color var(--motion-micro) var(--ease);
}

.btn--block {
  width: 100%;
}

.btn--primary {
  background: var(--covio-ink);
  color: var(--covio-paper);
}

.btn--primary:hover {
  background: #1C2F55;
}

.btn--secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--covio-ink);
}

.btn--secondary:hover {
  border-color: var(--covio-teal-link);
  color: var(--covio-teal-link);
}

.btn--ghost {
  background: transparent;
  color: var(--covio-ink);
}

.btn--ghost:hover {
  background: var(--pill-neutral-fill);
}

.btn--danger {
  background: var(--danger-ink);
  color: #FFFFFF;
}

.btn--danger:hover {
  background: #9A2F33;
}

/* Disabled is a flat neutral, not the enabled fill turned translucent: a washed
   out primary button reads as broken, where this reads as "not yet". */
.btn:disabled,
.btn[aria-disabled='true'],
.btn:disabled:hover,
.btn[aria-disabled='true']:hover {
  background: var(--pill-neutral-fill);
  border-color: transparent;
  color: rgba(19, 32, 58, .38);
  cursor: not-allowed;
}

/* Pending keeps the label in place and adds a spinner, so the button does not
   change width and the operator can still read what they asked for. */
.btn[data-pending='true'] {
  pointer-events: none;
  opacity: .8;
}

.btn[data-pending='true'] .btn__spinner {
  display: inline-block;
}

.btn__spinner {
  display: none;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: covio-spin 700ms linear infinite;
}

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

/* --------------------------------------------------------------------------
   .field — label ABOVE the input, optional help text, error text, and a slot
   for a leading or trailing icon or button.
   States: default · focus-within · invalid (.field--invalid) · disabled.
   A placeholder is never the label.
   -------------------------------------------------------------------------- */

.field {
  display: block;
  margin: 0 0 var(--space-4);
}

.field__label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--fs-secondary);
  line-height: var(--lh-secondary);
  font-weight: 600;
  color: var(--covio-ink);
}

.field__control {
  position: relative;
  display: flex;
  align-items: center;
}

.field__help {
  margin-top: var(--space-2);
  font-size: var(--fs-caption);
  line-height: var(--lh-caption);
  color: var(--muted-ink);
}

.field__error {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  font-size: var(--fs-caption);
  line-height: var(--lh-caption);
  font-weight: 500;
  color: var(--danger-ink);
}

.field__error:empty {
  display: none;
}

/* A trailing control inside the input: the password reveal button. It is a
   real button, so it keeps its own 44px hit area. */
.field__trailing {
  position: absolute;
  right: var(--space-1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--hit);
  min-height: var(--hit);
  padding: 0 var(--space-2);
  background: none;
  border: 0;
  border-radius: var(--radius-input);
  font-family: var(--ff-mono);
  font-size: var(--fs-mono);
  letter-spacing: var(--ls-mono);
  text-transform: uppercase;
  color: var(--muted-ink);
  cursor: pointer;
  transition: color var(--motion-micro) var(--ease);
}

.field__trailing:hover {
  color: var(--covio-teal-link);
}

.field:has(.field__trailing) .input {
  padding-right: 72px;
}

/* --------------------------------------------------------------------------
   .input / .select — text, email, password, select.
   States: idle · hover · focus · invalid (aria-invalid) · disabled · readonly.
   -------------------------------------------------------------------------- */

.input,
.select {
  width: 100%;
  min-height: var(--hit);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-input);
  font-family: var(--ff-ui);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--covio-ink);
  transition:
    border-color var(--motion-micro) var(--ease),
    box-shadow var(--motion-micro) var(--ease);
}

.input::placeholder {
  color: rgba(19, 32, 58, .38);
}

.input:hover,
.select:hover {
  border-color: rgba(19, 32, 58, .28);
}

/* The outline is the focus ring. Recolouring the border as well draws two
   concentric teal rings, which reads as an error state rather than as focus. */
.input:focus,
.select:focus {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.input[aria-invalid='true'] {
  border-color: var(--danger-ink);
}

.input:disabled,
.select:disabled {
  background: var(--covio-light);
  color: var(--muted-ink);
  cursor: not-allowed;
}

/* Usernames, codes and timestamps read as data, not prose. */
.input--mono {
  font-family: var(--ff-mono);
  letter-spacing: .04em;
}

/* --------------------------------------------------------------------------
   .checkbox — a real input with a drawn box.
   States: unchecked · checked · focus · disabled.
   -------------------------------------------------------------------------- */

.checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--hit);
  cursor: pointer;
  user-select: none;
}

.checkbox input {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--covio-teal-deep);
  cursor: pointer;
}

.checkbox span {
  font-size: var(--fs-secondary);
  line-height: var(--lh-secondary);
  color: var(--covio-ink);
}

/* --------------------------------------------------------------------------
   .switch — an on/off control for a setting that applies immediately.
   States: off · on · focus · disabled.
   -------------------------------------------------------------------------- */

.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--hit);
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch__track {
  position: relative;
  width: 40px;
  height: 22px;
  background: rgba(19, 32, 58, .18);
  border-radius: var(--radius-pill);
  transition: background-color var(--motion-standard) var(--ease);
}

.switch__track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: var(--surface);
  border-radius: 50%;
  transition: transform var(--motion-standard) var(--ease);
}

.switch input:checked + .switch__track {
  background: var(--covio-teal-deep);
}

.switch input:checked + .switch__track::after {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch__track {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.switch input:disabled + .switch__track {
  opacity: .45;
}

/* --------------------------------------------------------------------------
   .card — the work surface. A border, never a shadow: shadows mean "floating".
   States: default · .card--flush (no padding, for a table).
   -------------------------------------------------------------------------- */

.card {
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

.card--flush {
  padding: 0;
  overflow: hidden;
}

.card__title {
  margin-bottom: var(--space-2);
}

.card__lede {
  margin-bottom: var(--space-5);
  color: var(--muted-ink);
  font-size: var(--fs-secondary);
  line-height: var(--lh-secondary);
}

/* --------------------------------------------------------------------------
   .pill — a status in one word.
   Variants: active/approved · inactive/locked · pending · neutral · info,
   plus .pill--role for a role name. The fill and ink pairs are fixed.
   -------------------------------------------------------------------------- */

/* A pill is sometimes a link. It still has to read as a pill, not as prose. */
a.pill {
  text-decoration: none;
  transition: background-color var(--motion-micro) var(--ease), color var(--motion-micro) var(--ease);
}

a.pill:hover {
  background: rgba(19, 32, 58, .14);
  color: var(--covio-ink);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--fs-caption);
  line-height: var(--lh-caption);
  font-weight: 600;
  white-space: nowrap;
}

.pill--active {
  background: var(--pill-active-fill);
  color: var(--pill-active-ink);
}

.pill--inactive {
  background: var(--pill-inactive-fill);
  color: var(--pill-inactive-ink);
}

.pill--pending {
  background: var(--pill-pending-fill);
  color: var(--pill-pending-ink);
}

.pill--neutral {
  background: var(--pill-neutral-fill);
  color: var(--pill-neutral-ink);
}

.pill--info {
  background: var(--pill-info-fill);
  color: var(--pill-info-ink);
}

/* A role is a name, not a status: mono, so it reads as an assigned value. */
.pill--role {
  background: var(--pill-neutral-fill);
  color: var(--covio-ink);
  font-family: var(--ff-mono);
  font-size: var(--fs-mono);
  letter-spacing: .08em;
  font-weight: 500;
}

/* --------------------------------------------------------------------------
   .notice — a message about the page or the last action.
   Variants: info · success · warning · danger. Each carries an icon.
   The danger variant is what a failed sign-in shows.
   -------------------------------------------------------------------------- */

.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-input);
  font-size: var(--fs-secondary);
  line-height: var(--lh-secondary);
}

.notice__icon {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.notice--info {
  background: var(--pill-info-fill);
  border-color: rgba(62, 139, 255, .24);
  color: var(--info-ink);
}

.notice--success {
  background: var(--pill-active-fill);
  border-color: rgba(20, 184, 160, .24);
  color: var(--success-ink);
}

.notice--warning {
  background: var(--pill-pending-fill);
  border-color: rgba(245, 165, 36, .28);
  color: var(--warning-ink);
}

.notice--danger {
  background: var(--pill-inactive-fill);
  border-color: rgba(229, 72, 77, .24);
  color: var(--danger-ink);
}

/* --------------------------------------------------------------------------
   .table — dense, 44px rows, sticky mono header, no zebra, hover row,
   numbers right-aligned (.is-numeric).
   States: default · hover row · .is-selected.
   -------------------------------------------------------------------------- */

.table-scroll {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-secondary);
  line-height: var(--lh-secondary);
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: var(--space-3) var(--space-4);
  background: var(--covio-light);
  border-bottom: 1px solid var(--line);
  font-family: var(--ff-mono);
  font-size: var(--fs-mono);
  line-height: var(--lh-mono);
  font-weight: 500;
  letter-spacing: var(--ls-mono);
  text-transform: uppercase;
  text-align: left;
  color: var(--muted-ink);
  white-space: nowrap;
}

.table tbody td {
  height: var(--hit);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.table tbody tr {
  transition: background-color var(--motion-micro) var(--ease);
}

.table tbody tr:hover {
  background: rgba(19, 32, 58, .03);
}

.table tbody tr.is-selected {
  background: var(--pill-active-fill);
}

.table .is-numeric {
  text-align: right;
  font-family: var(--ff-mono);
  font-size: var(--fs-mono);
  letter-spacing: .04em;
}

/* --------------------------------------------------------------------------
   .skeleton — the shape of content that has not arrived.
   States: default (shimmering) · still, under reduced motion.
   -------------------------------------------------------------------------- */

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(19, 32, 58, .06) 25%,
    rgba(19, 32, 58, .11) 37%,
    rgba(19, 32, 58, .06) 63%
  );
  background-size: 400% 100%;
  border-radius: var(--radius-input);
  animation: covio-shimmer 1400ms ease-in-out infinite;
}

@keyframes covio-shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

/* --------------------------------------------------------------------------
   .empty-state — an icon, one factual sentence, one action.
   States: default. Never apologetic, never a shrug.
   -------------------------------------------------------------------------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-7) var(--space-5);
  text-align: center;
}

.empty-state__icon {
  width: 40px;
  height: 40px;
  color: var(--muted-ink);
}

.empty-state__text {
  max-width: 42ch;
  color: var(--muted-ink);
  font-size: var(--fs-secondary);
  line-height: var(--lh-secondary);
}

/* --------------------------------------------------------------------------
   .toast — transient confirmation, top-right, at most three at a time.
   States: enter · resting · leaving. Success and info dismiss themselves after
   4.5s; errors stay until dismissed, because an error the operator did not
   read is an error that did not happen.
   -------------------------------------------------------------------------- */

.toast-stack {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(360px, calc(100vw - var(--space-6)));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--muted-ink);
  border-radius: var(--radius-input);
  box-shadow: var(--shadow-overlay);
  font-size: var(--fs-secondary);
  line-height: var(--lh-secondary);
  pointer-events: auto;
  animation: covio-toast-in var(--motion-overlay) var(--ease);
}

.toast--success {
  border-left-color: var(--success-ink);
}

.toast--danger {
  border-left-color: var(--danger-ink);
}

.toast--warning {
  border-left-color: var(--warning-ink);
}

.toast--info {
  border-left-color: var(--info-ink);
}

.toast.is-leaving {
  animation: covio-toast-out var(--motion-standard) var(--ease) forwards;
}

.toast__body {
  flex: 1 1 auto;
}

.toast__close {
  flex: 0 0 auto;
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: var(--radius-input);
  color: var(--muted-ink);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.toast__close:hover {
  color: var(--covio-ink);
}

@keyframes covio-toast-in {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
}

@keyframes covio-toast-out {
  to {
    opacity: 0;
    transform: translateX(12px);
  }
}

/* --------------------------------------------------------------------------
   .drawer — a 440px panel from the right for editing one thing.
   States: closed · open. Traps focus, closes on Esc, and returns focus to
   whatever opened it.
   -------------------------------------------------------------------------- */

.drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
}

.drawer[open],
.drawer.is-open {
  display: block;
}

.drawer__scrim {
  position: absolute;
  inset: 0;
  background: rgba(7, 12, 22, .48);
  animation: covio-fade-in var(--motion-overlay) var(--ease);
}

.drawer__panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: min(440px, 100vw);
  background: var(--surface);
  box-shadow: var(--shadow-overlay);
  animation: covio-slide-in var(--motion-overlay) var(--ease);
}

.drawer__head,
.drawer__foot {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
}

.drawer__head {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.drawer__foot {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}

.drawer__body {
  flex: 1 1 auto;
  padding: var(--space-5);
  overflow-y: auto;
}

@keyframes covio-slide-in {
  from {
    transform: translateX(100%);
  }
}

/* --------------------------------------------------------------------------
   .modal — a decision that cannot be taken elsewhere.
   States: closed · open · typed-confirm (the action stays disabled until the
   operator types the exact word, for anything destructive).
   -------------------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal.is-open {
  display: flex;
}

.modal__scrim {
  position: absolute;
  inset: 0;
  background: rgba(7, 12, 22, .48);
  animation: covio-fade-in var(--motion-overlay) var(--ease);
}

.modal__panel {
  position: relative;
  width: min(480px, 100%);
  padding: var(--space-5);
  background: var(--surface);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow-overlay);
  animation: covio-rise var(--motion-overlay) var(--ease);
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

@keyframes covio-fade-in {
  from {
    opacity: 0;
  }
}

@keyframes covio-rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* --------------------------------------------------------------------------
   .avatar — initials in a teal ring. No photographs in the pilot.
   States: default · .avatar--dark, on a brand surface.
   -------------------------------------------------------------------------- */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--covio-teal-deep);
  border-radius: 50%;
  background: var(--pill-active-fill);
  font-family: var(--ff-mono);
  font-size: var(--fs-mono);
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--success-ink);
}

.avatar--dark {
  border-color: var(--covio-teal);
  background: rgba(63, 224, 197, .12);
  color: var(--covio-teal);
}

/* --------------------------------------------------------------------------
   .pill-list — pills as a list, so they read as a set to a screen reader.
   States: default.
   -------------------------------------------------------------------------- */

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-3) 0 0;
  padding: 0;
  list-style: none;
}

/* --------------------------------------------------------------------------
   .person-list — people, each as an avatar and a name.
   States: default.
   -------------------------------------------------------------------------- */

.person-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: var(--space-3) 0 var(--space-5);
  padding: 0;
  list-style: none;
}

.person {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--fs-secondary);
  line-height: var(--lh-secondary);
  font-weight: 500;
}
