/* ==========================================================
   enhancements.css — UI/UX polish for PIARC Toolkit
   Loaded AFTER style.css, sidebar.css, mobile.css
   ========================================================== */

/* ===== 1. SMOOTH THEME TRANSITIONS ===== */
html, html body,
.app, aside.site-nav, .mobile-topbar,
.form-section, .results-card, .modal .inner,
.tool, .hero-card, .btn, .mode-btn, .toggle button,
.backdrop {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* ===== 2. ELEVATION / SHADOW SYSTEM ===== */
:root {
  --shadow-xs: 0 1px 2px rgba(0,0,0,.05);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.14);
  --shadow-xl: 0 12px 48px rgba(0,0,0,.18);
}
[data-theme="dark"] {
  --shadow-xs: 0 1px 2px rgba(0,0,0,.15);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.25);
  --shadow-md: 0 4px 16px rgba(0,0,0,.30);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.40);
  --shadow-xl: 0 12px 48px rgba(0,0,0,.50);
}

/* Apply consistent shadows */
.tool { box-shadow: var(--shadow-sm); }
.form-section, .results-card, .hero-card { box-shadow: var(--shadow-md); }
.modal .inner { box-shadow: var(--shadow-xl); }
.tooltip { box-shadow: var(--shadow-lg); }

/* ===== 3. UNIFIED HOVER EFFECTS ===== */
/* Tool cards: lift + shadow deepen */
.tool {
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.tool:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-orange, #f4a000);
}

