* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: #2a2a2a; }

/* Страница карты выездов — flex-layout без absolute-магии */
body.map-page { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid #e0e0e0;
  background: #fff; flex: 0 0 auto;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.controls { display: flex; gap: 12px; align-items: center; }
.controls label { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.controls input, .controls select, .controls button {
  padding: 6px 10px; border: 1px solid #d0d0d0; border-radius: 4px; font-size: 13px;
}
.controls button { background: #2563eb; color: #fff; border: 0; cursor: pointer; }
.controls button:hover { background: #1d4ed8; }

.map-layout { flex: 1 1 auto; display: flex; min-height: 0; }
#map { flex: 1 1 auto; min-width: 0; }
#sidebar {
  flex: 0 0 340px; width: 340px;
  border-left: 1px solid #e0e0e0; overflow-y: auto;
  padding: 16px; background: #fafafa;
}
#sidebar h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }

/* Сводка-счётчик */
.summary {
  padding: 8px 10px; margin-bottom: 12px;
  font-size: 12px; color: #555;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 6px;
}

/* Группа выездов на одну дату */
.group { margin-bottom: 16px; }
.group-head {
  margin: 0 0 8px;
  font-size: 12px; font-weight: 600;
  color: #6b7280; text-transform: uppercase; letter-spacing: 0.04em;
  padding-bottom: 4px; border-bottom: 1px solid #e5e7eb;
}
.group--nodate .group-head { color: #b45309; }

/* Карточка выезда */
.trip {
  padding: 10px 12px; margin-bottom: 8px;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 6px;
  border-left: 4px solid #cbd5e1;
  font-size: 13px; cursor: pointer;
  transition: box-shadow 0.15s, transform 0.05s;
}
.trip:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.trip:active { transform: translateY(1px); }
.trip--noaddr { background: #fffbeb; }
.trip.is-highlighted {
  box-shadow: 0 0 0 2px #2563eb, 0 4px 12px rgba(37,99,235,0.18);
  border-color: #2563eb;
}
@keyframes trip-flash {
  0%   { background: #dbeafe; }
  100% { background: #fff; }
}
.trip--flash { animation: trip-flash 0.8s ease-out; }
.trip--noaddr.trip--flash { animation: none; background: #fffbeb; }

.trip-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  margin-bottom: 6px;
}
.trip-contract { font-weight: 600; font-size: 13px; color: #111827; }
.trip-contract--empty { color: #9ca3af; font-weight: 500; font-style: italic; }
.trip-date {
  font-size: 12px; color: #1f2937; white-space: nowrap;
  background: #eef2ff; padding: 2px 8px; border-radius: 999px;
}
.trip-date--empty { color: #9ca3af; background: #f3f4f6; font-style: italic; }
.trip-tag { font-size: 11px; font-weight: 600; white-space: nowrap; }
.trip-addr { color: #374151; line-height: 1.35; margin-bottom: 4px; }
.trip-noaddr { color: #b45309; font-style: italic; }
.trip-meta { color: #6b7280; font-size: 12px; }
.trip-actions { margin-top: 8px; display: flex; gap: 6px; }
.trip-open {
  font-size: 12px; padding: 4px 10px; border-radius: 4px; cursor: pointer;
  border: 1px solid #93c5fd; background: #eff6ff; color: #2563eb;
}
.trip-open:hover { background: #dbeafe; border-color: #2563eb; }

/* Кто едет — главное информационное поле для оператора */
.trip-riders-row { margin: 6px 0 4px; }
.trip-riders { font-size: 12px; color: #1f2937; }
.trip-riders-label { color: #6b7280; }
.trip-rider {
  display: inline-block; padding: 1px 6px; margin: 0 2px;
  background: #f3f4f6; border-radius: 4px; white-space: nowrap;
}
.trip-riders--empty { color: #b45309; font-style: italic; }

/* Тестовая метка — карточка чуть тонирована, плашка ТЕСТ ярко */
.trip--test { background: repeating-linear-gradient(45deg, #fffbeb, #fffbeb 8px, #fef3c7 8px, #fef3c7 12px); }
.trip-test {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  background: #b91c1c; color: #fff; padding: 1px 6px; border-radius: 3px; margin-right: 6px;
  vertical-align: middle;
}

.empty, .loading { color: #6b7280; font-size: 13px; padding: 8px 0; }

/* Виджет в сделке */
body.widget { padding: 12px; }
#widget-root { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
#map-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
#map-mini { height: 380px; border: 1px solid #e0e0e0; border-radius: 6px; }

/* Переключатель периода */
#period-bar {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 6px 8px; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px;
  font-size: 12px;
}
.period-label { color: #6b7280; margin-right: 4px; width: 100%; font-weight: 600; }
.period-group { display: flex; gap: 4px; padding: 2px 6px; border-radius: 4px; background: #fff; border: 1px solid #e5e7eb; }
.period-group--past { background: #f3f4f6; border-color: #e5e7eb; }
.period-btn {
  padding: 4px 10px; border: 1px solid #d1d5db; background: #fff; border-radius: 4px;
  cursor: pointer; font-size: 12px; color: #374151;
}
.period-btn:hover { border-color: #2563eb; color: #2563eb; }
.period-btn.active { background: #2563eb; color: #fff; border-color: #2563eb; }
/* Прошедшие — кнопки серого тона, активная серая (а не синяя) */
.period-group--past .period-btn { color: #6b7280; border-color: #e5e7eb; background: #fff; }
.period-group--past .period-btn:hover { color: #1f2937; border-color: #9ca3af; }
.period-group--past .period-btn.active { background: #6b7280; color: #fff; border-color: #6b7280; }
#custom-date {
  margin-left: auto; padding: 3px 6px; border: 1px solid #d1d5db; border-radius: 4px;
  font-size: 12px;
}

/* Список соседних выездов */
#nearby-trips {
  border: 1px solid #e5e7eb; border-radius: 6px; background: #fff;
  max-height: 220px; display: flex; flex-direction: column;
}
.nearby-head {
  padding: 6px 10px; font-size: 11px; font-weight: 600; color: #6b7280;
  text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid #e5e7eb;
}
.nearby-list { flex: 1; overflow-y: auto; padding: 4px; }
.nearby-empty { padding: 12px; color: #9ca3af; font-size: 12px; text-align: center; }
.nearby-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px;
  padding: 6px 8px; margin-bottom: 4px; border-radius: 4px;
  cursor: pointer; font-size: 12px; transition: background 0.1s;
  border: 1px solid transparent;
}
.nearby-item:hover { background: #eff6ff; border-color: #bfdbfe; }
.nearby-item.is-current { background: #fef3c7; border-color: #fcd34d; }
.nearby-item--past { opacity: 0.7; }
.nearby-item--past .nearby-addr { color: #6b7280; font-weight: 400; }
.nearby-item--past .nearby-date { background: #f3f4f6; color: #6b7280; }
.nearby-icon { font-size: 14px; }
.nearby-addr { color: #111827; font-weight: 500; line-height: 1.3; min-width: 0; word-break: break-word; }
.nearby-meta { color: #6b7280; font-size: 11px; margin-top: 2px; }
.nearby-date {
  white-space: nowrap; padding: 2px 6px; border-radius: 999px;
  background: #eef2ff; color: #1e40af; font-size: 11px; font-weight: 500;
  align-self: center;
}
#booking-form label { display: block; margin-bottom: 12px; font-size: 13px; }
#booking-form input[type=text], #booking-form input[type=date], #booking-form input[type=time] {
  width: 100%; padding: 6px 8px; border: 1px solid #d0d0d0; border-radius: 4px; font-size: 13px;
}
#booking-form fieldset { border: 1px solid #d0d0d0; border-radius: 4px; padding: 8px 12px; margin-bottom: 12px; }
#booking-form legend { font-size: 12px; color: #666; padding: 0 4px; }
/* Overlay-виджет сделки поверх карты */
#deal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.deal-overlay-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.45);
}
.deal-overlay-frame {
  position: relative; width: min(1100px, 95vw); height: min(85vh, 800px);
  background: #fff; border-radius: 8px; box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  display: flex; flex-direction: column; overflow: hidden;
}
.deal-overlay-head {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid #e5e7eb;
  background: #f9fafb; font-size: 13px; font-weight: 600;
}
.deal-overlay-head span { flex: 1; }
.deal-overlay-link { color: #2563eb; text-decoration: none; font-weight: 500; font-size: 12px; }
.deal-overlay-close {
  background: none; border: 0; font-size: 18px; cursor: pointer; color: #6b7280;
  padding: 0 6px;
}
.deal-overlay-close:hover { color: #111827; }
.deal-overlay-frame iframe { flex: 1; width: 100%; border: 0; }

/* Блок «Текущий план» виджета сделки */
.current-plan {
  border: 1px solid #16a34a; border-left: 4px solid #16a34a;
  background: #f0fdf4; border-radius: 6px;
  padding: 10px 12px; margin-bottom: 14px;
}
.current-plan.hidden { display: none; }
.cp-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.cp-icon { font-size: 18px; }
.cp-title { font-weight: 600; font-size: 14px; color: #15803d; }
.cp-body { font-size: 13px; color: #1f2937; }
.cp-when { margin-bottom: 4px; }
.cp-when strong { font-weight: 600; }
.cp-riders { color: #374151; }
.cp-rider {
  display: inline-block; padding: 1px 6px; margin: 2px 4px 0 0;
  background: #fff; border: 1px solid #d1fae5; border-radius: 4px;
  font-size: 12px;
}
.cp-actions { display: flex; gap: 8px; margin-top: 8px; }
.cp-actions button {
  font-size: 12px; padding: 4px 10px; border-radius: 4px;
  border: 1px solid #d1d5db; background: #fff; cursor: pointer;
}
.cp-actions .cp-edit { color: #2563eb; border-color: #93c5fd; }
.cp-actions .cp-edit:hover { background: #eff6ff; }
.cp-actions .cp-add-comment { color: #6b21a8; border-color: #d8b4fe; }
.cp-actions .cp-add-comment:hover { background: #faf5ff; }
.cp-actions .cp-cancel { color: #b91c1c; border-color: #fecaca; }
.cp-actions .cp-cancel:hover { background: #fef2f2; }
.cp-comment-form { margin-top: 8px; }
.cp-comment-form.hidden { display: none; }
.cp-comment-input {
  width: 100%; padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 4px;
  font-family: inherit; font-size: 13px; resize: vertical;
}
.cp-comment-form button {
  font-size: 12px; padding: 4px 10px; border-radius: 4px; cursor: pointer;
  border: 1px solid #d1d5db; background: #fff;
}
.cp-comment-save { color: #16a34a; border-color: #86efac !important; }
.cp-comment-save:hover { background: #f0fdf4; }

#booking-form textarea {
  width: 100%; padding: 6px 8px; border: 1px solid #d0d0d0; border-radius: 4px;
  font-family: inherit; font-size: 13px; resize: vertical;
}

/* Скрытие формы когда план уже есть, до клика «Перепланировать» */
#booking-form.has-plan > label,
#booking-form.has-plan > fieldset,
#booking-form.has-plan > button[type=submit] { display: none; }

.resource-row {
  display: grid; grid-template-columns: 22px 22px 1fr auto auto; align-items: center; gap: 8px;
  padding: 6px 8px; margin-bottom: 4px;
  border: 1px solid #e5e7eb; border-radius: 4px; background: #fff;
  cursor: pointer; font-size: 13px;
}
.resource-row:hover { border-color: #cbd5e1; background: #f9fafb; }
.resource-row input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
.resource-role { font-size: 16px; }
.resource-name { font-weight: 500; color: #111827; }
.resource-pos { font-size: 11px; color: #6b7280; }
.busy { font-size: 11px; }
#booking-form button { background: #16a34a; color: #fff; border: 0; padding: 10px 16px; border-radius: 6px; cursor: pointer; font-size: 14px; }
#booking-form button:hover { background: #15803d; }
