/* XamAI unified UI/UX layer — non-destructive visual and interaction polish. */
:root {
  --ux-primary: var(--primary-color, #0b5cff);
  --ux-primary-strong: var(--primary-hover, #0649d8);
  --ux-bg: var(--background-color, #ffffff);
  --ux-surface: var(--surface-color, #f6f8fc);
  --ux-card: var(--dash-card, var(--background-color, #ffffff));
  --ux-text: var(--text-color, #172033);
  --ux-muted: var(--text-muted, #66758a);
  --ux-border: var(--border-color, #dbe3ef);
  --ux-radius-sm: 10px;
  --ux-radius-md: 14px;
  --ux-radius-lg: 22px;
  --ux-shadow-sm: 0 6px 18px rgba(15, 23, 42, 0.06);
  --ux-shadow-md: 0 18px 48px rgba(15, 23, 42, 0.10);
  --ux-shadow-lg: 0 28px 80px rgba(15, 23, 42, 0.14);
  --ux-ease: cubic-bezier(.2,.75,.25,1);
  --surface: var(--background-color, #fff);
  --surface-muted: var(--surface-color, #f4f7fb);
  --text: var(--text-color, #172033);
  --border: var(--border-color, #dbe3ef);
}

[data-theme="dark"] {
  color-scheme: dark;
  --ux-shadow-sm: 0 6px 20px rgba(0, 0, 0, 0.20);
  --ux-shadow-md: 0 18px 52px rgba(0, 0, 0, 0.28);
  --ux-shadow-lg: 0 30px 90px rgba(0, 0, 0, 0.34);
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 88px;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body {
  min-width: 320px;
  accent-color: var(--ux-primary);
}

::selection {
  background: color-mix(in srgb, var(--ux-primary) 24%, transparent);
}

* {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--ux-primary) 40%, var(--ux-border)) transparent;
}

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ux-primary) 36%, var(--ux-border));
  background-clip: padding-box;
}

:where(a, button, input, select, textarea, summary):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--ux-primary) 38%, transparent) !important;
  outline-offset: 3px !important;
}

:where(button, .button, .expansion-button, [role="button"]) {
  -webkit-tap-highlight-color: transparent;
}

:where(button, .button, .expansion-button):not(:disabled) {
  transition:
    transform 180ms var(--ux-ease),
    box-shadow 180ms var(--ux-ease),
    border-color 180ms ease,
    background-color 180ms ease,
    color 180ms ease;
}

:where(button, .button, .expansion-button):not(:disabled):active {
  transform: translateY(1px) scale(.985);
}

:where(input, select, textarea) {
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

:where(input, select, textarea):hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--ux-primary) 35%, var(--ux-border));
}

:where(input, select, textarea):focus {
  border-color: var(--ux-primary) !important;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ux-primary) 14%, transparent) !important;
}

:where(input, select, textarea):disabled {
  cursor: not-allowed;
  opacity: .66;
}

/* Page loading and scroll feedback */
.ux-page-progress {
  position: fixed;
  inset: 0 auto auto 0;
  z-index: 9999;
  width: var(--ux-progress, 0%);
  height: 3px;
  pointer-events: none;
  background: linear-gradient(90deg, #0b5cff, #6d4aff, #18a8e8);
  box-shadow: 0 0 14px color-mix(in srgb, var(--ux-primary) 65%, transparent);
  transition: width 80ms linear;
}

.ux-back-to-top {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--ux-border);
  border-radius: 50%;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  background: color-mix(in srgb, var(--ux-card) 90%, transparent);
  color: var(--ux-text);
  box-shadow: var(--ux-shadow-md);
  backdrop-filter: blur(14px);
}

.ux-back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Loading state shared by all forms/actions */
.ux-is-busy {
  position: relative;
  pointer-events: none;
  opacity: .78;
}

.ux-is-busy::after {
  width: 15px;
  height: 15px;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  animation: ux-spin .75s linear infinite;
}

@keyframes ux-spin { to { transform: rotate(360deg); } }

.ux-skeleton {
  position: relative;
  overflow: hidden;
  color: transparent !important;
  border-radius: 8px;
  background: color-mix(in srgb, var(--ux-border) 48%, var(--ux-surface));
}

.ux-skeleton::after {
  position: absolute;
  inset: 0;
  content: "";
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, #fff 58%, transparent), transparent);
  animation: ux-shimmer 1.35s infinite;
}

@keyframes ux-shimmer { 100% { transform: translateX(100%); } }

/* Public navigation: accessible mobile drawer */
.ux-public-toggle {
  display: none;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--ux-border);
  border-radius: 12px;
  background: var(--ux-card);
  color: var(--ux-text);
  cursor: pointer;
}

.ux-public-overlay {
  position: fixed;
  inset: 0;
  z-index: 109;
  opacity: 0;
  visibility: hidden;
  background: rgba(4, 12, 28, .46);
  backdrop-filter: blur(4px);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.ux-public-drawer {
  position: fixed;
  z-index: 110;
  top: 0;
  right: 0;
  display: grid;
  align-content: start;
  width: min(88vw, 360px);
  height: 100dvh;
  padding: 20px;
  gap: 18px;
  transform: translateX(105%);
  background: var(--ux-card);
  color: var(--ux-text);
  box-shadow: var(--ux-shadow-lg);
  transition: transform 240ms var(--ux-ease);
}

.ux-public-drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--ux-border);
}

