/* Components layer: reusable UI primitives only. */

/* --- top bar --- */

.appbar {
  align-items: center;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: var(--space-4);
  inset-block-start: 0;
  padding: var(--space-3) var(--space-4);
  position: sticky;
  z-index: var(--z-header);
}

.appbar__brand {
  align-items: center;
  color: var(--text);
  display: flex;
  font-weight: 700;
  gap: var(--space-2);
  text-decoration: none;
}

.appbar__brand svg {
  color: var(--brand);
}

.appbar__nav {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.appbar__user {
  align-items: center;
  display: flex;
  gap: var(--space-2);
}

.link-btn {
  background: none;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  padding: var(--space-1) var(--space-2);
}

.link-btn:hover {
  color: var(--text);
}

/* --- surfaces --- */

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
}

.card--pad-none {
  padding: 0;
}

.card__head {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: var(--space-3);
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
}

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

.card__foot {
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  padding: var(--space-3) var(--space-4);
}

.panel-title {
  align-items: center;
  color: var(--text-muted);
  display: flex;
  font-size: var(--text-xs);
  font-weight: 650;
  gap: var(--space-2);
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
  text-transform: uppercase;
}

/* --- buttons --- */

.btn {
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 600;
  gap: var(--space-2);
  justify-content: center;
  min-height: 2.1rem;
  padding: var(--space-2) var(--space-4);
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}

.btn:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn--primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-contrast);
}

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

.btn--danger {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.btn--sm {
  font-size: var(--text-xs);
  min-height: 1.75rem;
  padding: var(--space-1) var(--space-2);
}

.btn--roll {
  font-size: var(--text-lg);
  min-height: 3rem;
  padding: var(--space-3) var(--space-6);
}

.btn-block {
  width: 100%;
}

/* --- forms --- */

.field {
  display: grid;
  gap: var(--space-1);
}

.field__label {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

.input,
.select,
.textarea {
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  padding: var(--space-2) var(--space-3);
  width: 100%;
}

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

.textarea {
  min-height: 5.5rem;
  resize: vertical;
}

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

.field__hint {
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: 1.5;
}

.field__error {
  color: var(--danger);
  font-size: var(--text-xs);
}

.form-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}

.checkbox {
  align-items: center;
  display: flex;
  gap: var(--space-2);
}

.checkbox input {
  accent-color: var(--brand);
  height: 1.05rem;
  width: 1.05rem;
}

.filters {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.filters .field {
  min-width: 9rem;
}

/* --- tables --- */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
}

.table {
  border-collapse: collapse;
  font-size: var(--text-sm);
  min-width: 100%;
  width: 100%;
}

.table caption {
  text-align: left;
}

.table th,
.table td {
  border-bottom: 1px solid var(--border);
  padding: var(--space-2) var(--space-3);
  text-align: left;
  vertical-align: middle;
}

.table th {
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
  white-space: nowrap;
}

.table tbody tr:hover {
  background: var(--bg-subtle);
}

.table .num {
  font-family: var(--font-mono);
  text-align: right;
}

.table__actions {
  display: flex;
  gap: var(--space-1);
  justify-content: flex-end;
  white-space: nowrap;
}

/* --- pills & badges --- */

.pill {
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  display: inline-flex;
  font-size: var(--text-2xs);
  font-weight: 700;
  gap: var(--space-1);
  letter-spacing: 0.02em;
  padding: 0.1rem var(--space-2);
  white-space: nowrap;
}

.pill--active,
.pill--valid {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

.pill--paused {
  background: var(--warning-soft);
  border-color: var(--warning);
  color: var(--warning);
}

.pill--ended,
.pill--void {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.pill--neutral {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
  color: var(--text-muted);
}

.pill--brand {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand);
}

.dot {
  border-radius: 50%;
  display: inline-block;
  height: 0.5rem;
  width: 0.5rem;
}

.dot--on {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.dot--off {
  background: var(--text-faint);
}

/* --- metrics --- */

.metric {
  display: grid;
  gap: var(--space-1);
}

.metric__value {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1.1;
}

.metric__hint {
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.bar {
  background: var(--bg-subtle);
  border-radius: var(--radius-pill);
  height: 0.4rem;
  overflow: hidden;
  width: 100%;
}

.bar__fill {
  background: var(--chart-1);
  border-radius: inherit;
  height: 100%;
  transition: width var(--dur) var(--ease);
}

/* --- modal & toast --- */

/* The UA sizes <dialog> to fit-content, so it has to be stretched over the
   viewport by hand before flex can centre the panel on both axes. */
.modal {
  align-items: center;
  background: transparent;
  border: 0;
  color: inherit;
  display: flex;
  height: 100%;
  inset: 0;
  justify-content: center;
  margin: 0;
  max-height: none;
  max-width: none;
  padding: var(--space-4);
  width: 100%;
}

.modal::backdrop {
  background: rgb(8 10 18 / 0.55);
  backdrop-filter: blur(2px);
}

.modal__panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  max-height: 100%;
  max-width: 34rem;
  width: 100%;
}

/* Tall forms scroll inside the panel instead of pushing it past the viewport. */
.modal__panel .card__body {
  min-height: 0;
  overflow-y: auto;
}

.modal__panel .card__head,
.modal__panel .card__foot {
  flex: none;
}

.toasts {
  bottom: var(--space-4);
  display: grid;
  gap: var(--space-2);
  left: 50%;
  position: fixed;
  transform: translateX(-50%);
  width: min(26rem, calc(100vw - var(--space-4)));
  z-index: var(--z-toast);
}

.toast {
  align-items: center;
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  font-size: var(--text-sm);
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
}

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

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

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

.toast__close {
  background: none;
  border: 0;
  color: var(--text-faint);
  cursor: pointer;
  font-size: var(--text-lg);
  line-height: 1;
  margin-inline-start: auto;
}

/* --- tabs & pager --- */

.tabs {
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
}

.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
  white-space: nowrap;
}

.tab[aria-current="true"] {
  border-bottom-color: var(--brand);
  color: var(--text);
}

.pager {
  align-items: center;
  display: flex;
  gap: var(--space-3);
  justify-content: space-between;
}

/* --- states --- */

.state {
  color: var(--text-muted);
  padding: var(--space-6) var(--space-4);
  text-align: center;
}

.state__icon {
  color: var(--text-faint);
  font-size: var(--text-2xl);
}

.skeleton {
  animation: pulse 1.4s var(--ease) infinite;
  background: var(--bg-subtle);
  border-radius: var(--radius);
  height: 0.9rem;
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

.spinner {
  animation: spin 0.9s linear infinite;
  border: 2px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  display: inline-block;
  height: 1rem;
  width: 1rem;
  vertical-align: -0.15rem;
}

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

.divider {
  background: var(--border);
  border: 0;
  height: 1px;
  margin: var(--space-4) 0;
}
