/* ============================================
   VTU PLATFORM — PHASE 12 POLISH
   Micro-interactions, hover refinements,
   cross-browser fixes, and final details.
   Import after all other CSS files.
   ============================================ */


/* ─── CROSS-BROWSER BASELINE ────────────────
   ─────────────────────────────────────────── */

/* Smooth scrolling everywhere */
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Better box sizing across all browsers */
*, *::before, *::after {
  box-sizing: border-box;
}

/* Prevent layout shift from scrollbar appearance */
html {
  overflow-y: scroll;
  scrollbar-width: thin;
  scrollbar-color: var(--border-soft) transparent;
}

::-webkit-scrollbar       { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-soft); border-radius: 2px; }

/* Better font rendering */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Fix iOS tap highlight */
a, button, [role="button"] {
  -webkit-tap-highlight-color: transparent;
}

/* Fix iOS Safari 100vh bug */
.page-wrapper,
.app-shell {
  min-height: 100dvh; /* dynamic viewport height */
  min-height: -webkit-fill-available;
}


/* ─── MICRO-INTERACTIONS ────────────────────
   ─────────────────────────────────────────── */

/* Buttons — subtle lift on hover */
.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    transform 150ms ease;
}

/* Cards — very slight hover lift */
.card:hover {
  border-color: var(--border-active);
  transition: border-color var(--transition-fast);
}

/* Nav items — clean active scale */
.bottom-nav__item {
  transition: transform var(--transition-fast), color var(--transition-fast);
}
.bottom-nav__item:active {
  transform: scale(0.88);
}

/* Service icons — bounce on tap */
.service-btn {
  transition: transform var(--transition-spring);
}
.service-btn:active {
  transform: scale(0.92);
}

/* Input focus ring — not default blue */
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-active);
  box-shadow: 0 0 0 3px rgba(240, 240, 240, 0.06);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

/* Checkboxes and toggles */
input[type="checkbox"] {
  accent-color: var(--text-primary);
}

/* Network chip hover */
.network-chip {
  transition: background-color var(--transition-fast), border-color var(--transition-fast),
              transform var(--transition-fast);
}
.network-chip:hover {
  transform: translateY(-1px);
}
.network-chip:active {
  transform: scale(0.95);
}

/* Transaction rows — highlight on hover */
.tx-item {
  transition: background-color var(--transition-fast);
  border-radius: var(--radius-md);
}
.tx-item:hover {
  background: var(--bg-hover);
}

/* Quick amount buttons */
.quick-amounts button {
  transition: background-color var(--transition-fast), border-color var(--transition-fast),
              transform var(--transition-fast);
}
.quick-amounts button:hover {
  background: var(--bg-hover);
  border-color: var(--border-active);
}
.quick-amounts button:active {
  transform: scale(0.94);
}


/* ─── FOCUS VISIBLE POLYFILL ────────────────
   Show focus ring only for keyboard users     */

:focus:not(:focus-visible) {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--border-active);
  outline-offset: 2px;
}


/* ─── IMG LOADING STATE ─────────────────────
   ─────────────────────────────────────────── */

img {
  /* Prevent layout shift while loading */
  display: block;
}

img[data-src] {
  /* Placeholder for lazy-loaded images */
  background: var(--bg-elevated);
  animation: shimmer 1.4s ease infinite;
  background-size: 400px 100%;
}

img.img-loaded {
  animation: none;
  background: none;
}

/* Avatar images */
.avatar {
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  overflow: hidden;
  flex-shrink: 0;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity var(--transition-normal);
}


/* ─── LINK TRANSITIONS ──────────────────────
   ─────────────────────────────────────────── */

a {
  transition: color var(--transition-fast), opacity var(--transition-fast);
}
a:hover {
  opacity: 0.8;
}


/* ─── PWA INSTALL SHEET ─────────────────────
   ─────────────────────────────────────────── */

