:root {
  --bg: #0e1014; --panel: #161920; --panel2: #1d212a; --line: #2a2f3a; --line2: #353b48;
  --text: #e8eaef; --muted: #8b93a3; --accent: #ff5a1f; --accent2: #ff7a45; --accentbg: rgba(255,90,31,.12);
  --ok: #2ecc71; --warn: #f5b041; --bad: #ef4444; --info: #3b9eff; --violet: #a78bfa;
  --r: 10px; --sh: 0 8px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
* { -webkit-tap-highlight-color: transparent; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -.2px; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; } .r { text-align: right; } .c { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* Layout */
.app { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 10px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; overflow-y: auto; }
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.logo .mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; font-weight: 900; color: #fff; font-size: 17px; box-shadow: 0 0 0 3px var(--accentbg); }
.logo b { display: block; font-size: 15px; } .logo span { font-size: 11px; color: var(--muted); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text); opacity: .82; margin-bottom: 2px; font-weight: 500; }
.nav a:hover { background: var(--panel2); text-decoration: none; opacity: 1; }
.nav a.active { background: var(--accentbg); color: var(--accent2); opacity: 1; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .badge { margin-left: auto; }
.side .foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.side .foot .who { font-weight: 600; } .side .foot .role { color: var(--muted); font-size: 12px; }
.side .foot button { margin-top: 8px; }
.main { padding: 22px 28px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.topbar .sp { flex: 1; }
.mobilebar { display: none; }

/* Panels */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.card + .card { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0,1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.g-main { grid-template-columns: minmax(0,2fr) minmax(300px,1fr); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.kpi .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .v.acc { color: var(--accent2); } .kpi .v.ok { color: var(--ok); } .kpi .v.bad { color: var(--bad); }

/* Buttons & forms */
button, .btn { font: inherit; border: 1px solid var(--line2); background: var(--panel2); color: var(--text); padding: 7px 13px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: #4a5160; text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent2); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: var(--panel2); }
button.danger { color: var(--bad); } button.danger:hover { border-color: var(--bad); }
button.sm, .btn.sm { padding: 4px 9px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line2); border-radius: 8px; padding: 8px 10px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accentbg); }
textarea { resize: vertical; min-height: 70px; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search { max-width: 340px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 11px; border-radius: 99px; border: 1px solid var(--line2); background: transparent; color: var(--muted); font-size: 13px; }
.chip.on { background: var(--accentbg); border-color: var(--accent); color: var(--accent2); }

/* Tables */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: var(--panel2); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl input, .tbl select { padding: 5px 7px; }
.tbl tfoot td { font-weight: 600; }
.tblwrap { overflow-x: auto; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--panel2); color: var(--muted); white-space: nowrap; }
.st-new { background: rgba(139,147,163,.18); color: #c3c8d2; }
.st-scheduled { background: rgba(59,158,255,.16); color: #7dbdff; }
.st-in_work { background: rgba(255,90,31,.16); color: var(--accent2); }
.st-waiting { background: rgba(245,176,65,.16); color: var(--warn); }
.st-done { background: rgba(46,204,113,.16); color: var(--ok); }
.st-issued { background: rgba(167,139,250,.16); color: var(--violet); }
.st-cancelled { background: rgba(239,68,68,.12); color: #f28b8b; text-decoration: line-through; }
.badge.red { background: var(--bad); color: #fff; } .badge.ok { background: rgba(46,204,113,.16); color: var(--ok); } .badge.warn { background: rgba(245,176,65,.16); color: var(--warn); }

/* Lists */
.list { display: flex; flex-direction: column; }
.li { display: flex; gap: 10px; align-items: center; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.li:last-child { border-bottom: 0; }
.li .time { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 46px; color: var(--accent2); }
.li .grow { flex: 1; min-width: 0; } .li .t { font-weight: 600; } .li .s { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li.click { cursor: pointer; } .li.click:hover { background: var(--panel2); }

/* Status pipeline */
.pipe { display: flex; gap: 6px; flex-wrap: wrap; }
.pipe button { border-radius: 99px; font-size: 13px; padding: 5px 12px; }
.pipe button.cur { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* Calendar */
.cal { display: grid; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--panel); position: relative; }
.cal .hcol { background: var(--panel2); border-right: 1px solid var(--line); }
.cal .colh { height: 38px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-weight: 600; background: var(--panel2); position: sticky; top: 0; z-index: 2; }
.cal .col { position: relative; border-right: 1px solid var(--line); }
.cal .col:last-child { border-right: 0; }
.cal .slot { height: 28px; border-bottom: 1px dashed rgba(255,255,255,.04); cursor: pointer; }
.cal .slot.hr { border-bottom: 1px solid var(--line); }
.cal .slot:hover { background: var(--accentbg); }
.cal .hl { height: 56px; font-size: 12px; color: var(--muted); padding: 2px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.cal .ev { position: absolute; left: 4px; right: 4px; border-radius: 7px; padding: 4px 7px; font-size: 12px; overflow: hidden; cursor: pointer; border-left: 3px solid; background: var(--panel2); box-shadow: 0 2px 8px rgba(0,0,0,.3); line-height: 1.3; }
.cal .ev b { display: block; font-size: 12.5px; }
.cal .ev.st-scheduled { border-color: var(--info); background: #182638; }
.cal .ev.st-new { border-color: #8b93a3; }
.cal .ev.st-in_work { border-color: var(--accent); background: #2a1c16; }
.cal .ev.st-waiting { border-color: var(--warn); background: #2a2416; }
.cal .ev.st-done { border-color: var(--ok); background: #15281e; }
.cal .ev.st-issued { border-color: var(--violet); background: #211d30; opacity: .75; }
.cal .now { position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); z-index: 3; pointer-events: none; }
.week { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); gap: 8px; }
.week .day { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); min-height: 220px; padding: 8px; }
.week .day.today { border-color: var(--accent); }
.week .day .dh { font-weight: 600; margin-bottom: 6px; display: flex; justify-content: space-between; cursor: pointer; }
.week .wev { font-size: 12px; padding: 5px 7px; border-radius: 6px; background: var(--panel2); margin-bottom: 5px; cursor: pointer; border-left: 3px solid var(--info); }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(5,6,8,.72); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; backdrop-filter: blur(2px); }
.modal { background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; width: 100%; max-width: 580px; box-shadow: var(--sh); }
.modal.wide { max-width: 860px; }
.modal .mh { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal .mh h2 { margin: 0; flex: 1; }
.modal .mb { padding: 16px 18px; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

/* Autocomplete */
.ac { position: relative; }
.ac .drop { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--panel2); border: 1px solid var(--line2); border-radius: 8px; z-index: 10; max-height: 260px; overflow-y: auto; box-shadow: var(--sh); }
.ac .opt { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.ac .opt:last-child { border-bottom: 0; }
.ac .opt:hover, .ac .opt.sel { background: var(--accentbg); }
.ac .opt .s { color: var(--muted); font-size: 12px; }

/* Toast */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--panel2); border: 1px solid var(--line2); border-left: 3px solid var(--ok); padding: 10px 14px; border-radius: 8px; box-shadow: var(--sh); max-width: 360px; animation: tin .2s ease; }
.toast.err { border-left-color: var(--bad); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 20% -10%, rgba(255,90,31,.18), transparent), var(--bg); }
.login .box { width: 100%; max-width: 360px; }
.login .logo { justify-content: center; padding-bottom: 22px; }
.login .logo .mark { width: 46px; height: 46px; font-size: 22px; }
.login .logo b { font-size: 20px; }

/* Bars */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 150px; padding-top: 10px; }
.bars .b { flex: 1; max-width: 36px; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; min-width: 4px; position: relative; }
.bars .b i { display: block; border-radius: 3px 3px 0 0; }
.bars .b i.in { background: var(--accent); } .bars .b i.out { background: #4a5160; }
.bars .b:hover::after { content: attr(data-t); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line2); padding: 4px 8px; border-radius: 6px; font-size: 12px; white-space: pre; z-index: 5; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.meter { height: 6px; background: var(--panel2); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.totals { margin-left: auto; width: 280px; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .big { font-size: 18px; font-weight: 700; border-top: 1px solid var(--line2); margin-top: 6px; padding-top: 8px; }
.log { max-height: 340px; overflow-y: auto; font-size: 13px; }
.log div { padding: 6px 0; border-bottom: 1px solid var(--line); }
.log .muted { font-size: 12px; }
pre.code { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 12px; white-space: pre-wrap; word-break: break-all; }

.grid > *, .row > * { min-width: 0; }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g-main { grid-template-columns: minmax(0,1fr); } .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--sh); }
  .side.open { transform: none; }
  .mobilebar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .mobilebar b { flex: 1; }
  .main { padding: 14px 12px 60px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .week { grid-template-columns: 1fr; } .week .day { min-height: 0; }
  .totals { width: 100%; }
  .tbl.resp thead { display: none; }
  .tbl.resp tr { display: block; border-bottom: 1px solid var(--line); padding: 6px 0; }
  .tbl.resp td { display: flex; justify-content: space-between; gap: 10px; border: 0; padding: 4px 8px; }
  .tbl.resp td::before { content: attr(data-l); color: var(--muted); font-size: 12px; white-space: nowrap; }
  .tbl.resp td { align-items: center; width: auto !important; min-width: 0 !important; }
  .tbl.resp td input, .tbl.resp td select { width: 62%; }
  .modal .mb .row { grid-template-columns: 1fr; }
}
@media print { .side, .mobilebar, .topbar button { display: none; } .app { display: block; } body { background: #fff; color: #000; } }

/* ===== Журнал записи (как Excel) ===== */
.jwrap { overflow: auto; max-height: calc(100vh - 170px); border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
.jr { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 1100px; table-layout: fixed; }
.jr th { position: sticky; top: 0; z-index: 3; background: var(--panel2); padding: 9px 8px; font-weight: 650; border-bottom: 1px solid var(--line2); border-right: 1px solid var(--line); text-align: center; }
.jr td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); vertical-align: top; padding: 4px; }
.jr .jd { position: sticky; left: 0; z-index: 2; background: var(--panel2); width: 78px; text-align: center; font-size: 12px; color: var(--muted); }
.jr th.jd { z-index: 4; }
.jr .jd b { display: block; color: var(--text); font-size: 14px; }
.jr tr.off td { background: repeating-linear-gradient(135deg, rgba(239,68,68,.05) 0 10px, rgba(239,68,68,.09) 10px 20px); }
.jr tr.off .jd { color: #f28b8b; background: #2a1d21; }
.jr .offl { font-size: 10px; text-transform: uppercase; letter-spacing: .4px; color: #f28b8b; margin-top: 2px; }
.offwarn { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.35); color: #f8b4b4; padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }
.jr tr.today td { background: rgba(255,90,31,.07); }
.jr tr.today .jd { background: var(--accent); color: #fff; }
.jr tr.today .jd b { color: #fff; }
.jcell { min-height: 64px; height: 64px; cursor: pointer; }
.jcell:hover { background: rgba(255,90,31,.06) !important; }
.jc { background: var(--c); color: #1b1b1b; border-radius: 6px; padding: 5px 7px; margin-bottom: 4px; font-size: 12px; line-height: 1.3; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.25); overflow: hidden; }
.jc:hover { filter: brightness(1.07); }
.jc b { font-size: 12.5px; }
.jc .jt { font-size: 11px; background: rgba(0,0,0,.12); padding: 0 5px; border-radius: 4px; white-space: nowrap; }
.jc .jx { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.jc.note { white-space: pre-line; font-style: normal; }
.swatch { width: 30px; height: 30px; padding: 0; display: inline-grid; place-items: center; }
.swatch i { width: 18px; height: 18px; border-radius: 50%; background: var(--sw); border: 1px solid rgba(0,0,0,.3); }
.checkgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 10px; margin-bottom: 6px; }
.ck { display: flex; gap: 7px; align-items: center; color: var(--text); font-size: 13px; margin: 0; cursor: pointer; }
.chip input[type=radio] + * { pointer-events: none; }
label.chip { cursor: pointer; margin: 0; }
@media (max-width: 860px) { .jwrap { max-height: none; } .jr { min-width: 900px; } }

.tbl select[data-f=master_id] { min-width: 140px; }
.bars { overflow: hidden; }

/* Сообщения */
.chatlog { height: calc(100vh - 290px); min-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px; }
.bubble { max-width: 75%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.bubble.in { align-self: flex-start; background: var(--panel2); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--accentbg); border: 1px solid rgba(255,90,31,.3); border-bottom-right-radius: 4px; }
.bubble .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
@media (max-width: 860px) { #thread { order: -1; } .grid[style*="minmax(220px"] { grid-template-columns: 1fr !important; } .chatlog { height: 50vh; } }

#doff .chip { min-width: 40px; justify-content: center; }

/* График работы */
select.nr { color: var(--bad); border-color: var(--bad); }
option.nr { color: #e5484d; }
.nrw { font-size: 11px; color: var(--bad); margin-top: 3px; }
.nrw:empty { display: none; }
.jr .nrl { font-size: 10px; color: #f28b8b; margin-top: 3px; line-height: 1.25; }
.sched { border-collapse: separate; border-spacing: 0; font-size: 12px; }
.sched th, .sched td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); text-align: center; padding: 0; min-width: 30px; height: 34px; }
.sched th { font-weight: 500; color: var(--muted); font-size: 11px; padding: 4px 2px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.sched th.we { color: #f28b8b; }
.sched .nm { text-align: left; padding: 4px 10px; min-width: 150px; position: sticky; left: 0; background: var(--panel); z-index: 2; white-space: nowrap; }
.sched .nm small { display: block; color: var(--muted); font-size: 10px; }
.sched td.c { cursor: pointer; font-variant-numeric: tabular-nums; }
.sched td.c:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.sched td.dflt-off { background: repeating-linear-gradient(135deg, transparent 0 5px, rgba(255,255,255,.04) 5px 10px); color: var(--muted); }
.sched td.w { color: var(--text); }
.sched td.w.ex { font-weight: 700; color: var(--accent); }
.sched td.st-off { background: rgba(120,130,150,.18); color: var(--muted); }
.sched td.st-vac { background: rgba(80,140,230,.22); color: #9cc2ff; font-weight: 600; }
.sched td.st-sick { background: rgba(230,160,40,.22); color: #f3c26b; font-weight: 600; }
.sched td.st-abs { background: rgba(229,72,77,.25); color: #ff8b8f; font-weight: 600; }
.sched td.today { box-shadow: inset 0 0 0 2px rgba(255,255,255,.25); }
.sched .tot { min-width: 54px; font-weight: 600; padding: 0 6px; }
.sched td[title] { position: relative; }
.sched td.hasnote::after { content: ''; position: absolute; right: 2px; top: 2px; border: 4px solid transparent; border-top-color: var(--accent); border-right-color: var(--accent); }

.scrim { display: none; }
/* ===== Смартфоны (Android / iOS) ===== */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  body { overflow-x: hidden; }
  .side { height: 100dvh; padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .scrim.on { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 39; }
  .mobilebar { padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left)); min-height: 52px; box-sizing: border-box; }
  .mobilebar button { padding: 8px; color: var(--text); }
  .mobilebar svg { width: 24px; height: 24px; display: block; }
  .mobilebar b { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .main { padding: 12px max(12px, env(safe-area-inset-right)) calc(70px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  /* iOS увеличивает страницу при фокусе на поле со шрифтом < 16px */
  input, select, textarea { font-size: 16px; }
  .tbl.resp td input, .tbl.resp td select { font-size: 16px; }
  button, .btn { min-height: 38px; }
  button.sm, .btn.sm { min-height: 34px; }
  .topbar { gap: 8px; margin-bottom: 12px; }
  .topbar h1 { font-size: 20px; width: 100%; margin: 0; }
  .topbar .sp { display: none; }
  .topbar .chips { overflow-x: auto; flex-wrap: nowrap; max-width: 100%; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .topbar .chips::-webkit-scrollbar { display: none; }
  .topbar .inline { flex-wrap: wrap; }
  .topbar input[type=date] { flex: 1 1 130px; min-width: 0; }
  .topbar input[type=search], .topbar > input { flex: 1 1 100%; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 12px; min-width: 0; } .kpi .v { font-size: 20px; overflow-wrap: anywhere; } .kpi .l { font-size: 11px; }
  .card { padding: 14px 12px; }
  /* таблицы без мобильной разметки — прокручиваются по горизонтали */
  .tbl:not(.resp) { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  .tblwrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tbl.resp td { flex-wrap: wrap; }
  .tbl.resp td .nrw { flex-basis: 100%; text-align: right; }
  /* окна — снизу на весь экран, прокрутка внутри */
  .overlay { padding: 0; align-items: flex-end; }
  .modal, .modal.wide { max-width: none; border-radius: 16px 16px 0 0; max-height: 92dvh; display: flex; flex-direction: column; border-bottom: 0; }
  .modal .mb { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; padding: 14px; }
  .modal .mh { padding: 12px 14px; }
  .modal .mf { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .modal .mf button { flex: 1 1 auto; justify-content: center; }
  .modal .mf button[style*="margin-right:auto"] { flex-basis: 100%; }
  .toasts { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .toasts > * { max-width: none; min-width: 0; white-space: normal; overflow-wrap: anywhere; }
  .toasts { width: auto; max-width: calc(100vw - 24px); }
  button { white-space: normal; text-align: center; }
  #payAll { width: 100%; justify-content: center; }
  .grid > *, .row > * { min-width: 0; }
  .g-main, .g2, .g3 { grid-template-columns: minmax(0, 1fr) !important; }
  .topbar > .inline, .topbar > div { max-width: 100%; min-width: 0; }
  .topbar > .inline:has(.chips) { width: 100%; }
  .topbar .inline .chips { flex: 1 1 100%; }
  /* журнал: узкие колонки, дата закреплена слева */
  .jwrap { max-height: calc(100dvh - 200px); }
  .jr { min-width: 0; width: max-content; }
  .jr th:not(.jd), .jr td:not(.jd) { width: 150px; min-width: 150px; max-width: 150px; }
  .jr .jd { width: 54px; min-width: 54px; }
  .legend { font-size: 11px; gap: 4px 10px; }
  .sched .nm { min-width: 110px; padding: 4px 6px; }
  .sched th, .sched td { min-width: 28px; }
  .bars { overflow-x: auto; }
}
@media (max-width: 380px) { .g4 { grid-template-columns: minmax(0, 1fr); } }

/* ===== Узкое окно на ПК (половина экрана, масштаб 125–150%): меню — полоса значков ===== */
@media (min-width: 861px) and (max-width: 1180px) {
  .app { grid-template-columns: 64px minmax(0, 1fr); }
  .side { padding: 14px 8px; align-items: stretch; }
  .logo { padding: 2px 0 14px; justify-content: center; }
  .logo > div:not(.mark) { display: none; }
  .nav a { justify-content: center; padding: 10px 0; position: relative; }
  .nav a > span:not(.badge) { display: none; }
  .nav svg { width: 20px; height: 20px; }
  .nav .badge { position: absolute; top: 2px; right: 2px; margin: 0; font-size: 10px; padding: 0 5px; min-width: 0; line-height: 16px; }
  .side .foot { padding: 10px 0 0; text-align: center; }
  .side .foot .who, .side .foot .role { display: none; }
  .side .foot .inline { flex-direction: column; gap: 4px; }
  .side .foot button { width: 100%; justify-content: center; padding: 4px 0; font-size: 11px; margin-top: 0; }
  .side .foot #myMax { font-size: 0; } .side .foot #myMax::before { content: 'MAX'; font-size: 11px; }
  .main { padding: 18px 18px 50px; }
}
select[data-f=master_id] { min-width: 170px; }
@media (max-width: 860px) { select[data-f=master_id] { min-width: 0; } }

/* Фото автомобиля */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.photos .ph { position: relative; aspect-ratio: 4 / 3; border-radius: 8px; overflow: hidden; border: 1px solid var(--line2); background: var(--bg); padding: 0; cursor: pointer; display: block; min-height: 0; }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .ph.add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-style: dashed; color: var(--muted); font-size: 11px; text-align: center; }
.photos .ph.add span { font-size: 22px; line-height: 1; }
.photos .ph.add:hover { border-color: var(--accent); color: var(--text); }
.photos.pick .ph input { position: absolute; top: 6px; left: 6px; width: 18px; height: 18px; z-index: 1; accent-color: var(--accent); }
.photos.pick .ph:has(input:not(:checked)) img { opacity: .35; }
.phview { position: relative; background: #000; border-radius: 8px; display: flex; align-items: center; justify-content: center; min-height: 200px; }
.phview img { max-width: 100%; max-height: 70vh; max-height: 70dvh; display: block; }
.phnav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.55); border: 0; color: #fff; font-size: 28px; width: 44px; height: 56px; justify-content: center; }
.phnav.l { left: 6px; } .phnav.r { right: 6px; }

/* ===== Режим приложения (iOS / Android, «На экран Домой») ===== */
.logo img.mark { width: 34px; height: 34px; border-radius: 9px; display: block; background: none; box-shadow: none; }
.tabbar { display: none; }
@media (max-width: 860px) {
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; background: rgba(22,25,32,.92); -webkit-backdrop-filter: saturate(160%) blur(14px); backdrop-filter: saturate(160%) blur(14px);
    border-top: 1px solid var(--line); padding: 4px max(4px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left)); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 0 3px; color: var(--muted); font-size: 10.5px; font-weight: 500; text-decoration: none; border-radius: 10px; min-width: 0; }
  .tabbar a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .tabbar a svg { width: 23px; height: 23px; }
  .tabbar a.active { color: var(--accent); }
  .tabbar a:active { background: var(--panel2); }
  .main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(70px + env(safe-area-inset-bottom)); }
  .mobilebar #burger { display: none; }
  .mobilebar b { text-align: center; }
  .mobilebar::before { content: ''; width: 0; }
  .modal .mf { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}
.pwahint { border-color: var(--accent); background: var(--accentbg); }
.shareic { display: inline-block; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; font-size: 11px; }
/* запуск с экрана «Домой» — ведём себя как приложение */
html.pwa, html.pwa body { overscroll-behavior: none; }
html.pwa .nav a, html.pwa .tabbar a, html.pwa button, html.pwa .chip, html.pwa .mobilebar { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
html.pwa .side { padding-top: max(16px, env(safe-area-inset-top)); }
@media (min-width: 861px) { html.pwa .main { padding-top: max(22px, env(safe-area-inset-top)); } }

/* Предварительный расчёт */
.st-estimate { background: rgba(167,139,250,.16); color: #c4b5fd; }
.estcard { border-color: rgba(167,139,250,.45); background: linear-gradient(180deg, rgba(167,139,250,.08), transparent); }

/* оплата через кассу Saby */
.saby-box{margin-top:12px;display:grid;gap:8px}
.saby-row{display:flex;justify-content:space-between;align-items:center;gap:10px;flex-wrap:wrap;padding:10px 12px;border-radius:10px;border:1px solid var(--line);background:var(--card)}
.saby-row.pending{border-color:var(--warn);background:color-mix(in srgb,var(--warn) 8%,var(--card))}
.saby-row.paid{border-color:var(--ok)}

/* «В долг» в заказ-наряде */
.debtchk{display:flex;gap:10px;align-items:flex-start;margin:2px 0 12px;padding:10px 12px;border:1px dashed var(--line);border-radius:10px;cursor:pointer;color:var(--text)}
.debtchk input{width:18px;height:18px;flex:none;margin-top:2px}
.linkbtn{background:none;border:0;padding:0;color:var(--accent);font:inherit;font-size:12px;cursor:pointer;text-decoration:underline dotted}

/* ===== Маркетинг ===== */
.mk-tabs { margin-bottom: 14px; flex-wrap: wrap; }
.mk-period input[type=date] { width: auto; }
.mk-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.mk-kpis .kpi span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.mk-kpis .kpi b { display: block; font-size: 24px; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.mk-kpis .kpi small { color: var(--muted); font-size: 12px; }
.mk-trend { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; height: 180px; align-items: end; }
.mk-col { display: flex; flex-direction: column; align-items: center; height: 100%; gap: 4px; }
.mk-col .bars { flex: 1; width: 100%; display: flex; gap: 2px; align-items: flex-end; justify-content: center; }
.mk-col .bars i { width: 42%; min-height: 2px; border-radius: 3px 3px 0 0; }
.mk-col span { font-size: 11px; color: var(--muted); }
i.rv { background: var(--accent); } i.ld { background: #4ea1ff; }
.mk-legend { margin-top: 8px; } .mk-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin-left: 6px; }
.mk-hbar { margin-bottom: 10px; font-size: 14px; } .mk-hbar .track { height: 6px; background: var(--line); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.mk-hbar .track i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.mk-cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin-top: 12px; }
.mk-wd { font-size: 11px; color: var(--muted); text-transform: uppercase; text-align: center; padding: 2px 0; }
.mk-day { min-height: 92px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mk-day:hover { border-color: var(--accent); } .mk-day.empty { border: 0; cursor: default; } .mk-day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.mk-day .dn { font-size: 12px; color: var(--muted); }
.mk-post { all: unset; cursor: pointer; font-size: 11px; line-height: 1.3; padding: 3px 5px; border-radius: 5px; background: var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mk-post b { font-weight: 600; } .mk-post.st-plan { background: color-mix(in srgb, var(--warn) 25%, transparent); } .mk-post.st-ready, .mk-post.st-published { background: color-mix(in srgb, var(--ok) 25%, transparent); }
.mk-post.st-published { text-decoration: none; opacity: .85; }
.mk-idea { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.mk-works { display: grid; gap: 10px; max-height: 520px; overflow: auto; }
.mk-work { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 10px; align-items: start; }
.mk-work img, .mk-work .nop { width: 84px; height: 64px; object-fit: cover; border-radius: 8px; background: var(--line); display: grid; place-items: center; font-size: 11px; color: var(--muted); }
.mk-work.used { opacity: .6; }
.mk-roi { padding: 8px 0; border-bottom: 1px solid var(--line); }
.mk-tpl { padding: 8px 0; border-bottom: 1px solid var(--line); }
.mk-list { margin: 0; padding-left: 18px; } .mk-list li { margin-bottom: 8px; font-size: 14px; }
@media (max-width: 900px) { .mk-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .mk-day { min-height: 54px; } .mk-post b { display: none; } .mk-post { font-size: 10px; padding: 2px 3px; } .mk-trend { height: 140px; } }
.mk-idea button { white-space: nowrap; flex: none; }

/* импорт клиентской базы */
.imp-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 12px; }
.imp-map label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.imp-stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin: 6px 0; }
.imp-stats div { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; } .imp-stats b { display: block; font-size: 20px; } .imp-stats span { font-size: 12px; color: var(--muted); }
@media (max-width: 640px) { .imp-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* SMS */
.sms-tpl { margin-bottom: 10px; } .sms-tpl textarea { margin-top: 4px; }

/* логотипы брендов (Настройки) */
.brand-adm { display: grid; gap: 6px; }
.ba { display: grid; grid-template-columns: 110px minmax(0,1fr) auto; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.ba .bl { height: 40px; display: grid; place-items: center; background: #e9eef2; border-radius: 8px; padding: 4px 8px; }
.ba .bl img { max-width: 100%; max-height: 32px; filter: brightness(0); opacity: .85; }
.ba .bn b { display: block; } 