.ux-public-drawer__brand { font-size: 1.1rem; font-weight: 800; }
.ux-public-drawer__close {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--ux-border);
  border-radius: 12px;
  background: transparent;
  color: inherit;
}

.ux-public-drawer__links {
  display: grid;
  gap: 6px;
}

.ux-public-drawer__links a {
  display: flex;
  min-height: 46px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  color: inherit;
  font-weight: 650;
}

.ux-public-drawer__links a:hover,
.ux-public-drawer__links a[aria-current="page"] {
  background: color-mix(in srgb, var(--ux-primary) 10%, var(--ux-surface));
  color: var(--ux-primary);
}

body.ux-public-nav-open { overflow: hidden; }
body.ux-public-nav-open .ux-public-overlay { opacity: 1; visibility: visible; }
body.ux-public-nav-open .ux-public-drawer { transform: translateX(0); }

/* Authenticated navigation: desktop priorities + mobile bottom bar */
.dash-header {
  box-shadow: 0 1px 0 color-mix(in srgb, var(--ux-border) 70%, transparent);
}

.dash-header__inner { max-width: 1500px; }

.dash-top-nav.ux-nav-enhanced {
  min-width: 0;
  overflow: visible;
}

.ux-desktop-more { flex: 0 0 auto; }
.ux-desktop-more .dash-more-menu__panel { left: auto; right: 0; }

.ux-app-mobile-nav {
  position: fixed;
  z-index: 100;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: 10px;
  display: none;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  min-height: 64px;
  padding: 7px;
  border: 1px solid color-mix(in srgb, var(--ux-border) 88%, transparent);
  border-radius: 20px;
  background: color-mix(in srgb, var(--ux-card) 91%, transparent);
  box-shadow: 0 18px 48px rgba(15, 23, 42, .20);
  backdrop-filter: blur(18px) saturate(1.2);
}

.ux-app-mobile-nav a,
.ux-app-mobile-nav button {
  display: grid;
  min-width: 0;
  place-items: center;
  align-content: center;
  gap: 4px;
  padding: 5px 3px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--ux-muted);
  font: inherit;
  font-size: .68rem;
  font-weight: 700;
  text-decoration: none;
}

.ux-app-mobile-nav i { font-size: 1rem; }
.ux-app-mobile-nav a[aria-current="page"],
.ux-app-mobile-nav button[aria-expanded="true"] {
  background: color-mix(in srgb, var(--ux-primary) 12%, var(--ux-surface));
  color: var(--ux-primary);
}

