:root {
  --bg: #F5F3EC;
  --surface-0: #F5F3EC;
  --surface-1: #F5F3EC;
  --surface-2: #FFFFFF;
  --text-primary: #1C1B17;
  --text-secondary: #6E6A5E;
  --text-muted: #A9A493;
  --border: #E3DFD2;
  --accent: #0F6E56;
  --accent-hover: #0B4C3B;
  --accent-bg: #E3F1EC;
  --accent-text: #0B4C3B;
  --success-bg: #EDF3E4;
  --success-text: #4F7942;
  --warning-bg: #FBF0DC;
  --warning-text: #B4780A;
  --danger-bg: #FBEAE7;
  --danger-text: #A83C32;
  --radius: 8px;
  --radius-card: 12px;
  --radius-badge: 6px;
  --nav-h: 58px;                                  /* высота нижнего меню без нижнего отступа iPhone */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-mono: 'SF Mono', 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }  /* manipulation = без двойного тапа-зума */

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 15px;
  touch-action: manipulation;
  -webkit-touch-callout: none;
}

.mono { font-family: var(--font-mono); }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 76px);   /* меню + запас под плавающую кнопку */
}
#app.screen-map { padding-bottom: 0; }

/* ---------- Шапка экрана ---------- */
.top-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 4px 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.top-bar .back {
  display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px;
  margin-left: -12px; cursor: pointer; font-size: 20px; color: var(--text-secondary);
}
.top-bar h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; min-width: 0; }
.top-bar .action {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px;
  font-size: 13px; color: var(--accent); cursor: pointer; font-weight: 500;
}
.top-bar-actions { display: flex; align-items: center; gap: 10px; }

.content { padding: 0 16px; }

/* ---------- Метрики ---------- */
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.metric-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: 14px; transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.metric-card .label { font-size: 12px; color: var(--text-secondary); margin: 0 0 4px; }
.metric-card .value { font-size: 22px; font-weight: 600; margin: 0; font-family: var(--font-mono); }

/* ---------- Поиск ---------- */
.search-box { position: relative; margin-bottom: 12px; }
.search-box::before {                          /* лупа — inline SVG в фоне: без эмодзи-глифов и наезда на текст */
  content: ""; position: absolute; left: 13px; top: 50%; width: 18px; height: 18px; margin-top: -9px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236E6A5E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.5-3.5'/%3E%3C/svg%3E") center / contain no-repeat;
  pointer-events: none;
}
/* (0,2,1): сильнее общего правила input[type=text] ниже, поэтому отступ под лупу не затирается */
.search-box input[type=text], .search-box input[type=search] { padding-left: 42px; margin-bottom: 0; }

/* ---------- Списки ---------- */
.list-row {
  display: flex; align-items: center; gap: 10px; min-height: 56px; text-align: left;
  padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius); margin-bottom: 8px; cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.12s ease, transform 0.12s ease;
}

/* Карточки заказов оформлены как посылочные этикетки: пунктирная рамка
   + ряд "перфорации" вдоль верхнего края (кружки в цвет фона страницы,
   создающие иллюзию пробитых отверстий). Только для заказов/выплат —
   у клиентов и магазинов рамка остаётся сплошной. */
.list-row.parcel-row,
.check-row.parcel-row {
  border-style: dashed;
  position: relative;
  overflow: visible;
}
.list-row.parcel-row::before,
.check-row.parcel-row::before {
  content: "";
  position: absolute;
  top: -6px; left: 14px; right: 14px; height: 12px;
  background-image: radial-gradient(circle at center, var(--bg) 3.5px, transparent 3.6px);
  background-repeat: repeat-x;
  background-size: 14px 12px;
  background-position: left center;
  pointer-events: none;
}

