:root {
  --bg: #ffffff;
  --ink: #111111;
  --muted: #6b6b6b;
  --line: #e7e7e7;
  --soft: #f5f5f4;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --off: #a3a3a3;
  --radius: 14px;
  --shadow: 0 -8px 30px rgb(0 0 0 / 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --panel-w: 380px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.4 var(--font); color: var(--ink); background: var(--bg); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1 { font-size: 22px; line-height: 1.15; letter-spacing: -0.02em; margin: 0; font-weight: 700; }
h2 { font-size: 19px; margin: 0 0 14px; letter-spacing: -0.01em; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
.error { color: var(--bad); font-size: 13px; min-height: 1em; margin: 8px 0 0; }
.grow { flex: 1; min-width: 0; }
.empty { padding: 18px 20px; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.primary { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-weight: 600; }
.primary:active { transform: scale(0.98); }
.ghost { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); font-weight: 500; white-space: nowrap; }
.ghost:hover { background: var(--soft); }
.link { padding: 6px 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.danger { color: var(--bad); }
.icon { width: 38px; height: 38px; border-radius: 10px; font-size: 20px; line-height: 1; flex: none; }
.icon:hover { background: var(--soft); }
input { font: inherit; width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* Вход */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--soft); }
.login-card { width: min(340px, 100%); display: grid; gap: 12px; background: #fff; padding: 28px 24px; border-radius: var(--radius); }
.login-card h1 { font-size: 30px; }
#pin { font-size: 22px; letter-spacing: 0.3em; text-align: center; }

/* Карта и панель */
.app { position: fixed; inset: 0; }
.map { position: absolute; inset: 0; background: #eceae6; }
.panel {
  position: absolute; z-index: 500; background: var(--bg); overflow: auto; overscroll-behavior: contain;
  left: 0; right: 0; bottom: 0; max-height: 52%; border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  padding-bottom: env(safe-area-inset-bottom);
}
.grip { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 8px auto 0; }
@media (min-width: 820px) {
  .panel { top: 16px; left: 16px; bottom: 16px; right: auto; width: var(--panel-w); max-height: none; border-radius: var(--radius); box-shadow: 0 10px 40px rgb(0 0 0 / 0.12); }
  .grip { display: none; }
}

.bar { display: flex; align-items: center; gap: 10px; padding: 16px 20px 12px; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.bar > div:first-child:not(.grow) { flex: 1; }
.foot { padding: 4px 20px 16px; }
.phone { display: inline-block; margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line); }

.couriers { list-style: none; margin: 0; padding: 0 8px; }
.courier { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 12px; border-radius: 12px; }
.courier:hover { background: var(--soft); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: 0 0 0 3px #fff, 0 0 0 4px var(--line); }
.courier .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--off); }
.status.ok::before { background: var(--ok); }
.status.warn::before { background: var(--warn); }
.status.bad::before { background: var(--bad); }
.battery { margin-left: auto; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.battery.low { color: var(--bad); font-weight: 600; }

.day { display: flex; gap: 8px; align-items: center; padding: 0 20px 12px; }
.day input { text-align: center; padding: 8px 10px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 0 20px 14px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.stats div { background: #fff; padding: 12px 14px; }
.stats div:first-child dd { font-size: 26px; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

.scrub { display: flex; align-items: center; gap: 12px; padding: 0 20px 14px; }
.scrub input { padding: 0; border: 0; accent-color: var(--ink); }
#slider-time { font-variant-numeric: tabular-nums; min-width: 42px; text-align: right; margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0 20px 20px; }
.timeline li { display: grid; grid-template-columns: 52px 1fr; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.timeline time { font-variant-numeric: tabular-nums; color: var(--muted); }
.timeline .kind-stop b { font-weight: 600; }

/* Диалоги */
.dlg { border: 0; border-radius: var(--radius); padding: 22px; width: min(400px, calc(100% - 32px)); box-shadow: 0 20px 60px rgb(0 0 0 / 0.25); }
.dlg::backdrop { background: rgb(0 0 0 / 0.35); }
.dlg label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.dlg menu { display: flex; gap: 8px; align-items: center; margin: 16px 0 0; padding: 0; }
.code-box { display: grid; gap: 2px; padding: 12px 14px; background: var(--soft); border-radius: 10px; }
.code-box strong, .big-code { font-size: 30px; letter-spacing: 0.18em; font-variant-numeric: tabular-nums; }
.big-code { display: block; text-align: center; padding: 16px 0 4px; font-size: 40px; }

/* Маркеры на карте */
.pin { display: flex; align-items: center; gap: 6px; white-space: nowrap; transform: translate(-7px, -7px); }
.pin i { width: 14px; height: 14px; border-radius: 50%; border: 2.5px solid #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 0.35); flex: none; }
.pin span { background: #fff; padding: 2px 7px; border-radius: 7px; font: 600 12px/1.3 var(--font); box-shadow: 0 1px 4px rgb(0 0 0 / 0.2); }
.pin.stale i { opacity: 0.45; }
.pin.stale span { color: var(--muted); }
.stop-pin { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); font: 700 11px/18px var(--font); text-align: center; transform: translate(-11px, -11px); }
.end-pin { width: 16px; height: 16px; border-radius: 4px; border: 3px solid #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 0.4); transform: translate(-8px, -8px); }
.now-pin { width: 18px; height: 18px; border-radius: 50%; background: var(--ink); border: 3px solid #fff; box-shadow: 0 1px 6px rgb(0 0 0 / 0.5); transform: translate(-9px, -9px); }

@media (prefers-reduced-motion: no-preference) {
  .panel { transition: max-height 0.3s var(--ease); }
}