.ux-app-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 101;
  opacity: 0;
  visibility: hidden;
  background: rgba(4, 12, 28, .48);
  backdrop-filter: blur(4px);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.ux-app-sheet {
  position: fixed;
  z-index: 102;
  right: 10px;
  bottom: 10px;
  left: 10px;
  display: grid;
  max-height: min(76dvh, 650px);
  padding: 18px;
  gap: 14px;
  overflow: auto;
  border: 1px solid var(--ux-border);
  border-radius: 24px;
  transform: translateY(calc(100% + 24px));
  background: var(--ux-card);
  box-shadow: var(--ux-shadow-lg);
  transition: transform 240ms var(--ux-ease);
}

.ux-app-sheet__handle {
  width: 42px;
  height: 4px;
  margin: -4px auto 2px;
  border-radius: 999px;
  background: var(--ux-border);
}

.ux-app-sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ux-app-sheet__head h2 { margin: 0; font-size: 1.05rem; }
.ux-app-sheet__close {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--ux-border);
  border-radius: 12px;
  background: transparent;
  color: inherit;
}

.ux-app-sheet__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ux-app-sheet__grid a {
  display: flex;
  min-height: 66px;
  align-items: center;
  padding: 12px;
  gap: 10px;
  border: 1px solid var(--ux-border);
  border-radius: 15px;
  background: var(--ux-surface);
  color: var(--ux-text);
  font-weight: 720;
  text-decoration: none;
}

.ux-app-sheet__grid a:hover,
.ux-app-sheet__grid a[aria-current="page"] {
  border-color: color-mix(in srgb, var(--ux-primary) 42%, var(--ux-border));
  background: color-mix(in srgb, var(--ux-primary) 9%, var(--ux-surface));
  color: var(--ux-primary);
}

body.ux-app-sheet-open { overflow: hidden; }
body.ux-app-sheet-open .ux-app-sheet-overlay { opacity: 1; visibility: visible; }
body.ux-app-sheet-open .ux-app-sheet { transform: translateY(0); }

/* Cards and information hierarchy */
:where(.feature-card, .pricing-card, .blog-card, .dashboard-card, .learning-panel, .learning-hero,
.expansion-card, .expansion-item, .product-card, .catalog-card, .attempt-card,
.notification-card, .admin-question-card, .legal-card, .auth-card, .test-shell, .result-panel) {
  transition: transform 200ms var(--ux-ease), box-shadow 200ms var(--ux-ease), border-color 200ms ease;
}

@media (hover: hover) and (pointer: fine) {
  :where(.feature-card, .pricing-card, .blog-card, .expansion-card, .product-card,
  .catalog-card, .attempt-card, .notification-card, .admin-question-card):hover {
    border-color: color-mix(in srgb, var(--ux-primary) 25%, var(--ux-border));
    transform: translateY(-3px);
    box-shadow: var(--ux-shadow-md);
  }
}

:where(.dashboard-card, .learning-panel, .expansion-card, .legal-card) {
  box-shadow: var(--ux-shadow-sm);
}

:where(.dashboard-card, .learning-panel, .expansion-card, .legal-card) h2,
:where(.dashboard-card, .learning-panel, .expansion-card, .legal-card) h3 {
  text-wrap: balance;
}

:where(.hero-copy, .section-heading > p, .learning-hero > div > p, .expansion-hero p) {
  text-wrap: pretty;
}

/* Tables remain useful on touch devices */
.table-scroll,
:where(.learning-panel, .expansion-card) table {
  scrollbar-gutter: stable;
}

table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--ux-card);
  box-shadow: 0 1px 0 var(--ux-border);
}

table tbody tr { transition: background-color 150ms ease; }
table tbody tr:hover { background: color-mix(in srgb, var(--ux-primary) 5%, transparent); }

