:root {
  --blue: #1f4fa3; --blue-d: #163a7a; --blue-l: #e8eef9;
  --yellow: #f5c400; --bg: #f4f6fa; --card: #fff; --text: #1b2230; --muted: #6b7486;
  --border: #dde2ec; --red: #c62828; --red-l: #fdecec; --green: #2e7d32; --green-l: #e8f5e9;
  --orange: #e67700; --orange-l: #fff4e5; --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--blue-d); color: #fff; display: flex; flex-direction: column; flex-shrink: 0; }
.brand { padding: 18px 20px; font-weight: 800; font-size: 20px; letter-spacing: 1px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand span { color: var(--yellow); }
.brand small { display: block; font-size: 11px; font-weight: 400; letter-spacing: 0; opacity: .7; }
.nav { flex: 1; padding: 8px 0; }
.nav a { display: flex; align-items: center; gap: 10px; color: #dbe4f5; padding: 9px 20px; border-left: 3px solid transparent; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.1); border-left-color: var(--yellow); color: #fff; }
.nav .ico { width: 18px; text-align: center; }
.userbox { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px; }
.userbox .role { opacity: .7; font-size: 12px; }
.userbox a { color: var(--yellow); font-size: 12px; margin-right: 10px; }
.main { flex: 1; min-width: 0; padding: 24px 28px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.burger { display: none; }

/* Cards & grid */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }
.stat.warn .v { color: var(--red); }

/* Tables */
.tbl-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #f9fafc; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--blue-l); }
td.num, th.num { text-align: right; white-space: nowrap; }
.card table th { background: none; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* Forms */
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-l); border-color: var(--blue); }
textarea { min-height: 70px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 140px; }
.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; min-width: 200px; }
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border); background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f1f3f8; text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-d); }
.btn.danger { color: var(--red); border-color: #f0c4c4; }
.btn.danger:hover { background: var(--red-l); }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #eef0f4; color: #4a5263; }
.b-new { background: #e3f2fd; color: #1565c0; }
.b-in_production, .b-assembly { background: var(--orange-l); color: var(--orange); }
.b-testing { background: #f3e5f5; color: #7b1fa2; }
.b-ready { background: var(--green-l); color: var(--green); }
.b-shipped { background: #e0e0e0; color: #424242; }
.b-cancelled, .b-scrapped { background: var(--red-l); color: var(--red); }
.b-repair { background: #fff8e1; color: #a66d00; }
.low { color: var(--red); font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Status flow */
.flow { display: flex; gap: 6px; flex-wrap: wrap; }
.flow .btn.current { background: var(--blue); color: #fff; border-color: var(--blue); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,25,45,.45); display: flex; align-items: flex-start; justify-content: center; padding: 50px 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal.wide { max-width: 860px; }
.modal-h { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-h h2 { margin: 0; flex: 1; }
.modal-h .x { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-b { padding: 18px 20px; }
.modal-f { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* Toast */
#toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1b2230; color: #fff; padding: 10px 16px; border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.2); max-width: 380px; }
.toast.err { background: var(--red); }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--blue-d); }
.login .card { width: 340px; padding: 28px; }
.login .brand { color: var(--blue-d); border: none; padding: 0 0 18px; text-align: center; font-size: 28px; }
.login .brand span { color: #d4a900; }
.err-msg { color: var(--red); margin-bottom: 10px; font-size: 13px; }

.items-tbl td { padding: 5px 6px; }
.items-tbl input, .items-tbl select { padding: 5px 7px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; }
.kv .k { color: var(--muted); }
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.alert.warn { background: var(--orange-l); color: #8a4b00; }
.alert.ok { background: var(--green-l); color: var(--green); }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -240px; top: 0; bottom: 0; z-index: 40; transition: left .2s; }
  .sidebar.open { left: 0; }
  .burger { display: inline-flex; }
  .main { padding: 16px; }
  .g2 { grid-template-columns: 1fr; }
  .filters input, .filters select { min-width: 0; flex: 1; }
}
@media print {
  .sidebar, .page-head .actions, .btn { display: none !important; }
  .main { padding: 0; }
}
.filters input[type=checkbox] { min-width: 0; width: auto; }

/* ===== v2 ===== */
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 14px 0 8px; }
a.stat { color: inherit; display: block; }
a.stat:hover { text-decoration: none; border-color: var(--blue); }
.sec-h { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.sec-h h2 { margin: 0; }
.sec-h .spacer, .line-h .spacer, .cfg-pos-h .spacer, .fld-h .spacer, .inv-line-h .spacer { flex: 1; }
.chk { display: inline-flex !important; align-items: center; gap: 6px; font-weight: 400 !important; color: inherit !important; font-size: 13px !important; margin: 0 !important; cursor: pointer; }
.chk input { width: auto; min-width: 0 !important; }
.pre { white-space: pre-wrap; }
.invalid { border-color: var(--red) !important; }
.ok { color: var(--green); font-weight: 600; }
.b { font-weight: 700; }
.hist { margin-bottom: 4px; }

.badge.light { background: #f1f3f8; color: #4a5263; font-weight: 500; }
.b-awaiting { background: #fff8e1; color: #a66d00; }
.b-production, .b-in_work { background: var(--orange-l); color: var(--orange); }
.b-partial { background: #e0f2f1; color: #00796b; }
.b-warn { background: #fff3e0; color: #b45309; }
.b-open { background: var(--red-l); color: var(--red); }
.b-issued { background: var(--green-l); color: var(--green); }
.badge.b-waiting { background: var(--red-l); color: var(--red); }
.badge.b-none { background: #f1f3f8; color: var(--muted); }

/* Рахунок: рядки і позиції */
.inv-line { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin-bottom: 10px; }
.inv-line-h { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
table.sub { margin-top: 8px; background: #fafbfd; border-radius: 6px; }
table.sub td { border-bottom: 1px solid #eef0f4; }
.inv-total { text-align: right; font-size: 15px; padding-top: 4px; }

/* Форма рахунку */
.line { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px 6px; margin-bottom: 12px; background: #fcfdff; }
.line-h { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.line-h .field { margin-bottom: 6px; }
.cfg-pos { border-left: 3px solid var(--yellow); background: #fff; padding: 8px 10px; margin: 6px 0; border-radius: 0 6px 6px 0; }
.cfg-pos-h { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; font-weight: 600; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; color: var(--muted); }
label.inline input { width: 80px; }
.cfg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 12px; }
.cfg-f label { margin-bottom: 3px; }
.cfg-slots { display: flex; flex-direction: column; gap: 4px; }
.cfg-other { margin-top: 3px; }
.line-f { display: flex; gap: 12px; align-items: center; padding: 4px 0; }

/* Каталог: характеристики */
.fld { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin-bottom: 10px; }
.fld-h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
table.opts td { padding: 6px 8px; }
.chip { display: inline-block; background: var(--blue-l); color: var(--blue-d); border-radius: 4px; padding: 1px 7px; margin: 2px 2px 2px 0; font-size: 12px; }
.addopt { display: flex; gap: 6px; margin-top: 8px; max-width: 360px; }
.dep-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.slot-n { display: inline-block; width: 16px; color: var(--muted); font-size: 11px; font-weight: 700; }
.cfg-slot { position: relative; }
.cfg-slot > .cfg-sel { width: calc(100% - 18px); }
.cfg-slots > .cfg-slot:only-child > .cfg-sel { width: 100%; }
.cfg-kids { margin: 3px 0 6px 18px; display: flex; flex-direction: column; gap: 3px; }
.cfg-kid-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.cfg-kid-row span { width: 92px; flex-shrink: 0; }
.cfg-kid-row select { padding: 4px 6px; font-size: 13px; }
.bi { border-top: 1px dashed var(--border); padding-top: 8px; margin-top: 8px; }
.bi:first-of-type { border-top: none; margin-top: 0; padding-top: 0; }
.bi-h { font-weight: 600; margin-bottom: 6px; }
.pcomment { flex: 1; max-width: 420px; padding: 4px 8px; font-size: 13px; }
.comment { color: #6b4e00; }
.kid-opts { margin-top: 4px; font-size: 12px; }
.kid-opt { display: inline-block; background: #f5f7fb; border-radius: 4px; padding: 1px 6px; margin: 2px 4px 2px 0; }
.danger-link { color: var(--red); }
.b-goods { background: #ede7f6; color: #5e35b1; }
.badge.b-stock { background: #ede7f6; color: #5e35b1; }
.sugg { background: #fffbea; border: 1px solid #f5e3a3; border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.sugg-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 4px 0; border-top: 1px dashed #f0dfa0; }
.sugg-row:first-of-type { border-top: none; }
.brand { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.brand small { flex-basis: 100%; }
.logo-img { height: 34px; max-width: 120px; object-fit: contain; }
.login .brand { justify-content: center; }
.login .logo-img { height: 56px; max-width: 200px; }
.brand-txt span { color: var(--yellow); }
.login .brand-txt span { color: #d4a900; }
.logo-prev { background: var(--blue-d); border-radius: 6px; padding: 14px; margin-bottom: 8px; min-height: 60px; display: flex; align-items: center; }
.logo-prev img { max-height: 60px; max-width: 220px; }
.brand > .brand-txt { color: #fff; }
.login .brand > .brand-txt { color: var(--blue-d); }
.logo-prev.light { background: #fff; border: 1px solid var(--border); }
.row > .logo-prev { flex: 1; }
.sidebar .logo-img { height: 21px; max-width: none; }
.sidebar .brand { font-size: 17px; gap: 7px; }
/* v2.3 */
textarea.big { min-height: 92px; font-size: 14px; }
.ro { padding: 7px 10px; background: #f4f6fa; border: 1px solid var(--border); border-radius: 6px; }
.line.locked { background: #fafafa; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tab { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.sn-list { display: flex; flex-wrap: wrap; gap: 6px; }
.sn { background: var(--blue-l); color: var(--blue-d); border-radius: 4px; padding: 3px 8px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.sn a { color: var(--red); margin-left: 4px; }
label.chk.sn { display: inline-flex !important; color: var(--blue-d) !important; }
.btn:disabled { opacity: .45; }
/* Шторки рахунків у Виробництві */
table.acc tr.acc-h { cursor: pointer; background: #f6f8fc; }
table.acc tr.acc-h:hover { background: var(--blue-l); }
table.acc tr.acc-h.open { background: #eaf0fb; }
table.acc tr.acc-h td { border-top: 2px solid var(--border); }
.acc-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.chev { width: 14px; color: var(--blue); font-size: 14px; }
.acc-inv { min-width: 120px; }
.acc-cust { flex: 1; min-width: 160px; color: var(--text); }
.acc-date { white-space: nowrap; }
.acc-sum { color: var(--muted); white-space: nowrap; }
.acc-st { display: flex; gap: 4px; flex-wrap: wrap; }
table.acc tr[data-child] td:first-child { padding-left: 34px; }
.badge.lg-warehouse { background: #2f3747; color: #fff; }
.badge.lg-picked { background: #fff4c2; color: #7a5a00; }
.badge.lg-sent { background: #f5c400; color: #1b2440; }

/* v1.7: сповіщення */
.nbadge { margin-left: auto; background: var(--yellow, #f5c400); color: #1b2440; border-radius: 10px; font-size: 11px; font-weight: 700; padding: 1px 7px; min-width: 20px; text-align: center; }
.nbadge[hidden] { display: none; }
.chk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 14px; margin: 6px 0 12px; }
.notif-list { padding: 0; overflow: hidden; }
.notif { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-bottom: 1px solid #edf0f5; cursor: pointer; }
.notif:last-child { border-bottom: 0; }
.notif:hover { background: #f7f9fc; }
.notif.unread { background: #fffbe8; }
.notif.unread .n-title { font-weight: 700; }
.notif .n-body { flex: 1; min-width: 0; }
.notif .n-title { margin-bottom: 2px; }
.n-ico { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: #eef0f4; flex: none; font-size: 14px; }
.n-ico.k-ready { background: #e3f6ea; color: #1d7a42; }
.n-ico.k-order { background: #e7efff; color: #2453b8; }
.n-ico.k-shipreq, .n-ico.k-shipment { background: #fff1d6; color: #9a6200; }
.n-ico.k-message { background: #f1e8ff; color: #6a3cc0; }

/* v1.8: історія змін рахунку */
.changes { max-height: 420px; overflow: auto; }
.chg { padding: 8px 0; border-bottom: 1px solid #edf0f5; }
.chg:last-child { border-bottom: 0; }
.chg-l { padding-left: 14px; position: relative; }
.chg-l::before { content: '•'; position: absolute; left: 3px; color: #9aa3b5; }

/* v1.9: оплата, етап */
.pay-sum { display: flex; gap: 36px; flex-wrap: wrap; }
.pay-sum b { font-size: 18px; }
.seg { display: flex; gap: 18px; flex-wrap: wrap; padding: 4px 0; }
.card.soft { background: #f7f9fc; box-shadow: none; border: 1px solid var(--border); }

/* v1.12: кольори відділів і ролей (ретранслятори — блакитний, наземні — зелений, дрони — фіолетовий,
   склад — темний, бухгалтерія — білий, логіст — жовтий, продажі — червоний) */
.dchip { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--c); color: var(--ink, #fff); line-height: 1.5; }
.dchip.outline { box-shadow: inset 0 0 0 1px #b9c1d0; }
.cdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c); margin-right: 6px; vertical-align: middle; box-shadow: 0 0 0 1px rgba(27,36,64,.25); }
tr.dstripe > td:first-child { box-shadow: inset 4px 0 0 var(--c); }
tr.dstripe > td { background: color-mix(in srgb, var(--c) 7%, transparent); }
.dstripe-l { box-shadow: inset 4px 0 0 var(--c); padding-left: 12px; }
.chg.dstripe-l { padding-left: 10px; }
.card.cstripe { border-top: 4px solid var(--c); }
.card.cstripe[style*="#ffffff"] { border-top-color: #d5dae4; }
.n-ico.by { background: var(--c); color: var(--ink); box-shadow: 0 0 0 1px rgba(27,36,64,.15); }
.acc-deps { display: inline-flex; gap: 2px; }
.userbox .dchip { margin-top: 3px; }