.pwa-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  z-index: calc(var(--z-modal) - 1);
  transition: background-color 350ms ease;
}
.pwa-overlay.is-open {
  background: rgba(0, 0, 0, 0.6);
}

.pwa-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-soft);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 16px var(--card-padding) max(24px, env(safe-area-inset-bottom));
  z-index: var(--z-modal);
  transform: translateY(100%);
  transition: transform 380ms cubic-bezier(0.32, 0.72, 0, 1);
  max-width: var(--max-content-width);
  margin: 0 auto;
}
.pwa-sheet.is-open {
  transform: translateY(0);
}

.pwa-sheet__handle {
  width: 36px; height: 4px;
  background: var(--border-soft);
  border-radius: var(--radius-full);
  margin: 0 auto 20px;
}

.pwa-sheet__header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}
.pwa-sheet__icon img {
  border-radius: var(--radius-md);
  width: 56px; height: 56px;
}
.pwa-sheet__meta { flex: 1; }
.pwa-sheet__name {
  font-size: var(--text-md);
  font-weight: var(--font-semi);
  color: var(--text-primary);
}
.pwa-sheet__tagline {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: 2px;
}
.pwa-sheet__close {
  background: none; border: none;
  color: var(--text-muted);
  font-size: 18px;
  padding: 8px;
  cursor: pointer;
  line-height: 1;
  transition: color var(--transition-fast);
}
.pwa-sheet__close:hover { color: var(--text-primary); }

.pwa-sheet__perks {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}
.pwa-perk {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
}
.pwa-perk__icon {
  font-size: 20px;
  flex-shrink: 0;
  line-height: 1;
  margin-top: 1px;
}
.pwa-perk__title {
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  color: var(--text-primary);
}
.pwa-perk__text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: 2px;
  line-height: var(--leading-normal);
}

.pwa-sheet__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}


/* ─── OFFLINE PAGE ──────────────────────────
   ─────────────────────────────────────────── */

.offline-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  padding: var(--space-xl) var(--page-padding-x);
  background: var(--bg-base);
  gap: var(--space-md);
}

.offline-page__icon {
  font-size: 64px;
  margin-bottom: var(--space-sm);
  animation: pulse 2s ease infinite;
}

.offline-page__title {
  font-size: var(--text-xl);
  font-weight: var(--font-semi);
  color: var(--text-primary);
}

.offline-page__text {
  font-size: var(--text-base);
  color: var(--text-secondary);
  max-width: 280px;
  line-height: var(--leading-loose);
}

.offline-page__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  width: 100%;
  max-width: 280px;
  margin-top: var(--space-sm);
}


/* ─── 404 PAGE ──────────────────────────────
   ─────────────────────────────────────────── */

.notfound-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  padding: var(--space-xl) var(--page-padding-x);
  background: var(--bg-base);
  gap: var(--space-md);
}

.notfound-page__code {
  font-family: var(--font-mono);
  font-size: 80px;
  font-weight: var(--font-bold);
  color: var(--border-soft);
  line-height: 1;
  letter-spacing: -2px;
}

.notfound-page__title {
  font-size: var(--text-xl);
  font-weight: var(--font-semi);
  color: var(--text-primary);
}

.notfound-page__text {
  font-size: var(--text-base);
  color: var(--text-secondary);
  max-width: 260px;
  line-height: var(--leading-loose);
}


/* ─── SAFE AREA INSETS (iOS notch/home bar) ─
   ─────────────────────────────────────────── */

