:root {
  --bg: #f4f6fa; --panel: #ffffff; --text: #1b2333; --muted: #667085; --line: #e3e7ee;
  --brand: #1f3a93; --brand-2: #2f54c9; --brand-soft: #e8eefc;
  --ok: #15803d; --ok-soft: #e7f6ec; --bad: #b42318; --bad-soft: #fdecea;
  --warn: #b45309; --warn-soft: #fff4e0; --info-soft: #eef2f7;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --sidebar: 248px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); background: #14244f; color: #dfe6f7; flex: 0 0 auto; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .logo { padding: 18px 18px 14px; font-weight: 700; font-size: 16px; color: #fff; display: flex; gap: 10px; align-items: center; }
.sidebar .logo .mark { flex: 0 0 auto; width: 28px; height: 28px; border-radius: 7px; background: var(--brand-2); display: grid; place-items: center; }
.nav { flex: 1; overflow: auto; padding: 4px 10px; }
.nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #8fa0c9; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 10px; border-radius: 8px; color: #dfe6f7; text-decoration: none; }
.nav a:hover { background: rgba(255,255,255,.07); }
.nav a.active { background: var(--brand-2); color: #fff; }
.badge-count { background: #ef4444; color: #fff; border-radius: 999px; font-size: 12px; padding: 0 7px; min-width: 20px; text-align: center; }
.sidebar .me { padding: 12px 18px; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px; }
.sidebar .me button { margin-top: 6px; }
.main { flex: 1; min-width: 0; padding: 24px 28px 60px; }
.topbar { display: none; }

@media (max-width: 860px) {
  .layout { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-105%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.25); }
  .sidebar.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 40; background: #14244f; color: #fff; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
  .topbar button { background: transparent; border: 0; color: #fff; font-size: 22px; padding: 2px 6px; }
  .topbar .title { font-weight: 600; flex: 1; }
  .main { padding: 16px 16px 80px; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 45; }
}

/* ---------- components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; }
@media (max-width: 700px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .cols { grid-template-columns: 1fr; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; touch-action: manipulation; }
.btn:hover { background: #f7f8fb; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.primary:hover { background: var(--brand); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { background: #fff; border-color: #f3b4ad; color: var(--bad); }
.btn.bad.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn.lg { min-height: 48px; padding: 10px 20px; font-size: 16px; }
.sidebar .btn { background: transparent; color: #dfe6f7; border-color: rgba(255,255,255,.25); }

label.f { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], input[type=time], input[type=date], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid #cfd6e2; border-radius: 8px; font: inherit; background: #fff; color: var(--text); }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b9c8f3; border-color: var(--brand-2); }
.check { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfd; }
table.list td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #f6f8fd; }
@media (max-width: 760px) {
  table.list.responsive thead { display: none; }
  table.list.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table.list.responsive td { display: flex; gap: 10px; border: 0; padding: 4px 10px; }
  table.list.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; min-width: 96px; }
}

.status { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.st-in_progress, .st-pending { background: var(--brand-soft); color: var(--brand); }
.st-approved { background: var(--ok-soft); color: var(--ok); }
.st-rejected { background: var(--bad-soft); color: var(--bad); }
.st-review, .st-new { background: var(--warn-soft); color: var(--warn); }
.st-cancelled, .st-skipped, .st-waiting { background: var(--info-soft); color: var(--muted); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 14px; cursor: pointer; }
.tabs button.active { background: var(--text); color: #fff; border-color: var(--text); }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.alert.warn { background: var(--warn-soft); color: #7a3e06; border: 1px solid #f6d9a8; }
.alert.bad { background: var(--bad-soft); color: #7a1a12; border: 1px solid #f3c1bb; }
.alert.ok { background: var(--ok-soft); color: #0f5b2c; border: 1px solid #b7e2c4; }
.alert.info { background: var(--brand-soft); color: #1f3a93; border: 1px solid #cdd9f7; }

dl.props { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; margin: 0; }
dl.props dt { color: var(--muted); font-size: 13.5px; }
dl.props dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { dl.props { grid-template-columns: 1fr; } dl.props dd { margin-bottom: 6px; } }

.files { display: grid; gap: 8px; }
.file { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe; }
.file .ico { width: 38px; height: 46px; border-radius: 5px; background: #e9eefb; color: var(--brand); display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: 0 0 auto; }
.file .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.file .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.route { list-style: none; margin: 0; padding: 0; }
.route li { position: relative; padding: 0 0 16px 30px; }
.route li::before { content: ""; position: absolute; left: 9px; top: 22px; bottom: 0; width: 2px; background: var(--line); }
.route li:last-child::before { display: none; }
.route .dot { position: absolute; left: 0; top: 2px; width: 20px; height: 20px; border-radius: 50%; background: #d0d5dd; color: #fff; font-size: 12px; display: grid; place-items: center; }
.route .dot.approved { background: var(--ok); } .route .dot.rejected { background: var(--bad); } .route .dot.pending { background: var(--brand-2); box-shadow: 0 0 0 4px var(--brand-soft); }
.route .who { font-weight: 600; }
.route .comment { margin-top: 4px; background: #f6f7f9; border-radius: 6px; padding: 6px 9px; font-size: 13.5px; }

.decision { border-color: #b9c8f3; box-shadow: 0 4px 18px rgba(47,84,201,.12); }
@media (max-width: 600px) { .file { flex-wrap: wrap; } .file .actions { width: 100%; justify-content: flex-start; padding-left: 50px; } }

.steps-editor .step { display: grid; grid-template-columns: 70px 1fr auto auto auto; gap: 8px; align-items: center; margin-bottom: 8px; }
@media (max-width: 560px) { .steps-editor .step { grid-template-columns: 60px 1fr auto; } .steps-editor .step .mv { display: none; } }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #14244f, #2f54c9); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #1b2333; color: #fff; padding: 11px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 1000; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--bad); }

.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 200; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; max-height: calc(100vh - 32px); overflow: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal.wide { max-width: 860px; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }

.sigpad { border: 1px dashed #9aa6bd; border-radius: 10px; background: #fff; width: 100%; aspect-ratio: 3 / 1; touch-action: none; display: block; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.log { font-size: 13.5px; }
.log div { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.chip { display: inline-block; background: var(--info-soft); border-radius: 6px; padding: 1px 7px; margin: 2px 4px 2px 0; font-size: 12.5px; }

/* ---------- редактор / просмотрщик документов */
.viewer { position: fixed; inset: 0; z-index: 300; background: #525a68; display: flex; flex-direction: column; }
.vbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); background: #1b2333; color: #fff; }
.vtools { display: flex; align-items: center; gap: 6px; padding: 0 10px 8px; background: #1b2333; overflow-x: auto; scrollbar-width: none; }
.vtools::-webkit-scrollbar { display: none; }
.vtools > * { flex: 0 0 auto; }
.vtools select.vbtn { width: auto; min-height: 40px; background: #1b2333; color: #fff; border: 1px solid rgba(255,255,255,.2); }
.vtools .sep { width: 1px; height: 26px; background: rgba(255,255,255,.2); margin: 0 2px; }
.vbar { flex-wrap: nowrap; }
.vbar .title { flex: 1 1 160px; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vbar .sep { width: 1px; height: 26px; background: rgba(255,255,255,.2); margin: 0 2px; }
.vbtn { min-width: 40px; min-height: 40px; border-radius: 8px; border: 1px solid rgba(255,255,255,.2); background: transparent; color: #fff; font: inherit; font-size: 14px; padding: 4px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; touch-action: manipulation; }
.vbtn.active { background: #fff; color: #1b2333; }
.vbtn.save { background: var(--ok); border-color: var(--ok); font-weight: 600; }
.vbtn:disabled { opacity: .4; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); cursor: pointer; padding: 0; }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px #1b2333, 0 0 0 4px #fff; }
.vscroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 16px 8px 60px; }
.vpage { position: relative; margin: 0 auto 16px; background: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.35); }
.vpage img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.vpage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.vpage .pno { position: absolute; right: 6px; bottom: -20px; color: #e5e7eb; font-size: 12px; }
.viewer.mode-pen .vpage canvas, .viewer.mode-stamp .vpage canvas { touch-action: none; cursor: crosshair; }
.viewer.mode-view .vpage canvas { pointer-events: none; }
.vhint { position: absolute; left: 50%; transform: translateX(-50%); bottom: 14px; background: rgba(0,0,0,.7); color: #fff; padding: 7px 12px; border-radius: 8px; font-size: 13px; pointer-events: none; max-width: calc(100% - 24px); text-align: center; }
@media (max-width: 600px) { .vbtn .lbl { display: none; } .vbar, .vtools { gap: 4px; } .vbtn { min-width: 38px; padding: 4px 8px; } }

/* подзадачи */
.subtasks { display: grid; gap: 8px; }
.subtask { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: #fbfcfe; }
.subtask.mine { border-color: #b9c8f3; background: var(--brand-soft); }
.tpl-row { display: grid; grid-template-columns: 1.4fr 1.2fr 110px auto; gap: 8px; align-items: center; margin-bottom: 8px; }
@media (max-width: 640px) { .tpl-row { grid-template-columns: 1fr auto; } .tpl-row select { grid-column: 1 / -1; } }

/* маршрут по этапам, сроки в часах/днях */
.steps-editor .stage-user { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; margin-bottom: 6px; }
.steps-editor .stage-user:has(> select + select) { grid-template-columns: minmax(0, 1fr) minmax(0, 240px) auto; }
@media (max-width: 700px) { .steps-editor .stage-user:has(> select + select) { grid-template-columns: 1fr auto; } .steps-editor .stage-user > select + select { grid-column: 1; } }
.stage-box .stage-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.duration { display: flex; gap: 6px; align-items: center; }
.duration input { width: 80px !important; min-width: 0; }
.duration select { width: auto !important; min-width: 0; }
.tpl-row { grid-template-columns: 1.3fr 1.1fr auto auto; }
.tpl-row .duration .muted { display: none; }
.ctrl-add { display: flex; gap: 8px; align-items: center; }
.ctrl-add select { flex: 1; min-width: 0; }
@media (max-width: 640px) { .tpl-row .duration { grid-column: 1 / -1; } }

/* уведомления в мессенджерах */
.msgr-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.msgr-row:first-child { border-top: 0; }
.msgr-ico { width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; flex: none; }
.msgr-ico.tg { background: #2aabee; }
.msgr-ico.max { background: linear-gradient(135deg, #4d6bfe, #9b3cf5); }
.msgr-code { font: 700 26px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 3px; padding: 10px 14px; margin: 8px 0; background: var(--bg, #f5f6fa); border: 1px dashed var(--line); border-radius: 10px; display: inline-block; cursor: copy; user-select: all; }