/* Status messages and empty states */
:where(.learning-status, .expansion-status, .auth-status, [role="status"]:not([hidden])) {
  border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
  box-shadow: 0 8px 20px color-mix(in srgb, currentColor 7%, transparent);
}

:where(.empty-state, .empty-inline) {
  border-radius: var(--ux-radius-md);
}

/* Toast API, exposed as window.XamAIUX.toast(...) */
.ux-toast-region {
  position: fixed;
  z-index: 10000;
  top: 86px;
  right: 16px;
  display: grid;
  width: min(360px, calc(100vw - 32px));
  gap: 10px;
  pointer-events: none;
}

.ux-toast {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 12px 13px;
  gap: 10px;
  border: 1px solid var(--ux-border);
  border-radius: 14px;
  opacity: 0;
  transform: translateY(-8px) scale(.98);
  background: var(--ux-card);
  color: var(--ux-text);
  box-shadow: var(--ux-shadow-md);
  pointer-events: auto;
  transition: opacity 180ms ease, transform 180ms var(--ux-ease);
}

.ux-toast.is-visible { opacity: 1; transform: translateY(0) scale(1); }
.ux-toast__icon { color: var(--ux-primary); }
.ux-toast--success .ux-toast__icon { color: #168a5b; }
.ux-toast--error .ux-toast__icon { color: #c23b52; }
.ux-toast__close { border: 0; background: transparent; color: var(--ux-muted); }

/* Better landing-page depth without changing content */
.site-header,
.legal-header,
body > header[class*="sticky"] {
  backdrop-filter: blur(18px) saturate(1.2);
}

.hero { overflow: clip; }
.feature-card { overflow: hidden; }

/* Legal readability */
.legal-main { max-width: 920px; }
.legal-card { line-height: 1.75; }
.legal-card li + li { margin-top: .45rem; }

/* Responsive behavior */
@media (max-width: 1179.98px) and (min-width: 901px) {
  .dash-top-nav.ux-nav-enhanced { display: flex !important; }
  .dash-top-nav.ux-nav-enhanced > a:nth-of-type(n+5) { display: none; }
}

@media (max-width: 1023.98px) {
  .ux-public-toggle { display: grid; }
  .navbar .nav-actions .nav-cta { display: none; }
  .legal-links { display: none !important; }
}

@media (max-width: 900px) {
  body.ux-has-mobile-app-nav { padding-bottom: 88px; }
  body.ux-has-mobile-app-nav .ux-back-to-top { bottom: 92px; }
  .ux-app-mobile-nav { display: grid; }
  .dash-top-nav { display: none !important; }
  .dash-header__inner { padding-inline: 14px !important; }
  .dash-header__actions { margin-left: auto; }
  .dash-header__actions .profile-link,
  .dash-header__actions .logout-button { display: none; }
  .ux-toast-region { top: 72px; }
}

@media (max-width: 640px) {
  .ux-back-to-top { right: 12px; }
  .ux-app-sheet__grid { grid-template-columns: 1fr 1fr; }
  .expansion-main,
  .learning-main { width: min(100% - 24px, 1180px) !important; }
  .learning-hero,
  .learning-panel,
  .expansion-card { border-radius: 18px; }
  .learning-hero { padding: 22px; }
  .learning-form-grid { grid-template-columns: 1fr; }
  .learning-field--full { grid-column: auto; }
  .chapter-checks { grid-template-columns: 1fr; }
  .ux-toast-region { right: 12px; width: calc(100vw - 24px); }
}

@media (max-width: 420px) {
  .ux-app-mobile-nav { right: 6px; bottom: max(6px, env(safe-area-inset-bottom)); left: 6px; }
  .ux-app-mobile-nav a, .ux-app-mobile-nav button { font-size: .61rem; }
  .ux-app-sheet { right: 6px; bottom: 6px; left: 6px; }
}

@media (pointer: coarse) {
  :where(button, .button, .expansion-button, input, select) { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
