/* Сайт учёта — один интерфейс для компьютера и телефона. Шрифт системный: внешних CDN нет. */
:root {
  --ink: #15171C; --ink2: #3F4553; --muted: #5B6170; --line: #E4E7EC; --line2: #EEF0F3; --bg: #F5F6F8;
  --head: #F1F3F6; --blue: #2650C8; --blue-d: #1A3A99; --blue-bg: #E8EEFC; --red: #B42318; --red-bg: #FDECEA;
  --amber: #7A4A00; --amber-bg: #FFF4D6; --green: #116B3A; --green-bg: #E5F5EC; --radius: 12px;
  --font: Inter, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-text-size-adjust: 100%; }
body.modal-open { overflow: hidden; }
a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-d); text-decoration: underline; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.strong { font-weight: 600; }
.muted { color: var(--muted); }
.text-red { color: var(--red); }
.r { text-align: right; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; }
.h1 { margin: 0; font-size: 22px; font-weight: 650; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.h2 { margin: 0; font-size: 16px; font-weight: 600; }
.stack > * + * { margin-top: 12px; }

/* каркас */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 248px; flex: none; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; align-self: flex-start; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; padding: 18px 20px; }
.brand-lg { padding: 0 0 8px; font-size: 18px; }
.brand-logo { width: 28px; height: 28px; border-radius: 8px; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 700; }
.nav { flex: 1; overflow: auto; padding: 4px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px; border-radius: 8px; color: var(--ink2); font-weight: 500; }
.nav-item:hover { background: var(--bg); text-decoration: none; color: var(--ink); }
.nav-on, .nav-on:hover { background: var(--blue-bg); color: #1F43A8; font-weight: 600; }
.nav-sep { margin: 14px 12px 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
.me { border-top: 1px solid var(--line); padding: 14px 16px; display: flex; align-items: center; gap: 10px; }
.me-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.me-text b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text small { color: var(--muted); font-size: 12px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--blue-bg); color: #1F43A8; display: grid; place-items: center; font-weight: 600; font-size: 12px; }
.main { flex: 1; min-width: 0; }
.page { padding: 24px 32px 48px; max-width: 1400px; }
.page-form { max-width: 960px; }
.page > * + * { margin-top: 16px; }
.page-head { display: flex; flex-direction: column; gap: 6px; }
.crumbs { font-size: 13px; color: var(--muted); }
.page-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.title-badge { display: inline-flex; }
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.tabbar, .sheet-back { display: none; }

/* элементы */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid #D6DAE1; background: #fff; color: var(--ink); font: 500 14px var(--font); cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: #B8BFCB; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-d); border-color: var(--blue-d); }
.btn-danger { color: var(--red); border-color: #F1B8B2; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; color: var(--blue); font: inherit; cursor: pointer; }
.icon-btn { width: 32px; height: 32px; border: 0; background: none; border-radius: 6px; font-size: 20px; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--line2); color: var(--ink2); }
.badge-blue { background: var(--blue-bg); color: #1F43A8; }
.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-grey { background: #ECEDEF; color: #5B6170; }
.tag { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 4px; background: var(--line2); font-size: 11px; color: var(--ink2); }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line2); flex-wrap: wrap; }
.card-actions { display: flex; gap: 8px; align-items: center; }
.card-body { padding: 16px 18px; }
.note { padding: 12px 14px; border-radius: 8px; font-size: 13px; line-height: 1.5; background: var(--blue-bg); color: #1F2F5C; }
.note-warn { background: var(--amber-bg); color: var(--amber); }
.note-error { background: var(--red-bg); color: var(--red); }
.note-ok { background: var(--green-bg); color: var(--green); }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.loading { padding: 24px; color: var(--muted); display: flex; gap: 8px; align-items: center; }

/* поля */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: 13px; font-weight: 500; color: var(--ink2); }
.req { color: var(--red); }
.field-msg { font-size: 12px; color: var(--red); }
.input { height: 40px; width: 100%; border: 1px solid #D6DAE1; border-radius: 8px; padding: 0 12px; font: 400 14px var(--font); color: var(--ink); background: #fff; }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px rgba(38, 80, 200, .15); }
.input-invalid, .field-error .input { border-color: var(--red); }
.input-sm { height: 32px; width: auto; padding: 0 8px; }
.input-auto { width: auto; margin-top: 12px; }
.num-input { text-align: right; font-variant-numeric: tabular-nums; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.radio-row { display: flex; gap: 20px; flex-wrap: wrap; }
.radio-row label { display: flex; gap: 6px; align-items: center; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.span2 { grid-column: span 2; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.subform { border: 1px dashed #C9CED8; border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.subform-title { font-weight: 600; }
.picked { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 8px 12px; }
.combo { position: relative; }
.combo-list { position: absolute; z-index: 20; left: 0; right: 0; top: 44px; margin: 0; padding: 4px; list-style: none; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(16, 24, 40, .12); max-height: 320px; overflow: auto; }
.combo-list button { width: 100%; display: flex; gap: 10px; align-items: center; justify-content: space-between; text-align: left; padding: 9px 10px; border: 0; background: none; border-radius: 6px; font: inherit; cursor: pointer; }
.combo-list button:hover { background: var(--bg); }
.combo-new { color: var(--blue); font-weight: 500; }
.combo-info { padding: 9px 10px; color: var(--muted); font-size: 13px; }

/* распределение */
.dist { display: flex; flex-direction: column; gap: 8px; }
.dist-row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(140px, 220px) 32px; gap: 10px; align-items: center; }
.dist-name { font-weight: 500; }
.dist-hint { grid-column: 2 / 4; margin-top: -4px; }
.dist-total { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 16px; }

/* таблицы */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { font-weight: 500; font-size: 12px; color: var(--muted); text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--head); white-space: nowrap; position: sticky; top: 0; }
.tbl th.r { text-align: right; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line2); vertical-align: top; white-space: nowrap; }
.tbl-mid td { vertical-align: middle; }
.toolbar .input-auto { margin-top: 0; }
.tbl td.wrap { white-space: normal; min-width: 140px; }
.tbl th { padding-left: 12px; padding-right: 12px; }
.tbl tbody tr:hover td { background: #FAFBFD; }
.tbl tbody tr[onclick], .tbl-cards tbody tr { cursor: pointer; }
.tbl tfoot td { font-weight: 600; background: #F7F8FA; border-top: 1px solid var(--line); }
.tbl .chk { width: 36px; }
.row-sel td { background: #F2F6FF !important; }
.group-row td { background: #F7F8FA; font-weight: 500; cursor: default; }
.list-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.pager { display: flex; align-items: center; gap: 12px; }

/* списки и фильтры */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { height: 40px; padding: 0 14px; border: 0; background: none; border-bottom: 2px solid transparent; font: 500 14px var(--font); color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab-on { color: var(--blue); border-bottom-color: var(--blue); }
.toolbar { display: flex; gap: 8px; }
.search { max-width: 420px; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; align-items: end; }
.selbar { position: sticky; top: 8px; z-index: 5; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: #1F2937; color: #fff; padding: 8px 12px; border-radius: 10px; }
.selbar .btn-ghost { color: #fff; }

/* главная */
.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.counters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.counter { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; color: var(--ink); }
.counter:hover { text-decoration: none; border-color: #C9D3EE; }
.counter-label { font-size: 13px; color: var(--muted); }
.counter-value { font-size: 24px; font-weight: 650; }
.counter-sub { font-size: 13px; color: var(--ink2); }
.counter-warn .counter-sub { color: var(--amber); font-weight: 500; }
.section-title { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-top: 24px !important; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-card { align-items: start; }
.control-total { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.big { font-size: 22px; font-weight: 650; }
.kv { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.kv > div { display: flex; justify-content: space-between; gap: 12px; }
.kv dt { color: var(--ink2); }
.kv dd { margin: 0; text-align: right; }
.kv-wide > div { justify-content: flex-start; }
.kv-wide dt { width: 150px; flex: none; color: var(--muted); }
.kv-wide dd { text-align: left; }
.recent, .history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.history li { border-left: 2px solid var(--line); padding-left: 10px; }
.calc-head { display: flex; gap: 24px; flex-wrap: wrap; }
.shares { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.shares > div { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.shares b { font-size: 18px; }

/* реестры и передачи */
.ship-counters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--ink2); }
.ship { display: inline-block; margin-top: 2px; font-size: 11px; font-weight: 500; padding: 0 6px; border-radius: 4px; }
.ship-none { background: var(--red-bg); color: var(--red); }
.ship-plan { background: var(--amber-bg); color: var(--amber); }
.ship-ok { background: var(--green-bg); color: var(--green); }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 18px; border-bottom: 1px solid var(--line2); }
.list > li:last-child { border-bottom: 0; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.sub-list { margin-top: 8px; padding: 8px 12px; background: var(--bg); border-radius: 8px; display: flex; flex-direction: column; gap: 6px; }
.control-line { display: flex; gap: 24px; flex-wrap: wrap; }
.pick-list { max-height: 50vh; overflow: auto; }

/* отчёты */
.report-bar { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.report-bar .tabs { border-bottom: 0; }
.filters-toggle { font-size: 16px; font-weight: 600; color: var(--ink); }
.hide-pd { padding-bottom: 10px; font-weight: 500; }
.input-multi { height: 96px; padding: 4px; }
.print-doc { padding: 20px 22px; }
.print-doc > * + * { margin-top: 14px; }
.doc-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.doc-title { text-align: center; font-size: 20px; margin: 4px 0 0; }
.doc-tbl { font-size: 13px; }
.doc-tbl td, .doc-tbl th { padding: 6px 8px; border: 1px solid #D6DAE1; }
.doc-grand { margin-left: auto; max-width: 360px; border: 1px solid var(--line); border-radius: 8px; }
.doc-grand > div { display: flex; justify-content: space-between; padding: 6px 12px; border-bottom: 1px solid var(--line2); }
.doc-grand > div:last-child { border-bottom: 0; }
.doc-sign { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; padding-top: 18px; }
.card-preview { width: 100%; border: 1px solid var(--line); border-radius: 8px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; margin-bottom: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 110px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { display: flex; height: 18px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-seg { display: block; height: 100%; }
.bar-value { text-align: right; }

/* окна и уведомления */
.modal-back { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 24px 48px rgba(16, 24, 40, .2); }
.modal-wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line2); }
.modal-x { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 20px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line2); }
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; width: min(520px, calc(100vw - 24px)); }
.toast { display: flex; gap: 12px; align-items: center; background: #1F2937; color: #fff; padding: 12px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(16, 24, 40, .25); }
.toast span { flex: 1; }
.toast a { color: #A9C1FF; font-weight: 500; }
.toast-error { background: var(--red); }
.toast-x { border: 0; background: none; color: inherit; font-size: 20px; cursor: pointer; }

/* вход */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 380px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }

/* ───────────── телефон ───────────── */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .page { padding: 16px 14px calc(88px + env(safe-area-inset-bottom)); }
  .h1 { font-size: 19px; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 58px; font: 500 11px var(--font); color: var(--muted); background: none; border: 0; cursor: pointer; }
  .tabbar-item:hover { text-decoration: none; }
  .tabbar-on { color: var(--blue); }
  .sheet-back { display: block; position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 45; }
  .sheet { position: absolute; left: 0; right: 0; bottom: 0; background: #fff; border-radius: 16px 16px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 2px; }
  .sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: #D6DAE1; margin: 4px auto 10px; }
  .sheet-item { display: flex; align-items: center; gap: 14px; height: 48px; padding: 0 8px; color: var(--ink); font-weight: 500; border-radius: 8px; }
  .sheet-me { margin: 10px 8px; color: var(--muted); font-size: 13px; }
  .counters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2, .form-grid, .shares { grid-template-columns: minmax(0, 1fr); }
  .card { min-width: 0; }
  .kv-wide dd { overflow-wrap: anywhere; }
  .span2 { grid-column: auto; }
  .quick .btn { flex: 1 1 100%; height: 48px; }
  .toolbar { flex-wrap: wrap; }
  .search { max-width: none; flex: 1; }
  .btn { height: 44px; }
  .btn-sm { height: 36px; }
  .input { height: 44px; font-size: 16px; } /* 16px — чтобы iPhone не увеличивал страницу */
  .form-actions { position: sticky; bottom: calc(66px + env(safe-area-inset-bottom)); background: var(--bg); padding: 8px 0; }
  .form-actions .btn { flex: 1; }
  .selbar { position: fixed; left: 8px; right: 8px; top: auto; bottom: calc(66px + env(safe-area-inset-bottom)); z-index: 41; }
  .kv-wide > div { flex-direction: column; gap: 0; }
  .kv-wide dt { width: auto; font-size: 12px; }
  .toasts { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .modal-back { place-items: end stretch; padding: 0; }
  .modal { max-width: none; border-radius: 16px 16px 0 0; max-height: 92vh; }
  /* таблицы → карточки */
  .tbl-cards thead { display: none; }
  .tbl-cards, .tbl-cards tbody, .tbl-cards tfoot { display: block; }
  .tbl-cards tr { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; padding: 12px 14px; border-bottom: 1px solid var(--line2); }
  .tbl-cards td { display: flex; flex-direction: column; padding: 2px 0; border: 0; text-align: left !important; white-space: normal; }
  .tbl-cards td[data-label]::before { content: attr(data-label); font-size: 11px; color: var(--muted); font-weight: 400; }
  .tbl-cards tr { position: relative; }
  .tbl-cards td.chk { position: absolute; right: 10px; top: 8px; padding: 6px; }
  .tbl-cards td.chk input { width: 22px; height: 22px; }
  .tbl-cards td { align-items: flex-start; }
  .tbl-cards td:empty { display: none; }
  .tbl-cards .group-row { display: block; }
  .tbl-cards tfoot tr { background: #F7F8FA; }
  .dist-row { grid-template-columns: 1fr minmax(120px, 46%) 32px; }
  .bar-row { grid-template-columns: 90px 1fr 80px; font-size: 12px; }
  .print-doc { padding: 12px; }
}
@media print {
  .sidebar, .tabbar, .page-actions, .toasts, .quick { display: none !important; }
  body { background: #fff; }
  .page:has(.print-doc) > :not(.print-doc) { display: none !important; }
  .page { padding: 0; max-width: none; }
  .print-doc { border: 0; padding: 0; }
  .doc-tbl { font-size: 10px; }
  .ship { padding: 0; background: none !important; }
}
