:root {
  --blue: #1a5fb4;
  --blue-dark: #14487f;
  --green: #2e9e4f;
  --green-soft: #e2f4e8;
  --red: #d0342c;
  --red-soft: #fbe5e4;
  --orange: #e0851a;
  --orange-soft: #fdf0dd;
  --gray: #5f6672;
  --bg: #f2f4f8;
  --card: #ffffff;
  --line: #e1e5ec;
  --text: #1c2230;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(23, 32, 52, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 90px;
}

/* ── Шапка ─────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--blue);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}
.topbar .back {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
}
.topbar .titles { flex: 1; min-width: 0; }
.topbar .title {
  font-weight: 700;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .subtitle {
  font-size: 13px;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .cashbox {
  text-align: right;
  flex-shrink: 0;
}
.topbar .cashbox .label { font-size: 11px; opacity: 0.8; }
.topbar .cashbox .value { font-weight: 700; font-size: 15px; }

/* ── Офлайн-банер ──────────────────────── */
.offline-bar {
  position: sticky;
  top: 62px;
  z-index: 9;
  background: var(--red);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 7px 12px;
}
.offline-bar.syncing { background: var(--orange); }

/* ── Загальне ──────────────────────────── */
.content { padding: 14px 14px 0; display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.progress-wrap { display: flex; align-items: center; gap: 10px; }
.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--line);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar > div { height: 100%; background: var(--green); transition: width 0.3s; }
.progress-text { font-size: 13px; color: var(--gray); white-space: nowrap; }

.gps-line {
  margin-top: 8px;
  font-size: 12px;
  color: var(--gray);
}
.gps-line.ok { color: var(--green); }
.gps-line.fail { color: var(--red); }

.topbar .demo-reset { opacity: 0.75; }
.topbar a.back {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 16px;
}

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge.pending { background: var(--line); color: var(--gray); }
.badge.arrived { background: var(--orange-soft); color: var(--orange); }
.badge.done { background: var(--green-soft); color: var(--green); }
.badge.refused { background: var(--red-soft); color: var(--red); }
.badge.skipped { background: var(--red-soft); color: var(--red); }
.badge.active { background: var(--orange-soft); color: var(--orange); }
.badge.planned { background: var(--line); color: var(--gray); }
.badge.finished { background: var(--green-soft); color: var(--green); }

/* ── Список точок ──────────────────────── */
.stop-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  cursor: pointer;
}
.stop-card .seq {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
}
.stop-card.is-done .seq { background: var(--green); }
.stop-card.dim { opacity: 0.5; cursor: default; }
.seq.pickable { background: var(--line); color: var(--gray); }
.seq.picked { background: var(--green); }
.reorder-bar .choice[disabled] { opacity: 0.5; cursor: default; }
.reorder-bar .question { margin-bottom: 4px; }
.stop-card.is-refused .seq, .stop-card.is-skipped .seq { background: var(--red); }
.stop-card.is-arrived .seq { background: var(--orange); }
.stop-card .info { flex: 1; min-width: 0; }
.stop-card .name { font-weight: 700; font-size: 15px; }
.stop-card .addr { font-size: 13px; color: var(--gray); margin-top: 2px; }
.stop-card .meta { font-size: 13px; margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; }
.stop-card .meta .cash { font-weight: 600; }
.stop-card .right { text-align: right; flex-shrink: 0; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.stop-card .chevron { color: var(--gray); font-size: 18px; }

/* ── Точка ─────────────────────────────── */
.client-head .name { font-size: 18px; font-weight: 700; }
.client-head .addr { color: var(--gray); font-size: 14px; margin-top: 4px; }
.client-links { display: flex; gap: 10px; margin-top: 12px; }
.client-links a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  background: var(--bg);
  color: var(--blue);
  font-weight: 600;
  font-size: 14px;
  padding: 10px;
  border-radius: 10px;
}

.timer-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--orange-soft);
  color: var(--orange);
  font-weight: 700;
  font-size: 22px;
  padding: 12px;
  border-radius: var(--radius);
  font-variant-numeric: tabular-nums;
}
.timer-chip .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--orange);
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 50% { opacity: 0.3; } }

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray);
  margin: 4px 0 -4px;
}

/* ── Накладні ──────────────────────────── */
.invoice { padding: 10px 0; border-bottom: 1px solid var(--line); }
.invoice:last-child { border-bottom: none; padding-bottom: 0; }
.invoice:first-child { padding-top: 0; }
.invoice .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.invoice .num { font-weight: 600; font-size: 14px; }
.invoice .amount { font-weight: 700; font-size: 15px; white-space: nowrap; }
.invoice .paytype { font-size: 12px; color: var(--gray); }
.invoice .paid-line { font-size: 13px; margin-top: 4px; display: flex; justify-content: space-between; }
.invoice .paid-line .ok { color: var(--green); font-weight: 600; }
.invoice .paid-line .due { color: var(--red); font-weight: 600; }
.pay-controls { display: flex; gap: 8px; margin-top: 8px; }
.pay-controls input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
}
.pay-controls button { flex-shrink: 0; }
.unpay { margin-top: 6px; }

