/* ============================================
   Shared UI / UX Enhancements (used on every page)
   Works together with assets/js/main.js
   ============================================ */
html {
  scroll-padding-top: 96px;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.ui-menu-open {
  overflow: hidden;
}

@media (min-width: 1081px) {
  body.ui-menu-open {
    overflow: auto;
  }
}

::selection {
  background: #ffd699;
  color: #0a1f44;
}

img {
  max-width: 100%;
}

/* --- Keyboard focus --- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #ff9900;
  outline-offset: 2px;
}

main:focus,
[tabindex="-1"]:focus {
  outline: none;
}

/* --- Skip link --- */
.ui-skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 2000;
  padding: 10px 18px;
  border-radius: 6px;
  background: #ff9900;
  color: #1a2332;
  font-weight: 700;
  text-decoration: none;
  transform: translateY(-150%);
  transition: transform 0.2s ease;
}

.ui-skip-link:focus {
  transform: translateY(0);
  color: #1a2332;
}

.ui-skip-link::after {
  content: none !important;
}

/* --- Scroll progress bar --- */
.ui-scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1100;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, #ff9900, #ffd166);
  transform: scaleX(0);
  transform-origin: 0 50%;
  pointer-events: none;
}

/* --- Back to top --- */
.ui-back-to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #0052a3;
  color: #fff;
  box-shadow: 0 6px 18px rgba(0, 41, 102, 0.35);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s, background-color 0.2s ease;
}

.ui-back-to-top svg {
  width: 22px;
  height: 22px;
}

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

.ui-back-to-top:hover {
  background: #ff9900;
  color: #1a2332;
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(0, 41, 102, 0.35);
}

@media (max-width: 600px) {
  .ui-back-to-top {
    right: 16px;
    bottom: 16px;
    width: 44px;
    height: 44px;
  }
}

/* --- Reveal on scroll --- */
.js .ui-reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  transition-delay: var(--reveal-delay, 0ms);
}

.js .ui-reveal.is-visible {
  opacity: 1;
  transform: none;
}

/* --- Toast notifications --- */
.ui-toast-container {
  position: fixed;
  top: 90px;
  right: 20px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: calc(100vw - 40px);
  pointer-events: none;
}

.ui-toast {
  min-width: 260px;
  max-width: 380px;
  padding: 14px 18px;
  border-left: 5px solid;
  border-radius: 8px;
  background: #fff;
  color: #1a2332;
  font-size: 0.95rem;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(10, 31, 68, 0.2);
  opacity: 0;
  transform: translateX(30px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: auto;
}

.ui-toast.show {
  opacity: 1;
  transform: none;
}

.ui-toast-success { border-color: #10b981; }
.ui-toast-error { border-color: #ef4444; }
.ui-toast-warning { border-color: #f59e0b; }
.ui-toast-info { border-color: #0066cc; }

/* --- Form validation --- */
form .is-invalid,
form .is-invalid:focus {
  border-color: #dc2626 !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15) !important;
}

form .is-valid {
  border-color: #10b981 !important;
}

.ui-field-error {
  display: block;
  margin-top: 6px;
  color: #dc2626;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.4;
}

.ui-field-error:empty {
  display: none;
}

button.is-loading,
input.is-loading {
  position: relative;
  cursor: progress;
  opacity: 0.85;
}

button.is-loading::before {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 10px;
  vertical-align: -3px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: ui-spin 0.7s linear infinite;
}

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

/* --- FAQ accordion --- */
.ui-faq-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  margin: 0;
  padding: 4px 0;
  border: none;
  border-radius: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  text-align: left;
  cursor: pointer;
}

.ui-faq-toggle:hover {
  transform: none;
  box-shadow: none;
  color: #ff9900;
}

.ui-faq-icon {
  position: relative;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #eef5ff;
  transition: background-color 0.2s ease, transform 0.3s ease;
}

.ui-faq-icon::before,
.ui-faq-icon::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 2px;
  border-radius: 2px;
  background: #0066cc;
  transform: translate(-50%, -50%);
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.ui-faq-icon::after {
  transform: translate(-50%, -50%) rotate(90deg);
}

.faq-item.is-open .ui-faq-icon {
  background: #ff9900;
  transform: rotate(180deg);
}

.faq-item.is-open .ui-faq-icon::before {
  background: #fff;
}

.faq-item.is-open .ui-faq-icon::after {
  opacity: 0;
}

.ui-faq-answer {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s ease;
}

.ui-faq-answer > * {
  min-height: 0;
  overflow: hidden;
}

.faq-item.is-open .ui-faq-answer {
  grid-template-rows: 1fr;
}

/* --- Print --- */
@media print {
  .site-header,
  .ui-scroll-progress,
  .ui-back-to-top,
  .ui-toast-container,
  .ui-skip-link {
    display: none !important;
  }

  .js .ui-reveal {
    opacity: 1 !important;
    transform: none !important;
  }
}
