/* ─────────────────────────────────────────────────────────────────
   css/ai-key-wizard.css
   --------------------------------------------------------------------
   Styles for the BYOK AI-key wizard (js/builder/ai-key-wizard.js).
   Two surfaces:
     1. The pill button injected into the Assistant rail header
        (#aiKeyWizardPill).
     2. The full-screen wizard modal (.aikw-root / .aikw-overlay /
        .aikw-modal).

   Tap targets >= 44px, mobile-first stack on <= 768px.
   LABEL: PILOT-READY.
───────────────────────────────────────────────────────────────── */

/* ── Pill button ─────────────────────────────────────────────── */
.aikw-pill {
  /* Sits inside .ai-rail at the top of the body. Full-width pill
     above the chat to give it the same "obvious" surface area as
     the Build → button below the prompt. */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  width: 100%;
  min-height: 44px; /* NN/g tap target */
  padding: 0.55rem 0.9rem;
  margin: 0 0 0.6rem 0;
  background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
  color: #9a3412;
  border: 1px solid #fed7aa;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.01em;
  box-shadow: 0 1px 2px rgba(154, 52, 18, 0.08);
  transition: background 120ms ease, transform 80ms ease, box-shadow 120ms ease;
}
.aikw-pill:hover {
  background: linear-gradient(135deg, #ffedd5 0%, #fed7aa 100%);
  box-shadow: 0 2px 6px rgba(154, 52, 18, 0.16);
}
.aikw-pill:active { transform: translateY(1px); }
.aikw-pill:focus-visible {
  outline: 2px solid #f97316;
  outline-offset: 2px;
}
.aikw-pill[data-has-key="1"] {
  /* Subtle green tint when a key is already saved — confirms "you're
     on your own key" without screaming. */
  background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
  color: #166534;
  border-color: #bbf7d0;
  box-shadow: 0 1px 2px rgba(22, 101, 52, 0.08);
}
.aikw-pill[data-has-key="1"]:hover {
  background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
}

/* ── Modal overlay + card ───────────────────────────────────── */
.aikw-root { /* unstyled wrapper — overlay does the heavy lifting */ }

.aikw-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 9999;
  -webkit-tap-highlight-color: transparent;
}

.aikw-modal {
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 2rem);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.3),
              0 2px 8px rgba(15, 23, 42, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: #111827;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
}

.aikw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.5rem;
  border-bottom: 1px solid #f1f5f9;
}
.aikw-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: #0f172a;
}
.aikw-close {
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: #475569;
  cursor: pointer;
  border-radius: 8px;
  padding: 0;
}
.aikw-close:hover { background: #f1f5f9; color: #0f172a; }
.aikw-close:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }

.aikw-lede {
  margin: 0;
  padding: 0.6rem 1.25rem 0.4rem;
  font-size: 0.88rem;
  color: #475569;
  line-height: 1.45;
}

.aikw-body {
  padding: 0.6rem 1.25rem 1.1rem;
  overflow-y: auto;
  flex: 1 1 auto;
}

/* ── Path: step list (Path A) ───────────────────────────────── */
.aikw-step-list {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin-top: 0.4rem;
}
.aikw-step {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 0.7rem;
  padding: 0.75rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
}
.aikw-step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.aikw-step-body strong {
  display: block;
  font-size: 0.95rem;
  color: #0f172a;
  margin-bottom: 0.25rem;
}
.aikw-step-body p {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  color: #475569;
  line-height: 1.4;
}
.aikw-step-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  background: #eef2ff;
  color: #3730a3;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
}

/* ── Path B: form-row pattern ──────────────────────────────── */
.aikw-form-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}
.aikw-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #334155;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.aikw-hint {
  margin: 0;
  font-size: 0.78rem;
  color: #64748b;
}
.aikw-link {
  font-size: 0.82rem;
  color: #2563eb;
  text-decoration: none;
  align-self: flex-start;
  padding: 0.2rem 0;
}
.aikw-link:hover { text-decoration: underline; }
.aikw-link:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }

/* ── Inputs ────────────────────────────────────────────────── */
.aikw-input,
.aikw-select {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.7rem;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  font-size: 16px; /* iOS-zoom defense */
  background: #fff;
  color: #0f172a;
  outline: none;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
.aikw-input:focus,
.aikw-select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

/* ── Buttons ───────────────────────────────────────────────── */
.aikw-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.4rem;
}
.aikw-btn {
  min-height: 44px;
  padding: 0.55rem 1rem;
  border-radius: 9px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: #0f172a;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}
.aikw-btn:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}
.aikw-btn-primary {
  background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.3);
}
.aikw-btn-primary:hover {
  filter: brightness(1.05);
}
.aikw-btn-secondary {
  background: #fff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}
.aikw-btn-secondary:hover {
  background: #eff6ff;
}
.aikw-btn-ghost {
  background: transparent;
  color: #475569;
  border-color: transparent;
}
.aikw-btn-ghost:hover {
  background: #f1f5f9;
  color: #0f172a;
}
.aikw-btn-danger {
  background: #fff;
  color: #b91c1c;
  border-color: #fecaca;
}
.aikw-btn-danger:hover {
  background: #fef2f2;
}

/* ── Status / error pills ──────────────────────────────────── */
.aikw-error {
  margin: 0.4rem 0 0.6rem;
  padding: 0.55rem 0.75rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
}
.aikw-status {
  margin: 0.4rem 0 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
}
.aikw-status[data-kind="ok"] {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}
.aikw-status[data-kind="info"] {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

/* ── Existing-key panel ────────────────────────────────────── */
.aikw-existing {
  margin-top: 1rem;
  padding: 0.8rem;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.aikw-existing-row {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.aikw-existing-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  font-weight: 700;
}
.aikw-existing-value {
  font-size: 0.9rem;
  color: #0f172a;
}
.aikw-existing-value code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  color: #334155;
  background: #fff;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
}

/* ── Mobile ≤768px: vertical stack ─────────────────────────── */
@media (max-width: 768px) {
  .aikw-overlay { padding: 0; align-items: flex-end; }
  .aikw-modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }
  .aikw-actions { flex-direction: column; }
  .aikw-actions .aikw-btn { width: 100%; }
}
