/* AXIOM — form elements v1. Brand-book canonical (see docs/concepts/brand
   README.md §9a "Form elements"). Every surface with inputs, selects,
   checkboxes, toggles, or masked API-key fields composes from these
   instead of re-implementing its own.

   Extracted from axiom-ide's `.rp-set`/`.cx-select`/`.cx-check`/
   `.api-key-*` rules (the most complete, most refined implementation of
   this pattern in the codebase) and generalized under a neutral `.ax-*`
   naming convention so any surface can use them, not just ide.

   Depends on axiom-tokens.css (link that FIRST) for --bg-0/--bg-1/--fg-0/
   --line-2/--accent/--accent-dim/--warn/--radius/--mono/--sans — this
   file adds no palette of its own, it only composes from the canonical
   one, exactly like every other AXIOM surface is supposed to. */

/* ── text input / textarea / native select ─────────────────────────── */
.ax-input,
.ax-textarea,
.ax-select {
  width: 100%;
  background: var(--bg-1);
  color: var(--fg-0);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
  transition: border-color 150ms, box-shadow 150ms;
}
/* Select: kill the native chrome entirely. Without this, WebKit/native
   renderers paint the closed control with system colors — dark label on
   dark background, unreadable. Custom chevron replaces the native arrow. */
.ax-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-color: var(--bg-1);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23a3a8b0' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}
.ax-select:hover { background-color: var(--bg-1); }
.ax-select option { background: var(--bg-1); color: var(--fg-0); }
.ax-input.mono, .ax-textarea.mono, .ax-select.mono { font-family: var(--mono); font-size: 12px; }
.ax-input:hover, .ax-textarea:hover, .ax-select:hover { border-color: var(--accent-dim); }
.ax-input:focus, .ax-textarea:focus, .ax-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(126, 224, 201, 0.14);
}
.ax-input::placeholder, .ax-textarea::placeholder { color: var(--fg-2); }
.ax-input:disabled, .ax-textarea:disabled, .ax-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.ax-textarea { resize: vertical; min-height: 64px; line-height: 1.5; }

/* Compact variant — dense settings rows / inline fields. */
.ax-input.small, .ax-textarea.small, .ax-select.small {
  padding: 5px 8px;
  font-size: 11px;
}

/* A labeled field: label above, control below, optional help text. */
.ax-field { display: flex; flex-direction: column; gap: 4px; }
.ax-field-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--fg-1);
}
.ax-field-help { font-size: 11px; color: var(--fg-2); line-height: 1.5; }
.ax-field-warn { font-size: 11px; color: var(--warn); }

/* ── masked API-key style field with a show/hide toggle button ────────
   Markup:
   <div class="ax-key-row">
     <span class="ax-key-label">Anthropic</span>
     <div class="ax-key-input-wrap">
       <input class="ax-input" type="password">
       <button class="ax-key-toggle" type="button">👁</button>
     </div>
     <span class="ax-key-badge set">set</span>
   </div>
──────────────────────────────────────────────────────────────────── */
.ax-key-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.ax-key-label {
  min-width: 90px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--fg-1);
}
.ax-key-input-wrap { flex: 1; display: flex; align-items: center; position: relative; }
.ax-key-input-wrap .ax-input {
  border-radius: var(--radius) 0 0 var(--radius);
  border-right: none;
  height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.ax-key-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  box-sizing: border-box;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--fg-2);
  cursor: pointer;
  transition: color 150ms, background 150ms, border-color 150ms;
  padding: 0;
}
.ax-key-toggle:hover { background: rgba(255, 255, 255, 0.06); color: var(--accent); border-color: var(--accent-dim); }
.ax-key-toggle:active { transform: scale(0.94); }
.ax-key-badge {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: var(--radius);
  white-space: nowrap;
}
.ax-key-badge.set { color: var(--accent); background: rgba(126, 224, 201, 0.08); border: 1px solid rgba(126, 224, 201, 0.2); }
.ax-key-badge.unset { color: var(--fg-3); background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line); }

