/* ════════════════════════════════════════════════════════════════════════
 * BUNYAN COMPONENTS V2
 *
 * Refined primitives built atop tokens.css + brand.css. These are scoped
 * to NEW classnames (.bn-btn, .bn-card, .bn-input…) so they don't fight
 * with legacy styles. As we refactor screens, swap classnames; legacy
 * styles remain as a fallback.
 * ════════════════════════════════════════════════════════════════════════ */

/* ── 1. Base reset (additive — does not break legacy) ─────────────────── */
:where(html) { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
:where(body) {
  font-family: var(--font-sans-ar);
  font-size: var(--text-base);
  line-height: var(--lh-normal);
  color: var(--color-text-primary);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:where(*) { box-sizing: border-box; }
:where(*:focus-visible) {
  outline: 2px solid var(--bn-gold-400);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
:where(::selection) {
  background: var(--bn-gold-300);
  color: var(--bn-ink-strong);
}
:where(img, svg, video) { max-width: 100%; }

/* Scrollbar — subtle, brand-tinted */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--bn-stone-200); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--bn-stone-300); background-clip: padding-box; }

/* ── 2. Button system ─────────────────────────────────────────────────── */
.bn-btn {
  --btn-bg: var(--bn-stone-500);
  --btn-fg: var(--bn-sand-50);
  --btn-border: transparent;
  --btn-shadow: var(--shadow-sm);
  --btn-shadow-hover: var(--shadow-md);

  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  white-space: nowrap;
  box-shadow: var(--btn-shadow);
  transition:
    transform var(--dur-fast) var(--ease-out-soft),
    box-shadow var(--dur-base) var(--ease-out-soft),
    background var(--dur-fast) var(--ease-out-soft),
    color var(--dur-fast) var(--ease-out-soft);
  position: relative; isolation: isolate;
}
.bn-btn:hover:not(:disabled)  { transform: translateY(-1px); box-shadow: var(--btn-shadow-hover); }
.bn-btn:active:not(:disabled) { transform: translateY(0); box-shadow: var(--btn-shadow); }
.bn-btn:disabled              { opacity: .55; cursor: not-allowed; }

.bn-btn--primary {
  --btn-bg: var(--bn-stone-500);
  --btn-fg: #fff;
  background-image: var(--grad-stone);
}
.bn-btn--accent {
  --btn-bg: var(--bn-gold-400);
  --btn-fg: var(--bn-ink-strong);
  background-image: var(--grad-gold);
  --btn-shadow: var(--shadow-glow-gold);
}
.bn-btn--trust {
  --btn-bg: var(--bn-palm-500);
  --btn-fg: #fff;
  background-image: var(--grad-palm);
}
.bn-btn--ghost {
  --btn-bg: transparent;
  --btn-fg: var(--bn-stone-500);
  --btn-border: var(--color-border-strong);
  --btn-shadow: none;
  --btn-shadow-hover: var(--shadow-xs);
  background-image: none;
}
.bn-btn--ghost:hover:not(:disabled) {
  background: var(--bn-sand-100);
}
.bn-btn--danger {
  --btn-bg: var(--bn-danger);
  --btn-fg: #fff;
}

.bn-btn--sm { padding: var(--space-2) var(--space-3); font-size: var(--text-sm); border-radius: var(--radius-sm); }
.bn-btn--lg { padding: var(--space-4) var(--space-6); font-size: var(--text-lg); }
.bn-btn--block { display: flex; width: 100%; }
.bn-btn--pill  { border-radius: var(--radius-pill); }

/* Polish: subtle shimmer on accent buttons */
.bn-btn--accent::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; z-index: -1;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,.45) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform var(--dur-anchor) var(--ease-out-soft);
  pointer-events: none;
}
.bn-btn--accent:hover::before { transform: translateX(100%); }

/* ── 3. Card system ───────────────────────────────────────────────────── */
.bn-card {
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur-base) var(--ease-out-soft),
              transform var(--dur-base) var(--ease-out-soft),
              border-color var(--dur-base) var(--ease-out-soft);
}
.bn-card--hover:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--bn-stone-300); }
.bn-card--sunk        { background: var(--color-surface-sunk); box-shadow: var(--shadow-xs); }
.bn-card--feature     {
  background:
    linear-gradient(135deg, rgba(255,255,255,.7), rgba(255,255,255,0) 60%),
    var(--color-surface-raised);
  border: 1px solid var(--bn-stone-200);
}
.bn-card--gold-edge   { border: 2px solid transparent; background:
    linear-gradient(var(--color-surface-raised), var(--color-surface-raised)) padding-box,
    var(--grad-gold) border-box; }