.bottom-nav {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.toast-container {
  top: calc(var(--top-bar-height) + env(safe-area-inset-top, 0px) + var(--space-md));
}

.modal {
  padding-bottom: max(var(--card-padding), env(safe-area-inset-bottom));
}


/* ─── CONTENT VISIBILITY OPTIMIZATION ──────
   ─────────────────────────────────────────── */

/* Below-fold sections — don't render until near viewport */
.below-fold {
  content-visibility: auto;
  contain-intrinsic-size: 0 400px;
}


/* ─── PRINT STYLES ──────────────────────────
   For PDF receipts opened in browser          */

@media print {
  .bottom-nav,
  .top-bar,
  .toast-container,
  .btn,
  .pwa-sheet,
  .pwa-overlay {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .card {
    border: 1px solid #ccc;
    box-shadow: none;
  }
}


/* ─── PREFERS-REDUCED-MOTION ────────────────
   Respect user's OS accessibility setting     */

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

  .skeleton,
  .skeleton--text,
  .skeleton--title,
  .skeleton--amount {
    animation: none;
    background: var(--bg-elevated);
  }

  .page-loader__logo {
    animation: none;
    opacity: 1;
  }

  .confetti-piece {
    display: none !important;
  }
}


/* ─── HIGH CONTRAST MODE ────────────────────
   Windows/Mac accessibility setting          */

@media (forced-colors: active) {
  .btn--primary {
    border: 2px solid ButtonText;
  }
  .card {
    border: 1px solid CanvasText;
  }
  .skeleton {
    background: ButtonFace;
    animation: none;
  }
}


/* ─── DARK / LIGHT MODE TRANSITION ─────────
   Smooth when user toggles theme             */

[data-theme] {
  transition:
    background-color 300ms ease,
    border-color 300ms ease,
    color 200ms ease;
}


/* ─── LOADING STATES ────────────────────────
   Button loading state cross-browser fix     */

.btn--loading {
  pointer-events: none;
  color: transparent;
}

.btn--loading::after {
  content: '';
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  /* Override color: transparent above for the spinner */
  color: var(--text-inverse);
}

.btn--primary.btn--loading::after {
  border-color: var(--text-inverse);
  border-top-color: transparent;
}

.btn--secondary.btn--loading::after,
.btn--ghost.btn--loading::after {
  border-color: var(--text-primary);
  border-top-color: transparent;
}


/* ─── EMPTY STATE ───────────────────────────
   Polish for existing empty state component  */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-2xl) var(--space-xl);
  gap: var(--space-sm);
  min-height: 260px;
  animation: fadeInUp 400ms ease forwards;
}

.empty-state__icon {
  font-size: 48px;
  margin-bottom: var(--space-sm);
}

.empty-state__title {
  font-size: var(--text-md);
  font-weight: var(--font-semi);
  color: var(--text-primary);
}

.empty-state__text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  max-width: 260px;
  line-height: var(--leading-loose);
}

.empty-state__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
  width: 100%;
  max-width: 200px;
}


/* ─── NETWORK STATUS BANNER ─────────────────
   Shown when user goes offline mid-session   */

.network-status-banner {
  position: fixed;
  top: var(--top-bar-height);
  left: 0; right: 0;
  background: var(--pending-soft);
  border-bottom: 1px solid var(--pending);
  color: var(--pending);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  text-align: center;
  padding: var(--space-xs) var(--space-md);
  z-index: var(--z-sticky);
  transform: translateY(-100%);
  transition: transform var(--transition-normal);
}

.network-status-banner.is-visible {
  transform: translateY(0);
}

.network-status-banner.is-online {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

/* ─── Error State Overlay (replaces error-state.js inline styles) ── */
.error-state-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  z-index: var(--z-top);
  padding: var(--space-xl);
  text-align: center;
}

/* ─── Offline Page ───────────────────────────────────────────────── */
.offline-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl) var(--page-padding-x);
}
.offline-inner {
  max-width: 360px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-lg);
  text-align: center;
}
.offline-icon {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-xl);
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.offline-title {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--text-primary);
}
.offline-sub {
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: var(--leading-loose);
}
.offline-features {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: var(--card-padding);
}
.offline-features-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: var(--space-sm);
  text-align: left;
}
.offline-feature-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.offline-feature-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.offline-feature-icon {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.offline-feature-icon--ok  { background: var(--success-soft); color: var(--success); }
.offline-feature-icon--err { background: var(--danger-soft);  color: var(--danger);  }
.offline-feature-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-align: left;
}