/* ── Кнопки ────────────────────────────── */
.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: var(--radius);
  padding: 15px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  box-sizing: border-box;
}
.btn.primary { background: var(--blue); color: #fff; }
.btn.success { background: var(--green); color: #fff; }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.ghost { background: var(--card); color: var(--blue); border: 1px solid var(--line); }
.btn.small { padding: 10px 14px; font-size: 14px; width: auto; border-radius: 10px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.choice-row { display: flex; gap: 8px; margin-top: 8px; }
.choice-row .choice {
  flex: 1;
  border: 1.5px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}
.choice-row .choice.on-yes { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.choice-row .choice.on-no { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.question { font-size: 15px; font-weight: 600; }
.field-block { margin-top: 12px; }
textarea.comment,
textarea.freetext {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  min-height: 64px;
  margin-top: 8px;
}

/* ── Інші кошти від клієнта ────────────── */
.extra-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.extra-row:first-child { padding-top: 0; }
.extra-comment { flex: 1; min-width: 0; }
.extra-amount { font-weight: 700; color: var(--green); white-space: nowrap; }
.extra-del {
  border: none;
  background: var(--red-soft);
  color: var(--red);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
}
.extra-hint {
  font-size: 13px;
  color: var(--gray);
  margin-bottom: 4px;
  line-height: 1.4;
}
.extra-comment-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  margin-top: 8px;
}

/* ── Фото накладних ────────────────────── */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--line);
}
.photo-thumb.pending {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  border: 2px dashed var(--line);
  background: var(--bg);
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
}
.photo-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(15, 22, 38, 0.65);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
}
.photo-add {
  aspect-ratio: 1;
  border: 2px dashed var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  color: var(--blue);
  font-size: 22px;
}
.photo-add span { font-size: 13px; font-weight: 600; }
.photo-view {
  align-items: center;
  justify-content: center;
}
.photo-view img {
  max-width: 94vw;
  max-height: 86vh;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, var(--bg) 30%);
  padding: 16px 14px calc(14px + env(safe-area-inset-bottom));
  z-index: 20;
}
.bottom-bar .inner { max-width: 452px; margin: 0 auto; display: flex; gap: 10px; }
.bottom-bar .btn { box-shadow: 0 4px 14px rgba(23, 32, 52, 0.18); }

/* ── Підсумок ──────────────────────────── */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}
.stat .label { font-size: 12px; color: var(--gray); }
.stat .value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.stat .value.green { color: var(--green); }
.stat .value.red { color: var(--red); }
.debt-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.debt-row:last-child { border-bottom: none; }
.debt-row .amt { font-weight: 700; color: var(--red); white-space: nowrap; }
.sum-stop-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.sum-stop-row:last-child { border-bottom: none; }
.sum-stop-row .n { color: var(--gray); width: 22px; flex-shrink: 0; }
.sum-stop-row .cl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sum-stop-row .dur { color: var(--gray); white-space: nowrap; }

.route-pick {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.route-pick .name { font-weight: 700; }
.route-pick .sub { font-size: 13px; color: var(--gray); margin-top: 3px; }

.empty {
  text-align: center;
  color: var(--gray);
  padding: 40px 20px;
  font-size: 15px;
}

/* ── Модальні вікна (нативні confirm/prompt не працюють у WebView) ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 38, 0.55);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-message { font-size: 15px; color: var(--text); margin-top: 8px; line-height: 1.45; }
.modal-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  min-height: 70px;
  margin-top: 12px;
}
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

/* ── Нотатка логіста ───────────────────── */
.note-card {
  background: #fdf6dd;
  border: 1px solid #e8d48a;
  font-size: 14px;
  line-height: 1.45;
}

/* ── Геозона: банер підказки прибуття ──── */
#geo-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 92px;
  max-width: 456px;
  margin: 0 auto;
  background: var(--card);
  border: 1.5px solid var(--blue);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(23, 32, 52, 0.25);
  padding: 12px 14px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#geo-banner .geo-text { font-size: 14px; line-height: 1.4; }
#geo-banner .geo-actions { display: flex; gap: 8px; justify-content: flex-end; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 100px;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 100;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.stop-summary-line { display: flex; justify-content: space-between; font-size: 14px; padding: 6px 0; }
.stop-summary-line .k { color: var(--gray); }
.stop-summary-line .v { font-weight: 600; }