/* ── custom checkbox ────────────────────────────────────────────────── */
.ax-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13px; color: var(--fg-0); }
.ax-check input[type="checkbox"] {
  appearance: none;
  width: 18px; height: 18px;
  border: 1.5px solid var(--line-2);
  border-radius: 3px;
  background: var(--bg-1);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background 150ms, border-color 150ms, box-shadow 150ms;
}
.ax-check input[type="checkbox"]:hover { border-color: var(--accent-dim); }
.ax-check input[type="checkbox"]:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(126, 224, 201, 0.25); }
.ax-check input[type="checkbox"]:checked,
.ax-check input[type="checkbox"]:indeterminate {
  background: var(--accent);
  border-color: var(--accent);
}
.ax-check input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 5px; top: 1px;
  width: 5px; height: 10px;
  border: solid var(--bg-0);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ── toggle switch ─────────────────────────────────────────────────── */
.ax-switch { position: relative; display: inline-block; width: 34px; height: 19px; flex-shrink: 0; }
.ax-switch input { opacity: 0; width: 0; height: 0; }
.ax-switch .ax-switch-slider {
  position: absolute; inset: 0;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 150ms, background 150ms;
}
.ax-switch .ax-switch-slider::before {
  content: "";
  position: absolute;
  width: 13px; height: 13px;
  left: 2px; top: 2px;
  background: var(--fg-2);
  border-radius: 50%;
  transition: transform 150ms, background 150ms;
}
.ax-switch input:checked + .ax-switch-slider { border-color: var(--accent-dim); background: rgba(126, 224, 201, 0.08); }
.ax-switch input:checked + .ax-switch-slider::before { transform: translateX(15px); background: var(--accent); }
/* Danger variant — e.g. dark-web / destructive toggles (see axiom-search). */
.ax-switch.danger input:checked + .ax-switch-slider { border-color: var(--warn); background: rgba(224, 108, 117, 0.08); }
.ax-switch.danger input:checked + .ax-switch-slider::before { background: var(--warn); }

/* ── custom dropdown (JS-driven, for searchable/rich option lists) ────
   Markup:
   <div class="ax-dropdown" tabindex="0">
     <span class="ax-dropdown-label">Model…</span>
     <div class="ax-dropdown-menu">
       <input class="ax-dropdown-search" placeholder="search…">
       <div class="ax-dropdown-group">GROUP</div>
       <div class="ax-dropdown-item">Option</div>
     </div>
   </div>
   Toggle `.open` on `.ax-dropdown` (and `.ax-dropdown-menu` too, if the
   menu is portaled to <body> for stacking-context reasons — see
   ide's own note on this exact issue).
──────────────────────────────────────────────────────────────────── */
.ax-dropdown {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  color: var(--fg-0);
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  transition: border-color 150ms, box-shadow 150ms, background 150ms;
}
.ax-dropdown:hover { background: var(--bg-0); border-color: var(--accent-dim); }
.ax-dropdown:focus-visible, .ax-dropdown.open {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(126, 224, 201, 0.14);
}
.ax-dropdown::after {
  content: "";
  width: 7px; height: 7px;
  margin-left: 10px;
  border-right: 1.5px solid var(--fg-2);
  border-bottom: 1.5px solid var(--fg-2);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 150ms;
}
.ax-dropdown.open::after { transform: rotate(-135deg) translateY(2px); }
.ax-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px); left: 0;
  min-width: 100%;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-0);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.5);
  padding: 4px;
  z-index: 200;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 150ms, transform 150ms;
}
.ax-dropdown.open .ax-dropdown-menu,
.ax-dropdown-menu.open { opacity: 1; transform: translateY(0); pointer-events: auto; }
.ax-dropdown-item { padding: 7px 10px; border-radius: 2px; font-size: 13px; cursor: pointer; transition: background 150ms; }
.ax-dropdown-item:hover, .ax-dropdown-item.active { background: rgba(255, 255, 255, 0.06); }
.ax-dropdown-item.selected { color: var(--accent); }
.ax-dropdown-search {
  width: 100%;
  padding: 6px 8px;
  margin-bottom: 4px;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: 2px;
  color: var(--fg-0);
  font-family: inherit;
  font-size: 12px;
}
.ax-dropdown-search:focus { outline: none; border-color: var(--accent); }
.ax-dropdown-group {
  padding: 6px 10px 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-2);
  font-weight: 600;
  user-select: none;
  pointer-events: none;
}