/* Sidebar nav links: smooth transition */
aside.site-nav nav a {
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
aside.site-nav nav a:hover {
  transform: translateX(2px);
}
[dir="rtl"] aside.site-nav nav a:hover {
  transform: translateX(-2px);
}

/* Form section cards: subtle lift on hover */
.form-section {
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.form-section:hover {
  box-shadow: var(--shadow-md);
}

/* Buttons: unified transition */
.button-row button,
.mode-btn,
.reset-defaults-btn,
.btn {
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
.button-row button:hover,
.mode-btn:hover,
.reset-defaults-btn:hover {
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.button-row button:active,
.mode-btn:active,
.reset-defaults-btn:active,
.btn:active {
  transform: translateY(0);
}

/* ===== 4. IMPROVED BUTTON STYLING ===== */
.button-row button,
.mode-btn,
.reset-defaults-btn {
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.btn {
  border-radius: 10px;
}

/* Button hierarchy: primary gets subtle glow */
.btn-accent:hover,
.btn-primary:hover,
.button-row button:not(.reset):hover {
  box-shadow: 0 4px 14px rgba(244, 160, 0, 0.35);
}
[data-theme="dark"] .btn-accent:hover,
[data-theme="dark"] .btn-primary:hover,
[data-theme="dark"] .button-row button:not(.reset):hover {
  box-shadow: 0 4px 14px rgba(244, 160, 0, 0.25);
}

/* Ghost/outline buttons */
.btn-outline-muted,
.btn-ghost {
  border-radius: 10px;
}

/* ===== 5. IMPROVED FORM INPUTS ===== */
.form-group input,
.form-group select {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--light-grey, #d7e1ea);
  font-size: 0.95rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  max-width: 200px; /* wider than cramped 120px default */
}
.form-group input[type="number"] {
  max-width: 140px;
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary-blue, #004681);
  box-shadow: 0 0 0 3px rgba(0, 70, 129, 0.12);
  outline: none;
}
[data-theme="dark"] .form-group input:focus,
[data-theme="dark"] .form-group select:focus {
  border-color: var(--blue, #1d80d0);
  box-shadow: 0 0 0 3px rgba(29, 128, 208, 0.2);
}

/* Placeholder styling */
::placeholder {
  color: var(--muted, #64748b);
  opacity: 0.6;
  font-style: italic;
}

/* Slider styling */
input[type="range"] {
  accent-color: var(--primary-orange, #f4a000);
  height: 6px;
}

/* ===== 6. IMPROVED TOOLTIP DESIGN ===== */
.tooltip {
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13.5px;
  line-height: 1.45;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

/* Delay tooltip appear to prevent accidental triggers */
.info-btn:hover + .tooltip,
.info-btn:focus + .tooltip {
  transition-delay: 0.15s;
}

/* ===== 7. SUBTLE GRADIENT ACCENTS ===== */
/* Hero card gets a subtle gradient border effect */
.hero-card {
  border-image: linear-gradient(135deg, var(--primary-blue, #004681), var(--primary-orange, #f4a000)) 1;
  border-width: 2px;
  border-style: solid;
  border-radius: 16px;
  border-image: none; /* border-image breaks border-radius, so use pseudo instead */
  position: relative;
  overflow: hidden;
}
.hero-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary-blue, #004681), var(--primary-orange, #f4a000), var(--primary-blue, #004681));
  background-size: 200% 100%;
  border-radius: 16px 16px 0 0;
}

/* Sidebar brand area: subtle gradient divider */
aside.site-nav .aside-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--ring, #d0d8e4), transparent);
  margin: 8px 0;
}

/* Section titles: subtle accent underline */
.section-title {
  position: relative;
  padding-bottom: 8px;
}
.section-title::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0;
  width: 40px; height: 3px;
  background: var(--primary-orange, #f4a000);
  border-radius: 2px;
}
[dir="rtl"] .section-title::after {
  left: auto; right: 0;
}

/* ===== 8. STICKY TABLE HEADERS ===== */
.results table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-colour, #f7fafa);
  z-index: 2;
  box-shadow: 0 1px 0 var(--light-grey, #d7e1ea);
}
[data-theme="dark"] .results table thead th {
  background: var(--surface, #1e1f21);
}

/* ===== 9. EMPTY STATES & ERROR STATES ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  text-align: center;
  color: var(--muted, #64748b);
}
.empty-state svg {
  width: 64px; height: 64px;
  margin-bottom: 1rem;
  opacity: 0.4;
}
.empty-state p {
  font-size: 1rem;
  margin: 0.25rem 0;
}

/* Inline error styling */
.input-error {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15) !important;
}
.error-msg {
  color: #ef4444;
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

/* ===== 10. BACKDROP BLUR ON MODALS/SIDEBAR ===== */
.backdrop {
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  background: rgba(15, 23, 42, 0.4);
  transition: opacity 0.2s ease;
}
.modal {
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* ===== 11. MICRO-ANIMATIONS ===== */
/* Fade-in on page load */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.hero-card {
  animation: fadeInUp 0.5s ease-out;
}
.tools-grid .tool {
  animation: fadeInUp 0.4s ease-out backwards;
}
.tools-grid .tool:nth-child(1) { animation-delay: 0.05s; }
.tools-grid .tool:nth-child(2) { animation-delay: 0.10s; }
.tools-grid .tool:nth-child(3) { animation-delay: 0.15s; }
.tools-grid .tool:nth-child(4) { animation-delay: 0.20s; }
.tools-grid .tool:nth-child(5) { animation-delay: 0.25s; }
.tools-grid .tool:nth-child(6) { animation-delay: 0.30s; }
.tools-grid .tool:nth-child(7) { animation-delay: 0.35s; }

/* Section fade-in (applied by IntersectionObserver) */
.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Smooth accordion/details transitions */
details {
  transition: box-shadow 0.2s ease;
}
details[open] {
  box-shadow: var(--shadow-sm);
}
details summary {
  transition: color 0.15s ease;
  cursor: pointer;
}
details summary:hover {
  color: var(--primary-blue, #004681);
}

/* Progress bar animation */
.cost-bar .segment {
  transition: width 0.6s ease-out;
}

/* ===== 12. IMPROVED MODAL DESIGN ===== */
.modal .inner {
  border-radius: 16px;
  animation: modalSlideIn 0.25s ease-out;
}
@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(24px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.close-x {
  width: 36px; height: 36px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  transition: background-color 0.15s ease;
}
.close-x:hover {
  background: rgba(0, 0, 0, 0.06);
}
[data-theme="dark"] .close-x:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* ===== 13. MOBILE TOUCH TARGETS ===== */
@media (max-width: 768px) {
  aside.site-nav nav a {
    padding: 12px 14px;
    min-height: 44px;
  }
  .button-row button,
  .mode-btn,
  .reset-defaults-btn,
  .btn {
    min-height: 44px;
    padding: 10px 16px;
  }
  .toggle button {
    min-height: 44px;
    padding: 8px 12px;
  }
  .form-group input,
  .form-group select {
    min-height: 44px;
    font-size: 16px; /* prevents iOS zoom on focus */
  }
}

/* ===== 14. SCROLL-TO-TOP BUTTON ===== */
.scroll-top-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 50;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--ring, #d0d8e4);
  background: var(--panel, #ffffff);
  color: var(--primary-blue, #004681);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease, background-color 0.15s ease;
}
.scroll-top-btn.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.scroll-top-btn:hover {
  background: var(--primary-blue, #004681);
  color: #fff;
  border-color: var(--primary-blue, #004681);
}
[dir="rtl"] .scroll-top-btn {
  right: auto;
  left: 24px;
}
[data-theme="dark"] .scroll-top-btn {
  background: var(--panel, #2a2b2d);
  color: var(--blue, #1d80d0);
  border-color: var(--ring, #233044);
}
[data-theme="dark"] .scroll-top-btn:hover {
  background: var(--blue, #1d80d0);
  color: #fff;
}

/* ===== 15. TOAST NOTIFICATION SYSTEM ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
[dir="rtl"] .toast-container {
  right: auto;
  left: 20px;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--panel, #ffffff);
  border: 1px solid var(--ring, #d0d8e4);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  font-weight: 500;
  min-width: 280px;
  max-width: 420px;
  animation: toastSlideIn 0.3s ease-out;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast.removing {
  opacity: 0;
  transform: translateX(20px);
}
[dir="rtl"] .toast.removing {
  transform: translateX(-20px);
}
.toast-icon {
  flex-shrink: 0;
  width: 20px; height: 20px;
}
.toast-msg { flex: 1; }
.toast-close {
  flex-shrink: 0;
  border: none; background: none;
  cursor: pointer; padding: 4px;
  color: var(--muted, #64748b);
  border-radius: 6px;
  transition: background-color 0.15s ease;
}
.toast-close:hover {
  background: rgba(0,0,0,0.06);
}

/* Toast variants */
.toast.success { border-left: 3px solid #22c55e; }
.toast.success .toast-icon { color: #22c55e; }
.toast.error { border-left: 3px solid #ef4444; }
.toast.error .toast-icon { color: #ef4444; }
.toast.warning { border-left: 3px solid #f59e0b; }
.toast.warning .toast-icon { color: #f59e0b; }
.toast.info { border-left: 3px solid #3b82f6; }
.toast.info .toast-icon { color: #3b82f6; }

[dir="rtl"] .toast.success,
[dir="rtl"] .toast.error,
[dir="rtl"] .toast.warning,
[dir="rtl"] .toast.info {
  border-left: none;
  border-right-width: 3px;
  border-right-style: solid;
}
[dir="rtl"] .toast.success { border-right-color: #22c55e; }
[dir="rtl"] .toast.error { border-right-color: #ef4444; }
[dir="rtl"] .toast.warning { border-right-color: #f59e0b; }
[dir="rtl"] .toast.info { border-right-color: #3b82f6; }

@keyframes toastSlideIn {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}
[dir="rtl"] .toast {
  animation-name: toastSlideInRtl;
}
@keyframes toastSlideInRtl {
  from { opacity: 0; transform: translateX(-30px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ===== 16. LOADING SPINNER ===== */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  gap: 1rem;
}
.loading-spinner::before {
  content: '';
  width: 36px; height: 36px;
  border: 3px solid var(--ring, #d0d8e4);
  border-top-color: var(--primary-blue, #004681);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--light-grey, #e3e8ef) 25%, rgba(255,255,255,0.4) 50%, var(--light-grey, #e3e8ef) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 8px;
}
[data-theme="dark"] .skeleton {
  background: linear-gradient(90deg, #2a2b2d 25%, rgba(255,255,255,0.06) 50%, #2a2b2d 75%);
  background-size: 200% 100%;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-text { height: 14px; margin: 6px 0; }
.skeleton-title { height: 20px; width: 60%; margin: 8px 0; }
.skeleton-img { height: 90px; width: 90px; border-radius: 12px; margin: 0 auto; }

/* ===== 17. ACTIVE SIDEBAR LINK — subtle indicator ===== */
aside.site-nav nav a.active {
  position: relative;
}
aside.site-nav nav a.active::before {
  content: '';
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 3px;
  background: #fff;
  border-radius: 0 3px 3px 0;
}
[dir="rtl"] aside.site-nav nav a.active::before {
  left: auto; right: 0;
  border-radius: 3px 0 0 3px;
}

/* ===== 18. ENHANCED CURRENCY PILL ===== */
.currency-pill {
  transition: background-color 0.15s ease, transform 0.15s ease;
}
.currency-pill:hover {
  transform: scale(1.05);
}

/* ===== 19. CARD BORDER ACCENT ON HOVER ===== */
.results-grid .item {
  border-left: 3px solid transparent;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.results-grid .item:hover {
  border-left-color: var(--primary-orange, #f4a000);
  box-shadow: var(--shadow-sm);
}
[dir="rtl"] .results-grid .item {
  border-left: none;
  border-right: 3px solid transparent;
}
[dir="rtl"] .results-grid .item:hover {
  border-right-color: var(--primary-orange, #f4a000);
}

/* ===== 20. SMOOTH SELECT DROPDOWNS ===== */
select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b'%3E%3Cpath d='M6 8.5L1 3.5h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px !important;
}
[dir="rtl"] select {
  background-position: left 10px center;
  padding-right: 12px !important;
  padding-left: 30px !important;
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .scroll-top-btn,
  .toast,
  .tool,
  .hero-card,
  .modal .inner {
    animation: none !important;
  }
}
