/* ============================================================================
   instant-ux.css — the "instant, zero-friction, expensive" experience layer
   ----------------------------------------------------------------------------
   Additive ONLY. Styles new components (command palette, nav progress, toasts,
   skeletons) + safe global micro-interactions. Uses design-system tokens with
   fallbacks so it tracks all 7 themes. Honors prefers-reduced-motion.
   Launch Doctrine — UX elevation.
   ========================================================================== */

:root {
  --iux-ease: cubic-bezier(0.22, 1, 0.36, 1);          /* gentle spring-out  */
  --iux-ease-in: cubic-bezier(0.4, 0, 1, 1);
  --iux-accent: var(--af-brand, var(--color-primary, #8a1538));
  --iux-radius: 14px;
  --iux-shadow: 0 24px 70px -18px rgba(15, 17, 24, 0.45), 0 6px 18px -8px rgba(15, 17, 24, 0.30);
  --iux-glass: color-mix(in srgb, var(--color-surface, #ffffff) 86%, transparent);
}

/* ── 1. Top navigation progress bar (perceived instant nav) ───────────────── */
#iux-progress {
  position: fixed; top: 0; left: 0; height: 2.5px; width: 0;
  z-index: 100000; pointer-events: none; border-radius: 0 3px 3px 0;
  background: linear-gradient(90deg,
      var(--iux-accent),
      color-mix(in srgb, var(--iux-accent) 55%, #f0abfc));
  box-shadow: 0 0 10px color-mix(in srgb, var(--iux-accent) 60%, transparent);
  opacity: 0; transition: width 180ms var(--iux-ease), opacity 220ms ease;
}
#iux-progress.active { opacity: 1; }

/* ── 2. Command palette (⌘K / Ctrl-K) — "knows what you want" ──────────────── */
#iux-palette-overlay {
  position: fixed; inset: 0; z-index: 99990; display: none;
  align-items: flex-start; justify-content: center;
  padding-top: clamp(60px, 14vh, 160px);
  background: rgba(10, 12, 18, 0.42);
  -webkit-backdrop-filter: blur(6px) saturate(120%); backdrop-filter: blur(6px) saturate(120%);
  opacity: 0; transition: opacity 160ms ease;
}
#iux-palette-overlay.open { opacity: 1; } /* display:flex is set by JS one frame earlier so the transition plays */

#iux-palette {
  width: min(640px, 92vw); max-height: min(80vh, 660px);
  display: block; overflow: hidden;
  background: var(--iux-glass);
  -webkit-backdrop-filter: blur(20px) saturate(150%); backdrop-filter: blur(20px) saturate(150%);
  border: 1px solid color-mix(in srgb, var(--color-border, #e5e7eb) 70%, transparent);
  border-radius: var(--iux-radius); box-shadow: var(--iux-shadow);
  transform: translateY(-8px) scale(0.985); opacity: 0;
  transition: transform 220ms var(--iux-ease), opacity 180ms ease;
}
#iux-palette-overlay.open #iux-palette { transform: translateY(0) scale(1); opacity: 1; }

.iux-palette-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid color-mix(in srgb, var(--color-border, #e5e7eb) 60%, transparent);
}
.iux-palette-head svg { flex: 0 0 auto; color: var(--color-text-secondary, #6b7280); opacity: 0.8; }
#iux-palette-input {
  flex: 1 1 auto; border: 0; outline: 0; background: transparent;
  font-size: 1.06rem; font-weight: 500; color: var(--color-text, #111827);
  font-family: inherit; letter-spacing: -0.01em;
}
#iux-palette-input::placeholder { color: var(--color-text-secondary, #9ca3af); opacity: 0.75; }
.iux-palette-hint {
  flex: 0 0 auto; font-size: 0.66rem; color: var(--color-text-secondary, #9ca3af);
  border: 1px solid color-mix(in srgb, var(--color-border, #e5e7eb) 70%, transparent);
  border-radius: 6px; padding: 2px 7px; font-weight: 600; letter-spacing: 0.02em;
}

/* position:static/relative overrides the design-system's global [role=listbox]{position:absolute},
   which would otherwise pull the results out of flow and collapse the palette card. */
.iux-palette-results { position: relative; inset: auto; overflow-y: auto; overflow-x: hidden; padding: 8px; scroll-behavior: smooth; max-height: 54vh; }
.iux-group-label {
  font-size: 0.64rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--color-text-secondary, #9ca3af); padding: 10px 12px 4px;
}
.iux-result {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: 10px; cursor: pointer; color: var(--color-text, #1f2937);
  transition: background 120ms ease, transform 120ms var(--iux-ease);
}
.iux-result .iux-ricon {
  flex: 0 0 auto; width: 30px; height: 30px; display: grid; place-items: center;
  border-radius: 8px; font-size: 0.95rem;
  background: color-mix(in srgb, var(--iux-accent) 12%, transparent);
  color: var(--iux-accent);
}
.iux-result .iux-rtext { flex: 1 1 auto; min-width: 0; }
.iux-result .iux-rtitle { font-size: 0.92rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iux-result .iux-rsub { font-size: 0.74rem; color: var(--color-text-secondary, #9ca3af); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iux-result .iux-rkey {
  flex: 0 0 auto; font-size: 0.66rem; color: var(--color-text-secondary, #9ca3af);
  border: 1px solid color-mix(in srgb, var(--color-border, #e5e7eb) 70%, transparent);
  border-radius: 5px; padding: 1px 6px; font-weight: 600;
}
.iux-result.active, .iux-result:hover {
  background: color-mix(in srgb, var(--iux-accent) 10%, transparent);
  transform: translateX(2px);
}
.iux-result mark { background: color-mix(in srgb, var(--iux-accent) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.iux-palette-empty { padding: 28px 16px; text-align: center; color: var(--color-text-secondary, #9ca3af); font-size: 0.88rem; }
.iux-palette-foot {
  display: flex; gap: 16px; align-items: center; justify-content: flex-start;
  padding: 9px 16px; border-top: 1px solid color-mix(in srgb, var(--color-border, #e5e7eb) 60%, transparent);
  font-size: 0.7rem; color: var(--color-text-secondary, #9ca3af);
}
.iux-palette-foot kbd {
  font-family: inherit; font-size: 0.66rem; border: 1px solid color-mix(in srgb, var(--color-border, #e5e7eb) 70%, transparent);
  border-radius: 5px; padding: 1px 6px; margin: 0 1px; font-weight: 600;
}

/* ── 3. Shortcuts help overlay (?) ────────────────────────────────────────── */
#iux-help-overlay {
  position: fixed; inset: 0; z-index: 99980; display: none; align-items: center; justify-content: center;
  background: rgba(10, 12, 18, 0.42); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  opacity: 0; transition: opacity 160ms ease;
}
#iux-help-overlay.open { opacity: 1; } /* display:flex set by JS one frame earlier */
.iux-help-card {
  width: min(520px, 92vw); background: var(--iux-glass);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border: 1px solid color-mix(in srgb, var(--color-border, #e5e7eb) 70%, transparent);
  border-radius: var(--iux-radius); box-shadow: var(--iux-shadow); padding: 22px 24px;
  transform: scale(0.97); opacity: 0; transition: transform 200ms var(--iux-ease), opacity 160ms ease;
}
#iux-help-overlay.open .iux-help-card { transform: scale(1); opacity: 1; }
.iux-help-card h3 { margin: 0 0 14px; font-size: 1.05rem; font-weight: 700; }
.iux-help-row { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid color-mix(in srgb, var(--color-border, #e5e7eb) 45%, transparent); }
.iux-help-row:last-child { border-bottom: 0; }
.iux-help-row span { font-size: 0.86rem; color: var(--color-text, #374151); }
.iux-help-row kbd {
  font-family: inherit; font-size: 0.72rem; background: color-mix(in srgb, var(--color-border, #e5e7eb) 30%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-border, #e5e7eb) 70%, transparent);
  border-radius: 6px; padding: 2px 8px; font-weight: 600; margin-left: 3px;
}

/* ── 4. Toast stack (unify position; works with app.js showToast + utils Toast) */
.toast-container,
.flash-message.iux-toast-zone { position: fixed; top: 18px; right: 18px; z-index: 99970; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast-container > * { pointer-events: auto; }

/* ── 5. Loading skeleton shimmer ──────────────────────────────────────────── */
.iux-skeleton {
  position: relative; overflow: hidden;
  background: color-mix(in srgb, var(--color-border, #e5e7eb) 35%, transparent);
  border-radius: 8px;
}
.iux-skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--color-surface, #fff) 55%, transparent), transparent);
  animation: iux-shimmer 1.25s infinite;
}
@keyframes iux-shimmer { 100% { transform: translateX(100%); } }

/* ── 6. Safe global micro-interactions ("expensive" feel) ─────────────────── */
@media (hover: hover) {
  a.btn, button.btn, .btn { transition: transform 120ms var(--iux-ease), box-shadow 160ms ease, filter 160ms ease; }
  a.btn:active, button.btn:active, .btn:active { transform: translateY(1px) scale(0.985); }
}
/* crisp, consistent keyboard focus ring across the app */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--iux-accent) 60%, transparent);
  outline-offset: 2px; border-radius: 6px;
}
/* gentle content enter on load (perceived speed) */
main#main-content { animation: iux-rise 320ms var(--iux-ease) both; }
@keyframes iux-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

html { scroll-behavior: smooth; }

/* ── 6b. Premium toast stack (overrides in-flow flash positioning) ────────── */
#iux-toast-region {
  position: fixed; top: 18px; right: 18px; z-index: 99970;
  display: flex; flex-direction: column; gap: 10px; pointer-events: none;
  max-width: min(380px, 92vw);
}
.iux-toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px;
  padding: 12px 15px; border-radius: 12px;
  background: var(--iux-glass);
  -webkit-backdrop-filter: blur(16px) saturate(150%); backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid color-mix(in srgb, var(--color-border, #e5e7eb) 70%, transparent);
  box-shadow: 0 16px 40px -14px rgba(15, 17, 24, 0.4);
  color: var(--color-text, #1f2937); font-size: 0.88rem; font-weight: 500;
  transform: translateX(120%); opacity: 0;
  transition: transform 360ms var(--iux-ease), opacity 240ms ease;
}
.iux-toast.in { transform: translateX(0); opacity: 1; }
.iux-toast .iux-toast-ic { flex: 0 0 auto; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; font-size: 0.8rem; font-weight: 700; color: #fff; }
.iux-toast-success .iux-toast-ic { background: #16a34a; }
.iux-toast-error .iux-toast-ic { background: #dc2626; }
.iux-toast-info .iux-toast-ic { background: var(--iux-accent); }

/* inline button spinner (submit loading state) */
.iux-spin {
  display: inline-block; width: 13px; height: 13px; vertical-align: -2px; margin-right: 5px;
  border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
  border-top-color: currentColor; border-radius: 50%; animation: iux-spin 0.7s linear infinite;
}
.btn.iux-busy { opacity: 0.85; cursor: progress; }
@keyframes iux-spin { to { transform: rotate(360deg); } }

/* make the "live" eyebrow dot actually pulse (it never did) */
.af-eyebrow-pulse-dot { animation: iux-pulse 2.2s ease-in-out infinite; }
@keyframes iux-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.45; transform: scale(0.72); } }

/* skip-to-content link (a11y) — visible only on keyboard focus */
.iux-skip {
  position: fixed; top: 8px; left: 8px; z-index: 100001;
  background: var(--iux-accent); color: #fff; padding: 9px 16px; border-radius: 9px;
  font-size: 0.85rem; font-weight: 600; text-decoration: none;
  transform: translateY(-160%); transition: transform 180ms var(--iux-ease);
}
.iux-skip:focus { transform: translateY(0); outline: 2px solid #fff; outline-offset: 2px; }

/* ── 8. Premium Glassmorphic Cards & UI Glow ────────────────────────────── */
.card, .app-card, .dashboard-hero {
  transition: transform 220ms var(--iux-ease), box-shadow 220ms var(--iux-ease), border-color 220ms var(--iux-ease);
}
.card:hover, .app-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 36px -12px color-mix(in srgb, var(--iux-accent) 15%, rgba(15, 17, 24, 0.25)), var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.06));
  border-color: color-mix(in srgb, var(--iux-accent) 30%, var(--color-border));
}

#iux-palette:focus-within {
  border-color: var(--iux-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--iux-accent) 15%, transparent), var(--iux-shadow);
}

.quantix-header {
  transition: background 220ms ease, box-shadow 220ms ease;
}

.header-search-trigger {
  box-sizing: border-box;
}
.header-search-trigger:hover {
  background: rgba(255,255,255,0.12) !important;
  border-color: rgba(255,255,255,0.2) !important;
  color: #fff !important;
  box-shadow: 0 0 12px rgba(255,255,255,0.06);
}
.header-search-trigger:active {
  transform: scale(0.97);
}


/* ── 9. Theme Manager settings panel glassmorphic override ──────────────── */
.tm-panel {
  background: color-mix(in srgb, var(--color-surface, #ffffff) 90%, transparent) !important;
  backdrop-filter: blur(24px) saturate(140%) !important;
  -webkit-backdrop-filter: blur(24px) saturate(140%) !important;
  border: 1px solid color-mix(in srgb, var(--color-border, #e5e7eb) 70%, transparent) !important;
  box-shadow: var(--shadow-xl, 0 20px 60px rgba(0,0,0,0.15)) !important;
}
.tm-theme-swatch {
  background: color-mix(in srgb, var(--color-surface) 60%, transparent) !important;
  border-color: color-mix(in srgb, var(--color-border) 40%, transparent) !important;
}


/* ── 7. Respect reduced-motion ────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
  main#main-content { animation: none; }
}
