/* Reset, typography, controls and scroll affordance. */

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

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--color-void);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.45;
  letter-spacing: var(--tracking-tight);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

h1,
h2,
h3,
h4,
p,
figure {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 1px;
}

/* --------------------------------------------------------------- utility */

.label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.muted {
  color: var(--color-text-secondary);
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------------------ access gate */

/* Covers the page until the session has been restored. Opaque and on top of
   everything, so nothing behind it is ever briefly readable. */
.gate {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  background: var(--color-surface-base);
}

.gate__mark {
  width: 44px;
  height: 44px;
  display: block;
}

.gate__text {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* ----------------------------------------------------------------- brand */

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--control-height-lg);
  padding-right: var(--space-4);
  background: var(--color-surface-overlay);
  border: 1px solid var(--color-border);
  text-decoration: none;
  color: inherit;
}

/* The mark carries its own plate, so it sits flush against the border and
   reads as the left edge of the lockup rather than a pasted-on square. */
.brand__mark {
  width: var(--control-height-lg);
  height: var(--control-height-lg);
  display: block;
  flex: none;
}

.brand__text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  min-width: 0;
}

.brand__name {
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.1;
  color: var(--color-text);
}

.brand__product {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  line-height: 1.1;
  color: var(--color-text-muted);
}

a.brand:hover {
  border-color: var(--color-accent-line);
}

/* -------------------------------------------------------------- surfaces */

.panel {
  background: var(--color-surface-overlay);
  border: 1px solid var(--color-border);
  color: var(--color-text);
}

.panel__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--control-height-lg);
  flex: none;
  padding-inline: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  overflow: hidden;
}

/* A quiet brand cue on dialog headers — the mark, not a second wordmark. */
.panel__brand {
  width: 20px;
  height: 20px;
  flex: none;
  display: block;
}

.panel__title {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.panel__body {
  padding: var(--space-4);
}

.panel__spacer {
  margin-left: auto;
}

/* -------------------------------------------------------------- controls */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-0);
  background: var(--color-surface-raised);
  color: var(--color-text);
  font-size: var(--text-md);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--motion-fast) var(--motion-ease),
    border-color var(--motion-fast) var(--motion-ease), color var(--motion-fast) var(--motion-ease);
}

.btn:hover:not(:disabled) {
  background: var(--color-surface-hover);
  border-color: var(--color-accent-line);
}

.btn:active:not(:disabled) {
  background: var(--color-surface-active);
}

.btn:disabled {
  color: var(--color-text-muted);
  border-color: var(--color-border-faint);
  cursor: not-allowed;
}

.btn--primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
  min-height: var(--control-height-lg);
  padding-inline: var(--space-4);
  font-weight: 500;
}

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

.btn--primary:disabled {
  background: var(--color-surface-raised);
  border-color: var(--color-border);
  color: var(--color-text-muted);
}

.btn--lg {
  min-height: var(--control-height-lg);
}

.btn--quiet {
  background: transparent;
  border-color: transparent;
  color: var(--color-text-secondary);
}

.btn--quiet:hover:not(:disabled) {
  background: var(--color-surface-hover);
  border-color: transparent;
  color: var(--color-text);
}

.btn--danger:hover:not(:disabled) {
  border-color: var(--color-danger);
  color: var(--color-danger);
}

/* A destructive action waiting for its second click. It says what it is about
   to do and looks like it means it, so the app never needs a native dialog. */
.btn--armed,
.btn--armed:hover:not(:disabled) {
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.btn--icon {
  width: var(--control-height);
  min-height: var(--control-height);
  padding: 0;
}

.btn--mono {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

.btn[aria-pressed="true"],
.btn--on {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

/* Segmented control — mutually exclusive options on one axis. */
.segment {
  display: inline-flex;
  gap: 1px;
  background: var(--color-border);
  border: 1px solid var(--color-border);
}

.segment > .btn {
  border: 0;
  min-width: 48px;
  font-family: var(--font-mono);
  font-size: var(--text-md);
}

/* Fields */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field__label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

.input,
.select {
  height: var(--control-height);
  width: 100%;
  padding: 0 var(--space-2);
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-0);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: var(--text-md);
  font-variant-numeric: tabular-nums;
}

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

.select {
  appearance: none;
  padding-right: var(--space-6);
  background-image: linear-gradient(45deg, transparent 50%, var(--color-text-secondary) 50%),
    linear-gradient(135deg, var(--color-text-secondary) 50%, transparent 50%);
  background-position: calc(100% - 14px) 13px, calc(100% - 9px) 13px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.select option {
  background: var(--color-surface-overlay);
  color: var(--color-text);
}

/* Range — stationary track, only the indicator moves. */
.range {
  --range-fill: 50%;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  cursor: pointer;
}

.range::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(
    to right,
    var(--color-accent) 0 var(--range-fill),
    var(--color-border-strong) var(--range-fill) 100%
  );
}

.range::-webkit-slider-thumb {
  appearance: none;
  width: 10px;
  height: 14px;
  margin-top: -6px;
  background: var(--color-accent);
  border: 0;
  border-radius: var(--radius-0);
}

.range::-moz-range-track {
  height: 2px;
  background: var(--color-border-strong);
}

.range::-moz-range-progress {
  height: 2px;
  background: var(--color-accent);
}

.range::-moz-range-thumb {
  width: 10px;
  height: 14px;
  background: var(--color-accent);
  border: 0;
  border-radius: var(--radius-0);
}

.range:disabled {
  cursor: not-allowed;
}

.range:disabled::-webkit-slider-thumb {
  background: var(--color-text-muted);
}

/* Status */
.dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: var(--radius-circle);
  background: var(--color-neutral);
}

.dot--ok {
  background: var(--color-success);
}
.dot--busy {
  background: var(--color-accent);
}
.dot--warn {
  background: var(--color-warning);
}
.dot--bad {
  background: var(--color-danger);
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 var(--space-2);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface-sunken);
  color: var(--color-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  white-space: nowrap;
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  height: 22px;
  padding: 0 var(--space-2);
  border: 1px solid currentColor;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

.status--queued {
  color: var(--color-neutral);
}
.status--pending {
  color: var(--color-warning);
}
.status--completed {
  color: var(--color-success);
}
.status--failed {
  color: var(--color-danger);
}
.status--cancelled {
  color: var(--color-text-muted);
}

/* Progress — stationary track, animated indicator only. */
.progress {
  position: relative;
  height: 2px;
  background: var(--color-border);
  overflow: hidden;
}

.progress__bar {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--color-accent);
  transition: width var(--motion-base) var(--motion-ease);
}

.progress--indeterminate .progress__bar {
  width: 30%;
  animation: indeterminate 1.4s var(--motion-ease) infinite;
}

@keyframes indeterminate {
  0% {
    transform: translateX(-110%);
  }
  100% {
    transform: translateX(360%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .progress--indeterminate .progress__bar {
    animation: none;
    width: 100%;
    opacity: 0.4;
  }
}

/* ------------------------------------------------------ scroll affordance */

* {
  scrollbar-color: var(--color-border-strong) var(--color-surface-sunken);
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: var(--color-surface-sunken);
  border-left: 1px solid var(--color-border-faint);
}

*::-webkit-scrollbar-thumb {
  background: var(--color-border-strong);
  border: 3px solid var(--color-surface-sunken);
  border-block: 0;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
  border-width: 2px;
}

*::-webkit-scrollbar-thumb:active {
  background: var(--color-accent);
}

*::-webkit-scrollbar-corner {
  background: var(--color-surface-sunken);
}

@media (forced-colors: active) {
  * {
    scrollbar-color: auto;
  }
}
