* { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  --bg: #ffffff;
  --fg: #0f172a;
  --muted: #64748b;
  --line: #cbd5e1;
  --accent: #2563eb;
  --danger: #dc2626;
}

html, body { margin: 0; height: 100%; font-family: system-ui, sans-serif; color: var(--fg); }

#map { position: fixed; inset: 0; z-index: 0; }

button, input, select, textarea {
  font: inherit;
  font-size: 16px; /* elak iPhone zoom bila fokus */
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--fg);
}
button { cursor: pointer; min-height: 44px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--danger); border-color: var(--danger); }
input[type="color"] { padding: 4px; height: 44px; width: 100%; }

#topbar {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  left: 8px;
  right: 8px;
  z-index: 1000;
  display: flex;
  gap: 8px;
  align-items: center;
  max-width: 460px;
}
#topbar select { flex: 1; min-width: 0; }
#topbar > * { box-shadow: 0 2px 8px rgb(0 0 0 / 0.25); }

.dot { flex: none; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; }
.dot.online { background: #16a34a; }
.dot.offline { background: var(--danger); }

#actions {
  position: fixed;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 28px);
  z-index: 1000;
  display: flex;
  gap: 8px;
}
#actions button { box-shadow: 0 2px 10px rgb(0 0 0 / 0.3); }

#banner, #toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--fg);
  color: #fff;
}
#banner { top: calc(env(safe-area-inset-top) + 64px); display: flex; gap: 12px; align-items: center; }
#toast { bottom: calc(env(safe-area-inset-bottom) + 90px); }

#panel {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  z-index: 1050;
  width: min(360px, 100%);
  overflow-y: auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 16px);
  background: var(--bg);
  box-shadow: -4px 0 16px rgb(0 0 0 / 0.25);
}
#panel input { width: 100%; }
#panel ul { list-style: none; margin: 0 0 12px; padding: 0; }
#panel li { display: flex; gap: 6px; margin-bottom: 6px; }
#panel li .item { flex: 1; text-align: left; display: flex; gap: 10px; align-items: center; min-width: 0; }
#panel > button { width: 100%; margin-top: 8px; }
.item small { display: block; color: var(--muted); }
.item span:last-child { min-width: 0; overflow-wrap: anywhere; }
.chip { flex: none; width: 14px; height: 14px; border-radius: 50%; }

dialog {
  width: min(460px, 100%);
  max-width: 100%;
  max-height: 92dvh;
  border: 0;
  border-radius: 16px;
  padding: 16px;
  color: var(--fg);
}
dialog::backdrop { background: rgb(15 23 42 / 0.5); }
@media (max-width: 600px) {
  dialog { margin: auto 0 0; border-radius: 16px 16px 0 0; }
}
dialog h2 { margin: 0 0 12px; }
label { display: block; flex: 1; min-width: 0; margin-bottom: 10px; font-size: 14px; color: var(--muted); }
label input, label select, label textarea { display: block; width: 100%; margin-top: 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
form > .row { margin-bottom: 10px; }
form > .row > button { flex: 1; }
form > .row.between > button { flex: none; }
.hint { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.hint:empty, .error:empty { display: none; }
.error { color: var(--danger); margin: 0 0 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.swatches button { width: 36px; height: 36px; min-height: 36px; border-radius: 50%; padding: 0; border: 3px solid var(--line); }

/* Pin marker: dikongsi oleh Google Maps dan Leaflet */
.pin { display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.pin-head {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 3px solid #fff;
  border-radius: 50%;
  font-size: 18px;
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.5);
}
.pin-tail { width: 3px; height: 10px; background: #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 0.5); }
.pin-label {
  position: absolute;
  top: 100%;
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgb(15 23 42 / 0.85);
  color: #fff;
  font-size: 12px;
}
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #3b82f6; border: 3px solid #fff; box-shadow: 0 0 0 8px rgb(59 130 246 / 0.3); }
.leaflet-pin { background: none; border: 0; }
/* Pilihan Satelit/Jalan diletakkan di atas butang tindakan */
.leaflet-bottom.leaflet-left { bottom: calc(env(safe-area-inset-bottom) + 80px); }
.leaflet-pin .pin { position: absolute; left: 0; bottom: 0; transform: translateX(-50%); }
.leaflet-pin .me-dot { position: absolute; transform: translate(-50%, -50%); }
