:root {
  --bg: #f3f5f2;
  --card: #ffffff;
  --ink: #1d2420;
  --muted: #66716a;
  --line: #dfe4df;
  --wire: #b9c3bb;
  --accent: #2f6b3f;
  --accent-ink: #ffffff;
  --accent-soft: #e5f0e7;
  --alt: #2c5d86;
  --move: #d9480f;
  --move-soft: #fff0e8;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --bad: #b3261e;
  --bad-soft: #fde8e6;
  --radius: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--alt); }
h1 { font-size: 1.4rem; margin: .4rem 0 .8rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: .8rem; margin: 1rem 0 .4rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; display: flex; align-items: center; gap: .35rem; }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.wrap { max-width: 960px; margin: 0 auto; padding: 1rem; padding-bottom: 5rem; }
.ico { width: 1.15em; height: 1.15em; vertical-align: -.2em; flex-shrink: 0; }
.ico.big { width: 1.6em; height: 1.6em; }

/* header */
.top { background: var(--accent); color: var(--accent-ink); position: sticky; top: 0; z-index: 10; }
.top a { color: inherit; text-decoration: none; }
.top-row { max-width: 960px; margin: 0 auto; padding: .6rem 1rem .2rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.brand { font-weight: 700; }
.who { display: flex; align-items: center; gap: .8rem; font-size: .9rem; }
.who form { margin: 0; }
.linkbtn { background: none; border: 0; color: inherit; font: inherit; cursor: pointer; opacity: .85; padding: 0; text-decoration: underline; }
.nav { max-width: 960px; margin: 0 auto; padding: 0 .5rem; display: flex; overflow-x: auto; scrollbar-width: none; }
.nav a { padding: .5rem .55rem .6rem; white-space: nowrap; opacity: .8; border-bottom: 3px solid transparent; font-size: .95rem; }
.nav a.on { opacity: 1; border-color: #fff; font-weight: 600; }

/* auth */
body.auth { display: grid; place-items: center; min-height: 100vh; }
body.auth .wrap { width: 100%; max-width: 380px; padding-bottom: 1rem; }
.auth-box { background: var(--card); border-radius: var(--radius); padding: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.auth-box h1 { margin-top: 0; }

/* cards & rows */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card.attention { border-color: #e0b54d; background: #fffbef; }
details.card > summary { cursor: pointer; }
.rows { display: flex; flex-direction: column; }
.rows.card { padding: 0 1rem; }
.row { display: flex; gap: .8rem; justify-content: space-between; align-items: center; padding: .7rem 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.row:last-child { border-bottom: 0; }
.row-main { min-width: 0; }
.row-title { font-size: .95rem; }
.row-sub { font-size: .85rem; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; text-align: right; flex-shrink: 0; }
.row-side small { color: var(--muted); white-space: nowrap; }

/* badges */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; background: #eceeec; color: var(--muted); white-space: nowrap; }
.st-in_transit { background: var(--move-soft); color: var(--move); }
.rq-in_work { background: var(--warn-soft); color: var(--warn); }
.st-received, .rq-done { background: var(--accent-soft); color: var(--accent); }
.st-short, .rq-rejected { background: var(--bad-soft); color: var(--bad); }
.rq-open { background: #e4eef8; color: var(--alt); }
.kind { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.st-pending { background: var(--warn-soft); color: var(--warn); }
.k-adjust { color: #6b4fa0; }
.alert.wo { background: var(--warn-soft); border-color: #e6c27a; }
.alert.wo .alert-head { color: var(--warn); }
.wo-row { padding: .55rem 0; border-top: 1px solid rgba(0,0,0,.07); }
.wo-row .ilist { margin: .2rem 0 .4rem; }
.wo-actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.wo-actions form { margin: 0; display: flex; gap: .4rem; flex-wrap: wrap; flex: 1; }
.wo-actions input { flex: 1 1 140px; width: auto; padding: .4rem .6rem; font-size: .9rem; }
.obs .cnt { background: var(--warn); color: #fff; border-radius: 99px; font-size: .72rem; font-weight: 700; padding: 0 .4rem; }
.k-send { color: var(--alt); } .k-intake { color: var(--accent); } .k-writeoff { color: var(--bad); }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); padding: .65rem 1.1rem; border-radius: 10px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.btn.alt { background: var(--alt); border-color: var(--alt); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.danger { color: var(--bad); }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn.wide { width: 100%; margin: .5rem 0 1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; font-weight: 600; font-size: .95rem; }
.field small { font-weight: 400; color: var(--muted); }
input, select, textarea { font: inherit; padding: .6rem .7rem; border: 1px solid #c9d0ca; border-radius: 9px; background: #fff; color: var(--ink); width: 100%; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: flex; align-items: center; gap: .4rem; font-weight: 400; }
.check input { width: auto; }
.inline { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.inline > input, .inline > select { flex: 1 1 160px; width: auto; }
.flash { padding: .7rem .9rem; border-radius: 10px; margin-bottom: .9rem; background: var(--accent-soft); color: var(--accent); }
.flash.err { background: var(--bad-soft); color: var(--bad); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.flash.info { background: #e4eef8; color: var(--alt); }
.tabs { display: flex; gap: .4rem; margin-bottom: .8rem; }
.tabs a { padding: .4rem .9rem; border-radius: 99px; background: var(--card); border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: .9rem; }
.tabs a.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* segmented tabs: Дроны / Комплектующие */
.seg { display: flex; background: #e6eae6; border-radius: 12px; padding: 4px; gap: 4px; margin: .3rem 0 .8rem; }
.seg-btn { flex: 1; border: 0; background: transparent; padding: .65rem .5rem; border-radius: 9px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg-btn.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg-count:not(:empty) { display: inline-block; min-width: 1.4em; padding: 0 .35em; border-radius: 99px; background: var(--accent); color: #fff; font-size: .75rem; margin-left: .2rem; }

/* photos */
.thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: #eef1ee; flex-shrink: 0; }
.thumb.sm { width: 36px; height: 36px; }
.thumb.xs { width: 30px; height: 30px; border-radius: 6px; }
.nophoto { display: inline-grid; place-items: center; font-size: .58rem; color: var(--muted); text-align: center; line-height: 1.1; }
.thumb.xs.nophoto { font-size: 0; }

/* alerts on home */
.alert { border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: .8rem; border: 1px solid; }
.alert.in { background: var(--move-soft); border-color: #f3b896; color: var(--ink); }
.alert.in .alert-head { color: var(--move); }
.alert.note { background: #fffbea; border-color: #ecd98a; }
.alert.req { background: #eef4fb; border-color: #bcd2ea; }
.alert-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .3rem; }
.alert-head form { margin: 0 0 0 auto; font-size: .85rem; }
.alert-row { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .45rem 0; border-top: 1px solid rgba(0,0,0,.07); color: inherit; text-decoration: none; font-size: .92rem; }
.note-row { padding: .35rem 0; font-size: .92rem; border-top: 1px solid rgba(0,0,0,.06); }

/* ===== СХЕМА ===== */
.scheme { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem .4rem .6rem; margin-bottom: 1rem; overflow-x: auto; }
.observers { display: flex; justify-content: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.obs { display: inline-flex; align-items: center; gap: .4rem; border: 1px dashed #9aa79d; background: #f7f8f7; border-radius: 99px; padding: .35rem .9rem; font: inherit; font-size: .88rem; color: var(--ink); cursor: pointer; }
.obs .ico { color: var(--alt); }
.org { margin: 0 auto; width: max-content; padding: .35rem 1rem; border-radius: 99px; background: #e9ece9; color: var(--muted); font-size: .85rem; font-weight: 600; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; display: flex; justify-content: center; }
.tree li { position: relative; display: flex; flex-direction: column; align-items: center; padding: 0 3px; flex: 1 1 0; min-width: 80px; }
.tree ul > li::before, .tree ul > li::after { content: ""; position: absolute; top: 0; width: 50%; border-top: 2px solid var(--wire); }
.tree ul > li::before { left: 0; }
.tree ul > li::after { right: 0; }
.tree ul > li:first-child::before, .tree ul > li:last-child::after { display: none; }
.stem { width: 2px; height: 16px; background: var(--wire); }
.edge { position: relative; width: 2px; height: 46px; background: var(--wire); margin-bottom: 7px; }
.edge::after { content: ""; position: absolute; bottom: -7px; left: 50%; transform: translateX(-50%); border: 6px solid transparent; border-top: 7px solid var(--wire); border-bottom: 0; }
.edge.moving { width: 3px; background: repeating-linear-gradient(to bottom, var(--move) 0 6px, transparent 6px 11px); background-size: 3px 11px; animation: flow .7s linear infinite; }
.edge.moving::after { border-top-color: var(--move); }
@keyframes flow { to { background-position: 0 11px; } }
.truck { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2; display: inline-flex; align-items: center; gap: .25rem; background: var(--move); color: #fff; border: 2px solid #fff; border-radius: 99px; padding: .15rem .5rem; font: inherit; font-size: .8rem; cursor: pointer; box-shadow: 0 2px 6px rgba(217,72,15,.35); white-space: nowrap; }
.truck .ico { animation: bob 1.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-1.5px); } }
.node { position: relative; width: 100%; max-width: 160px; display: flex; flex-direction: column; align-items: center; gap: .05rem; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: .5rem .3rem .45rem; font: inherit; color: var(--ink); cursor: pointer; transition: transform .1s, box-shadow .1s; }
.node:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(0,0,0,.08); }
.node.me { border-color: var(--accent); background: var(--accent-soft); }
.node.has-in { border-color: var(--move); box-shadow: 0 0 0 3px rgba(217,72,15,.12); }
.n-name { font-weight: 700; font-size: clamp(.8rem, 3.5vw, .95rem); line-height: 1.15; overflow-wrap: normal; word-break: normal; white-space: nowrap; }
.tree li li li .node, .tree ul ul ul .node { padding-left: .15rem; padding-right: .15rem; }
.n-pos { font-size: .68rem; color: var(--muted); line-height: 1.1; }
.n-org { font-size: .62rem; font-weight: 700; color: var(--muted); background: #e9ece9; border-radius: 99px; padding: 0 .4rem; margin: .1rem 0; }
.n-qty { font-size: .8rem; font-weight: 600; color: var(--accent); }
.n-flags { display: flex; gap: .2rem; flex-wrap: wrap; justify-content: center; margin-top: .1rem; }
.flag { font-size: .65rem; font-weight: 700; padding: 0 .35rem; border-radius: 99px; }
.flag.req { background: #e4eef8; color: var(--alt); }
.flag.note { background: #fff1c2; color: #7a5a00; }
.n-me { position: absolute; top: -9px; right: -4px; background: var(--accent); color: #fff; font-size: .62rem; font-weight: 700; padding: 0 .4rem; border-radius: 99px; }
.hint { text-align: center; color: var(--muted); font-size: .8rem; margin: .9rem .5rem 0; }

/* bottom sheet / dialog */
dialog.sheet { border: 0; padding: 1rem 1.1rem 1.4rem; border-radius: 16px; width: min(560px, calc(100vw - 1.5rem)); max-height: 85vh; overflow: auto; color: var(--ink); }
dialog.sheet::backdrop { background: rgba(20, 30, 25, .45); }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: .6rem; position: sticky; top: -1rem; background: #fff; padding-top: .2rem; z-index: 1; }
.sheet-name { font-size: 1.25rem; }
.x { border: 0; background: #eef0ee; width: 2.2rem; height: 2.2rem; border-radius: 99px; font-size: 1.4rem; line-height: 1; cursor: pointer; flex-shrink: 0; }
.sheet-actions { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .4rem; }
.sheet-actions .btn { width: 100%; padding: .8rem; }
.sheet h3 .ico { color: var(--move); width: 1.4em; height: 1.4em; }
.ship { border: 1px solid var(--line); border-radius: 10px; padding: .5rem .7rem; margin-bottom: .5rem; }
.ship > summary { cursor: pointer; font-size: .92rem; }
.ship .btn { margin-top: .4rem; }
.ilist { list-style: none; margin: .3rem 0; padding: 0; }
.ilist li { display: flex; align-items: center; gap: .55rem; padding: .3rem 0; border-bottom: 1px dashed var(--line); font-size: .92rem; }
.ilist li:last-child { border-bottom: 0; }
.ilist li > span:not(.thumb) { flex: 1; min-width: 0; }
.ilist li small { display: block; color: var(--muted); font-size: .74rem; }
.note-form { display: flex; flex-direction: column; gap: .4rem; margin-top: 1rem; align-items: flex-start; }
@media (max-width: 560px) {
  dialog.sheet { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 88vh; }
}

/* tables */
.tablewrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; margin-top: .5rem; }
.tbl th { text-align: left; font-size: .76rem; color: var(--muted); font-weight: 600; padding: .4rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: .45rem .4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bad { color: var(--bad); font-weight: 700; }
.cell-item { display: flex; align-items: center; gap: .5rem; }
.cell-item small { display: block; color: var(--muted); font-size: .76rem; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0 0 .8rem; font-size: .92rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.route { font-size: 1.05rem; margin: 0 0 .6rem; }

/* item picker */
.pick-list { display: flex; flex-direction: column; gap: .4rem; }
.pick { display: flex; align-items: center; gap: .7rem; padding: .5rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.pick.has { border-color: var(--accent); background: #f4faf5; }
.pick-name { flex: 1; min-width: 0; }
.pick-name small { display: block; color: var(--muted); font-size: .78rem; }
.stepper { display: flex; align-items: center; gap: .2rem; flex-shrink: 0; }
.stepper input { width: 3.8rem; text-align: center; padding: .5rem .2rem; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.step { width: 2.3rem; height: 2.3rem; border-radius: 8px; border: 1px solid var(--line); background: #f5f7f5; font-size: 1.2rem; cursor: pointer; color: var(--ink); }
.sticky-bar { position: sticky; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .7rem 1rem; margin: 0 -1rem; background: rgba(243,245,242,.96); backdrop-filter: blur(6px); border-top: 1px solid var(--line); }
.sticky-bar [data-total] { font-size: .9rem; color: var(--muted); }

/* catalog */
.catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .6rem; margin-bottom: .6rem; }
.cat-item { display: flex; gap: .7rem; border: 1px solid var(--line); border-radius: 10px; padding: .6rem; }
.cat-photo { width: 84px; height: 84px; border-radius: 8px; object-fit: cover; background: #eef1ee; flex-shrink: 0; }
.cat-body p { margin: .2rem 0; color: var(--muted); }
.cat-title { display: flex; gap: .5rem; margin-bottom: .7rem; }
.cat-title input { font-size: 1.1rem; font-weight: 700; flex: 1; }
.slot { display: flex; gap: .6rem; border: 1px solid var(--line); border-radius: 10px; padding: .55rem; scroll-margin-top: 7rem; }
.slot.empty { border-style: dashed; background: #fafbfa; }
.slot:target { outline: 2px solid var(--accent); }
.slot-photo { position: relative; cursor: pointer; flex-shrink: 0; }
.slot-photo-hint { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.55); color: #fff; font-size: .65rem; text-align: center; border-radius: 0 0 8px 8px; padding: .1rem 0; }
.slot-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .35rem; }
.slot-body input { padding: .45rem .6rem; }
.slot-foot { display: flex; justify-content: space-between; align-items: center; gap: .4rem; flex-wrap: wrap; }
.slot-foot .btn { margin-left: auto; }

/* users */
.user { padding: .8rem 0; border-bottom: 1px solid var(--line); }
.user:last-child { border-bottom: 0; }
.user.off { opacity: .55; }
.user-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem; margin-bottom: .5rem; }
.user-grid label { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; color: var(--muted); }
.user-grid label[hidden] { display: none; }
.user-grid input, .user-grid select { padding: .45rem .55rem; font-size: .92rem; }
.user-foot { display: flex; justify-content: space-between; align-items: center; }

/* notes */
.note-item { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.note-item:last-child { border-bottom: 0; }
.note-item.new { background: #fffbea; margin: 0 -1rem; padding: .6rem 1rem; }
.note-meta { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; font-size: .9rem; }
.note-meta form { margin: 0 0 0 auto; }
.note-meta .linkbtn { color: var(--bad); }

@media (max-width: 560px) {
  .wrap { padding: .8rem; padding-bottom: 5rem; }
  .scheme { margin-left: -.3rem; margin-right: -.3rem; }
  .thumb { width: 48px; height: 48px; }
  .tbl { font-size: .85rem; }
}
