/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 550;
  line-height: 1;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background var(--dur) var(--ease), border-color var(--dur), color var(--dur), transform 80ms, box-shadow var(--dur);
}
.btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}
.btn-primary {
  background: var(--brand);
  border-color: transparent;
  color: var(--brand-contrast);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--brand) 40%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--brand) 88%, #000);
  border-color: transparent;
}
.btn-danger {
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-bg);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}
.btn-solid-danger {
  background: var(--danger);
  border-color: transparent;
  color: #fff;
}
.btn-solid-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 85%, #000);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: transparent;
}
.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}
.btn-lg {
  height: 42px;
  padding: 0 18px;
  font-size: 15px;
}
.btn-icon {
  width: 36px;
  padding: 0;
}
.btn-icon.btn-sm {
  width: 30px;
}
.btn-discord {
  background: #5865f2;
  border-color: transparent;
  color: #fff;
}
.btn-discord:hover:not(:disabled) {
  background: #4752c4;
  border-color: transparent;
}

/* Checkboxes & radio buttons (custom, theme-aware). */
input[type='checkbox'],
input[type='radio'] {
  -webkit-appearance: none;
  appearance: none;
  display: inline-grid;
  place-content: center;
  flex: none;
  width: 16px;
  height: 16px;
  margin: 0;
  border: 1.5px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  vertical-align: -3px;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur);
}
input[type='radio'] {
  border-radius: 50%;
}
input[type='checkbox']::before,
input[type='radio']::before {
  content: '';
  transform: scale(0);
  transition: transform 120ms var(--ease);
}
input[type='checkbox']::before {
  width: 10px;
  height: 10px;
  background: var(--brand-contrast);
  /* Check mark */
  clip-path: polygon(14% 52%, 0 66%, 38% 100%, 100% 22%, 86% 8%, 37% 70%);
}
input[type='radio']::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
}
input[type='checkbox']:hover:not(:disabled),
input[type='radio']:hover:not(:disabled) {
  border-color: var(--brand);
}
input[type='checkbox']:checked,
input[type='checkbox']:indeterminate {
  border-color: var(--brand);
  background: var(--brand);
}
input[type='radio']:checked {
  border-color: var(--brand);
}
input[type='checkbox']:checked::before,
input[type='radio']:checked::before,
input[type='checkbox']:indeterminate::before {
  transform: scale(1);
}
input[type='checkbox']:indeterminate::before {
  height: 2px;
  border-radius: 1px;
  clip-path: none;
}
input[type='checkbox']:focus-visible,
input[type='radio']:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}
input[type='checkbox']:disabled,
input[type='radio']:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
/* Read-only task lists in rendered Markdown are disabled but should look normal. */
.prose input[type='checkbox']:disabled {
  opacity: 1;
  cursor: default;
}
/* Windows high-contrast mode: fall back to native controls. */
@media (forced-colors: active) {
  input[type='checkbox'],
  input[type='radio'] {
    -webkit-appearance: auto;
    appearance: auto;
  }
  input[type='checkbox']::before,
  input[type='radio']::before {
    content: none;
  }
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field > label,
.label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.hint {
  font-size: 12.5px;
  color: var(--text-subtle);
}
.input,
.select,
.textarea {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 14px;
  transition: border-color var(--dur), box-shadow var(--dur);
}
.textarea {
  height: auto;
  min-height: 96px;
  padding: 10px 12px;
  line-height: 1.55;
  resize: vertical;
}
.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--border-strong);
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus);
}
.input-sm {
  height: 32px;
  font-size: 13px;
}

/* Dropdowns (<select>).
   Closed control: custom chevron in every browser.
   Open list: fully styled where the browser supports customizable selects
   (appearance: base-select); elsewhere the native list is used. Native
   keyboard, screen-reader and mobile picker behaviour is kept either way. */
.select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 34px;
  background-image: var(--select-chevron);
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.select.input-sm {
  padding-right: 28px;
  background-position: right 8px center;
  background-size: 14px;
}
.select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
/* Native option lists (Firefox/Windows) follow the theme colours. */
.select option {
  background-color: var(--surface);
  color: var(--text);
}

@supports (appearance: base-select) {
  .select,
  .select::picker(select) {
    appearance: base-select;
  }
  .select {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding-right: 10px;
    background-image: none;
  }
  .select.input-sm {
    padding-right: 8px;
  }
  /* The chevron becomes the select's own picker icon so it can rotate when open. */
  .select::picker-icon {
    content: '';
    flex: none;
    width: 16px;
    height: 16px;
    margin-left: auto;
    background: var(--select-chevron) no-repeat center / 16px;
  }
  .select.input-sm::picker-icon {
    width: 14px;
    height: 14px;
    background-size: 14px;
  }
  .select::picker(select) {
    /* Always open below the control (the browser default flips it upward when
       space is short). The list shrinks to the space below and scrolls instead;
       percentages resolve against the area beneath the control. */
    position-area: block-end span-inline-end;
    position-try-fallbacks: none;
    min-width: anchor-size(width);
    /* At least ~3 rows so the list stays usable right at the bottom edge. */
    max-height: max(136px, min(320px, calc(100% - 12px)));
    overflow-y: auto;
    margin-block: 6px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lg);
  }
  .select option {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 34px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    background: transparent;
    font-size: 14px;
    white-space: nowrap;
    cursor: pointer;
  }
  .select.input-sm option {
    min-height: 30px;
    font-size: 13px;
  }
  .select option:hover,
  .select option:focus-visible {
    outline: none;
    background: var(--bg-hover);
  }
  .select option:checked {
    background: var(--brand-soft);
    color: var(--brand-text);
    font-weight: 600;
  }
  /* Check mark on the right, in the brand colour. */
  .select option::checkmark {
    order: 1;
    margin-left: auto;
    color: var(--brand-text);
  }
  .select option:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
}
.input-with-icon {
  position: relative;
}
.input-with-icon svg {
  position: absolute;
  left: 11px;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}