.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent-bg);
  color: var(--accent-text); display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px; flex-shrink: 0;
}
.avatar svg { width: 18px; height: 18px; }
.row-main { flex: 1; min-width: 0; text-align: left; }
.row-title { font-size: 14px; font-weight: 600; margin: 0; color: var(--text-primary); overflow-wrap: anywhere; }
.row-sub { font-size: 12px; color: var(--text-secondary); margin: 2px 0 0; overflow-wrap: anywhere; }
.badge { font-size: 10px; padding: 3px 8px; border-radius: var(--radius-badge); flex-shrink: 0; font-weight: 600; }
.badge.warn { background: var(--warning-bg); color: var(--warning-text); }
.badge.ok { background: var(--success-bg); color: var(--success-text); }
.badge.danger { background: var(--danger-bg); color: var(--danger-text); }
.badge.neutral { background: var(--surface-1); color: var(--text-secondary); }

.card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: 16px 18px; margin-bottom: 16px;
}
.card table { width: 100%; font-size: 13px; border-collapse: collapse; }
.card table td { padding: 5px 0; }
.card table td:first-child { color: var(--text-secondary); width: 1%; min-width: 90px; white-space: nowrap; padding-right: 12px; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2); font-size: 14px; cursor: pointer; font-weight: 500;
  color: var(--text-primary); font-family: inherit;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.warning { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-bg); }
.btn.ghost { background: none; border: 1px solid transparent; color: var(--text-secondary); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.6; pointer-events: none; }
.btn svg { width: 18px; height: 18px; }

.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%);
  max-width: 448px;
  width: calc(100% - 32px);
  z-index: 20;
}
.fab:active { transform: translateX(-50%) scale(0.98); }

/* Нажатие на сенсорном экране: лёгкое сжатие + смена фона. Hover — только у устройств с мышью,
   иначе после тапа «залипает». */
.list-row:active, .metric-card:active, .chip:active, .sheet-item:active { transform: scale(0.98); background: var(--accent-bg); border-color: var(--accent); }
.btn:active { transform: scale(0.98); background: var(--accent-bg); }
.btn.primary:active { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.warning:active { background: #F6E5C4; }
.btn.ghost:active { background: var(--accent-bg); }
@media (hover: hover) {
  .metric-card:hover { background: var(--accent-bg); border-color: var(--accent); }
  .list-row:hover { border-color: var(--accent); }
  .btn:hover { background: var(--bg); }
  .btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
  .btn.warning:hover { background: #F6E5C4; border-color: #F6E5C4; }
  .btn.ghost:hover { background: none; text-decoration: underline; }
  .chip:hover { border-color: var(--accent); }
  .top-bar .action:hover, .fee-edit:hover { color: var(--accent-hover); }
}

/* ---------- Формы ---------- */
label { font-size: 12px; color: var(--text-secondary); display: block; margin-bottom: 5px; }
input[type=text], input[type=number], input[type=tel], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border-radius: var(--radius); border: 1px solid var(--border);
  font-size: 16px; background: var(--surface-2); margin-bottom: 14px; font-family: inherit; color: var(--text-primary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type=text]:focus, input[type=number]:focus, input[type=tel]:focus, input[type=date]:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 110, 86, 0.15);
}
textarea { resize: none; min-height: 70px; }

.section-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 0 0 8px; }

/* Чипы-фильтры (страны клиентов, статусы заявок) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
  position: relative; display: inline-flex; align-items: center; gap: 5px; min-height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); font-size: 13px;
  color: var(--text-secondary); cursor: pointer; white-space: nowrap; user-select: none;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
.chip::before { content: ""; position: absolute; left: 0; right: 0; top: -4px; bottom: -4px; }  /* зона нажатия 44px */
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .chip-count { font-family: var(--font-mono); font-size: 11px; opacity: 0.75; }

/* Компактная панель селектов/поиска над списком */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters select, .filters input[type=text] {
  width: auto; flex: 1 1 calc(50% - 8px); min-width: 0; margin-bottom: 0; padding: 7px 10px; font-size: 15px;   /* по два в ряд: подписи не обрезаются */
}
.filters input.filter-wide { flex: 1 1 100%; }

