/* MoneyinOrder home-screen app polish (iPhone + Android).
   Applies only when the site runs as an installed app (html.is-standalone),
   except for the install banner/sheet, which only appears in the browser. */

:root {
  --pwa-top: env(safe-area-inset-top, 0px);
  --pwa-bottom: env(safe-area-inset-bottom, 0px);
  --pwa-left: env(safe-area-inset-left, 0px);
  --pwa-right: env(safe-area-inset-right, 0px);
  --pwa-bar: #1a8c4a;
}
[data-theme='dark'] { --pwa-bar: #0f1117; }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) { --pwa-bar: #0f1117; } }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* ---------- Installed-app behaviour ---------- */
html.is-standalone,
html.is-standalone body { overscroll-behavior-y: none; }
html.is-standalone body { -webkit-tap-highlight-color: transparent; }

/* iPhone draws the clock and battery in white over the page. Give them a solid
   brand-coloured strip so they stay readable on light and dark screens. */
html.is-standalone body::before {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--pwa-top);
  background: var(--pwa-bar);
  z-index: 2147483000;
  pointer-events: none;
}

/* Pages without their own safe-area handling start below the status bar. */
html.is-standalone body:not(.pwa-own-insets) {
  padding-top: var(--pwa-top);
  padding-left: var(--pwa-left);
  padding-right: var(--pwa-right);
}
html.is-standalone body:not(.pwa-own-insets) .nav,
html.is-standalone body:not(.pwa-own-insets) .pc-top { top: var(--pwa-top); }

/* App screen (app.html already pads its top bar for the notch). */
html.is-standalone .sidebar { padding-top: var(--pwa-top); padding-bottom: var(--pwa-bottom); padding-left: var(--pwa-left); }
html.is-standalone .main-wrapper,
html.is-standalone body:not(.pwa-own-insets) { padding-bottom: var(--pwa-bottom); }
html.is-standalone .main-wrapper { padding-right: var(--pwa-right); }
html.is-standalone .toast { bottom: calc(24px + var(--pwa-bottom)); }
html.is-standalone .modal-overlay { padding-top: var(--pwa-top); padding-bottom: var(--pwa-bottom); }
html.is-standalone .modal { max-height: calc(100dvh - var(--pwa-top) - var(--pwa-bottom) - 24px); }
html.is-standalone .ft-cookie { bottom: calc(16px + var(--pwa-bottom)) !important; }
html.is-standalone .invoice-preview-toolbar { padding-top: calc(20px + var(--pwa-top)); }

/* Phones zoom into inputs smaller than 16px; keep form fields steady on iPhone. */
@media (max-width: 900px) and (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea { font-size: max(16px, 1em); }
}

/* ---------- Install prompt (browser only) ---------- */
.mio-install-nav[hidden], .mio-a2hs[hidden], .mio-sheet[hidden] { display: none !important; }

.mio-a2hs {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(12px + var(--pwa-bottom));
  z-index: 9000;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 14px;
  border-radius: 16px;
  background: #0f2a1d;
  color: #eaf6ef;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .3);
  font: 14px/1.4 Satoshi, system-ui, -apple-system, "Segoe UI", sans-serif;
  animation: mio-rise .25s ease-out;
}
.mio-a2hs img { width: 44px; height: 44px; border-radius: 11px; flex: none; }
.mio-a2hs-text { flex: 1; min-width: 0; }
.mio-a2hs-text b { display: block; font-size: 15px; color: #fff; }
.mio-a2hs-text span { color: #b9d4c4; }
.mio-a2hs-go, .mio-sheet-done {
  flex: none;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: #22a35a;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.mio-a2hs-x {
  flex: none;
  width: 36px; height: 44px;
  border: 0;
  background: none;
  color: #b9d4c4;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.mio-a2hs-go:focus-visible, .mio-a2hs-x:focus-visible, .mio-sheet-done:focus-visible { outline: 2px solid #9be3b8; outline-offset: 2px; }

.mio-sheet {
  position: fixed;
  inset: 0;
  z-index: 9500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, .45);
}
.mio-sheet-card {
  width: 100%;
  max-width: 480px;
  margin: 0 8px calc(8px + var(--pwa-bottom));
  padding: 22px 20px 18px;
  border-radius: 20px;
  background: var(--color-surface, #fff);
  color: var(--color-text, #17251e);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .35);
  font: 15px/1.5 Satoshi, system-ui, -apple-system, "Segoe UI", sans-serif;
  animation: mio-rise .25s ease-out;
}
.mio-sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.mio-sheet-head img { width: 48px; height: 48px; border-radius: 12px; }
.mio-sheet-head h2 { margin: 0; font-size: 18px; }
.mio-sheet ol { margin: 0 0 14px; padding-left: 22px; }
.mio-sheet li { margin: 8px 0; }
.mio-sheet li svg { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; margin: 0 2px; color: #0a84ff; }
.mio-sheet-note { margin: 0 0 16px; font-size: 13px; color: var(--color-text-muted, #5b6b62); }
.mio-sheet-done { width: 100%; }

@keyframes mio-rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .mio-a2hs, .mio-sheet-card { animation: none; } }

/* Phone layouts shorten the top bar padding; keep it clear of the notch/Dynamic Island. */
html.is-standalone .topbar {
  padding-top: calc(var(--space-2, 8px) + var(--pwa-top)) !important;
  padding-left: calc(var(--space-3, 12px) + var(--pwa-left)) !important;
  padding-right: calc(var(--space-3, 12px) + var(--pwa-right)) !important;
}
