/* ============================================================
   PWA INSTALL UI — append to the end of styles.css
   Uses the existing :root tokens (--indigo, --ink, --gray,
   --border, --shadow-lg) with fallbacks.
   Stacking: above the mobile sidebar (40), below modals (100),
   the toast (200) and the loader (300).
   ============================================================ */

.ios-install-banner[hidden] {
  display: none !important;
}

/* ---------- Install card (login screen, above sign-in) ---------- */

.install-card[hidden],
.install-card [hidden] {
  display: none !important;
}

.install-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 10px 14px 14px;
  background: #fff;
  color: var(--ink, #1a1a1a);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 18px;
  box-shadow: 0 14px 36px rgba(3, 38, 91, .14);
  font-family: "Poppins", system-ui, sans-serif;
  animation: pwa-rise .35s cubic-bezier(.2, .8, .2, 1);
}

.install-card__icon {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(3, 38, 91, .14);
}

.install-card__body {
  flex: 1;
  min-width: 0;
}

.install-card__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--navy, #03265b);
}

.install-card__text {
  margin: 3px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--gray, #6b7280);
}

.install-card__text strong {
  color: var(--ink, #1a1a1a);
  font-weight: 600;
}

.install-card__hint {
  margin: 4px 0 0;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--gray, #6b7280);
}

.install-card__action {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  margin-top: 10px;
  padding: 9px 18px 9px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--brand-grad-x, linear-gradient(90deg, #f39a2e, #e3232b));
  color: #fff;
  font: 600 13.5px/1.2 "Poppins", system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(235, 33, 42, .22);
  -webkit-tap-highlight-color: transparent;
}

a.install-card__action {
  text-decoration: none;   /* the Windows / Android download links */
}

.install-card__action:hover {
  filter: brightness(1.05);
}

.install-card__action:active {
  transform: scale(.98);
}

.install-card__action:focus-visible,
.install-card__close:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.install-card__action svg {
  width: 17px;
  height: 17px;
}

.install-card__close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin: -8px -2px 0 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--gray, #6b7280);
  cursor: pointer;
}

.install-card__close:hover {
  background: #f3f4f6;
  color: var(--ink, #1a1a1a);
}

.install-card__close svg {
  width: 18px;
  height: 18px;
}

/* ---------- iOS Safari banner ---------- */

.ios-install-banner {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 190;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 8px 14px 14px;
  background: #fff;
  color: var(--ink, #111827);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 16px;
  box-shadow: var(--shadow-lg, 0 12px 32px rgba(16, 24, 40, .12));
  font-family: "Poppins", system-ui, sans-serif;
  opacity: 0;
  transform: translateY(calc(100% + 24px));
  transition: transform .35s cubic-bezier(.2, .8, .2, 1), opacity .25s ease;
}

.ios-install-banner.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.ios-install-banner__icon {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 10px;
}

.ios-install-banner__body {
  flex: 1;
  min-width: 0;
}

.ios-install-banner__title {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
}

.ios-install-banner__text {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--gray, #4b5563);
}

.ios-install-banner__text strong {
  color: var(--ink, #111827);
  font-weight: 500;
}

.ios-install-banner__hint {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--gray, #6b7280);
}

.ios-install-banner__glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin: 0 2px;
  vertical-align: -6px;
  border-radius: 6px;
  background: var(--indigo-light, #e9eff8);
  color: #007aff;              /* iOS system blue, matches Safari's toolbar */
}

.ios-install-banner__glyph svg {
  width: 15px;
  height: 15px;
}

.ios-install-banner__close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;                 /* full touch target */
  height: 44px;
  margin: -10px 0 -10px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--gray, #6b7280);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ios-install-banner__close:hover {
  background: #f3f4f6;
  color: var(--ink, #111827);
}

.ios-install-banner__close:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: -3px;
}

.ios-install-banner__close svg {
  width: 18px;
  height: 18px;
}

/* ---------- Motion ---------- */

@keyframes pwa-rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .install-card,
  .ios-install-banner {
    animation: none;
    transition: none;
  }
}


/* ============================================================
   IN-APP DOCUMENT VIEWER — installed app, phones and tablets
   Invoices and receipts open here instead of a pop-up window.
   Sits above everything, the loader (300) included.
   ============================================================ */

.doc-viewer[hidden] {
  display: none !important;
}

.doc-viewer {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  flex-direction: column;
  background: #e5e7eb;
  font-family: "Poppins", system-ui, sans-serif;
}

.doc-viewer__bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding:
    calc(8px + env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    8px
    max(6px, env(safe-area-inset-left));
  background: var(--navy, #03265b);
  color: #fff;
}

.doc-viewer__title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-viewer__btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--brand-grad-x, linear-gradient(90deg, #f39a2e, #e3232b));
  color: #fff;
  font: 600 14px/1.2 "Poppins", system-ui, sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.doc-viewer__btn[hidden] {
  display: none !important;
}

/* Share PDF while the PDF is still being drawn */
.doc-viewer__btn:disabled {
  cursor: progress;
  opacity: .85;
}
.doc-viewer__btn.is-busy svg {
  animation: doc-viewer-pulse 1s ease-in-out infinite;
}
@keyframes doc-viewer-pulse {
  50% { opacity: .35; }
}
@media (prefers-reduced-motion: reduce) {
  .doc-viewer__btn.is-busy svg { animation: none; }
}

.doc-viewer__btn:hover {
  filter: brightness(1.25);
}

.doc-viewer__btn--ghost {
  padding: 8px 10px;
  background: transparent;
  color: #fff;
}

.doc-viewer__btn--ghost:hover {
  filter: none;
  background: rgba(255, 255, 255, .12);
}

.doc-viewer__btn:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.doc-viewer__btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.doc-viewer__scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Phones: icon-only buttons; the label stays for screen readers */
@media (max-width: 480px) {
  .doc-viewer__label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }
  .doc-viewer__btn {
    padding: 8px 10px;
  }
  /* …except Share PDF: the one action that matters here keeps its words */
  [data-doc-share] .doc-viewer__label {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
  }
}

/* Printing from the viewer prints only the document */
@media print {
  html.doc-viewer-open,
  html.doc-viewer-open body {
    height: auto !important;
    overflow: visible !important;
    background: #fff !important;
  }
  html.doc-viewer-open body > *:not(#doc-viewer) {
    display: none !important;
  }
  html.doc-viewer-open .doc-viewer {
    position: static !important;
    display: block !important;
    background: #fff !important;
  }
  html.doc-viewer-open .doc-viewer__bar {
    display: none !important;
  }
  html.doc-viewer-open .doc-viewer__scroll {
    overflow: visible !important;
    padding: 0 !important;
  }
}

/* ============================================================
   "NEW VERSION" BAR — shown when an update arrives while the
   person is mid-task (a form or document open). pwa-install.js
   ============================================================ */
.update-bar[hidden] { display: none !important; }
.update-bar {
  position: fixed;
  left: 50%;
  top: calc(10px + env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 8px 8px 8px 14px;
  border-radius: 12px;
  background: var(--navy, #03265b);
  color: #fff;
  font: 500 13px/1.3 "Poppins", system-ui, sans-serif;
  box-shadow: 0 8px 24px rgba(3, 38, 91, .28);
}
.update-bar--app { top: auto; bottom: calc(76px + env(safe-area-inset-bottom)); flex-wrap: wrap; justify-content: flex-end; }
.update-bar--app span { flex: 1 1 200px; }
.update-bar__btn--quiet { background: transparent !important; color: inherit !important; box-shadow: inset 0 0 0 1px currentColor; opacity: .85; }

.update-bar__btn {
  flex-shrink: 0;
  min-height: 36px;
  padding: 6px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--brand-grad-x, linear-gradient(90deg, #f39a2e, #e3232b));
  color: #fff;
  font: 600 13px/1 "Poppins", system-ui, sans-serif;
  cursor: pointer;
}