/* Заголовок группы в списке (страна клиентов) */
.group-label {
  display: flex; align-items: center; gap: 6px; margin: 16px 0 8px;
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
}
.group-label .count { font-family: var(--font-mono); font-weight: 500; color: var(--text-muted); }

/* Строка «Приём» в карточке заказа + переключатель «Приём оплачен» */
.fee-row {
  flex-basis: 100%; width: 100%; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--border); font-size: 12px; color: var(--text-secondary);
}
.fee-row .fee-actions { display: flex; align-items: center; gap: 12px; }
.tap { display: inline-flex; align-items: center; min-height: 44px; padding: 0 6px; cursor: pointer; }
.fee-edit { color: var(--accent); cursor: pointer; font-weight: 500; }
.link-danger { color: var(--danger-text); font-weight: 600; font-size: 12px; }
.switch { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; margin: 0; min-height: 44px; font-size: 12px; color: var(--text-secondary); user-select: none; position: relative; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 34px; height: 20px; border-radius: 999px; background: var(--border); position: relative; flex-shrink: 0; transition: background-color 0.15s ease; }
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.15s ease;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px rgba(15, 110, 86, 0.25); }

/* Пустое состояние — ТОЛЬКО для текста «ничего нет»; контейнеры списков этот класс носить не должны */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); font-size: 13px; }

/* ---------- Скелетоны (вместо «Загрузка…») ---------- */
.skel { background: var(--border); border-radius: 6px; animation: skelPulse 1.2s ease-in-out infinite; }
@keyframes skelPulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
.skel-row {
  display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 10px 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px;
}
.skel-avatar { width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; }
.skel-lines { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.skel-line { height: 11px; }
.skel-line.w60 { width: 60%; } .skel-line.w40 { width: 40%; } .skel-line.w80 { width: 80%; }
.skel-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 16px 18px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 10px; }
.skel-metric { height: 78px; border-radius: var(--radius-card); }
.skel-search { height: 44px; border-radius: var(--radius); margin-bottom: 12px; }
.skel-chips { display: flex; gap: 6px; margin-bottom: 14px; }
.skel-chip { height: 36px; width: 84px; border-radius: 999px; }

/* ---------- Модалки и нижний лист ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(28,27,23,0.45); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 20px;
  animation: fadeIn 0.16s ease-out;
}
.modal { background: var(--surface-2); border-radius: var(--radius-card); padding: 20px; max-width: 340px; width: 100%; }
.modal.warning { background: var(--warning-bg); border: 1.5px solid var(--warning-text); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet-overlay { position: fixed; inset: 0; z-index: 60; background: rgba(28,27,23,0); transition: background-color 0.2s ease; }
.sheet-overlay.open { background: rgba(28,27,23,0.45); }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 480px; margin: 0 auto;
  background: var(--surface-2); border-radius: 16px 16px 0 0;
  padding: 10px 12px calc(12px + var(--safe-bottom));
  transform: translateY(100%); transition: transform 0.22s ease-out;
}
.sheet-overlay.open .sheet { transform: translateY(0); }
.sheet-grabber { width: 36px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 8px; }
.sheet-item {
  display: flex; align-items: center; gap: 14px; min-height: 52px; padding: 0 12px; border-radius: var(--radius);
  font-size: 15px; color: var(--text-primary); cursor: pointer; border: 1px solid transparent;
}
.sheet-item svg { width: 22px; height: 22px; flex-shrink: 0; color: var(--text-secondary); }

/* ---------- Представители: выбор клиентов ---------- */
.modal.tall { max-width: 380px; max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; }
.pick-list { overflow-y: auto; margin: 4px 0 10px; flex: 1 1 auto; min-height: 120px; }
.pick-list .check-row { cursor: pointer; margin-bottom: 6px; }
.pick-list .check-row.disabled { opacity: 0.6; cursor: default; }
.row-link { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; align-self: stretch; cursor: pointer; }
.hint-warn { color: var(--warning-text); }

