/* Courier Route Optimizer - mobile-first, RTL */
:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ccfbf1;
  --waze: #33ccff;
  --waze-text: #04293a;
  --success: #15803d;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Hebrew", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  direction: rtl;
}
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--primary); color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
.brand { font-weight: 800; font-size: 19px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; background: rgba(255, 255, 255, 0.15); border-radius: 999px; padding: 3px; }
.tab {
  border: 0; background: transparent; color: #fff; padding: 6px 11px; border-radius: 999px;
  font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.tab.active { background: #fff; color: var(--primary-dark); }

.banner {
  margin: 10px auto 0; max-width: 760px; padding: 10px 14px;
  background: var(--warn-bg); color: #78350f; border-radius: 10px; font-size: 15px;
}

main { max-width: 760px; margin: 0 auto; padding: 12px 12px 24px; }
.view { display: flex; flex-direction: column; gap: 12px; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; border: 0; margin: 0; min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-title { font-size: 17px; font-weight: 800; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; padding: 0; }
.card-head .card-title { margin: 0; }
.count { color: var(--muted); font-weight: 600; }
.dot {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  color: #fff; font-size: 12px;
}
.dot-start { background: var(--success); }
.dot-end { background: #334155; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 16px; border-radius: 12px; border: 0;
  font-weight: 700; font-size: 16px; text-decoration: none; cursor: pointer;
  transition: transform 0.05s ease, filter 0.15s ease; text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-xl { width: 100%; min-height: 58px; font-size: 19px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-success { background: var(--success); color: #fff; }
.btn-waze { background: var(--waze); color: var(--waze-text); }
.btn-waze:hover { filter: brightness(0.95); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }
.btn-text {
  background: none; border: 0; padding: 8px 2px; color: var(--primary-dark);
  font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}
.btn-text.small { font-size: 14px; padding: 4px 0; display: inline-block; }
.btn-text.danger { color: var(--danger); }
.icon-btn {
  flex: 0 0 44px; height: 44px; border-radius: 10px; border: 0; background: #f1f5f9;
  color: var(--muted); font-size: 18px; cursor: pointer;
}
.icon-btn:hover { background: var(--danger-bg); color: var(--danger); }
:focus-visible { outline: 3px solid #0ea5e9; outline-offset: 2px; }

/* ---------- address rows ---------- */
.place-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.place { display: block; }
.place-row { display: flex; align-items: center; gap: 8px; }
.num {
  flex: 0 0 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary-dark); font-weight: 800; font-size: 14px;
}
.addr-input {
  flex: 1; min-width: 0; width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1.5px solid #cbd5e1; border-radius: 10px; background: #fff; font-size: 17px;
}
.addr-input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
.place[data-status="ok"] .addr-input { border-color: #86efac; }
.place[data-status="choose"] .addr-input { border-color: #fbbf24; }
.place[data-status="not_found"] .addr-input, .place[data-status="error"] .addr-input { border-color: #f87171; }

.place-status:empty { display: none; }
.place-status { margin-top: 6px; }
li.place .place-status { margin-inline-start: 38px; }
.st { font-size: 15px; border-radius: 10px; padding: 8px 10px; }
.st-checking { color: var(--muted); background: #f8fafc; }
.st-ok { color: #14532d; background: #f0fdf4; }
.st-ok.conf-medium, .st-ok.conf-low { color: #78350f; background: var(--warn-bg); }
.st-warn { font-size: 14px; margin-top: 2px; }
.st-details { font-size: 14px; color: var(--muted); }
.st-bad { color: var(--danger); background: var(--danger-bg); }
.st-choose { background: var(--warn-bg); color: #78350f; }
.st-msg { margin: 0 0 8px; font-weight: 700; }
.cand {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
  text-align: start; background: #fff; border: 1.5px solid #fcd34d; border-radius: 10px;
  padding: 10px 12px; margin-bottom: 6px; cursor: pointer; min-height: 48px;
}
.cand:hover { border-color: var(--warn); }
.cand-label { font-weight: 700; color: var(--text); }
.cand-sec { font-size: 14px; color: var(--muted); }
.cand-warn { font-size: 13px; color: var(--warn); }
.conf { font-size: 12px; font-weight: 700; border-radius: 999px; padding: 1px 8px; }
.conf-high { background: #dcfce7; color: #166534; }
.conf-medium { background: #fef3c7; color: #92400e; }
.conf-low { background: var(--danger-bg); color: var(--danger); }
.hint { font-size: 14px; color: var(--muted); margin: 4px 0; }

/* ---------- checkboxes / radios ---------- */
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; margin-bottom: 6px; }
.check input, .radio input { width: 22px; height: 22px; accent-color: var(--primary); flex: 0 0 auto; }
.modes { display: flex; flex-direction: column; gap: 8px; }
.modes > legend { float: right; width: 100%; }
.radio {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px; border: 1.5px solid var(--line);
  border-radius: 12px; cursor: pointer;
}
.radio input { margin-top: 2px; }
.radio:has(input:checked) { border-color: var(--primary); background: #f0fdfa; }
.radio span { display: flex; flex-direction: column; }
.radio small { color: var(--muted); font-size: 14px; }

/* ---------- sticky bottom action ---------- */
.sticky-action {
  position: sticky; bottom: 0; z-index: 900;
  margin: 0 -12px -24px; padding: 10px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 80%, rgba(241, 245, 249, 0));
  display: flex; flex-direction: column; gap: 8px;
}
.calc-status:empty { display: none; }
.calc-status { text-align: center; font-weight: 700; color: var(--primary-dark); }

/* ---------- results ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stat { background: #f8fafc; border-radius: 12px; padding: 10px 4px; display: flex; flex-direction: column; }
.stat-val { font-size: 21px; font-weight: 800; color: var(--primary-dark); }
.stat-lbl { font-size: 13px; color: var(--muted); }
.notice { font-size: 14px; background: #eff6ff; color: #1e3a8a; border-radius: 10px; padding: 8px 10px; margin: 10px 0 0; }
.meta { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

.map { height: 45vh; min-height: 260px; border-radius: var(--radius); box-shadow: var(--shadow); z-index: 1; }
.map-small { height: 320px; margin-top: 10px; box-shadow: none; }
.map-card summary { font-weight: 800; cursor: pointer; min-height: 32px; display: flex; align-items: center; }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.tl { display: flex; gap: 10px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; transition: background 0.3s; }
.tl.flash { background: #ecfeff; }
.tl-num {
  flex: 0 0 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: #2563eb; color: #fff; font-weight: 800; border: 0; cursor: pointer; font-size: 16px;
}
.tl-start .tl-num { background: var(--success); cursor: default; }
.tl-end .tl-num { background: #334155; cursor: default; }
.tl-done .tl-num { background: #94a3b8; }
.tl-skipped .tl-num { background: #f59e0b; }
.tl-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.tl-title { font-weight: 800; overflow-wrap: anywhere; }
.tl-sub { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.tl-leg { font-size: 14px; color: var(--primary-dark); font-weight: 600; }
.tl-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 6px; }
.tl-actions .btn { flex: 1 1 180px; }

.warn-box { background: var(--warn-bg); color: #78350f; border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.warn-box.warn-low { background: var(--danger-bg); color: #7f1d1d; }

/* ---------- courier mode ---------- */
.progress-head { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.progress-text { font-size: 22px; font-weight: 900; }
.progress { height: 10px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin: 8px 0 6px; }
.progress-bar { height: 100%; width: 0; background: var(--success); transition: width 0.3s; }
.progress-sub { font-size: 14px; color: var(--muted); }

.current { display: flex; flex-direction: column; gap: 10px; border-top: 6px solid #2563eb; }
.current.is-done { border-top-color: #94a3b8; }
.current.finished { border-top-color: var(--success); }
.cur-top { display: flex; align-items: center; gap: 10px; }
.cur-num {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  background: #2563eb; color: #fff; font-size: 24px; font-weight: 900;
}
.cur-kicker { font-weight: 700; color: var(--muted); }
.cur-title { font-size: 22px; font-weight: 900; }
.cur-label { font-size: 24px; font-weight: 900; line-height: 1.25; overflow-wrap: anywhere; }
.cur-sub { color: var(--muted); overflow-wrap: anywhere; }
.cur-details { font-weight: 700; background: #f1f5f9; border-radius: 8px; padding: 6px 10px; }
.cur-leg { color: var(--primary-dark); font-weight: 700; }
.badge { align-self: flex-start; font-weight: 800; border-radius: 999px; padding: 4px 12px; }
.badge-done { background: #dcfce7; color: #166534; }
.badge-skip { background: #fef3c7; color: #92400e; }
.next { font-size: 16px; }
.next-kicker { color: var(--muted); font-weight: 700; }

.cour-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cl { display: flex; gap: 6px; align-items: stretch; }
.cl-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: start;
  background: #f8fafc; border: 1.5px solid transparent; border-radius: 10px; padding: 8px 10px;
  cursor: pointer; min-height: 48px;
}
.cl-current .cl-main { border-color: #2563eb; background: #eff6ff; }
.cl-done .cl-label { text-decoration: line-through; color: var(--muted); }
.cl-num {
  flex: 0 0 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: #2563eb; color: #fff; font-weight: 800; font-size: 14px;
}
.cl-done .cl-num { background: #94a3b8; }
.cl-skipped .cl-num { background: #f59e0b; }
.cl-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { flex: 0 0 auto; font-size: 12px; font-weight: 800; border-radius: 999px; padding: 2px 8px; }
.chip-pending { background: #e2e8f0; color: #334155; }
.chip-done { background: #dcfce7; color: #166534; }
.chip-skipped { background: #fef3c7; color: #92400e; }
.chip-current { background: #2563eb; color: #fff; }
.cl-act {
  flex: 0 0 48px; border: 0; border-radius: 10px; background: #e2e8f0; font-size: 18px;
  font-weight: 800; cursor: pointer;
}
.cl-act:hover { background: #cbd5e1; }
.bottom-gap { margin-bottom: 16px; }

/* ---------- map pins ---------- */
.pin span {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: #2563eb; color: #fff; font-weight: 800; font-size: 14px;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  font-family: system-ui, Arial, sans-serif;
}
.pin-start span { background: var(--success); font-size: 12px; }
.pin-end span { background: #334155; font-size: 12px; }
.pin-done span { background: #94a3b8; }
.pin-skipped span { background: #f59e0b; }
.pin-current span { background: #dc2626; transform: scale(1.25); }
.leaflet-container { font-family: inherit; }
.popup { direction: rtl; text-align: right; display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
.popup-waze { font-weight: 800; }

/* ---------- toast & dialogs ---------- */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 30px);
  max-width: min(92vw, 520px); padding: 12px 16px; border-radius: 12px;
  background: #0f172a; color: #fff; font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 3000; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--danger); }
.toast-success { background: var(--success); }

dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(94vw, 560px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(15, 23, 42, 0.5); }
.dlg { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.dlg h2 { margin: 0; font-size: 20px; }
textarea {
  width: 100%; min-height: 180px; padding: 10px 12px; border: 1.5px solid #cbd5e1; border-radius: 10px;
  resize: vertical; font-size: 16px; line-height: 1.6;
}
textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }

/* ---------- larger screens ---------- */
@media (min-width: 900px) {
  main { max-width: 980px; }
  #view-results { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  #view-results .summary, #view-results .sticky-action { grid-column: 1 / -1; }
  #view-results .map { position: sticky; top: 70px; height: calc(100vh - 110px); grid-column: 2; grid-row: 2 / span 2; }
  #view-results .timeline { grid-column: 1; grid-row: 2; }
}
@media (max-width: 380px) {
  .tab { padding: 6px 8px; font-size: 13px; }
  .brand { font-size: 16px; }
}
