/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--line-strong);
}

.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover {
  border-color: var(--btn);
  filter: brightness(1.15);
}

.btn-signal {
  background: var(--signal);
  color: var(--signal-ink);
}

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

.btn-danger {
  background: var(--bad);
  color: #fff;
}

.btn-danger-text {
  color: var(--bad);
}

.btn-small {
  min-height: 32px;
  padding: 4px 12px;
  font-size: var(--step--1);
}

.btn-link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  justify-self: start;
}

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

/* Forms */
.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field-label {
  font-weight: 650;
  font-size: 0.9375rem;
}

.field-help {
  font-size: var(--step--1);
  color: var(--muted);
}

.field-error {
  font-size: var(--step--1);
  color: var(--bad);
  font-weight: 600;
}

.input,
.select,
.textarea {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
}

.textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
}

.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  border-color: var(--ink);
}

.input[aria-invalid='true'],
.select[aria-invalid='true'],
.textarea[aria-invalid='true'] {
  border-color: var(--bad);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  cursor: pointer;
}

.check input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--ink);
  flex: none;
}

.check-disabled {
  color: var(--muted);
  cursor: not-allowed;
}

/* Toggle switch built on a checkbox */
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  cursor: pointer;
}

.switch input {
  appearance: none;
  flex: none;
  width: 42px;
  height: 24px;
  margin: 0;
  border-radius: var(--radius-pill);
  background: var(--line-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}

.switch input::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  transition: transform 0.15s;
}

.switch input:checked {
  background: var(--ok);
}

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

.switch input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.switch-disabled {
  color: var(--muted);
  cursor: not-allowed;
}

/* Notices */
.notice {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-s);
  border-left: 4px solid var(--line-strong);
  background: var(--surface-2);
  font-size: 0.9375rem;
}

.notice-error {
  border-left-color: var(--bad);
  background: var(--bad-wash);
}

.notice-warn {
  border-left-color: var(--signal);
  background: var(--signal-wash);
}

.notice-ok {
  border-left-color: var(--ok);
  background: var(--ok-wash);
}

.loading {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--muted);
  padding: var(--space-5) 0;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Chips */
.chip,
.tchip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px 2px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--step--1);
  font-weight: 600;
  background: var(--surface-2);
  color: var(--ink-soft);
  white-space: nowrap;
  max-width: 100%;
}

.chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.chip-ok {
  background: var(--ok-wash);
  color: var(--ok);
}

.chip-bad {
  background: var(--bad-wash);
  color: var(--bad);
}

.chip-busy {
  background: var(--busy-wash);
  color: var(--busy);
}

.chip-warn {
  background: var(--warn-wash);
  color: var(--warn);
}

.tchip-name {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
}

.tchip-status::before {
  content: '';
  display: inline-block;
  width: 1px;
  height: 0.9em;
  margin-right: 6px;
  vertical-align: -1px;
  background: currentColor;
  opacity: 0.4;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Provider tag: a small platform marker, not a logo */
.ptag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: var(--radius-s);
  border: 1px solid var(--line-strong);
  color: var(--ink-soft);
}

/* Avatars */
.avatar {
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  background: var(--surface-2);
}

.avatar-s {
  width: 24px;
  height: 24px;
  font-size: 0.625rem;
}

.avatar-m {
  width: 36px;
  height: 36px;
  font-size: 0.8125rem;
}

.avatar-l {
  width: 56px;
  height: 56px;
  font-size: 1.125rem;
}

.avatar-fallback {
  display: inline-grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: var(--space-5);
  display: grid;
  gap: var(--space-4);
  min-width: 0;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
}

.panel-head p {
  color: var(--muted);
  font-size: 0.9375rem;
}

/* Empty state */
.empty {
  display: grid;
  gap: var(--space-2);
  justify-items: start;
  padding: var(--space-5);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-m);
  color: var(--muted);
}

.empty-title {
  font-family: var(--font-display);
  font-weight: 650;
  color: var(--ink);
  font-size: var(--step-1);
}

/* Inline confirm */
.confirm {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.confirm-q {
  font-size: var(--step--1);
  font-weight: 600;
}

/* Toasts */
.toasts {
  position: fixed;
  z-index: 60;
  right: var(--space-4);
  bottom: var(--space-4);
  display: grid;
  gap: var(--space-2);
  max-width: min(420px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-s);
  background: var(--btn);
  color: var(--btn-ink);
  box-shadow: var(--lift);
  animation: toast-in 0.18s ease-out;
}

.toast-error {
  background: var(--bad);
  color: #fff;
}

.toast span {
  flex: 1;
}

.toast-close {
  background: none;
  border: 0;
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

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

@media (max-width: 760px) {
  .toasts {
    bottom: calc(76px + env(safe-area-inset-bottom));
    right: var(--space-4);
    left: var(--space-4);
    max-width: none;
  }
}

/* Drawer (native dialog) */
.drawer {
  margin: 0 0 0 auto;
  height: 100%;
  max-height: 100vh;
  width: min(560px, 100vw);
  max-width: 100vw;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--lift);
}

.drawer::backdrop {
  background: rgba(15, 21, 36, 0.45);
}

.drawer[open] {
  animation: drawer-in 0.2s ease-out;
}

@keyframes drawer-in {
  from {
    transform: translateX(24px);
    opacity: 0;
  }
}

.drawer-inner {
  display: grid;
  gap: var(--space-5);
  padding: var(--space-5);
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-s);
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  flex: none;
}