.input-with-icon .input {
  padding-left: 34px;
}
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

.color-input {
  display: flex;
  gap: 8px;
  align-items: center;
}
.color-input input[type='color'] {
  width: 38px;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

/* Switch */
.switch {
  /* Contains the visually hidden checkbox below; without this it is positioned
     against the page and can make scroll containers' parents grow. */
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  user-select: none;
}
.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch-track {
  position: relative;
  width: 34px;
  height: 20px;
  flex: none;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background var(--dur) var(--ease);
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .switch-track {
  background: var(--brand);
}
.switch input:checked + .switch-track::after {
  transform: translateX(14px);
}
.switch input:focus-visible + .switch-track {
  box-shadow: var(--focus);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-body {
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header h2,
.card-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
  vertical-align: middle;
  background: var(--bg-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge-brand {
  background: var(--brand-soft);
  color: var(--brand-text);
  border-color: color-mix(in srgb, var(--brand) 22%, transparent);
}
.badge-success {
  background: var(--success-bg);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 25%, transparent);
}
.badge-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 25%, transparent);
}
.badge-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 25%, transparent);
}
.badge-info {
  background: var(--info-bg);
  color: var(--info);
  border-color: color-mix(in srgb, var(--info) 25%, transparent);
}

/* Text followed by a badge, e.g. "Latest  [Default]". */
.label-with-badge {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}

/* Avatar */
.avatar {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-muted);
  border: 1px solid var(--border);
}
.avatar-sm {
  width: 24px;
  height: 24px;
}
.avatar-lg {
  width: 56px;
  height: 56px;
}

/* Dropdown */
.dropdown {
  position: relative;
}
.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 60;
  min-width: 220px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: rise-in 140ms var(--ease);
}
.dropdown-menu.left {
  left: 0;
  right: auto;
}
.dropdown-menu.up {
  top: auto;
  bottom: calc(100% + 8px);
}
/* A menu opened inside something that clips or scrolls (e.g. a table's .table-wrap) is placed against
   the window instead, so it isn't cut off; main.js sets its top and left. */
.dropdown-menu.floating {
  position: fixed;
  right: auto;
  bottom: auto;
  z-index: 70;
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 14px;
  text-align: left;
  color: var(--text);
}
.dropdown-item:hover,
.dropdown-item.active {
  background: var(--bg-hover);
}
.dropdown-item svg {
  width: 16px;
  height: 16px;
  color: var(--text-subtle);
}
.dropdown-sep {
  height: 1px;
  margin: 6px 0;
  background: var(--border);
}
.dropdown-label {
  padding: 6px 10px 4px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh 16px 16px;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  animation: fade-in 140ms var(--ease);
}
.modal {
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: rise-in 180ms var(--ease);
}
.modal-wide {
  max-width: 760px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}
.modal-body {
  padding: 20px;
  overflow: auto;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tab {
  position: relative;
  padding: 10px 12px;
  border: 0;
  background: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 550;
  white-space: nowrap;
  transition: color var(--dur);
}
.tab:hover {
  color: var(--text);
}
.tab[aria-selected='true'] {
  color: var(--text);
}
.tab[aria-selected='true']::after {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--brand);
}
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
}
.segmented button,
.segmented a {
  display: inline-flex;
  align-items: center;
  /* Icon and label: flex drops the space character between them, so the gap provides it. */
  gap: 6px;
  text-decoration: none;
  height: 28px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 550;
}
.segmented button[aria-pressed='true'],
.segmented a[aria-pressed='true'] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Toasts */
.toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 40px));
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  animation: rise-in 180ms var(--ease);
}
.toast > .grow {
  text-align: center;
}
.toast.leaving {
  animation: toast-out 180ms var(--ease) forwards;
  pointer-events: none;
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(12px) scale(0.98);
  }
}
.toast-success {
  border-left-color: var(--success);
}
.toast-danger {
  border-left-color: var(--danger);
}
.toast-warning {
  border-left-color: var(--warning);
}

/* Feedback states */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.loading-center {
  display: flex;
  justify-content: center;
  padding: 64px 0;
}
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--bg-muted) 0%, var(--bg-hover) 50%, var(--bg-muted) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
}
.empty svg {
  width: 28px;
  height: 28px;
  color: var(--text-subtle);
}
.empty h3 {
  margin: 4px 0 0;
  font-size: 15px;
  color: var(--text);
}
.empty p {
  margin: 0;
  max-width: 420px;
  font-size: 14px;
}
.alert {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--c, var(--info)) 25%, transparent);
  background: var(--c-bg, var(--info-bg));
  border-radius: var(--radius);
  font-size: 14px;
}
.alert svg {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--c, var(--info));
  margin-top: 1px;
}
.alert-danger {
  --c: var(--danger);
  --c-bg: var(--danger-bg);
}
.alert-warning {
  --c: var(--warning);
  --c-bg: var(--warning-bg);
}
.alert-success {
  --c: var(--success);
  --c-bg: var(--success-bg);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-subtle);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--bg-subtle);
}
.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td {
  border-bottom: 0;
}
.table tbody tr {
  transition: background var(--dur);
}
.table tbody tr:hover {
  background: var(--bg-subtle);
}
.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}

kbd.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-subtle);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 5px;
}

/* Borderless fields that fill a styled container: the container (or, for the
   search dialog, the dialog itself) shows focus, so the global focus ring on
   the inner field would draw a stray box. */
.search-input-row input:focus-visible,
.composer-input:focus-visible,
.editor-title:focus-visible,
.tag-input input:focus-visible {
  box-shadow: none;
}
