/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-m);
  background: var(--bg-input);
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover {
  background: var(--bg-hover);
}
.btn:active {
  background: var(--bg-active);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn.danger.primary {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
:root[data-theme-resolved="dark"] .btn.danger.primary {
  color: #1f1f1f;
}
.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}
.btn.small {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-m);
  background: transparent;
  color: var(--text-2);
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.icon-btn:active,
.icon-btn[aria-pressed="true"],
.icon-btn[aria-expanded="true"] {
  background: var(--bg-active);
  color: var(--text);
}
.icon-btn:disabled,
.icon-btn[aria-disabled="true"] {
  color: var(--text-disabled);
  pointer-events: none;
}

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

/* ---------- form fields ---------- */
.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}
.field-label {
  font-weight: 600;
  color: var(--text-2);
  font-size: 12px;
}
.field-hint {
  margin: 0;
  color: var(--text-3);
  font-size: 12px;
}
.field-error {
  margin: 0;
  color: var(--danger);
  font-size: 12px;
  min-height: 0;
}
.field-error:empty {
  display: none;
}
.input,
.select,
textarea.input {
  width: 100%;
  min-height: 32px;
  padding: 5px 9px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-m);
  background: var(--bg-input);
  color: var(--text);
}
.input:focus,
.select:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: inset 0 0 0 1px var(--focus);
}
.input[aria-invalid="true"] {
  border-color: var(--danger);
}
textarea.input {
  resize: vertical;
  min-height: 80px;
  line-height: 1.45;
}
.input::placeholder {
  color: var(--text-3);
}
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}
.check-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* ---------- menus ---------- */
.menu {
  position: fixed;
  z-index: 1000;
  min-width: 200px;
  max-width: min(360px, calc(100vw - 16px));
  padding: 4px;
  overflow-y: auto;
  border: 1px solid var(--card-line);
  border-radius: var(--radius-l);
  background: var(--bg-menu);
  color: var(--text);
  /* A floating surface needs separation from the canvas behind it. */
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14), 0 1px 3px rgba(0, 0, 0, 0.08);
  outline: none;
}
:root[data-theme-resolved="dark"] .menu {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 30px;
  padding: 4px 10px 4px 8px;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text);
  text-align: left;
}
.menu-item:focus,
.menu-item:hover {
  outline: none;
  background: var(--bg-hover);
}
.menu-item:focus-visible {
  box-shadow: inset 0 0 0 2px var(--focus);
}
.menu-item[aria-disabled="true"] {
  color: var(--text-disabled);
}
.menu-item.danger {
  color: var(--danger);
}
.menu-lead {
  display: grid;
  place-items: center;
  width: 18px;
  flex: none;
  color: var(--text-2);
}
.menu-item.danger .menu-lead {
  color: var(--danger);
}
.menu-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.menu-hint,
.menu-shortcut {
  color: var(--text-3);
  font-size: 12px;
  margin-left: 16px;
  white-space: nowrap;
}
.menu-chev {
  color: var(--text-3);
  margin-right: -4px;
}
.menu-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--line);
}
.menu-header {
  padding: 6px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.menu-swatch,
.swatch {
  display: block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--swatch);
  border: 1px solid rgba(0, 0, 0, 0.15);
}
.menu-swatches {
  display: grid;
  grid-template-columns: repeat(6, 26px);
  gap: 4px;
  padding: 6px 8px;
}
.menu-swatches .swatch {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 4px;
}
.menu-swatches .swatch:hover,
.menu-swatches .swatch:focus {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}
.menu-swatches .swatch[aria-checked="true"] {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.swatch.none {
  background: var(--bg-input) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M2 18L18 2' stroke='%23c42b1c' stroke-width='2'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
}

/* ---------- dialogs ---------- */
.dialog {
  width: min(var(--dialog-width, 440px), calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--card-line);
  border-radius: 10px;
  background: var(--bg-menu);
  color: var(--text);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.22);
}
.dialog::backdrop {
  background: rgba(0, 0, 0, 0.32);
}
.dialog-form {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 34px);
}
.dialog-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px 6px 20px;
}
.dialog-title {
  flex: 1;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.dialog-body {
  padding: 8px 20px 12px;
  overflow: auto;
}
.dialog-message {
  margin: 0 0 4px;
  color: var(--text-2);
  line-height: 1.5;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 20px 18px;
}

/* ---------- toasts ---------- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 1100;
  display: grid;
  gap: 8px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 24px);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 6px 6px 6px 14px;
  border-radius: var(--radius-l);
  background: var(--bg-tooltip);
  color: var(--text-on-tooltip);
  pointer-events: auto;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  animation: toast-in var(--dur) var(--ease);
}
.toast.error {
  background: var(--danger);
  color: #fff;
}
.toast.leaving {
  opacity: 0;
  transition: opacity 150ms;
}
.toast-msg {
  flex: 1;
}
.toast-action {
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 700;
  padding: 6px 8px;
  border-radius: var(--radius-s);
  text-decoration: underline;
}
.toast-action:hover {
  background: rgba(127, 127, 127, 0.25);
}
.toast-close {
  width: 28px;
  height: 28px;
  color: inherit;
  opacity: 0.8;
}
.toast-close:hover {
  background: rgba(127, 127, 127, 0.25);
  color: inherit;
}
@keyframes toast-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
}

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed;
  z-index: 1200;
  max-width: 280px;
  padding: 6px 9px;
  border-radius: var(--radius-m);
  background: var(--bg-tooltip);
  color: var(--text-on-tooltip);
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
}
.tooltip-title {
  font-weight: 600;
}
.tooltip-key {
  font-weight: 400;
  opacity: 0.85;
}
.tooltip-desc {
  margin-top: 2px;
  opacity: 0.9;
}

/* ---------- misc ---------- */
.kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-input);
  font-family: var(--font-ui);
  font-size: 11px;
  text-align: center;
}
.empty-state {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 32px 16px;
  color: var(--text-3);
  text-align: center;
}
.empty-state .icon:not(.ico) {
  color: var(--text-3);
}
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.segmented {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-m);
  overflow: hidden;
}
.segmented button {
  border: 0;
  padding: 5px 12px;
  background: var(--bg-input);
  color: var(--text-2);
}
.segmented button + button {
  border-left: 1px solid var(--line-strong);
}
.segmented button[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

/* ---------- KeyTips ---------- */
.keytips {
  position: fixed;
  inset: 0;
  z-index: 1300;
  pointer-events: none;
}
.keytip {
  position: fixed;
  min-width: 16px;
  padding: 1px 4px;
  transform: translateX(-50%);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--bg-tooltip);
  color: var(--text-on-tooltip);
  font-size: 11px;
  font-weight: 600;
  line-height: 14px;
  text-align: center;
}
.keytip.dim {
  opacity: 0.25;
}
