/* Buttons ------------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  user-select: none;
  transition: background-color 0.1s, border-color 0.1s;
}

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

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

.btn:disabled {
  opacity: 0.55;
}

/* The display above would otherwise win over the hidden attribute. */
.btn[hidden],
.icon-btn[hidden] {
  display: none;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-inverse);
}

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

.btn.primary:active:not(:disabled) {
  background: var(--accent-active);
}

.btn.primary:focus-visible {
  outline-offset: 2px;
}

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

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

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

.btn.ghost {
  border-color: transparent;
  background: transparent;
}

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

.btn.sm {
  height: var(--control-sm-h);
  padding: 0 8px;
  font-size: var(--fs-sm);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--control-h);
  height: var(--control-h);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
}

.icon-btn.sm {
  width: var(--control-sm-h);
  height: var(--control-sm-h);
}

.icon-btn:hover:not(:disabled),
.icon-btn[aria-expanded='true'] {
  background: var(--bg-hover);
  color: var(--text);
}

.icon-btn[aria-pressed='true'] {
  background: var(--bg-active);
  color: var(--text);
}

.icon-btn:disabled {
  opacity: 0.4;
}

.split-btn {
  display: inline-flex;
}

.split-btn > .btn:first-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.split-btn > .btn:last-child {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left-color: color-mix(in srgb, var(--text-inverse) 30%, transparent);
  padding: 0 6px;
}

.split-btn > .btn:not(.primary):last-child {
  border-left-color: var(--border-strong);
  margin-left: -1px;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-text);
  font-weight: 500;
}

.link-btn:hover {
  text-decoration: underline;
}

/* Inputs ------------------------------------------------------------------- */
.input,
.select,
.textarea {
  width: 100%;
  height: var(--control-h);
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.textarea {
  height: auto;
  min-height: 80px;
  padding: 8px 10px;
  resize: vertical;
  line-height: 1.5;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-faint);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--focus);
  outline: 1px solid var(--focus);
  outline-offset: -1px;
}

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

.select {
  appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > label,
.field-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
}

.field-hint {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.field-error {
  margin: 0;
  min-height: 1em;
  font-size: var(--fs-sm);
  color: var(--danger);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

input[type='checkbox'],
input[type='radio'] {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Switch built on a checkbox. */
.switch {
  appearance: none;
  position: relative;
  width: 30px !important;
  height: 18px !important;
  border-radius: 9px;
  background: var(--border-strong);
  transition: background-color 0.15s;
}

.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}

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

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

.switch:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Segmented control and radio pills. */
.segmented {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  border-radius: var(--radius);
  background: var(--bg-muted);
}

.segmented button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: calc(var(--control-sm-h) - 2px);
  padding: 0 10px;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
}

.segmented button[aria-checked='true'],
.segmented button[aria-pressed='true'],
.segmented button[aria-selected='true'] {
  background: var(--surface);
  color: var(--text);
  outline: 1px solid var(--border);
}

.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}

.radio-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  cursor: pointer;
  min-height: var(--control-sm-h);
}

.radio-row label:has(input:checked) {
  color: var(--text);
}

