/* One button vocabulary, one form-control vocabulary, used everywhere. */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  height: 32px;
  padding: 0 var(--s-3);
  border-radius: var(--r-md);
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--t-13);
  font-weight: var(--w-medium);
  white-space: nowrap;
  box-shadow: var(--shadow-1);
  transition: background var(--d-fast) var(--ease),
              border-color var(--d-fast) var(--ease),
              color var(--d-fast) var(--ease),
              box-shadow var(--d-fast) var(--ease),
              opacity var(--d-fast) var(--ease);
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn:active { background: var(--surface-active); box-shadow: none; }
.btn svg { color: var(--ink-3); }

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--ink-invert);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-active); }
.btn-primary svg { color: currentColor; }

.btn-danger { color: var(--bad-ink); border-color: var(--hairline-strong); }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn-danger svg { color: currentColor; }

.btn-ghost { background: none; border-color: transparent; box-shadow: none; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--ink); }

.btn-lg { height: 38px; padding: 0 var(--s-4); font-size: var(--t-14); border-radius: var(--r-lg); }
.btn-sm { height: 26px; padding: 0 var(--s-2); font-size: var(--t-12); border-radius: var(--r-sm); }
.btn-icon { width: 32px; padding: 0; }
.btn-icon.btn-sm { width: 26px; }
.btn-icon.btn-lg { width: 38px; }
.btn-block { width: 100%; }

.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.45;
  box-shadow: none;
  pointer-events: none;
}

/* Inline spinner: the button keeps its width, the label stays legible. */
.btn[data-busy="true"] { pointer-events: none; position: relative; color: transparent; }
.btn[data-busy="true"] svg { opacity: 0; }
.btn[data-busy="true"]::after {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: var(--ink-2);
  animation: spin 620ms linear infinite;
}
.btn-primary[data-busy="true"]::after { color: var(--ink-invert); }

/* ---- Segmented control ------------------------------------------------ */
.segmented {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  background: var(--surface-3);
  border-radius: var(--r-md);
}
.segmented button {
  padding: 5px var(--s-3);
  border-radius: 6px;
  font-size: var(--t-12);
  font-weight: var(--w-medium);
  color: var(--ink-2);
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"], .segmented button[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}

/* ---- Fields ----------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label {
  font-size: var(--t-12);
  font-weight: var(--w-medium);
  color: var(--ink-2);
}
.field-hint { font-size: var(--t-11); color: var(--ink-3); }
.field-error { font-size: var(--t-11); color: var(--bad-ink); font-weight: var(--w-medium); }

.input, .select, .textarea {
  width: 100%;
  min-height: 34px;
  padding: 6px var(--s-3);
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-md);
  color: var(--ink);
  font-size: var(--t-13);
  transition: border-color var(--d-fast) var(--ease), box-shadow var(--d-fast) var(--ease);
}
.textarea { min-height: 96px; padding: var(--s-2) var(--s-3); resize: vertical; line-height: 1.6; }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-4); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--surface-3);
  color: var(--ink-disabled);
  cursor: not-allowed;
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--bad); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px oklch(0.55 0.2 25 / 0.28); }

.select {
  appearance: none;
  padding-right: var(--s-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237a7a7a' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
  cursor: pointer;
}

.input-mono { font-family: var(--font-mono); font-size: var(--t-12); }

.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap svg { position: absolute; left: var(--s-3); color: var(--ink-4); pointer-events: none; }
.input-wrap .input { padding-left: var(--s-8); }
.input-wrap .input-suffix {
  position: absolute; right: var(--s-2);
  font-size: var(--t-11); color: var(--ink-3);
}

.checkbox, .radio {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--s-2);
  font-size: var(--t-13);
  cursor: pointer;
  line-height: 1.4;
}
.checkbox input, .radio input {
  appearance: none;
  width: 16px; height: 16px;
  flex: none;
  margin-top: 2px;
  border: 1px solid var(--hairline-strong);
  border-radius: 4px;
  background: var(--surface);
  transition: background var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease);
}
.radio input { border-radius: 50%; }
.checkbox input:checked, .radio input:checked {
  background: var(--accent) 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='white' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6L9 17l-5-5'/%3E%3C/svg%3E") center / 11px no-repeat;
  border-color: var(--accent);
}
.radio input:checked { background-image: none; box-shadow: inset 0 0 0 3px var(--surface); }
.checkbox input:focus-visible, .radio input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.switch { display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; }
.switch input { appearance: none; width: 40px; height: 24px; flex: none;
  border-radius: var(--r-full); background: var(--hairline-strong); position: relative;
  transition: background var(--d-base) var(--ease); }
.switch input::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-1);
  transition: transform var(--d-base) var(--ease);
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s-4) var(--s-5);
}
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 620px) { .form-grid .span-2 { grid-column: span 1; } }

kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid var(--hairline-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink-3);
  font-family: var(--font);
  font-size: var(--t-11);
  text-align: center;
  line-height: 1.5;
}
