:root {
  --brand: #0f766e; --brand-d: #115e59; --brand-l: #ccfbf1; --accent: #facc15;
  --bg: #f4f6f8; --card: #fff; --line: #e2e8f0; --line-2: #cbd5e1;
  --text: #0f172a; --muted: #64748b; --danger: #dc2626;
  --radius: 12px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.06);
  --side: 210px; --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: Manrope, system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 10% -10%, #99f6e4 0, transparent 60%), radial-gradient(900px 500px at 110% 110%, #fde68a 0, transparent 55%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 20px; padding: 32px 28px; box-shadow: 0 20px 60px rgba(15,23,42,.12); }
.login-card .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-card .logo img { width: 48px; height: 48px; border-radius: 12px; }
.login-card h1 { font-size: 22px; margin: 0; line-height: 1.2; }
.login-card .sub { color: var(--muted); font-size: 13px; }

/* ---------- каркас ---------- */
.layout { display: flex; min-height: 100vh; }
.side { width: var(--side); background: #0b3b38; color: #d1fae5; position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; padding: 16px 12px; z-index: 20; }
.side .brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 20px; color: #fff; font-weight: 800; }
.side .brand img { width: 34px; height: 34px; border-radius: 9px; }
.side .brand small { display: block; font-weight: 500; color: #99f6e4; font-size: 12px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: #ccfbf1; text-decoration: none; font-weight: 600; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.07); }
.nav a.on { background: var(--brand); color: #fff; }
.nav svg { width: 20px; height: 20px; flex: none; }
.side .me a { color: #99f6e4; }
.side .me { margin-top: auto; padding: 12px; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px; }
.side .me button { background: none; border: 0; color: #99f6e4; padding: 0; cursor: pointer; text-decoration: underline; }
.main { flex: 1; margin-left: var(--side); min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 10; background: rgba(244,246,248,.92); backdrop-filter: blur(8px); padding: 10px 16px 10px 24px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.top h2 { margin: 0; font-size: 20px; margin-right: auto; }
.content { padding: 12px 16px 24px; flex: 1; min-width: 0; }
.bottom-nav { display: none; }

/* ---------- элементы ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line-2); background: #fff; padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; min-height: 40px; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.big { min-height: 52px; font-size: 16px; border-radius: 14px; width: 100%; }
.btn.sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 12px; background: #fff; min-height: 42px; outline: none; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-l); }
textarea.input { min-height: 84px; resize: vertical; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.pager { display: flex; gap: 6px; align-items: center; }
.pager .btn { min-width: 40px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-new { background: #f1f5f9; color: #475569; }
.st-assigned { background: #dbeafe; color: #1d4ed8; }
.st-on_way { background: #fef3c7; color: #b45309; }
.st-started { background: #ede9fe; color: #6d28d9; }
.st-done { background: #dcfce7; color: #15803d; }
.st-cancelled { background: #fee2e2; color: #b91c1c; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.seg { display: inline-flex; background: #e2e8f0; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.on { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ---------- расписание ---------- */
.sched-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.sched { display: grid; min-width: 980px; }
.sched .hd { position: sticky; top: 0; background: #f8fafc; border-bottom: 1px solid var(--line); padding: 10px; font-weight: 700; font-size: 13px; text-align: center; }
.sched .hd.today { color: var(--brand); background: #f0fdfa; }
.sched .hd small { display: block; color: var(--muted); font-weight: 500; }
.sched .who { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; font-weight: 700; font-size: 14px; background: #fff; position: sticky; left: 0; z-index: 2; border-right: 1px solid var(--line); }
.sched .who small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.sched .cell { border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); padding: 6px; min-height: 84px; display: flex; flex-direction: column; gap: 6px; cursor: pointer; transition: background .15s; }
.sched .cell:hover { background: #f8fafc; }
.sched .cell.today { background: #f0fdfa66; }
.sched .cell.drop { background: var(--brand-l); }
.sched .cell .plus { opacity: 0; color: var(--muted); font-size: 12px; text-align: center; margin-top: auto; }
.sched .cell:hover .plus { opacity: 1; }
.jcard { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--wt, #64748b); border-radius: 8px; padding: 6px 8px; font-size: 12.5px; line-height: 1.3; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.jcard:hover { border-color: var(--line-2); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.jcard b { font-size: 13px; }
.jcard .addr { color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.jcard.is-done { opacity: .6; }
.jcard.is-cancelled { opacity: .45; text-decoration: line-through; }
.jcard .ln { display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.jcard .sdot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.unsched { margin-top: 18px; }
.unsched-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }

/* ---------- списки ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; gap: 14px; align-items: center; cursor: pointer; text-decoration: none; color: inherit; border-left: 4px solid var(--wt, transparent); }
.item:hover { box-shadow: 0 2px 4px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.08); }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 700; }
.item .s { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .r { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters .input { width: auto; flex: 1 1 200px; }

/* ---------- заявка ---------- */
.job-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.mini-map { height: 220px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.form-map { height: 240px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); margin-bottom: 14px; }
.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.timeline li { display: flex; gap: 10px; font-size: 14px; }
.timeline li::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); margin-top: 7px; flex: none; }
.timeline .when { color: var(--muted); font-size: 12px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photos a { display: block; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: #e2e8f0; }
.photos img { width: 100%; height: 100%; object-fit: cover; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.status-flow { display: grid; gap: 10px; }
h3 { font-size: 15px; margin: 0 0 12px; }
.sec + .sec { margin-top: 16px; }
.geo-results { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: -8px 0 14px; }
.geo-results button { text-align: left; border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 9px 12px; cursor: pointer; font-size: 13px; }
.geo-results button:hover { background: #f0fdfa; }

/* ---------- карта ---------- */
.map-page { position: relative; flex: 1; display: flex; }
#bigmap { flex: 1; min-height: calc(100vh - 61px); }
.map-panel { position: absolute; z-index: 500; top: 12px; right: 12px; width: 300px; max-width: calc(100% - 24px); max-height: calc(100% - 24px); overflow: auto; background: #fff; border-radius: 14px; box-shadow: 0 8px 30px rgba(15,23,42,.18); padding: 14px; }
.map-panel .check { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; font-weight: 600; cursor: pointer; }
.map-panel .check input { width: 18px; height: 18px; accent-color: var(--brand); }
.map-panel .seg { display: flex; }
.map-panel .seg button { flex: 1; padding: 6px 4px; font-size: 13px; }
.map-panel hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.who-list { display: flex; flex-direction: column; gap: 6px; }
.who-list button { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 7px 9px; cursor: pointer; text-align: left; }
.who-list button:hover { border-color: var(--brand); }
.who-list .avatar { width: 28px; height: 28px; font-size: 11px; }
.pin-worker { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; color: #fff; font-weight: 800; font-size: 12px; display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.pin-worker.old { filter: grayscale(.8); opacity: .75; }
.pin-job { width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.leaflet-popup-content { font-family: Manrope, system-ui, sans-serif; font-size: 13px; }

/* ---------- модалка, тост ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1200; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; animation: fade .15s; }
.modal { background: #fff; border-radius: 18px; width: 100%; max-width: 640px; box-shadow: 0 30px 80px rgba(0,0,0,.25); animation: pop .18s; }
.modal.wide { max-width: 1280px; }
.modal-h { display: flex; align-items: center; gap: 10px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-h h3 { margin: 0; font-size: 18px; flex: 1; }
.modal-b { padding: 20px; }
.modal-f { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.x { border: 0; background: #f1f5f9; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 20px; line-height: 1; }
@keyframes fade { from { opacity: 0 } }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0 } }
#toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: #0f172a; color: #fff; padding: 11px 18px; border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none; transition: .25s; z-index: 2000; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- экран мастера ---------- */
.geo-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; font-size: 14px; font-weight: 600; margin-bottom: 14px; }
.geo-bar.on { background: #dcfce7; color: #166534; }
.geo-bar.off { background: #fef3c7; color: #92400e; }
.geo-bar .btn { margin-left: auto; }
.wjob { background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 16px; border-left: 5px solid var(--wt, #64748b); text-decoration: none; color: inherit; display: block; }
.wjob .time { font-size: 18px; font-weight: 800; }
.wjob .addr { font-weight: 600; margin: 4px 0; }
.day-title { font-weight: 800; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 8px; }

/* ---------- телефон ---------- */
@media (max-width: 860px) {
  .side { display: none; }
  .main { margin-left: 0; padding-bottom: calc(64px + var(--safe-b)); }
  .top { padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
  .top h2 { font-size: 18px; }
  .content { padding: 14px 16px 24px; }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100; background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; font-size: 11px; font-weight: 700; color: var(--muted); text-decoration: none; }
  .bottom-nav a.on { color: var(--brand); }
  .bottom-nav svg { width: 22px; height: 22px; }
  .job-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
  .overlay { padding: 0; align-items: stretch; }
  .modal { border-radius: 0; min-height: 100%; max-width: none; }
  .modal-f { position: sticky; bottom: 0; background: #fff; padding-bottom: calc(14px + var(--safe-b)); }
  .modal-f .btn { flex: 1; }
  .sched { min-width: 0; }
  #bigmap { min-height: calc(100vh - 60px - 64px); }
  .map-panel { top: auto; bottom: 10px; left: 10px; right: 10px; width: auto; max-height: 45%; }
  .map-panel.collapsed .body { display: none; }
  .item { padding: 12px 14px; }
  .hide-m { display: none !important; }
}
@media (min-width: 861px) { .hide-d { display: none !important; } }

/* ---------- на весь экран ---------- */
.main { transition: margin-left .2s; }
.side { transition: width .2s; }
.side-toggle { position: absolute; top: 18px; right: -13px; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line-2); background: #fff; color: var(--text); display: grid; place-items: center; cursor: pointer; padding: 0; box-shadow: 0 1px 4px rgba(0,0,0,.15); z-index: 21; }
.side-toggle svg { width: 16px; height: 16px; transition: transform .2s; }
body.side-mini { --side: 64px; }
body.side-mini .side-toggle svg { transform: rotate(180deg); }
body.side-mini .side .brand > div, body.side-mini .nav a span, body.side-mini .side .me { display: none; }
body.side-mini .side .brand { padding: 4px 3px 20px; }
body.side-mini .nav a { justify-content: center; padding: 10px 0; }
/* расписание тянется на всю высоту окна */
.sched-wrap { min-height: calc(100vh - 61px - 36px); display: flex; }
.sched { flex: 1; grid-auto-rows: minmax(84px, 1fr); grid-template-rows: auto; }
/* окно заявки: поля слева, карта справа */
.form-2col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.form-map-col .form-map { height: 100%; min-height: 420px; margin-bottom: 14px; }
.form-map-col { display: flex; flex-direction: column; }
@media (max-width: 860px) {
  .form-2col { grid-template-columns: 1fr; gap: 0; }
  .form-map-col .form-map { height: 260px; min-height: 0; }
  .sched-wrap { min-height: 0; }
  .side-toggle { display: none; }
}

/* ---------- версия 2: бригады, чек-листы, смены, офлайн ---------- */
.net { display: flex; align-items: center; gap: 8px; padding: 8px 16px; font-size: 13px; font-weight: 700; }
.net svg { width: 16px; height: 16px; flex: none; }
.net.off { background: #fee2e2; color: #991b1b; }
.net.wait { background: #fef3c7; color: #92400e; }
.mini-av { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: #fff; font-size: 9px; font-weight: 800; flex: none; vertical-align: middle; }
.crew { display: flex; gap: 2px; margin-top: 4px; flex-wrap: wrap; }
.crew .mini-av { width: 18px; height: 18px; font-size: 8px; }
.crew-line { display: flex; flex-wrap: wrap; gap: 4px 10px; justify-content: flex-end; }
.crew-list { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.crew-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line-2); background: #fff; border-radius: 99px; padding: 5px 12px 5px 5px; cursor: pointer; font-weight: 600; font-size: 14px; }
.chip:hover { border-color: var(--brand); }
.chip.on { background: var(--brand-l); border-color: var(--brand); color: var(--brand-d); }
.chip-ok svg { width: 15px; height: 15px; display: block; }
.on-shift { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #16a34a; margin-left: 6px; vertical-align: middle; box-shadow: 0 0 0 3px #dcfce7; }
.role-admin { color: var(--brand); font-weight: 700; }
.role-foreman { color: #b45309; font-weight: 700; }
.role-worker { color: var(--muted); }
.tg-on { color: #0284c7; font-weight: 600; }
.geo-bar.idle { background: #f1f5f9; color: #334155; }
.geo-bar span:nth-child(2) { flex: 1; }
.warn { background: #fef3c7; color: #92400e; border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.checklist { display: flex; flex-direction: column; }
.ck-row { padding: 12px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.ck-row:first-child { border-top: 0; padding-top: 0; }
.ck-line { display: flex; align-items: center; gap: 10px; }
.ck-click { cursor: pointer; }
.ck-head { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.ck-mark { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line-2); display: grid; place-items: center; flex: none; color: #fff; }
.ck-mark.ok { background: #16a34a; border-color: #16a34a; }
.ck-mark svg { width: 14px; height: 14px; }
.ck-text { font-weight: 600; }
.req { color: var(--danger); font-weight: 800; }
.ck-box { width: 26px; height: 26px; accent-color: var(--brand); flex: none; }
.ck-edit { display: flex; flex-direction: column; gap: 8px; }
.ck-edit-row { display: grid; grid-template-columns: 120px 1fr auto auto auto auto; gap: 6px; align-items: center; }
.ck-req { display: flex; gap: 4px; align-items: center; font-size: 13px; color: var(--muted); white-space: nowrap; }
.ck-edit .btn.sm.ghost { min-width: 32px; padding: 4px; }
.photos a.queued { position: relative; opacity: .75; }
.photos a.queued::after { content: 'ждёт'; position: absolute; left: 4px; bottom: 4px; background: #92400e; color: #fff; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.timeline li.local { opacity: .7; }
body.native .top { padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
@media (max-width: 860px) {
  .ck-edit-row { grid-template-columns: 1fr auto auto auto; }
  .ck-edit-row select { grid-column: 1 / -1; }
  .ck-edit-row input.input { grid-column: 1 / -1; }
  .geo-bar { flex-wrap: wrap; }
}