.bn-card-title { font-size: var(--text-lg); font-weight: 700; margin: 0 0 var(--space-2); color: var(--bn-ink-strong); }
.bn-card-sub   { font-size: var(--text-sm); color: var(--color-text-secondary); margin: 0; line-height: var(--lh-snug); }

/* ── 4. Input system ──────────────────────────────────────────────────── */
.bn-field { display: flex; flex-direction: column; gap: var(--space-2); }
.bn-label { font-size: var(--text-sm); font-weight: 600; color: var(--bn-stone-600); }
.bn-input, .bn-select, .bn-textarea {
  appearance: none;
  font: inherit;
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-raised);
  color: var(--color-text-primary);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  line-height: var(--lh-snug);
  transition: border-color var(--dur-fast) var(--ease-out-soft),
              box-shadow var(--dur-fast) var(--ease-out-soft),
              background var(--dur-fast) var(--ease-out-soft);
}
.bn-input:focus, .bn-select:focus, .bn-textarea:focus {
  outline: none;
  border-color: var(--bn-gold-400);
  box-shadow: 0 0 0 3px rgba(201, 164, 90, .22);
  background: #fff;
}
.bn-input::placeholder, .bn-textarea::placeholder { color: var(--color-text-muted); }
.bn-input[aria-invalid="true"] { border-color: var(--bn-danger); }
.bn-textarea { resize: vertical; min-height: 88px; }
.bn-help    { font-size: var(--text-xs); color: var(--color-text-muted); }

