:root {
  --navy: #1f3864; --mid: #2e5597; --light: #d9e2f3; --bg: #f4f6fa; --card: #fff; --line: #d5dcea; --text: #1b2330; --muted: #5d6879;
  --h: #f8cbad; --m: #ffe699; --l: #c6efce; --err: #c00000; --err-bg: #ffe5e5; --warn: #8a5a00; --warn-bg: #fff4d6; --ok: #1e7a3c; --ok-bg: #e3f4e8;
  --sc: #fce4d6; --rw: #fdecea; --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: var(--radius); padding: 6px 12px; }
button:hover { background: #eef2f9; }
button.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
button.primary:hover { background: var(--mid); }
button.ghost { border-color: transparent; background: transparent; }
button.danger { color: var(--err); }
button:disabled { opacity: .5; cursor: default; }
a { color: var(--mid); }
input[type=text], input[type=password], input:not([type]), select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9db6e4; outline-offset: -1px; border-color: var(--mid); }
.top { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 48px; position: sticky; top: 0; z-index: 20; }
.top .brand { font-weight: 600; letter-spacing: .3px; color: #fff; text-decoration: none; }
.top .brand small { font-weight: 400; opacity: .75; margin-left: 6px; }
.top .sp { flex: 1; }
.top button { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.top button:hover { background: rgba(255,255,255,.12); }
.top .save { font-size: 12px; opacity: .85; min-width: 90px; text-align: right; }
.top .save.err { color: #ffb4b4; opacity: 1; }
main { padding: 16px; max-width: 1800px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
h1 { font-size: 20px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
label.f { display: block; font-size: 12px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { margin-top: 3px; color: var(--text); font-size: 14px; }
.login { max-width: 360px; margin: 10vh auto; }
.login .card { padding: 24px; }
.login label.f { margin-bottom: 12px; }
.error { color: var(--err); font-size: 13px; min-height: 18px; }

/* Список деталей */
.parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.part { cursor: pointer; transition: border-color .1s; }
.part:hover { border-color: var(--mid); }
.part .num { font-size: 12px; color: var(--muted); }
.part .nm { font-weight: 600; font-size: 15px; margin: 2px 0 8px; }
.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--light); color: var(--navy); }
.pill.err { background: var(--err-bg); color: var(--err); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.H { background: var(--h); color: #7a2a00; } .pill.M { background: var(--m); color: #6b4f00; } .pill.L { background: var(--l); color: #1b5e20; }

/* Вкладки детали */
.head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.head .sp { flex: 1; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--navy); border-bottom-color: var(--navy); font-weight: 600; }
.tabs a .pill { margin-left: 4px; }

/* Сводка */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; font-weight: 600; }
.stat span { font-size: 12px; color: var(--muted); }
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { padding: 8px 10px; border-radius: 6px; margin-bottom: 4px; display: flex; gap: 10px; align-items: baseline; cursor: pointer; }
.checks li.error { background: var(--err-bg); } .checks li.warn { background: var(--warn-bg); }
.checks li:hover { outline: 1px solid var(--mid); }
.checks li .lv { font-size: 11px; font-weight: 700; min-width: 72px; }
.checks li.error .lv { color: var(--err); } .checks li.warn .lv { color: var(--warn); }

/* Таблицы-редакторы */
.tbl-wrap { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; max-height: calc(100vh - 230px); }
table.ed { border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 100%; }
table.ed th { position: sticky; top: 0; z-index: 3; background: var(--navy); color: #fff; font-weight: 600; font-size: 12px; padding: 6px; text-align: center; border-right: 1px solid #3a548a; white-space: pre-line; }
table.ed thead tr.grp th { top: 0; background: var(--mid); height: 28px; padding: 4px 6px; }
table.ed thead tr.grp + tr th { top: 27px; }
table.ed td { border-bottom: 1px solid var(--line); border-right: 1px solid #eef1f6; padding: 0; vertical-align: top; background: #fff; }
table.ed td.c { text-align: center; vertical-align: middle; }
table.ed .stick1 { position: sticky; left: 0; z-index: 2; }
table.ed th.stick1 { z-index: 4; }
table.ed textarea, table.ed input, table.ed select { border: 0; border-radius: 0; background: transparent; padding: 6px; resize: none; min-height: 32px; display: block; }
table.ed textarea { overflow: hidden; line-height: 1.35; }
table.ed input.num { text-align: center; font-weight: 600; }
table.ed td:focus-within { background: #f3f7ff; box-shadow: inset 0 0 0 2px #9db6e4; }
table.ed tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { background: #fff3a8; } 100% { background: #fff; } }
table.ed tr.group td { background: #eef2f9; font-weight: 600; color: var(--navy); padding: 6px 10px; position: sticky; left: 0; }
table.ed tr.group td .row { justify-content: space-between; }
table.ed tr.rework td { background: var(--rw); }
table.ed .ap { font-weight: 700; display: block; padding: 8px 0; }
table.ed .ap.H { background: var(--h); } table.ed .ap.M { background: var(--m); } table.ed .ap.L { background: var(--l); }
table.ed .sc { color: var(--err); font-weight: 700; }
table.ed td.sel-sc select { background: var(--sc); color: var(--err); font-weight: 700; }
table.ed td.bad { box-shadow: inset 0 0 0 2px #f0a0a0; }
table.ed .ro { padding: 7px 6px; color: var(--muted); display: block; }
.acts { white-space: nowrap; padding: 4px !important; vertical-align: middle !important; }
.acts button { padding: 2px 6px; font-size: 12px; }
.kind { font-size: 16px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar .sp { flex: 1; }
.legend { font-size: 12px; color: var(--muted); }
.history { font-size: 13px; }
.history .it { padding: 6px 0; border-bottom: 1px solid var(--line); }
.history .who { color: var(--muted); font-size: 12px; }
.history code { background: #f0f2f7; padding: 0 4px; border-radius: 4px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: 90vw; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 40; }
.modal { background: #fff; border-radius: 12px; padding: 20px; width: min(520px, 92vw); max-height: 90vh; overflow: auto; }
.modal h2 { margin-bottom: 14px; }
.modal .row { justify-content: flex-end; margin-top: 16px; }
.pw { font-family: ui-monospace, Consolas, monospace; font-size: 18px; background: #f0f2f7; padding: 8px 12px; border-radius: 6px; user-select: all; }
table.list { border-collapse: collapse; width: 100%; font-size: 13px; }
table.list th, table.list td { border-bottom: 1px solid var(--line); padding: 8px; text-align: left; }
table.list th { color: var(--muted); font-weight: 600; font-size: 12px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
@media (max-width: 700px) { main { padding: 10px; } .top .brand small { display: none; } .tbl-wrap { max-height: none; } }
@media print { .top, .tabs, .toolbar, .acts { display: none !important; } .tbl-wrap { max-height: none; overflow: visible; border: 0; } }