/* Tabs --------------------------------------------------------------------- */
.tabs {
  display: flex;
  align-items: stretch;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

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

.tab[aria-selected='true'] {
  color: var(--text);
}

.tab[aria-selected='true']::after {
  content: '';
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
}

.tab .count {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.tab .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* Method labels ------------------------------------------------------------ */
.method {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 10.5px;
  letter-spacing: 0.02em;
  color: var(--m-other);
}

.method[data-m='GET'] { color: var(--m-get); }
.method[data-m='POST'] { color: var(--m-post); }
.method[data-m='PUT'] { color: var(--m-put); }
.method[data-m='PATCH'] { color: var(--m-patch); }
.method[data-m='DELETE'] { color: var(--m-delete); }
.method[data-m='HEAD'] { color: var(--m-head); }
.method[data-m='OPTIONS'] { color: var(--m-options); }
.method[data-m='WS'] { color: var(--info); }

/* Status pills --------------------------------------------------------------- */
.status-pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.status-pill[data-class='success'] { background: var(--success-soft); color: var(--success); }
.status-pill[data-class='redirect'],
.status-pill[data-class='info'] { background: var(--info-soft); color: var(--info); }
.status-pill[data-class='client'] { background: var(--warning-soft); color: var(--warning); }
.status-pill[data-class='server'],
.status-pill[data-class='none'] { background: var(--danger-soft); color: var(--danger); }

.badge {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  border-radius: 9px;
  background: var(--bg-muted);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
}

/* Menus and popovers ------------------------------------------------------- */
.menu,
.popover {
  position: fixed;
  z-index: 300;
  min-width: 180px;
  max-width: min(360px, calc(100vw - 16px));
  max-height: min(480px, calc(100dvh - 16px));
  overflow: auto;
  padding: 4px;
  border: 1px solid var(--overlay-border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
}

.popover {
  padding: 12px;
  max-width: min(420px, calc(100vw - 16px));
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 30px;
  padding: 4px 8px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  text-align: left;
  white-space: nowrap;
}

.menu-item .icon {
  color: var(--text-muted);
}

.menu-item .menu-kbd {
  margin-left: auto;
  padding-left: 16px;
  color: var(--text-faint);
  font-size: var(--fs-sm);
}

.menu-item .menu-check {
  margin-left: auto;
  color: var(--accent-text);
}

.menu-item:hover,
.menu-item:focus-visible,
.menu-item.active {
  background: var(--bg-hover);
  outline: none;
}

.menu-item[aria-disabled='true'] {
  opacity: 0.5;
  pointer-events: none;
}

.menu-item.danger,
.menu-item.danger .icon {
  color: var(--danger);
}

.menu-sep {
  height: 1px;
  margin: 4px -4px;
  background: var(--border);
}

.menu-label {
  padding: 6px 8px 2px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* Dialogs ------------------------------------------------------------------ */
dialog.dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 1px solid var(--overlay-border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}

dialog.dialog.wide {
  width: min(820px, calc(100vw - 24px));
}

dialog.dialog::backdrop {
  background: var(--scrim);
}

dialog.dialog[open] {
  display: flex;
  flex-direction: column;
  animation: dialog-in 0.12s ease-out;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.99);
  }
}

.dialog-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
}

.dialog-title {
  flex: 1;
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 600;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 16px 16px;
  overflow: auto;
}

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
}

.dialog-foot .spacer {
  flex: 1;
}

@media (max-width: 600px) {
  dialog.dialog,
  dialog.dialog.wide {
    width: 100vw;
    max-width: 100vw;
    max-height: 92dvh;
    margin: auto 0 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: 0;
  }
}

/* Toasts ------------------------------------------------------------------- */
.toasts {
  position: fixed;
  z-index: 400;
  right: 16px;
  bottom: calc(var(--statusbar-h) + 12px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 10px 10px 12px;
  border: 1px solid var(--overlay-border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  pointer-events: auto;
  animation: toast-in 0.16s ease-out;
}

.toast .icon {
  margin-top: 1px;
}

.toast[data-kind='success'] > .icon { color: var(--success); }
.toast[data-kind='error'] > .icon { color: var(--danger); }
.toast[data-kind='info'] > .icon { color: var(--info); }
.toast[data-kind='warning'] > .icon { color: var(--warning); }

.toast-body {
  flex: 1;
  min-width: 0;
}

.toast-title {
  font-weight: 600;
}

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

.toast-actions {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}

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

@media (max-width: 600px) {
  .toasts {
    left: 12px;
    right: 12px;
    align-items: stretch;
  }
  .toast {
    max-width: none;
  }
  /* Dialogs are bottom sheets on phones: toasts raised over one go to the top, clear of its buttons. */
  dialog > .toasts {
    top: 12px;
    bottom: auto;
  }
}

/* Tooltip ------------------------------------------------------------------ */
.tooltip {
  position: fixed;
  z-index: 500;
  max-width: 280px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-size: var(--fs-sm);
  pointer-events: none;
  white-space: nowrap;
}

/* Empty states ------------------------------------------------------------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
}

.empty > .icon {
  color: var(--text-faint);
}

.empty-title {
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

.empty p {
  margin: 0;
  max-width: 340px;
}

/* Callouts ----------------------------------------------------------------- */
.callout {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg-muted);
  color: var(--text);
  font-size: var(--fs-sm);
}

.callout .icon {
  margin-top: 1px;
  flex: none;
}

.callout[data-kind='warning'] { background: var(--warning-soft); }
.callout[data-kind='warning'] .icon { color: var(--warning); }
.callout[data-kind='error'] { background: var(--danger-soft); }
.callout[data-kind='error'] .icon { color: var(--danger); }
.callout[data-kind='info'] { background: var(--info-soft); }
.callout[data-kind='info'] .icon { color: var(--info); }

/* Avatar ------------------------------------------------------------------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: var(--fs-sm);
  font-weight: 700;
  flex: none;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
