/* =============================================================
 * IKS Portnumbay - PWA UI (mobile-first)
 * Status dock (online/offline + prepare/install), progress modal,
 * toast, GPS locate control.
 * ============================================================= */

/* ---- Floating dock (bottom-left) ---- */
.pwa-dock {
  position: fixed;
  left: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

/* ---- Navbar-embedded variant (mobile-first) ---- */
/* Base = mobile: icon-only, square 44px tap targets, breathing room. */
.pwa-navbar-mount {
  display: flex;
  align-items: center;
  padding: 0;
  margin: 0;
  list-style: none;
}
.pwa-dock--navbar {
  position: static;
  left: auto;
  bottom: auto;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin: 0 8px;        /* keep clear of the screen edge & user menu */
  padding: 6px 0;
}
.pwa-dock--navbar .pwa-status,
.pwa-dock--navbar .pwa-home-btn,
.pwa-dock--navbar .pwa-gps,
.pwa-dock--navbar .pwa-prepare-btn,
.pwa-dock--navbar .pwa-install-btn,
.pwa-dock--navbar .iks-oq-badge {
  box-shadow: none;
  min-height: 44px;     /* mobile tap target */
  border-radius: 10px;
  font-size: 13px;
  justify-content: center;
}
.pwa-dock--navbar .pwa-home-btn,
.pwa-dock--navbar .pwa-gps,
.pwa-dock--navbar .pwa-prepare-btn,
.pwa-dock--navbar .pwa-install-btn,
.pwa-dock--navbar .iks-oq-badge {
  min-width: 44px;
  padding: 0 12px;
}
.pwa-dock--navbar .pwa-home-btn { border: 1px solid #e3e9f0; }
.pwa-dock--navbar .pwa-status { padding: 0 12px; gap: 6px; }
.pwa-dock--navbar i { font-size: 16px; }

/* Mobile: hide the button text labels, show icon only */
.pwa-dock--navbar .pwa-prepare-btn span,
.pwa-dock--navbar .pwa-install-btn span { display: none; }

/* Tablet/desktop: roomier, show full labels */
@media (min-width: 768px) {
  .pwa-dock--navbar { gap: 10px; margin: 0 14px 0 8px; }
  .pwa-dock--navbar .pwa-status,
  .pwa-dock--navbar .pwa-prepare-btn,
  .pwa-dock--navbar .pwa-install-btn,
  .pwa-dock--navbar .iks-oq-badge { min-height: 38px; border-radius: 8px; }
  .pwa-dock--navbar .pwa-prepare-btn,
  .pwa-dock--navbar .pwa-install-btn { padding: 0 16px; gap: 8px; }
  .pwa-dock--navbar .pwa-prepare-btn span,
  .pwa-dock--navbar .pwa-install-btn span { display: inline; }
}

/* ---- Online / Offline indicator ---- */
.pwa-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  -webkit-user-select: none;
  user-select: none;
}
.pwa-status .pwa-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
}
.pwa-status.is-online { background: #1e8e3e; }
.pwa-status.is-online .pwa-dot { animation: pwa-pulse 2s infinite; }
.pwa-status.is-offline { background: #d93025; }
.pwa-status.is-offline .pwa-dot { background: #ffd0cc; }

/* ---- Home button ---- */
.pwa-home-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #ffffff;
  color: #0d6efd;
  font-size: 16px;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}
.pwa-home-btn:active { transform: scale(0.97); }
.pwa-home-btn:hover { color: #0b5ed7; }

/* ---- GPS indicator (works offline) ---- */
.pwa-gps {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  background: #d93025;            /* default = off (red) until confirmed active */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}
.pwa-gps:active { transform: scale(0.97); }
.pwa-gps.is-on { background: #1e8e3e; }   /* GPS aktif → hijau */
.pwa-gps.is-off { background: #d93025; }  /* GPS mati → merah */
.pwa-gps.is-checking { background: #6b7280; } /* sedang cek → abu netral */
.pwa-gps.is-checking i { animation: pwa-spin 0.9s linear infinite; }

/* ---- Pre-flight kesiapan offline ---- */
.pwa-pf-verdict {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-radius: 12px; font-weight: 700; font-size: 14px; margin-bottom: 14px;
}
.pwa-pf-verdict.ok { background: #e6f4ea; color: #1e7e34; }
.pwa-pf-verdict.bad { background: #fff3cd; color: #8a6d00; }
.pwa-pf-list { display: flex; flex-direction: column; gap: 8px; max-height: 52vh; overflow-y: auto; }
.pwa-pf-item { display: flex; align-items: flex-start; gap: 10px; font-size: 13.5px; color: #1b2733; }
.pwa-pf-item i { font-size: 18px; margin-top: 1px; }
.pwa-pf-item.ok i { color: #1e8e3e; }
.pwa-pf-item.bad i { color: #d93025; }
.pwa-pf-tx { min-width: 0; }
.pwa-pf-hint { font-size: 12px; color: #b06000; margin-top: 1px; }

/* ---- Offline cached list (read-only lookup) ---- */
.iks-offline-list { margin: 10px 0; }
.iks-ol-bar {
  background: #e7f1ff; color: #0b4c9c; border: 1px solid #cfe2ff;
  border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 10px;
}
.iks-ol-bar i { margin-right: 6px; }
.iks-ol-bar #iks-ol-when { color: #5c6b7a; font-size: 11px; }
#iks-ol-search { width: 100%; min-height: 44px; margin-bottom: 10px; }
.iks-ol-rows { display: flex; flex-direction: column; gap: 8px; }
.iks-ol-item {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border: 1px solid #eef2f7; border-radius: 10px; background: #fff;
}
.iks-ol-main { min-width: 0; }
.iks-ol-main b { font-size: 14px; color: #1b2733; }
.iks-ol-sub { font-size: 12px; color: #5c6b7a; margin-top: 2px; word-break: break-word; }
.iks-ol-meta { white-space: nowrap; }
.iks-ol-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; color: #fff; font-size: 11px; font-weight: 700; }
.iks-ol-empty { text-align: center; color: #5c6b7a; font-size: 14px; padding: 24px 8px; }
.iks-ol-pager {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-top: 12px; font-size: 13px; color: #1b2733;
}
.iks-ol-pager button {
  min-width: 44px; min-height: 40px; border: 1px solid #d0d7de; border-radius: 10px;
  background: #fff; color: #0d6efd; font-size: 18px; cursor: pointer;
}
.iks-ol-pager button:disabled { color: #c0c8d0; cursor: default; }

/* ---- Offline mode: hide online-only menus/cards ---- */
.pwa-hide-offline { display: none !important; }

.pwa-offline-banner {
  background: #343a40;
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  padding: 10px 14px;
  border-radius: 10px;
  margin: 10px;
}
.pwa-offline-banner i { color: #ffc107; margin-right: 6px; }
.pwa-offline-banner b { color: #ffd54f; }

@keyframes pwa-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.6); }
  70%  { box-shadow: 0 0 0 7px rgba(255, 255, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}

/* ---- Prepare / Install buttons ---- */
.pwa-prepare-btn,
.pwa-install-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 9px 15px;
  border: 0;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.22);
  transition: transform 0.1s ease, filter 0.15s ease;
}
/* Offline submission queue badge */
.iks-oq-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  color: #fff;
  background: #b06000;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(176, 96, 0, 0.35);
}
.iks-oq-badge:active { transform: scale(0.97); }

.pwa-prepare-btn { background: #0d6efd; }
.pwa-install-btn { background: #6f42c1; }
.pwa-prepare-btn:active,
.pwa-install-btn:active { transform: scale(0.97); }
.pwa-prepare-btn.done { background: #1e8e3e; }

/* ---- Toast (transient state change) ---- */
.pwa-toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(20px);
  z-index: 10002;
  max-width: 92vw;
  padding: 11px 18px;
  border-radius: 12px;
  background: #343a40;
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}
.pwa-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.pwa-toast.ok { background: #1e8e3e; }
.pwa-toast.warn { background: #b06000; }
.pwa-toast i { margin-right: 6px; }

/* ---- Prepare-offline modal ---- */
.pwa-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10003;
  background: rgba(17, 24, 39, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: pwa-fade 0.2s ease;
}
.pwa-modal {
  width: 100%;
  max-width: 480px;
  background: #fff;
  border-radius: 18px 18px 0 0;
  overflow: hidden;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.3);
  animation: pwa-slide-up 0.25s ease;
}
.pwa-modal-head {
  padding: 16px 20px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  background: #0d6efd;
}
.pwa-modal-head i { margin-right: 8px; }
.pwa-modal-body { padding: 18px 20px 8px; }
.pwa-prep-sub { margin: 0 0 14px; font-size: 14px; color: #5c6b7a; line-height: 1.5; }
.pwa-steps { margin: 0 0 8px; padding-left: 20px; }
.pwa-steps li { font-size: 14.5px; color: #1b2733; line-height: 1.55; margin-bottom: 10px; }
.pwa-steps li b { color: #0d6efd; }
.pwa-steps i { color: #0d6efd; }
.pwa-progress {
  height: 10px;
  background: #e9eef5;
  border-radius: 999px;
  overflow: hidden;
}
.pwa-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0d6efd, #4d9bff);
  border-radius: 999px;
  transition: width 0.25s ease;
}
.pwa-prep-count { margin-top: 10px; font-size: 13px; font-weight: 600; color: #1b2733; }
.pwa-prep-url {
  margin-top: 4px;
  font-size: 12px;
  color: #8a97a6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pwa-modal-foot { padding: 12px 20px calc(18px + env(safe-area-inset-bottom, 0px)); }
.pwa-btn-primary {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  background: #0d6efd;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.pwa-btn-primary:disabled { background: #9bbdf5; cursor: default; }
.pwa-btn-secondary {
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
  border: 1px solid #d0d7de;
  border-radius: 14px;
  background: #fff;
  color: #5c6b7a;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* Unsynced queue list */
.pwa-q-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.pwa-q-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #eef2f7;
  border-radius: 10px;
  background: #fafcff;
}
.pwa-q-main { min-width: 0; }
.pwa-q-main b { font-size: 14px; color: #1b2733; }
.pwa-q-who { font-size: 12.5px; color: #5c6b7a; margin-top: 2px; word-break: break-word; }
.pwa-q-meta { text-align: right; font-size: 11px; color: #8a97a6; white-space: nowrap; }
.pwa-q-stat { display: inline-block; margin-top: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.pwa-q-stat.wait { background: #fff3cd; color: #8a6d00; }
.pwa-q-stat.err { background: #fde2e1; color: #b3261e; white-space: normal; }
.pwa-q-empty { text-align: center; color: #5c6b7a; font-size: 14px; padding: 24px 8px; }
.pwa-q-del {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; margin-top: 6px; margin-left: 4px;
  border: 1px solid #f1c6c2; border-radius: 8px; background: #fff;
  color: #d93025; font-size: 18px; line-height: 1; cursor: pointer;
}

@keyframes pwa-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pwa-slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* Desktop: center the modal instead of bottom-sheet */
@media (min-width: 576px) {
  .pwa-modal-overlay { align-items: center; padding: 20px; }
  .pwa-modal { border-radius: 18px; }
}

/* ---- Leaflet GPS "locate me" control ---- */
.pwa-locate a {
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  font-size: 16px;
  color: #0d6efd;
  background: #fff;
}
.pwa-locate a:hover { background: #f4f7ff; }
.pwa-locate a.locating i { animation: pwa-spin 0.9s linear infinite; }
@keyframes pwa-spin { to { transform: rotate(360deg); } }

@media (max-width: 575.98px) {
  .pwa-locate a { width: 40px; height: 40px; font-size: 18px; }
}
