:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2430; --muted: #6b7280; --line: #e3e6ea;
  --accent: #e8590c; --accent-dark: #c2470a;
  --red: #e03131; --red-bg: #fff0f0; --yellow: #d98a00; --yellow-bg: #fff8e1;
  --green: #2b8a3e; --green-bg: #ebfbee; --gray-bg: #f1f3f5;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body.operator { padding-bottom: 76px; }
a { color: var(--accent-dark); }
h1 { font-size: 1.45rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 .6rem; }
.card h2:first-child, .card h2:first-of-type { margin-top: 0; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.grow { flex: 1; }
.nowrap { white-space: nowrap; }
.num { text-align: right; }
.empty { color: var(--muted); padding: 12px 0; }

/* шапка */
.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: #1d2430; color: #fff; flex-wrap: wrap; }
.top a { color: #fff; text-decoration: none; }
.brand { font-weight: 700; font-size: 1.05rem; }
.top nav { display: flex; gap: 16px; align-items: center; margin-left: auto; flex-wrap: wrap; }
.top nav a:hover { text-decoration: underline; }
.who { opacity: .75; }
.top .linkbtn { color: #fff; opacity: .75; }

/* нижня навігація оператора */
.bottom { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: #fff;
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.bottom > * { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 8px 0 6px;
  text-decoration: none; color: var(--muted); font-size: .8rem; }
.bottom b { font-size: 1.3rem; line-height: 1.2; }
.bottom .active { color: var(--accent); font-weight: 600; }
.bottom .soon { opacity: .45; }
.bottom small { font-size: .65rem; }

/* кнопки і форми */
.btn { display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 9px 16px; border-radius: 8px; font: inherit; cursor: pointer; text-decoration: none; text-align: center; }
.btn:hover { border-color: #c5cad1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.wide { display: block; width: 100%; }
.btn.big { padding: 15px; font-size: 1.05rem; }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn:disabled { opacity: .6; }
.btn.danger { color: var(--red); border-color: #f5c2c2; background: #fff; }
.btn.danger:hover { background: var(--red-bg); border-color: var(--red); }
.delete-box { margin-top: 8px; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent-dark); cursor: pointer; text-decoration: underline; }
.linkbtn.danger { color: var(--red); }
form.inline { display: inline; margin: 0; }
label { display: block; margin: 0 0 14px; font-weight: 600; font-size: .9rem; }
input, select, textarea { display: block; width: 100%; margin-top: 5px; padding: 10px 11px; font: inherit; font-weight: 400;
  border: 1px solid #cfd4da; border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #ffc9a3; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; display: inline; margin: 0 6px 0 0; }
label.check { font-weight: 400; display: flex; align-items: center; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend { font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.urgency { display: flex; gap: 8px; flex-wrap: wrap; }
.urgency legend { width: 100%; }
.pill { margin: 0; font-weight: 400; }
.pill input { position: absolute; opacity: 0; }
.pill span { display: inline-block; padding: 8px 14px; border: 1px solid #cfd4da; border-radius: 99px; cursor: pointer; }
.pill input:checked + span { border-color: var(--accent); background: #fff4ec; font-weight: 600; }
.pill input:focus-visible + span { outline: 2px solid #ffc9a3; }
.station-fixed { font-weight: 600; background: var(--gray-bg); padding: 10px 12px; border-radius: 8px; }

/* картки */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card.narrow { max-width: 460px; margin: 24px auto; }
.login h1 { text-align: center; }
.login > p { text-align: center; }
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--gray-bg); }
.flash.ok { background: var(--green-bg); color: #1b5e2b; }
.flash.error { background: var(--red-bg); color: #9b1c1c; }
.crumbs { margin: 0 0 6px; }
.crumbs a { text-decoration: none; }
.head-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.head-row p { margin: 0; }

/* статуси */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--gray-bg); color: var(--muted); white-space: nowrap; }
.st-new { background: var(--red-bg); color: var(--red); }
.st-in_progress { background: var(--yellow-bg); color: #9a6200; }
.st-done { background: var(--green-bg); color: var(--green); }
.st-rejected { background: var(--gray-bg); color: var(--muted); }
.urg-high { background: var(--red); color: #fff; }
.urg-low { background: var(--gray-bg); color: var(--muted); }
.pill .urg-high, .pill .urg-low { background: #fff; color: inherit; }

/* список заявок */
.req-list { display: grid; gap: 10px; }
.req { display: block; background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; color: inherit; text-decoration: none; }
.req:hover { border-color: #c5cad1; }
.req.urg-line-high { border-left-color: var(--red); }
.req.urg-line-normal { border-left-color: var(--yellow); }
.req.unseen { box-shadow: 0 0 0 2px #ffd8bf; }
.req.unseen .req-no::after { content: " ●"; color: var(--accent); }
.req-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.req-top h1 { margin: 0; }
.req-no { font-weight: 700; color: var(--muted); }
.req-desc { margin: 6px 0 4px; }

/* показники */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 8px 0 4px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; color: inherit; text-decoration: none; }
.stat b { display: block; font-size: 1.45rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.red b { color: var(--red); } .stat.yellow b { color: #b07000; } .stat.green b { color: var(--green); }

/* плитки станцій */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.tile { display: flex; flex-direction: column; gap: 3px; background: #fff; border: 1px solid var(--line);
  border-top: 4px solid var(--green); border-radius: var(--radius); padding: 12px 14px; color: inherit; text-decoration: none; }
.tile:hover { border-color: #c5cad1; }
.tile.red { border-top-color: var(--red); background: linear-gradient(#fff6f6, #fff 60%); }
.tile.yellow { border-top-color: var(--yellow); }
.tile b { font-size: 1.05rem; }

/* вкладки */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 10px 0 14px; overflow-x: auto; }
.tab { padding: 9px 14px; border-bottom: 3px solid transparent; color: var(--muted); text-decoration: none; white-space: nowrap; }
.tab.active { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }
.tab.soon { opacity: .5; }
.tab small { font-size: .7rem; }

/* сторінка заявки */
.layout-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 900px) { .layout-2 { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); } }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 12px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.desc { white-space: pre-wrap; background: var(--gray-bg); padding: 12px; border-radius: 8px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--gray-bg); }
.timeline { list-style: none; padding: 0; margin: 0 0 16px; }
.timeline li { padding: 8px 0 8px 14px; border-left: 2px solid var(--line); }
.timeline li.from-admin { border-left-color: var(--accent); }
.comment { white-space: pre-wrap; }
.admin-box { border-color: #ffd8bf; }
.private { font-weight: 400; font-size: .8rem; color: var(--muted); }

/* таблиці */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 11px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; background: #fafbfc; }
tbody tr[onclick] { cursor: pointer; }
tbody tr[onclick]:hover { background: #fafbfc; }
tr.unseen td:first-child { box-shadow: inset 3px 0 var(--accent); }
tr.archived, .archived { opacity: .55; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters select, .filters input { width: auto; margin: 0; }
.row-form { display: flex; gap: 6px; align-items: center; margin: 0; flex-wrap: wrap; }
.row-form input { margin: 0; flex: 1; min-width: 120px; }
td select { margin: 0; padding: 6px; }
.cat-row { display: flex; gap: 10px; align-items: center; padding: 6px 0; }
.cat-row .row-form { flex: 1; }

/* замовлення */
.ost-new { background: var(--red-bg); color: var(--red); }
.ost-confirmed { background: var(--yellow-bg); color: #9a6200; }
.ost-shipped { background: #e7f0ff; color: #1c4fb8; }
.ost-delivered { background: var(--green-bg); color: var(--green); }
.ost-cancelled { background: var(--gray-bg); color: var(--muted); }
.catalog { display: grid; gap: 8px; margin-bottom: 14px; }
.prod { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name name" "stock step"; gap: 6px 10px;
  align-items: end; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.prod.picked { border-color: var(--accent); background: #fff8f3; }
.prod-name { grid-area: name; }
.prod .stock { grid-area: stock; margin: 0; font-weight: 400; font-size: .8rem; color: var(--muted); }
.prod .stock input { margin-top: 2px; max-width: 110px; padding: 8px; }
.stepper { grid-area: step; display: flex; align-items: center; gap: 4px; }
.stepper input { width: 58px; margin: 0; text-align: center; font-weight: 700; padding: 8px 4px; }
.step { width: 40px; height: 40px; padding: 0; font-size: 1.3rem; line-height: 1; }
.inline-step { display: inline-flex; vertical-align: middle; }
.inline-step .step { width: 32px; height: 32px; font-size: 1.1rem; }
.inline-step input { width: 52px; padding: 6px 2px; }
.qty-add { width: 80px; margin: 0; display: inline-block; text-align: center; }
td select { min-width: 200px; }
.corr { color: var(--accent-dark); }
tr.removed td { opacity: .55; }
tr.removed td:first-child { text-decoration: line-through; }
.row-form input.short { flex: 0 0 90px; min-width: 70px; }

/* працівники і доступи */
.chip { display: inline-block; margin: 2px 4px 2px 0; padding: 2px 8px; border-radius: 99px; font-size: .78rem;
  background: #eef2ff; color: #3343a8; white-space: nowrap; }
.chip.admin { background: #fff1e6; color: var(--accent-dark); font-weight: 600; }
.perm-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.perm-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.perm-head select { width: auto; margin: 0; font-size: .85rem; padding: 6px; }
.perm { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; margin: 0 0 10px; cursor: pointer; }
.perm input { margin-top: 4px; }
.perm-box .admin-note { display: none; margin: 0; }
.perm-box.is-admin .perm { opacity: .45; }
.perm-box.is-admin .admin-note { display: block; }
.audit td { font-size: .9rem; }

/* лічильники */
.card.narrow-left { max-width: 520px; }
.machine { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.machine-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.machine .calc { margin: -8px 0 10px; min-height: 1em; color: var(--accent-dark); }
.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.due-row { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.add-machine { margin-top: 10px; }
.stat b .badge { font-size: .9rem; }
.counter-row { display: grid; grid-template-columns: 1fr 120px; grid-template-areas: "lbl inp" "calc reset"; gap: 2px 10px;
  align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.counter-row > label:first-child { grid-area: lbl; margin: 0; font-weight: 500; }
.counter-row > label:first-child .muted { display: block; font-weight: 400; }
.counter-row input.cvalue { grid-area: inp; margin: 0; text-align: right; font-weight: 700; }
.counter-row .calc { grid-area: calc; margin: 0; }
.counter-row .tiny { grid-area: reset; margin: 0; font-size: .78rem; justify-content: flex-end; color: var(--muted); }
.counter-row.is-total > label:first-child { font-weight: 700; }
.photo-label { margin: 10px 0 0; }
.req.sub { cursor: default; }
.sub-items { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: .9rem; }
.sub-item.is-total { font-weight: 600; }
.sub-item .plus { color: var(--green); font-weight: 600; }
.norms { margin: 6px 0 14px; }
.norms td, .norms th { padding: 4px; }
.norms input { margin: 0; padding: 6px; width: 64px; text-align: right; }
.counter-list { margin: 8px 0; }
.counter-list .cat-row { padding: 3px 0; }
input.is-total { font-weight: 700; }
.machine-name { font-weight: 700; }

/* для постачальника */
.matrix th a { color: inherit; }
.matrix .total { background: #fff8f3; }
.matrix td.num { min-width: 64px; }
.station-lists { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.station-list h3 { margin: 0 0 8px; font-size: 1.05rem; }
.station-list td { padding: 6px 4px; }
@media print {
  .top, .bottom, .noprint, .flash { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .card, .table-wrap { border-color: #999; }
  .station-list { break-inside: avoid; }
}

/* діаграма категорій */
.bar-row { margin-bottom: 10px; }
.bar-label { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; }
.bar { height: 8px; background: var(--gray-bg); border-radius: 99px; overflow: hidden; margin-top: 3px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

@media (max-width: 600px) {
  main { padding: 12px; }
  .top nav { gap: 12px; font-size: .9rem; }
  .card { padding: 14px; }
}
.filled-by { background: #fff7ed; border: 1px solid #fed7aa; border-radius: 10px; padding: 10px 12px; font-weight: 600; }
.filled-by input { margin-top: 6px; font-weight: 400; background: #fff; }
.shared-box { align-items: flex-start; margin-top: 12px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 10px; }
.photo-label.need { color: var(--red, #b91c1c); outline: 2px solid #fca5a5; border-radius: 8px; padding: 6px; }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.flash.shake { animation: shake .3s 2; }
/* фото з телефона через QR-код */
.pp { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0 12px; }
.pp-thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.pp-thumbs .thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 2px solid var(--green, #16a34a); }
.pp-modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.pp-modal[hidden] { display: none; }
.pp-box { background: #fff; border-radius: 16px; padding: 20px; max-width: 360px; width: 100%; text-align: center; }
.pp-box h2 { margin-top: 0; }
.pp-qr svg { width: 240px; height: 240px; max-width: 100%; }
.pp-status { font-weight: 600; }
.phone-up { text-align: center; }
.phone-what { font-size: 1.1rem; }
.file-btn { cursor: pointer; margin-top: 10px; }
.file-btn input[type=file] { display: none !important; }
.tg-qr { text-align: center; } .tg-qr svg { width: 200px; height: 200px; }
.steps li { margin-bottom: 6px; }
