:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #027ad6;       /* фирменный синий «Сфера» */
  --primary-dark: #0264b0;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 16px rgba(15, 23, 42, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 10px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
[hidden] { display: none !important; }

/* ---------- шапка ---------- */
.topbar { display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 500; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo { height: 42px; width: auto; display: block; }
.brand-text { padding-left: 14px; border-left: 1px solid var(--line); }
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tab { border: none; background: transparent; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--muted); font-weight: 500; }
.tab:hover { background: var(--bg); color: var(--text); }
.tab.active { background: #dbeafe; color: var(--primary-dark); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.notice { padding: 10px 20px; background: #fff4d6; color: #7c4a03; border-bottom: 1px solid #f5d78a; text-align: center; font-weight: 600; font-size: 15px; }
.net-status { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: #e2e8f0; color: var(--muted); }
.net-status.on { background: #dcfce7; color: #166534; }
.net-status.off { background: #fef3c7; color: #92400e; }

/* ---------- общие элементы ---------- */
main { padding: 16px 20px 40px; }
.view { display: none; }
.view.active { display: block; }
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.btn { border: 1px solid var(--line); background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500; transition: background .15s, border-color .15s; }
.btn:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: #f1f5f9; border-color: transparent; }
.btn-xs { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fef2f2; }
.empty { color: var(--muted); padding: 18px 8px; text-align: center; font-size: 13px; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; background: #f1f5f9; color: #334155; font-size: 12px; white-space: nowrap; }
.chip.ok { background: #dcfce7; color: #166534; }
.chip.info { background: #dbeafe; color: #1e40af; }
.chip.warn { background: #fef3c7; color: #92400e; }
.chip a { cursor: pointer; margin-left: 4px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 13px; }
.field > span { color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea, .filters input, .filters select {
  padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff; color: var(--text); width: 100%;
}
.field input:focus, .field select:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }
.addr-row { display: flex; gap: 6px; position: relative; }
.addr-row input { flex: 1; }
.addr-status { font-size: 12px; color: var(--ok); min-height: 16px; }
.suggest { position: absolute; z-index: 600; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); margin-top: 2px; width: 100%; max-height: 260px; overflow: auto; }
.field { position: relative; }
.suggest-item { padding: 8px 10px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.suggest-item:hover { background: #f1f5f9; }
.suggest-src { font-size: 10px; color: var(--muted); min-width: 24px; }
.suggest-note { padding: 8px 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.form-hint { font-size: 12px; color: var(--muted); margin-top: 8px; min-height: 16px; }
.form-hint.error { color: var(--danger); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .span2 { grid-column: span 2; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.chk input { width: auto; }
.days-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.settings-data { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid var(--line); margin-top: 6px; font-size: 12px; color: var(--muted); }

/* ---------- вкладка планирования ---------- */
.plan-layout { display: grid; grid-template-columns: 360px minmax(0, 1fr) 400px; gap: 16px; align-items: start; }
.form-panel { position: sticky; top: 76px; }
.map-col { position: sticky; top: 76px; height: calc(100vh - 100px); min-height: 420px; display: flex; flex-direction: column; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: #fff; }
#map { flex: 1; min-height: 300px; }
#map.picking { cursor: crosshair; }
.map-legend { padding: 8px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); background: #fff; }
.candidates-panel { max-height: calc(100vh - 100px); overflow: auto; }
.candidates-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.candidates-head .muted { font-size: 12px; }
.candidates { display: flex; flex-direction: column; gap: 10px; }
.cand { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; transition: border-color .15s, box-shadow .15s; }
.cand-ok { cursor: pointer; }
.cand-ok:hover { border-color: #93c5fd; }
.cand.selected { border-color: var(--primary); box-shadow: 0 0 0 3px #dbeafe; }
.cand-best { background: #f0fdf4; }
.cand-infeasible { background: #fff7ed; }
.cand-unavailable { background: #f8fafc; opacity: .8; }
.cand-head { display: flex; align-items: center; gap: 8px; }
.cand-rank { width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.cand-name { font-weight: 600; flex: 1; }
.cand-badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #e2e8f0; }
.cand-badge.best { background: var(--ok); color: #fff; }
.cand-veh { font-size: 12px; color: var(--muted); margin: 2px 0 8px; }
.cand-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; margin-bottom: 8px; }
.metric { display: flex; flex-direction: column; }
.metric b { font-size: 15px; }
.metric span { font-size: 11px; color: var(--muted); }
.cand-route { font-size: 12px; color: #334155; margin-bottom: 6px; }
.cand-hints { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.cand-hints .chip { background: #dbeafe; color: #1e40af; }
.cand-reasons { margin: 6px 0 0; padding-left: 18px; font-size: 12px; color: #9a3412; }
.cand-unavailable .cand-reasons { color: var(--muted); }
.cand-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* маркеры */
.wh-pin { width: 26px; height: 26px; border-radius: 6px; color: #fff; font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.stop-pin { width: 24px; height: 24px; border-radius: 50%; background: #fff; border: 3px solid #0ea5e9; color: #0f172a; font-weight: 700; font-size: 11px; display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.target-pin { width: 28px; height: 28px; border-radius: 50%; background: rgba(244, 63, 94, .25); display: flex; align-items: center; justify-content: center; animation: pulse 1.6s infinite; }
.target-pin span { width: 14px; height: 14px; border-radius: 50%; background: #f43f5e; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(244,63,94,.5); } 70% { box-shadow: 0 0 0 14px rgba(244,63,94,0); } 100% { box-shadow: 0 0 0 0 rgba(244,63,94,0); } }
.leaflet-popup-content { font-size: 13px; line-height: 1.4; }

/* ---------- график ---------- */
.schedule-layout { display: flex; flex-direction: column; gap: 16px; }
.schedule-layout > * { min-width: 0; }
.week-nav { display: flex; gap: 6px; align-items: stretch; }
.week-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; flex: 1; }
.week-day { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; font-family: inherit; }
.week-day:hover { border-color: #93c5fd; }
.week-day.active { border-color: var(--primary); background: #dbeafe; }
.week-day.today .wd-num { color: var(--primary); }
.wd-name { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.wd-num { font-size: 18px; font-weight: 700; }
.wd-count { font-size: 11px; color: var(--muted); text-align: center; }
.wd-count em { font-style: normal; color: var(--warn); }
.schedule-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }

.gantt { display: flex; flex-direction: column; gap: 4px; overflow-x: auto; }
.gantt-head, .gantt-row { display: grid; grid-template-columns: 180px minmax(400px, 1fr); gap: 10px; align-items: center; }
.gantt-row.off { opacity: .6; }
.gantt-label { font-size: 13px; display: flex; flex-direction: column; line-height: 1.3; }
.gantt-label small { color: var(--muted); font-size: 11px; }
.gantt-track { position: relative; height: 30px; background: #f8fafc; border-radius: 6px; border: 1px solid var(--line); }
.gantt-axis { height: 18px; background: none; border: none; }
.gantt-hour { position: absolute; top: 0; font-size: 10px; color: var(--muted); transform: translateX(-50%); }
.seg { position: absolute; top: 4px; height: 20px; border-radius: 4px; min-width: 2px; }
.seg-shift { top: 0; height: 100%; background: #eef2ff; border-radius: 6px; }
.seg-travel { background: #cbd5e1; top: 9px; height: 10px; }
.seg-load { background: #f59e0b; }
.seg-drop { background: var(--ok); }
.seg-drop.late { background: var(--danger); }
.seg-wait { background: repeating-linear-gradient(45deg, #fde68a, #fde68a 3px, #fff 3px, #fff 6px); }
.gantt-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin-top: 8px; }
.gantt-legend i { display: inline-block; width: 14px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: middle; position: static; }
.gantt-legend i.seg-shift { border: 1px solid #c7d2fe; }

.routes { display: flex; flex-direction: column; gap: 12px; }
.route-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; margin-bottom: 8px; }
.route-stats { font-size: 12px; color: var(--muted); }
.route-warn { background: #fef2f2; color: #991b1b; padding: 6px 10px; border-radius: 6px; font-size: 12px; margin-bottom: 8px; }
.stops { list-style: none; margin: 0; padding: 0; }
.stop { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.stop:first-child { border-top: none; }
.stop.done { opacity: .55; }
.stop-time { width: 48px; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; padding-top: 2px; flex-shrink: 0; }
.stop-num { width: 22px; height: 22px; border-radius: 50%; background: #0ea5e9; color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stop-dot { width: 12px; height: 12px; border-radius: 50%; margin: 5px; flex-shrink: 0; }
.stop-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.stop-body small { color: var(--muted); font-size: 12px; }
.stop-actions { display: flex; gap: 4px; flex-shrink: 0; }
.route-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }

/* ---------- списки и таблицы ---------- */
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.list-head h2 { margin: 0; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 4px; background: #fff; }
.card.inactive { opacity: .6; }
.card-head { display: flex; justify-content: space-between; align-items: center; font-size: 15px; }
.card-line { font-size: 13px; }
.days { display: flex; gap: 4px; }
.day { font-size: 11px; padding: 2px 6px; border-radius: 4px; background: #f1f5f9; color: #94a3b8; }
.day.on { background: #dbeafe; color: #1e40af; font-weight: 600; }
.card-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 6px; }

/* ---------- модальные окна, уведомления ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 640px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 16px 18px; overflow: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); }
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 1100; }
.toast { background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); transition: all .25s; max-width: 380px; }
.toast.show { opacity: 1; transform: none; }
.toast-success { background: #166534; }
.toast-error { background: #991b1b; }

/* ---------- адаптив ---------- */
@media (max-width: 1200px) {
  .plan-layout { grid-template-columns: 340px minmax(0, 1fr); }
  .candidates-panel { grid-column: 1 / -1; max-height: none; }
  .map-col { height: 60vh; }
}
@media (max-width: 800px) {
  main { padding: 12px 16px 32px; }
  .topbar { padding: 8px 16px; gap: 10px; }
  .brand { gap: 10px; }
  .brand-logo { height: 34px; }
  .brand-text { padding-left: 10px; }
  .brand-sub { display: none; }
  .plan-layout { grid-template-columns: 1fr; }
  .form-panel, .map-col { position: static; }
  .map-col { height: 50vh; }
  .field-row { flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: span 1; }
  .gantt-head, .gantt-row { grid-template-columns: 120px minmax(300px, 1fr); }
  .week-nav { flex-wrap: wrap; }
  .week-days { flex: 1 1 100%; order: 2; gap: 3px; }
  .week-day { padding: 6px 2px; }
  .wd-count { display: none; }
}

