/* TMMS — calm industrial UI. Mobile-first for contractors in the field, sidebar on desktop. */
:root {
  --bg: #f3f5f7; --panel: #fff; --ink: #14212b; --ink2: #4a5a67; --muted: #7a8894; --line: #e1e6ea; --line2: #eef1f4;
  --brand: #12344d; --brand2: #1d4f73; --accent: #f5a524;
  --blue: #1f6feb; --blue-bg: #e8f0fe; --green: #0f7b5f; --green-bg: #e3f4ee; --amber: #9a5b00; --amber-bg: #fff3dc;
  --red: #c0362c; --red-bg: #fdecea; --violet: #6b46c1; --violet-bg: #efe9fb; --grey: #5f6b75; --grey-bg: #eef1f4;
  --r: 10px; --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 1px 1px rgba(16, 32, 48, .04);
  --side: 236px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); font-size: 15px; line-height: 1.45;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: -.01em; }
.muted { color: var(--muted); } .small { font-size: .82rem; } .big { font-size: 1.1rem; }
.t-red { color: var(--red); } .t-green { color: var(--green); } .t-amber { color: var(--amber); }
.row { display: flex; align-items: center; } .gap { gap: .5rem; } .wrap { flex-wrap: wrap; } .between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; } .center { text-align: center; } .right { text-align: right; }
.mt { margin-top: .75rem; } .mb { margin-bottom: 1rem; } .pad { padding: .75rem 0; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- layout ---------- */
.app { min-height: 100vh; }
.side { position: fixed; inset: 0 auto 0 0; width: var(--side); background: var(--brand); color: #dfe8ef; display: flex; flex-direction: column; z-index: 30; }
.brand { display: flex; gap: .7rem; align-items: center; padding: 1.1rem 1rem; }
.brand b { display: block; color: #fff; font-size: 1.05rem; } .brand small { color: #9fb4c4; font-size: .75rem; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: #fff; color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: 1.1rem; position: relative; }
.logo::after { content: ""; position: absolute; right: 4px; bottom: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.side nav { flex: 1; overflow-y: auto; padding: .25rem .5rem; }
.side nav a { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: 8px; color: #cbd8e2; font-weight: 500; position: relative; }
.side nav a:hover { background: rgba(255, 255, 255, .07); text-decoration: none; color: #fff; }
.side nav a.on { background: rgba(255, 255, 255, .13); color: #fff; }
.nb { margin-left: auto; background: var(--accent); color: #1b1300; font-style: normal; font-size: .72rem; font-weight: 700; border-radius: 99px; padding: 0 .45rem; min-width: 1.3rem; text-align: center; }
.nb[hidden], .nb:empty { display: none; }
.me { border-top: 1px solid rgba(255, 255, 255, .1); padding: .8rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.me b { color: #fff; display: block; font-size: .9rem; } .me small { color: #9fb4c4; font-size: .75rem; }
.me .btn { color: #dfe8ef; border-color: rgba(255, 255, 255, .25); }
.top, .tabs { display: none; }
main { margin-left: var(--side); padding: 1.5rem 2rem 4rem; max-width: 1280px; }

@media (max-width: 860px) {
  .side { transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .nav-open .side { transform: none; }
  .top { display: flex; position: sticky; top: 0; z-index: 20; background: var(--brand); color: #fff; height: 52px; align-items: center; padding: 0 .5rem; gap: .5rem; }
  .top-title { flex: 1; }
  .menu-btn { background: none; border: 0; color: #fff; font-size: 1.4rem; width: 44px; height: 44px; }
  .top-scan { color: #fff; width: 44px; height: 44px; display: grid; place-items: center; }
  .top-scan .ic { width: 24px; height: 24px; }
  main { margin: 0; padding: 1rem 1rem calc(80px + env(safe-area-inset-bottom)); }
  .tabs { display: flex; position: fixed; inset: auto 0 0 0; z-index: 20; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .45rem 0 .4rem; color: var(--muted); font-size: .7rem; font-weight: 600; position: relative; }
  .tabs a.on { color: var(--brand2); }
  .tabs a:hover { text-decoration: none; }
  .tabs .nb { position: absolute; top: 2px; left: 55%; margin: 0; }
  h1 { font-size: 1.3rem; }
  .tiles { grid-template-columns: 1fr 1fr; gap: .6rem; }
  .tile { padding: .7rem .8rem; } .tile b { font-size: 1.5rem; } .tile span { font-size: .8rem; }
}

/* ---------- page parts ---------- */
.page-head { margin-bottom: 1.1rem; }
.page-head p { margin: .25rem 0 0; }
.page-head h1 .badge { vertical-align: middle; }
.back { display: inline-block; margin-bottom: .3rem; font-size: .88rem; }
.sec { margin: 1.6rem 0 .6rem; font-size: 1rem; color: var(--ink2); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.card-head h3 { margin: 0; }
.ok-card { border-color: #9fd5c3; background: #f6fcf9; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }
.grid5 { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr .6fr; gap: 0 .75rem; align-items: end; }
.span2 { grid-column: span 2; } .span3 { grid-column: 1 / -1; }
.grid2 > .card { margin-bottom: 1rem; }
@media (max-width: 860px) { .grid2, .grid3 { grid-template-columns: 1fr; } .grid5 { grid-template-columns: 1fr 1fr; } .span2, .span3 { grid-column: auto; } }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: var(--r); }
.empty.err { color: var(--red); }
.note { background: var(--amber-bg); color: var(--amber); padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; }
.note.red { background: var(--red-bg); color: var(--red); }
.loading { display: grid; place-items: center; padding: 4rem; } .loading.full { height: 100vh; }

/* home tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .75rem; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: .9rem 1rem; color: var(--ink); box-shadow: var(--shadow); border-left: 4px solid var(--line); }
.tile:hover { text-decoration: none; border-color: var(--brand2); }
.tile b { display: block; font-size: 1.8rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile span { color: var(--ink2); font-size: .85rem; }
.tile.amber { border-left-color: var(--accent); } .tile.blue { border-left-color: var(--blue); } .tile.red { border-left-color: var(--red); }
.tile.zero b { color: var(--muted); }
.actions-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .75rem; }
.action { display: flex; gap: .8rem; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: .9rem 1rem; color: var(--ink); box-shadow: var(--shadow); }
.action:hover { text-decoration: none; border-color: var(--brand2); }
.action .ic { width: 34px; height: 34px; padding: 7px; border-radius: 9px; background: var(--blue-bg); color: var(--brand2); }
.action b { display: block; } .action small { color: var(--muted); }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; margin: 0 -.2rem; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; padding: .5rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: .6rem .6rem; border-bottom: 1px solid var(--line2); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl.clickable tbody tr { cursor: pointer; } .tbl.clickable tbody tr:hover { background: #f8fafb; }
main > .tbl-wrap, #list > .tbl-wrap, #recent > .tbl-wrap, #units > .tbl-wrap, #body > .tbl-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); margin: 0; box-shadow: var(--shadow); }
@media (max-width: 640px) {
  .tbl thead { display: none; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl tr { padding: .6rem .8rem; border-bottom: 1px solid var(--line); }
  .tbl td { border: 0; padding: .12rem 0; display: flex; gap: .75rem; justify-content: space-between; text-align: right; }
  .tbl td::before { content: attr(data-h); color: var(--muted); font-size: .78rem; text-align: left; flex: none; }
  .tbl td[data-h=""]::before { content: none; }
  .tbl .num { text-align: right; }
}

/* ---------- badges, chips ---------- */
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; white-space: nowrap; text-transform: capitalize; }
.badge.blue { background: var(--blue-bg); color: var(--blue); } .badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber); } .badge.red { background: var(--red-bg); color: var(--red); }
.badge.violet { background: var(--violet-bg); color: var(--violet); } .badge.grey { background: var(--grey-bg); color: var(--grey); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .6rem; }
.chip { background: var(--line2); border-radius: 99px; padding: .2rem .7rem; font-size: .85rem; }

/* ---------- forms ---------- */
.fld { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .8rem; min-width: 0; }
.fld > span { font-size: .8rem; font-weight: 600; color: var(--ink2); }
.fld.sm { margin-bottom: 0; flex: 1 1 90px; max-width: 150px; } .fld.sm input { width: 100%; } .fld.sm b { white-space: nowrap; padding: .55rem 0; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #cfd7de; border-radius: 8px; padding: .55rem .65rem; min-height: 42px; width: 100%; }
input.sm { width: 120px; min-height: 36px; padding: .35rem .5rem; }
textarea { min-height: 42px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31, 111, 235, .25); border-color: var(--blue); }
.check { display: flex; align-items: center; gap: .5rem; margin: .4rem 0; font-size: .92rem; }
.check input { width: 18px; height: 18px; min-height: 0; }
.multi { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 1rem; max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: .3rem .7rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters > * { width: auto; min-width: 170px; flex: 1 1 170px; max-width: 320px; }
.actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; align-items: center; }
.actions.sticky { position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0; border-top: 1px solid var(--line); }
@media (max-width: 860px) { .actions.sticky { bottom: calc(60px + env(safe-area-inset-bottom)); } }
.seg { display: inline-flex; background: var(--line2); border-radius: 9px; padding: 3px; }
.seg a { padding: .35rem .9rem; border-radius: 7px; color: var(--ink2); font-weight: 600; font-size: .9rem; }
.seg a.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.seg a:hover { text-decoration: none; }
.gps-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; background: var(--line2); border-radius: 8px; padding: .4rem .7rem; font-size: .9rem; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; font-size: .92rem; border-radius: 8px;
  border: 1px solid #cfd7de; background: #fff; color: var(--ink); padding: .5rem .95rem; min-height: 40px; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; background: #f6f8fa; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--brand2); border-color: var(--brand2); color: #fff; } .btn.primary:hover { background: var(--brand); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; } .btn.ghost:hover { background: rgba(0, 0, 0, .04); }
.btn.danger.ghost { background: transparent; color: var(--red); border-color: #f0b8b3; }
.btn.sm { min-height: 32px; padding: .25rem .65rem; font-size: .84rem; }
.btn.big { min-height: 50px; padding: .7rem 1.4rem; font-size: 1rem; }
.btn.block { width: 100%; margin-top: .5rem; }
.x { background: none; border: 0; font-size: 1.4rem; line-height: 1; color: var(--muted); cursor: pointer; width: 36px; height: 36px; border-radius: 8px; flex: none; }
.x:hover { background: var(--red-bg); color: var(--red); }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .7s linear infinite; opacity: .7; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---------- lines, pick lists ---------- */
.lines-box { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .75rem .75rem; margin-bottom: 1rem; }
.line { display: flex; align-items: center; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--line2); }
.line:last-child { border-bottom: 0; }
.line.inst { align-items: flex-start; }
.line-edit { margin-bottom: .5rem; } .line-edit select { flex: 2; } .line-edit input { flex: 1; max-width: 160px; }
.pick-list { max-height: 55vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.pick-list.short { max-height: 280px; }
.pick { display: flex; gap: .7rem; align-items: flex-start; padding: .55rem .75rem; border-bottom: 1px solid var(--line2); cursor: pointer; }
.pick:last-child { border-bottom: 0; }
.pick input[type=checkbox] { width: 20px; height: 20px; min-height: 0; margin-top: 2px; flex: none; }
.pick:has(input:checked) { background: var(--blue-bg); }
.pick.ret { flex-wrap: wrap; } .pick .row { flex-wrap: wrap; }
.grn-line .drum-row { border-bottom: 1px dashed var(--line); padding-top: .4rem; }
.grn-line .len { padding: .6rem 0; }

/* ---------- details ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.kv dt { color: var(--muted); font-size: .85rem; } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 1rem; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 .9rem .5rem; }
.timeline li::before { content: ""; position: absolute; left: -1.43rem; top: .35rem; width: 10px; height: 10px; border-radius: 50%; background: var(--brand2); border: 2px solid #fff; }
.meter { height: 10px; background: var(--green-bg); border-radius: 99px; overflow: hidden; margin: .8rem 0 .3rem; }
.meter div { height: 100%; background: var(--brand2); }
.blockers { margin: .4rem 0 0; padding-left: 1.2rem; color: var(--amber); }
.cred { background: var(--line2); border-radius: 8px; padding: .8rem 1rem; display: grid; gap: .3rem; font-size: 1rem; }

/* photos */
.photos { display: flex; flex-wrap: wrap; gap: .5rem; }
.photo, .photo-add { width: 84px; height: 84px; border-radius: 8px; overflow: hidden; position: relative; background: var(--line2); display: grid; place-items: center; }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo .x { position: absolute; top: 2px; right: 2px; width: 24px; height: 24px; font-size: 1rem; background: rgba(255, 255, 255, .85); }
.photo-add { border: 2px dashed #c6d0d8; cursor: pointer; color: var(--muted); text-align: center; line-height: 1.1; }
.photo-add b { font-size: 1.6rem; display: block; } .photo-add small { font-size: .7rem; }

/* ---------- modal ---------- */
.modal-open { overflow: hidden; }
.modal-back { position: fixed; inset: 0; background: rgba(12, 24, 36, .45); z-index: 100; display: grid; place-items: center; padding: 1rem; }
.modal { background: #fff; border-radius: 14px; padding: 1.2rem 1.3rem; width: min(480px, 100%); max-height: calc(100vh - 2rem); overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.wide { width: min(760px, 100%); }
@media (max-width: 640px) { .modal-back { place-items: end stretch; padding: 0; } .modal { border-radius: 14px 14px 0 0; max-height: 92vh; padding-bottom: calc(1.2rem + env(safe-area-inset-bottom)); } }
.scanner { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 4 / 3; margin-bottom: .75rem; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner.off { aspect-ratio: auto; background: var(--line2); } .scanner.off video, .scanner.off .scan-frame { display: none; }
.scan-frame { position: absolute; inset: 18% 22%; border: 3px solid rgba(255, 255, 255, .9); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); }
.scan-msg { position: absolute; left: 0; right: 0; bottom: .5rem; margin: 0; text-align: center; color: #fff; font-size: .85rem; }
.scanner.off .scan-msg { position: static; color: var(--ink2); padding: 1rem; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 20px); opacity: 0; transition: .25s; background: var(--ink); color: #fff; padding: .7rem 1.1rem; border-radius: 10px; z-index: 200; max-width: calc(100vw - 2rem); box-shadow: 0 8px 30px rgba(0, 0, 0, .25); }
.toast.show { opacity: 1; transform: translate(-50%, 0); } .toast.err { background: var(--red); }
@media (max-width: 860px) { .toast { bottom: calc(76px + env(safe-area-inset-bottom)); } }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, var(--brand) 0%, #0b2233 100%); }
.login-card { width: min(380px, 100%); padding: 1.6rem; }
.brand.big { padding: 0 0 1.2rem; } .brand.big b { color: var(--ink); font-size: 1.2rem; } .brand.big small { color: var(--muted); }
.brand.big .logo { background: var(--brand); color: #fff; width: 42px; height: 42px; }

/* map */
.map { height: 62vh; min-height: 360px; border-radius: var(--r); border: 1px solid var(--line); z-index: 0; }

/* ---------- labels (A6 105 x 148 mm) ---------- */
.labels { display: flex; flex-wrap: wrap; gap: 1rem; }
.label { width: 105mm; height: 148mm; background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 6mm; display: flex; flex-direction: column; align-items: center; text-align: center; color: #000; overflow: hidden; }
.lb-org { font-weight: 700; font-size: 11pt; letter-spacing: .08em; text-transform: uppercase; border-bottom: 2px solid #000; width: 100%; padding-bottom: 2mm; }
.lb-qr { width: 78mm; height: 78mm; margin: 5mm 0 3mm; image-rendering: pixelated; }
.lb-tag { font-family: ui-monospace, Consolas, monospace; font-weight: 800; font-size: 26pt; letter-spacing: .02em; line-height: 1; }
.lb-item { font-size: 12pt; font-weight: 600; margin-top: 2mm; }
.lb-meta { font-size: 10pt; margin-top: 1mm; }
.lb-foot { margin-top: auto; font-size: 8pt; color: #333; border-top: 1px solid #000; width: 100%; padding-top: 1.5mm; }

/* ---------- A4 document ---------- */
.a4 { background: #fff; color: #000; width: 210mm; max-width: 100%; min-height: 297mm; padding: 14mm; margin: 0 auto; box-shadow: var(--shadow); font-size: 10pt; }
.a4 h2 { margin: 0; font-size: 16pt; }
.a4 .doc-qr { width: 22mm; height: 22mm; margin-top: 2mm; }
.a4 table { width: 100%; border-collapse: collapse; margin-top: 6mm; }
.a4 th, .a4 td { border: 1px solid #000; padding: 1.5mm 2mm; text-align: left; vertical-align: top; }
.a4 .kvt th { width: 18%; background: #f1f1f1; } .a4 .lines th { background: #f1f1f1; } .a4 .num { text-align: right; }
.a4 .sigs { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6mm; margin-top: 18mm; }
.a4 .sigs div { border-top: 1px solid #000; padding-top: 2mm; min-height: 22mm; }

@media print {
  body.printing .side, body.printing .top, body.printing .tabs, body.printing .no-print, body.printing .toast { display: none !important; }
  body.printing main { margin: 0; padding: 0; max-width: none; }
  body.printing { background: #fff; }
  body.print-labels .labels { display: block; }
  body.print-labels .label { border: 0; border-radius: 0; page-break-after: always; break-after: page; margin: 0; }
  body.print-a4 .a4 { box-shadow: none; padding: 0; min-height: 0; width: auto; }
}
