/* ==========================================================================
   MediHub PWA + cross-device polish
   Animated launch splash · install prompt · safe-area / touch refinements.
   Loaded after main.css so it can layer on top of the design system.
   ========================================================================== */

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

/* ---------------------------- device polish ------------------------------ */

/* Keep the sticky header clear of notches / status bars when installed. */
body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.site-header {
  top: var(--safe-top);
}

/* Anchor jumps clear the sticky header. */
html {
  scroll-padding-top: calc(var(--header-height) + 24px);
}

/* Momentum scrolling on horizontally scrollable regions (iOS). */
.table-wrap,
.search-suggest {
  -webkit-overflow-scrolling: touch;
}

/* Comfortable touch targets on small screens. */
@media (max-width: 880px) {
  .nav-link,
  .header-action,
  .btn,
  .page-btn {
    min-height: 44px;
  }
  .qty input,
  .qty button {
    min-height: 44px;
  }
}

/* Prevent iOS from zooming when focusing a field. */
@media (max-width: 640px) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

/* Gentle page entrance (disabled for reduced motion by the global rule). */
@keyframes mh-page-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
.main {
  animation: mh-page-in 0.35s ease both;
}

/* --------------------------- animated splash ----------------------------- */

.mh-splash { display: none; }

html.mh-splash-on .mh-splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(760px 460px at 50% -6%, #eefbfe, transparent 68%),
    #ffffff;
  opacity: 1;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

html.mh-splash-done .mh-splash {
  opacity: 0;
  visibility: hidden;
}

.mh-splash-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.mh-splash-logo {
  width: min(62vw, 232px);
  height: auto;
  animation: mh-logo-in 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.mh-splash-cross {
  width: 46px;
  height: 46px;
  animation: mh-cross-in 0.7s 0.15s ease both, mh-cross-pulse 1.6s 1s ease-in-out infinite;
}

.mh-splash-cross path { fill: #39b54a; }

.mh-splash-bar {
  display: block;
  width: 168px;
  height: 4px;
  border-radius: 999px;
  background: #d7f4fd;
  overflow: hidden;
}

.mh-splash-bar i {
  display: block;
  width: 40%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #00aeef, #39b54a);
  animation: mh-bar 1.25s ease-in-out infinite;
}

@keyframes mh-logo-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes mh-cross-in { from { opacity: 0; transform: scale(0.4); } to { opacity: 1; transform: scale(1); } }
@keyframes mh-cross-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.14); } }
@keyframes mh-bar { 0% { transform: translateX(-120%); } 100% { transform: translateX(320%); } }

/* --------------------------- install prompt ------------------------------ */

.mh-install {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9000;
  display: flex;
  justify-content: center;
  padding: 0 12px calc(12px + var(--safe-bottom));
  pointer-events: none;
}

.mh-install-card {
  pointer-events: auto;
  width: min(540px, 100%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.93);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid rgba(0, 174, 239, 0.2);
  box-shadow: 0 18px 44px rgba(0, 66, 92, 0.22);
  opacity: 0;
  transform: translateY(140%);
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s ease;
}

.mh-install.is-visible .mh-install-card {
  opacity: 1;
  transform: none;
}

.mh-install-icon {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  flex: 0 0 auto;
  box-shadow: 0 4px 12px rgba(0, 66, 92, 0.16);
}

.mh-install-body { flex: 1; min-width: 0; }
.mh-install-body strong { display: block; font-size: 0.98rem; }
.mh-install-body p {
  margin: 2px 0 0;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--color-text-muted);
}

.mh-share-ic {
  width: 18px;
  height: 18px;
  vertical-align: -3px;
  color: var(--color-primary-600);
  animation: mh-share 1.8s ease-in-out infinite;
}

.mh-install-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.mh-install-go {
  border: 0;
  background: var(--color-primary-500);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.mh-install-go:hover { background: var(--color-primary-600); }

.mh-install-close {
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  padding: 6px 9px;
  border-radius: 9px;
}

.mh-install-close:hover { background: rgba(0, 0, 0, 0.05); }

@keyframes mh-share { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

@media (max-width: 460px) {
  .mh-install-card { flex-wrap: wrap; }
  .mh-install-body { flex-basis: calc(100% - 68px); }
  .mh-install-actions { width: 100%; justify-content: flex-end; }
}

/* ------------------------------- standalone ------------------------------ */

@media all and (display-mode: standalone) {
  .topbar { display: none; }
  .toast-wrap { bottom: calc(var(--space-5) + var(--safe-bottom)); }
}
