:root {
  --pri: #0f4c5c; --pri-2: #16697a; --acc: #e36414; --bg: #f4f6f8; --card: #fff; --line: #e2e6ea;
  --txt: #1d2730; --mut: #6b7782; --ok: #2d8a4e; --warn: #c98a00; --err: #c0392b; --wa: #1f9d55;
  --r: 10px; --side: 232px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; font-size: 14px; color: var(--txt);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--pri-2); }
h1, h2, h3, h4 { margin: 0; }
h3 { font-size: 15px; }
kbd { font: 10px/1 monospace; background: rgba(0,0,0,.08); border-radius: 3px; padding: 2px 4px; margin-left: 6px; color: inherit; opacity: .8; }
.hidden { display: none !important; }
.muted { color: var(--mut); }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.neg { color: var(--err); }

/* layout */
#root { min-height: 100vh; }
body:not(.auth) #root { display: flex; }
#side { width: var(--side); background: var(--pri); color: #dfeef1; position: fixed; inset: 0 auto 0 0; overflow-y: auto; z-index: 20; }
.brand { display: flex; gap: 10px; align-items: center; padding: 16px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand b { display: block; color: #fff; font-size: 14px; line-height: 1.2; }
.brand small { opacity: .7; }
.logo { width: 38px; height: 38px; border-radius: 9px; background: var(--acc); color: #fff; display: grid; place-items: center; font-size: 20px; flex: none; }
nav { padding: 8px 0 20px; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .55; padding: 14px 18px 4px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 8px 18px; color: inherit; text-decoration: none; border-left: 3px solid transparent; }
nav a:hover { background: rgba(255,255,255,.06); }
nav a.active { background: rgba(255,255,255,.12); border-left-color: var(--acc); color: #fff; }
nav a kbd { margin-left: auto; }
.ni { width: 18px; text-align: center; }
#main { margin-left: var(--side); flex: 1; min-width: 0; }
#top { display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
#top h2 { font-size: 18px; flex: 1; }
.top-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 20px; padding: 4px 10px; font-size: 12px; }
.net { font-size: 12px; } .net.on { color: var(--ok); } .net.off { color: var(--err); }
.menu { display: none; }
#page { padding: 20px; max-width: 1300px; }

/* cards & grids */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 16px; }
.card > h3 { margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 16px; margin-bottom: 14px; }
.span2 { grid-column: span 2; }
.card.narrow, form.narrow { max-width: 760px; }
.toolbar, .quick { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.filters label { min-width: 140px; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; }
.note { background: #eef6f8; border-left: 4px solid var(--pri-2); padding: 10px 14px; border-radius: 6px; margin: 10px 0; color: var(--mut); }
.note.warn { background: #fff7e6; border-color: var(--warn); color: #7a5500; }
.empty { padding: 30px; text-align: center; color: var(--mut); }
.empty.small { padding: 12px; }
.empty.err { color: var(--err); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat small { color: var(--mut); display: block; }
.stat b { font-size: 24px; display: block; margin: 4px 0; }
.stat span { font-size: 12px; color: var(--mut); }
.stat.accent { background: var(--pri); color: #fff; border-color: var(--pri); }
.stat.accent small, .stat.accent span { color: #cfe5ea; }

/* forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--mut); font-weight: 500; }
input, select, textarea { font: inherit; font-size: 14px; color: var(--txt); padding: 8px 10px; border: 1px solid #cfd6dc; border-radius: 7px; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(22,105,122,.35); border-color: var(--pri-2); }
input:disabled { background: var(--bg); }
input.r { text-align: right; }
input.big { font-size: 18px; padding: 12px 14px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--txt); }
label.check input { width: auto; }
fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px 14px; display: grid; gap: 10px; margin: 0; }
legend { font-weight: 600; color: var(--pri); padding: 0 6px; }
.form .parties { margin-bottom: 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 7px;
  border: 1px solid #cfd6dc; background: #fff; color: var(--txt); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--pri-2); border-color: var(--pri-2); color: #fff; }
.btn.primary:hover { background: var(--pri); }
.btn.danger { color: var(--err); border-color: #e8b4ae; }
.btn.ghost { background: transparent; }
.btn.wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.block { width: 100%; padding: 11px; margin-top: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--mut); padding: 2px 8px; line-height: 1; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; flex-wrap: wrap; }
.actions.left { justify-content: flex-start; }
.file-btn { flex-direction: row; color: var(--txt); font-size: 14px; }

.pay-box { background: var(--bg); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.seg { display: flex; border: 1px solid #cfd6dc; border-radius: 8px; overflow: hidden; background: #fff; }
.seg label { flex: 1; flex-direction: row; margin: 0; }
.seg input { display: none; }
.seg span { flex: 1; text-align: center; padding: 9px 4px; cursor: pointer; font-size: 13px; color: var(--txt); }
.seg input:checked + span { background: var(--pri-2); color: #fff; }
.grand { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 0; border-top: 1px dashed #cfd6dc; }
.grand b { font-size: 28px; color: var(--pri); }

/* tables */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--mut); padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th.r, .tbl td.r { text-align: right; }
.tbl tfoot td { border-top: 2px solid var(--line); border-bottom: 0; }
.tbl.click tbody tr { cursor: pointer; }
.tbl.click tbody tr:hover { background: #f0f7f9; }
.tbl.items td { padding: 4px; }
.tbl.items input, .tbl.items select { padding: 6px 8px; }
.tbl.items td:nth-child(3), .tbl.items td:nth-child(4), .tbl.items td:nth-child(5) { width: 110px; }
.tbl.items td:nth-child(2) { width: 130px; }
.sumline { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 10px; color: var(--mut); }
.sumline b { color: var(--txt); margin-left: auto; }

.badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 20px; white-space: nowrap; background: #eee; }
.st-booked { background: #e8eef9; color: #2a4d9b; }
.st-loaded { background: #fff1db; color: #9a5b00; }
.st-transit { background: #fde8dc; color: #b04a0b; }
.st-arrived { background: #e3f2fd; color: #0f5f8a; }
.st-delivered { background: #e2f4e8; color: #1d6b3a; }
.st-cancelled { background: #f4e1df; color: #9b2c20; text-decoration: line-through; }

.dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 0 0 14px; }
.dl.cols { grid-template-columns: 90px 1fr 90px 1fr; }
.dl dt { color: var(--mut); } .dl dd { margin: 0; }

.timeline { list-style: none; padding: 0 0 0 18px; margin: 0; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 14px 12px; display: flex; flex-direction: column; background: none; }
.timeline li::before { content: ""; position: absolute; left: -26px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--pri-2); border: 2px solid #fff; }
.timeline li.st-delivered::before { background: var(--ok); }
.timeline li.st-cancelled::before { background: var(--err); }
.timeline li span, .timeline li small { color: var(--mut); font-size: 12px; }
.track p { margin: 0 0 12px; }
.checklist { display: grid; gap: 6px; max-height: 300px; overflow: auto; margin: 10px 0 14px; }
.checklist label { flex-direction: row; gap: 8px; align-items: center; color: var(--txt); font-weight: 400; font-size: 14px; }
.checklist input { width: auto; }

/* modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(15,30,40,.45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; }
.modal-body p { margin-top: 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px); background: #1d2730; color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: .25s; z-index: 200; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--err); }

/* auth */
body.auth #root { display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, var(--pri), var(--pri-2)); }
.auth-card { background: #fff; border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.auth-card.wide { max-width: 640px; }
.auth-card form { display: grid; gap: 12px; }
.auth-card h4 { color: var(--pri); margin-top: 6px; }
.brand-big { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; }
.brand-big .logo { width: 48px; height: 48px; font-size: 26px; }
.brand-big h1 { font-size: 20px; } .brand-big p { margin: 2px 0 0; color: var(--mut); }

/* mobile */
@media (max-width: 900px) {
  #side { transform: translateX(-100%); transition: transform .2s; }
  body.nav-open #side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  #main { margin-left: 0; }
  .menu { display: block; }
  #top { padding: 8px 12px; flex-wrap: wrap; }
  #top h2 { font-size: 16px; }
  #page { padding: 12px; }
  .grid4 { grid-template-columns: 1fr 1fr; }
  nav a kbd, .btn kbd { display: none; }
}
@media (max-width: 600px) {
  .grid2, .grid4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .dl.cols { grid-template-columns: 90px 1fr; }
  .top-right .chip:last-of-type { display: none; }
  .tbl.items thead { display: none; }
  .tbl.items tr.item { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 4px; padding: 6px 0; border-bottom: 1px solid var(--line); }
  .tbl.items tr.item td { width: auto !important; border: 0; }
  .tbl.items tr.item td:first-child { grid-column: 1 / -1; }
  .tbl.items tr.item td:nth-child(2) { grid-column: 1 / -1; }
  .stat b { font-size: 20px; }
}

/* ---------- print ---------- */
#print { display: none; }
@media print {
  @page { size: A4; margin: 8mm; }
  body { background: #fff; }
  body > #root, .modal-back, .toast { display: none !important; }
  #print { display: block; font-family: Arial, sans-serif; color: #000; font-size: 11px; }
  .bp { height: 136mm; border: 1.5px solid #000; padding: 4mm 5mm; margin-bottom: 6mm; display: flex; flex-direction: column; gap: 2.5mm; page-break-inside: avoid; overflow: hidden; }
  .bp:nth-child(2n) { page-break-after: always; }
  .bp-head { display: flex; justify-content: space-between; border-bottom: 1.5px solid #000; padding-bottom: 2mm; }
  .bp-head h1 { font-size: 20px; } .bp-head p { margin: 1mm 0 0; }
  .bp-no { text-align: right; } .bp-no small { display: block; text-transform: uppercase; font-size: 9px; border: 1px solid #000; padding: 1px 4px; }
  .bp-no b { display: block; font-size: 18px; }
  .bp-route, .bp-parties { display: flex; gap: 4mm; align-items: center; }
  .bp-route > div, .bp-parties > div { flex: 1; } .bp-route .arrow { flex: none; font-size: 18px; }
  .bp-route small, .bp-parties small { display: block; font-size: 9px; text-transform: uppercase; color: #444; }
  .bp-route b, .bp-parties b { font-size: 13px; display: block; }
  .bp-pay { flex: none !important; border: 2px solid #000; padding: 2mm 4mm; font-weight: 700; font-size: 14px; text-transform: uppercase; }
  .bp-pay.topay { background: #000; color: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #print table { width: 100%; border-collapse: collapse; }
  #print th, #print td { border: 1px solid #000; padding: 1.2mm 2mm; text-align: left; }
  #print th { background: #eee; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .bp-foot { display: flex; gap: 4mm; margin-top: auto; }
  .bp-notes { flex: 1; } .terms { font-size: 8.5px; color: #333; margin: 1mm 0 0; }
  .bp-tot { width: 60mm !important; } .bp-tot td:last-child { text-align: right; } .bp-tot tr.g td { font-weight: 700; font-size: 13px; }
  .bp-sign { display: flex; justify-content: space-between; padding-top: 6mm; font-size: 10px; }
  .bp-sign span { border-top: 1px solid #000; padding-top: 1mm; min-width: 40mm; text-align: center; }
  .mp h1 { font-size: 20px; } .mp h2 { font-size: 15px; margin: 2mm 0; }
  .mp .tbl th, .mp .tbl td { font-size: 11px; }
  .mp a { color: #000; text-decoration: none; }
}