/* ── 5. Pills / badges ────────────────────────────────────────────────── */
.bn-pill {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-3);
  font-size: var(--text-xs); font-weight: 700;
  border-radius: var(--radius-pill);
  background: var(--bn-sand-100); color: var(--bn-stone-600);
  border: 1px solid var(--bn-stone-200);
}
.bn-pill--gold   { background: var(--grad-gold); color: var(--bn-ink-strong); border-color: transparent; }
.bn-pill--palm   { background: var(--grad-palm); color: #fff; border-color: transparent; }
.bn-pill--ink    { background: var(--bn-ink); color: #fff; border-color: transparent; }
.bn-pill--ghost  { background: transparent; }
.bn-pill--danger { background: #fff0f0; color: var(--bn-danger); border-color: #f3c8cc; }

/* ── 6. Modal ──────────────────────────────────────────────────────────── */
.bn-modal {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: flex; align-items: center; justify-content: center;
  padding: var(--gutter);
  background: var(--color-surface-veil);
  backdrop-filter: blur(8px) saturate(140%);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
  animation: bn-modal-in var(--dur-base) var(--ease-out-soft);
}
@keyframes bn-modal-in { from { opacity: 0; } to { opacity: 1; } }
.bn-modal--hidden { display: none; }
.bn-modal-card {
  background: var(--color-surface-raised);
  border-radius: var(--radius-xl);
  max-width: 640px;
  width: 100%;
  max-height: min(92vh, 800px);
  overflow-y: auto;
  padding: var(--space-6) var(--space-8);
  box-shadow: var(--shadow-xl);
  position: relative;
  animation: bn-card-in var(--dur-slow) var(--ease-out-soft);
}
@keyframes bn-card-in {
  from { opacity: 0; transform: translateY(16px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── 7. Surface helpers ───────────────────────────────────────────────── */
.bn-divider     { height: 1px; background: var(--color-divider); border: 0; margin: var(--space-6) 0; }
.bn-divider-v   { width: 1px; background: var(--color-divider); align-self: stretch; }
.bn-bg-sand     { background: var(--bn-sand-100); }
.bn-bg-sunk     { background: var(--color-surface-sunk); }
.bn-text-muted  { color: var(--color-text-muted); }
.bn-text-accent { color: var(--color-accent); }

/* ── 8. Skeleton / loading ────────────────────────────────────────────── */
@keyframes bn-shimmer {
  0%   { background-position: -200px 0; }
  100% { background-position: calc(200px + 100%) 0; }
}
.bn-skeleton {
  background: linear-gradient(90deg, var(--bn-sand-100) 0%, var(--bn-sand-200) 50%, var(--bn-sand-100) 100%);
  background-size: 200px 100%;
  background-repeat: no-repeat;
  border-radius: var(--radius-sm);
  animation: bn-shimmer 1.4s ease-in-out infinite;
}

/* ── 8b. Trust Badges (Design-journey credibility system) ─────────────────
 * Three levels signal who is accountable for each output:
 *   trust-auto      🟢  computed deterministically — verifiable
 *   trust-copilot   🟡  AI proposal — reviewed by platform architect
 *   trust-engineer  🔴  must be sealed by a licensed engineering office
 * The badge is clickable; the modal explains what the level means and
 * what the next step is. The visual rhythm is consistent everywhere
 * the user sees AI output (journey, share page, PDF cover).
 * ──────────────────────────────────────────────────────────────────────── */
.trust-badge {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .28rem .7rem;
  border-radius: 999px;
  font-size: .78rem; font-weight: 700;
  line-height: 1.2;
  letter-spacing: .01em;
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: transform .12s ease, box-shadow .12s ease;
  font-family: var(--font-sans-ar, inherit);
}
.trust-badge:hover    { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(0,0,0,.06); }
.trust-badge:focus-visible { outline: 2px solid var(--bn-gold-400); outline-offset: 2px; }
.trust-badge .tb-dot  { width: .55rem; height: .55rem; border-radius: 50%; flex-shrink: 0; }
.trust-badge .tb-i    { opacity: .6; font-weight: 600; font-size: .7rem; }

.trust-auto {
  background: #e7f5ec; color: #0e7a3f; border-color: #b9e2c8;
}
.trust-auto .tb-dot   { background: #0e7a3f; box-shadow: 0 0 0 3px rgba(14,122,63,.15); }

.trust-copilot {
  background: #fdf3cc; color: #7a5b00; border-color: #f0dc8b;
}
.trust-copilot .tb-dot { background: #d49a00; box-shadow: 0 0 0 3px rgba(212,154,0,.18); }

.trust-engineer {
  background: #fbe1e4; color: #8a1a2a; border-color: #f1b8c0;
}
.trust-engineer .tb-dot { background: #a02333; box-shadow: 0 0 0 3px rgba(160,35,51,.18); }

/* Inline-row variant: place a badge above a result heading */
.trust-row {
  display: flex; align-items: center; gap: .7rem;
  margin: 0 0 .6rem 0; flex-wrap: wrap;
}
.trust-row .trust-label {
  font-size: .8rem; color: var(--color-text-muted, #6b6358);
}

/* Explainer modal */
.trust-modal-backdrop {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(20,16,10,.55);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  animation: tb-fade .18s ease;
}
.trust-modal {
  background: #fffaf0;
  border-radius: 16px;
  max-width: 460px; width: 100%;
  padding: 1.5rem 1.4rem 1.2rem;
  box-shadow: 0 24px 60px rgba(0,0,0,.25);
  font-family: var(--font-sans-ar, inherit);
  direction: rtl;
  animation: tb-pop .22s cubic-bezier(.2,.9,.3,1.2);
}
.trust-modal h4 {
  margin: 0 0 .4rem; font-size: 1.15rem; display: flex; align-items: center; gap: .5rem;
}
.trust-modal p { margin: .55rem 0; line-height: 1.65; color: #3a3025; font-size: .92rem; }
.trust-modal .tb-next {
  background: #fdf3cc; border-right: 3px solid #d49a00;
  padding: .6rem .8rem; border-radius: 6px; margin-top: .8rem;
  font-size: .87rem;
}
.trust-modal .tb-close {
  margin-top: 1rem; width: 100%;
  background: #0e2746; color: #fff;
  border: none; border-radius: 10px;
  padding: .65rem 1rem; font-weight: 700; cursor: pointer;
  font-family: inherit;
}
.trust-modal .tb-close:hover { background: #143358; }

@keyframes tb-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes tb-pop  { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }

/* ── 9. Navbar V2 (used by the refreshed brand) ───────────────────────── */
.bn-nav {
  position: sticky; top: 0; z-index: var(--z-sticky);
  background: rgba(254, 252, 246, 0.85);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--color-divider);
}
.bn-nav-inner {
  max-width: var(--max-w-content);
  margin: 0 auto;
  padding: var(--space-3) var(--gutter);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-6);
}

/* ── 10. Container queries — layout that adapts to its own width ──────── */
@supports (container-type: inline-size) {
  .bn-container { container-type: inline-size; }
}

/* ── 11. Utility: visually hide but keep accessible ──────────────────── */
.bn-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