/* ---------- Нижнее меню ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  max-width: 480px; width: 100%; background: var(--surface-2); border-top: 1px solid var(--border);
  display: flex; padding: 0 0 var(--safe-bottom);
  z-index: 40;
}
.bottom-nav .nav-item {
  position: relative; flex: 1 1 0; min-width: 0; min-height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-muted); cursor: pointer; padding: 6px 0 4px;
  transition: color 0.15s ease, background-color 0.12s ease, transform 0.12s ease;
}
.bottom-nav .nav-item:active { transform: scale(0.98); background: var(--accent-bg); }
.bottom-nav .nav-item.active { color: var(--accent); }
.bottom-nav .nav-item.active::before {
  content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 28px; height: 2px; background: var(--accent); border-radius: 2px;
}
.bottom-nav .nav-icon { position: relative; width: 22px; height: 22px; display: block; }
.bottom-nav .nav-icon svg { width: 22px; height: 22px; display: block; }
.bottom-nav .nav-label { font-size: 11px; line-height: 13px; white-space: nowrap; overflow: hidden; max-width: 100%; }
.bottom-nav .nav-item.active .nav-label { font-weight: 600; }
.nav-badge {
  position: absolute; top: -6px; left: 13px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--danger-text); color: #fff; font-size: 10px; line-height: 16px; font-weight: 600; text-align: center;
}
.nav-badge[hidden] { display: none; }

.toast {
  position: fixed; bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px); left: 50%; transform: translateX(-50%);
  background: var(--text-primary); color: #fff; padding: 10px 18px; border-radius: var(--radius);
  font-size: 13px; z-index: 100; max-width: calc(100% - 32px); text-align: center;
  animation: fadeIn 0.16s ease-out;
}

.item-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; align-items: end; background: var(--surface-1); border-radius: var(--radius); padding: 10px; margin-bottom: 8px; }
.item-row input { margin-bottom: 0; }
.item-row .del { cursor: pointer; color: var(--text-muted); font-size: 16px; }

.check-row {
  display: flex; align-items: center; gap: 10px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 6px; min-height: 52px;
}
.check-row input { width: auto; min-height: 0; margin: 0; }
.check-row input[type=checkbox] { width: 22px; height: 22px; flex-shrink: 0; }

/* ---------- Экран «Карта» ---------- */
.map-head { padding: 0 16px; }
.map-counter { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 8px; font-size: 13px; color: var(--text-secondary); }
.map-counter b { color: var(--text-primary); font-weight: 600; }
.map-toggle { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); font-weight: 500; cursor: pointer; white-space: nowrap; }
.map-unfound { max-height: 30vh; overflow-y: auto; margin-bottom: 8px; }
.map-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0 0 8px; font-size: 12px; color: var(--text-secondary); }
.map-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.map-box { padding: 0 16px; }
#leafletMap {
  position: relative; z-index: 0; isolation: isolate;      /* слои Leaflet (z-index до 1000) не должны перекрывать меню и шапку */
  width: 100%; min-height: 240px; border: 1px solid var(--border); border-radius: var(--radius-card); overflow: hidden; background: var(--surface-1);
}
.leaflet-touch .leaflet-bar a { width: 40px; height: 40px; line-height: 40px; }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; line-height: 1.4; text-align: left; color: var(--text-primary); }
.leaflet-popup-content .pp-name { font-weight: 600; font-size: 14px; margin: 0 0 4px; }
.leaflet-popup-content .pp-line { margin: 0 0 3px; color: var(--text-secondary); }
.leaflet-popup-content .btn { margin-top: 8px; width: 100%; }
.leaflet-container { font-family: inherit; }
#leafletMap:focus, #leafletMap .leaflet-container:focus { outline: none; }

/* ---------- Движение: отключается настройкой системы «уменьшить движение» ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
