:root {
  color-scheme: light;
  --bg: #f7f7f5; --surface: #fff; --text: #16181d; --muted: #6b6f76; --faint: #9a9ea5;
  --border: #e6e6e3; --border-strong: #d4d4cf; --hover: #f1f1ee;
  --accent: #1f5fd1; --accent-soft: #eaf1fd;
  --ok: #1d7a46; --ok-soft: #e7f5ec; --warn: #9a6400; --warn-soft: #fdf4e3;
  --err: #b42318; --err-soft: #fdecea; --info: #1f5fd1; --info-soft: #eaf1fd;
  --radius: 8px; --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }
h3 { font-size: 13px; font-weight: 600; margin: 0 0 8px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; } .nowrap { white-space: nowrap; } .right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* каркас */
.shell { display: grid; grid-template-columns: 208px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--border); background: var(--surface); padding: 18px 12px;
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px; }
.brand { font-weight: 700; font-size: 16px; padding: 2px 10px 16px; letter-spacing: -.02em; }
.brand span { color: var(--accent); }
.nav a { display: flex; justify-content: space-between; padding: 7px 10px; border-radius: 6px; color: var(--text); }
.nav a:hover { background: var(--hover); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav .sep { height: 1px; background: var(--border); margin: 10px 6px; }
.side .me { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.side .me b { color: var(--text); font-weight: 500; display: block; }
.main { padding: 22px 28px 60px; min-width: 0; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.head .grow { flex: 1; }

/* элементы */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit;
  font-size: 13px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1a51b3; }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
input, select, textarea { font: inherit; font-size: 13px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 6px; height: 32px; padding: 0 9px; width: 100%; }
textarea { height: auto; padding: 7px 9px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: 15px; height: 15px; padding: 0; accent-color: var(--accent); vertical-align: middle; flex: none; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.field { margin-bottom: 10px; }
.row { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); margin: 0; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--hover);
  color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.info { background: var(--info-soft); color: var(--info); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; margin-right: 5px; }
.spin { display: inline-block; width: 11px; height: 11px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: s .7s linear infinite; vertical-align: -1px; margin-right: 5px; }
@keyframes s { to { transform: rotate(360deg); } }

/* таблицы */
.tbl-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 9px 10px;
  border-bottom: 1px solid var(--border); white-space: nowrap; background: #fcfcfb; position: sticky; top: 0; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: #fbfbf9; }
.tbl tr.clickable { cursor: pointer; }
.tbl .sub { color: var(--muted); font-size: 12px; }
.tbl .cb { width: 30px; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

/* фильтры и панель действий */
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.filters .wide { grid-column: span 2; }
.bulkbar { display: none; align-items: center; gap: 8px; padding: 8px 12px; margin-bottom: 10px;
  background: var(--text); color: #fff; border-radius: var(--radius); }
.bulkbar.show { display: flex; }
.bulkbar .btn { background: transparent; color: #fff; border-color: #444; }
.bulkbar .btn:hover { background: #2a2d33; }
.pager { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 10px; }

/* загрузка */
.drop { border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 14px 16px;
  display: flex; align-items: center; gap: 14px; background: var(--surface); margin-bottom: 12px; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .grow { flex: 1; }
.drop code { background: var(--hover); padding: 2px 6px; border-radius: 4px; font-family: var(--mono); font-size: 12px; }
.toast { position: fixed; right: 20px; bottom: 20px; max-width: 420px; background: var(--text); color: #fff;
  padding: 12px 14px; border-radius: var(--radius); font-size: 13px; box-shadow: 0 8px 30px rgba(0,0,0,.18); z-index: 50; }
.toast ul { margin: 6px 0 0; padding-left: 18px; }

/* карточка документа */
.doc-grid { display: grid; grid-template-columns: minmax(0, 46%) minmax(0, 1fr); gap: 16px; align-items: start; }
.viewer { position: sticky; top: 12px; height: calc(100vh - 24px); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.viewer .bar { display: flex; gap: 6px; align-items: center; padding: 6px 8px; border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--muted); }
.viewer iframe, .viewer .img { flex: 1; width: 100%; border: 0; overflow: auto; background: #eceae6; }
.viewer .img img { display: block; max-width: 100%; margin: 0 auto; transform-origin: top center; }
.stages { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.stage { font-size: 11.5px; padding: 2px 8px; border-radius: 99px; background: var(--hover); color: var(--faint); }
.stage.success { background: var(--ok-soft); color: var(--ok); }
.stage.in_progress { background: var(--info-soft); color: var(--info); }
.stage.error { background: var(--err-soft); color: var(--err); }
.stage.skipped { color: var(--muted); }
.issues { list-style: none; margin: 0; padding: 0; }
.issues li { display: flex; gap: 8px; align-items: flex-start; padding: 7px 10px; border-radius: 6px; margin-bottom: 4px;
  font-size: 13px; }
.issues li.error { background: var(--err-soft); color: var(--err); }
.issues li.warning { background: var(--warn-soft); color: var(--warn); }
.issues li.acked { background: var(--hover); color: var(--muted); text-decoration: line-through; }
.issues li .grow { flex: 1; }
.parties { display: grid; grid-template-columns: 1fr 36px 1fr; gap: 10px; align-items: start; }
.parties .swap { margin-top: 26px; }
.party { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.party.client { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.party .tag { font-size: 11px; color: var(--accent); font-weight: 500; }
.lines { width: 100%; min-width: 940px; border-collapse: collapse; font-size: 12.5px; }
.lines th { font-weight: 500; font-size: 11.5px; color: var(--muted); text-align: left; padding: 4px 3px;
  border-bottom: 1px solid var(--border); white-space: nowrap; }
.lines td { padding: 3px; border-bottom: 1px solid var(--border); vertical-align: top; }
.lines input, .lines textarea { height: 28px; padding: 0 5px; font-size: 12.5px; border-color: transparent;
  background: transparent; }
.lines textarea { height: 28px; min-height: 28px; padding: 5px; line-height: 1.3; resize: vertical; }
.lines input:hover, .lines textarea:hover { border-color: var(--border); }
.lines input:focus, .lines textarea:focus { background: var(--surface); border-color: var(--accent); }
.lines .n input { text-align: right; font-variant-numeric: tabular-nums; }
.lines tr.bad td { background: var(--err-soft); }
.lines tr.edited td:first-child { box-shadow: inset 2px 0 0 var(--warn); }
.menu { position: relative; display: inline-block; }
.menu > summary { list-style: none; cursor: pointer; padding: 3px 6px; border-radius: 4px; color: var(--muted); }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary:hover { background: var(--hover); }
.menu .pop { position: absolute; right: 0; top: 100%; z-index: 20; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.1); padding: 6px; min-width: 220px; }
.menu .pop button, .menu .pop a { display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 7px 9px; border-radius: 5px; font: inherit; font-size: 13px; color: var(--text); cursor: pointer; }
.menu .pop button:hover, .menu .pop a:hover { background: var(--hover); text-decoration: none; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; max-width: 360px; margin-left: auto; font-size: 13px; }
.totals input { text-align: right; height: 30px; }
.actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 6px;
  display: flex; gap: 8px; align-items: center; }
.actions .grow { flex: 1; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--text); border-bottom-color: var(--text); font-weight: 500; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat .v { font-size: 26px; font-weight: 600; letter-spacing: -.02em; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 110px; padding-top: 10px; }
.bars div { flex: 1; background: var(--accent); opacity: .8; border-radius: 3px 3px 0 0; min-height: 1px; position: relative; }
.bars div:hover { opacity: 1; }
.login { max-width: 360px; margin: 12vh auto; padding: 0 16px; }
@media (max-width: 600px) { .login { margin-top: 6vh; } }
.alert { padding: 10px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.alert.ok { background: var(--ok-soft); color: var(--ok); } .alert.err { background: var(--err-soft); color: var(--err); }
.alert.info { background: var(--info-soft); color: var(--info); }
details.more > summary { cursor: pointer; color: var(--muted); font-size: 12px; margin: 6px 0; }
@media (max-width: 1100px) { .doc-grid { grid-template-columns: minmax(0, 1fr); } .viewer { position: static; height: 70vh; } }
@media (max-width: 760px) { .shell { grid-template-columns: 1fr; } .side { position: static; height: auto; }
  .main { padding: 16px; } .parties { grid-template-columns: 1fr; } }

body.wide .doc-grid { grid-template-columns: minmax(0, 1fr); }
body.wide .viewer { display: none; }
.show-viewer { display: none; }
body.wide .show-viewer { display: inline-flex; }

.catbtn { background: none; border: 1px solid transparent; border-radius: 5px; padding: 4px 5px; text-align: left;
  width: 100%; cursor: pointer; font: inherit; color: var(--text); line-height: 1.25; }
.catbtn:hover { border-color: var(--border); background: var(--surface); }
dialog::backdrop { background: rgba(20, 20, 20, .25); }

.catline { display: flex; align-items: center; gap: 4px; padding: 0 5px 3px; font-size: 11.5px; }
.catline .catbtn { width: auto; padding: 1px 6px; border: 1px dashed var(--border-strong); color: var(--muted); }
.catline .catbtn.set { border-style: solid; border-color: var(--ok-soft); background: var(--ok-soft); color: var(--ok); }

/* тёмная тема: по системе или выбором в настройках */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark;
  --bg: #121316; --surface: #1a1c20; --text: #e7e8ea; --muted: #9ea3ab; --faint: #6f747c;
  --border: #2a2d33; --border-strong: #3a3e45; --hover: #22252a; --accent: #6ea0ff; --accent-soft: #1d2a44;
  --ok: #5cc98a; --ok-soft: #173325; --warn: #e5b45a; --warn-soft: #362a14; --err: #ff7b72; --err-soft: #3a1b1a;
  --info: #6ea0ff; --info-soft: #1d2a44; } }
:root[data-theme="dark"] { color-scheme: dark;
  --bg: #121316; --surface: #1a1c20; --text: #e7e8ea; --muted: #9ea3ab; --faint: #6f747c;
  --border: #2a2d33; --border-strong: #3a3e45; --hover: #22252a; --accent: #6ea0ff; --accent-soft: #1d2a44;
  --ok: #5cc98a; --ok-soft: #173325; --warn: #e5b45a; --warn-soft: #362a14; --err: #ff7b72; --err-soft: #3a1b1a;
  --info: #6ea0ff; --info-soft: #1d2a44; }
:root[data-theme="dark"] .tbl th, :root[data-theme="dark"] .tbl tbody tr:hover td { background: var(--hover); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tbl th,
  :root:not([data-theme="light"]) .tbl tbody tr:hover td { background: var(--hover); } }
.bulkbar { background: #16181d; }
/* узкое меню */
:root[data-compact="1"] .shell { grid-template-columns: 64px 1fr; }
:root[data-compact="1"] .side { padding: 18px 6px; }
:root[data-compact="1"] .nav a { font-size: 0; padding: 8px 0; justify-content: center; }
:root[data-compact="1"] .nav a::first-letter { font-size: 14px; }
:root[data-compact="1"] .brand { font-size: 12px; padding: 2px 4px 14px; text-align: center; }
:root[data-compact="1"] .side .me b, :root[data-compact="1"] .side .me > span { display: none; }
/* в сетках отступ задаёт gap, а не соседство карточек */
.stats > .card + .card, [style*="grid"] > .card + .card, [style*="grid"] > div > .card:first-child { margin-top: 0; }
.checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px; }

/* v1.5: выбор «чей учёт», переход к строке, фильтр строк */
.whose{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:8px;margin-top:8px}
.whose-card{display:flex;flex-direction:column;gap:3px;text-align:left;padding:10px 12px;border:1px solid var(--border);border-radius:8px;background:var(--surface);color:var(--text);cursor:pointer;font:inherit}
.whose-card:hover{border-color:var(--accent);box-shadow:0 0 0 2px color-mix(in srgb,var(--accent) 20%,transparent)}
.whose-card b{font-size:14px}
a.lnlink{color:inherit;text-decoration:underline dotted}
tr.flash td{animation:flash 1.6s ease-out}
@keyframes flash{0%{background:color-mix(in srgb,var(--warn-soft) 100%,transparent)}100%{background:transparent}}
.lines.only-nocat tr[data-cat="1"]{display:none}
.stages-box{margin:0 0 10px}.stages-box summary{cursor:pointer;list-style:none}.stages-box summary::-webkit-details-marker{display:none}.stages-box summary::before{content:"▸ "}.stages-box[open] summary::before{content:"▾ "}
.doc-tabs{margin:0 0 10px;overflow-x:auto;white-space:nowrap}
.doc-tabs a.stuck .muted{color:var(--warn);font-weight:600}
.stuck-why{font-size:12px;color:var(--warn);margin-top:2px}
.more-filters{display:contents}
.more-filters>summary{list-style:none;cursor:pointer}
.more-filters>summary::-webkit-details-marker{display:none}
.filters-more{grid-column:1/-1;display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:8px;padding:10px;border:1px solid var(--border);border-radius:8px;background:var(--surface)}
.camera-btn{display:none}
@media (pointer:coarse){.camera-btn{display:inline-flex}}
.tip{margin:-4px 0 12px;color:var(--muted)}
.tip summary{cursor:pointer;display:inline}
.tip>div{margin-top:6px;line-height:1.5}
/* v1.5: телефон — меню полосой сверху, без горизонтальной прокрутки страницы */
@media (max-width: 760px) {
  .side { padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
  .brand { padding: 0 6px 0 0; }
  .side .nav { display: flex; gap: 2px; overflow-x: auto; white-space: nowrap; flex: 1; }
  .side .nav .sep, .side .me { display: none; }
  .nav a { padding: 6px 8px; }
  .main { padding: 14px 16px 60px; }
  .drop { flex-wrap: wrap; }
  .drop .grow { flex-basis: 100%; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .wide { grid-column: 1 / -1; }
  .tbl-wrap { overflow-x: auto; }
  h1 { font-size: 20px; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { flex-direction: row; min-width: 0; height: auto; position: static; }
  #doc-table .tbl th:nth-child(3), #doc-table .tbl td:nth-child(3),
  #doc-table .tbl th:nth-child(4), #doc-table .tbl td:nth-child(4),
  #doc-table .tbl th:nth-child(5), #doc-table .tbl td:nth-child(5),
  #doc-table .tbl th:nth-child(8), #doc-table .tbl td:nth-child(8),
  #doc-table .tbl th:nth-child(9), #doc-table .tbl td:nth-child(9) { display: none; }
}
@media (max-width: 760px) {
  .head a.btn:not(.primary) { display: none; }
  #doc-table .tbl td:nth-child(6), #doc-table .tbl td:nth-child(7) { white-space: nowrap; }
}
@media (max-width: 760px) { .viewer { height: 55vh; } .whose { grid-template-columns: minmax(0,1fr); } }
@media (pointer:coarse), (max-width: 760px) { .kbd-hint { display: none; } }
.onboarding{margin-bottom:12px}
.ob-bar{height:4px;background:var(--hover);border-radius:2px;overflow:hidden;margin-bottom:8px}
.ob-bar span{display:block;height:100%;background:var(--ok)}
.ob-steps{list-style:none;margin:0;padding:0}
.ob-steps li{display:flex;gap:12px;align-items:flex-start;padding:10px 0;border-top:1px solid var(--border)}
.ob-steps li:first-child{border-top:0}
.ob-steps li.done b{color:var(--muted);text-decoration:line-through}
.ob-num{flex:none;width:24px;height:24px;border-radius:50%;display:grid;place-items:center;font-size:12px;font-weight:600;background:var(--accent-soft);color:var(--accent)}
.ob-steps li.done .ob-num{background:var(--ok-soft);color:var(--ok)}
.ob-kinds{display:flex;gap:6px;flex-wrap:wrap;align-items:center;margin-top:8px}
.ob-steps .grow,.onboarding .grow{flex:1}
.ticket-body{white-space:pre-wrap;overflow-wrap:anywhere;line-height:1.5}
@media (max-width: 900px){.support-grid{grid-template-columns:minmax(0,1fr) !important}}
.nav a.support-link{color:var(--muted)}
