:root {
  --bg: #f4f2ec; --card: #ffffff; --ink: #1b2420; --muted: #6b756f; --line: #e7e3d8; --soft: #efece3;
  --brand: #1f7a4d; --brand-2: #17613c; --brand-ink: #ffffff; --brand-soft: #e3f1e9;
  --amber: #e9a31b; --amber-soft: #fbf0d3; --red: #d64545; --red-soft: #fbe5e3; --blue: #2f6fdb; --blue-soft: #e3ecfb; --gray-soft: #ecebe6;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 14px rgba(20, 30, 25, .06);
  --r: 16px; --tab-h: 64px;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #0e1411; --card: #17201b; --ink: #edf2ee; --muted: #93a39a; --line: #25312a; --soft: #1e2923; --brand: #34b277; --brand-2: #2a9663; --brand-ink: #06130c; --brand-soft: #173326; --amber: #f0b43b; --amber-soft: #3a2f12; --red: #ee6b66; --red-soft: #3a1c1a; --blue: #6ea0f5; --blue-soft: #1a2740; --gray-soft: #222b26; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35); }
}
:root[data-theme="dark"] { --bg: #0e1411; --card: #17201b; --ink: #edf2ee; --muted: #93a39a; --line: #25312a; --soft: #1e2923; --brand: #34b277; --brand-2: #2a9663; --brand-ink: #06130c; --brand-soft: #173326; --amber: #f0b43b; --amber-soft: #3a2f12; --red: #ee6b66; --red-soft: #3a1c1a; --blue: #6ea0f5; --blue-soft: #1a2740; --gray-soft: #222b26; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
body.noscroll { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.s { width: 18px; height: 18px; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; background: var(--bg); }
#top { padding: calc(var(--sat) + 10px) 16px 8px; display: flex; align-items: center; gap: 10px; min-height: 52px; }
#top h1 { font-size: 26px; line-height: 1.1; margin: 0; letter-spacing: -.02em; flex: 1; }
#top .sub { font-size: 13px; color: var(--muted); font-weight: 500; }
#main { flex: 1; position: relative; min-height: 0; }
.view { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px calc(var(--tab-h) + var(--sab) + 24px); display: none; }
.view.on { display: block; }
#v-map.view { padding: 0; overflow: hidden; }

#tabbar { display: flex; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 6px 4px calc(var(--sab) + 4px); position: relative; z-index: 20; }
#tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; color: var(--muted); font-size: 11px; font-weight: 600; position: relative; border-radius: 12px; }
#tabbar button.on { color: var(--brand); }
#tabbar .badge { position: absolute; top: 0; left: 55%; background: var(--red); color: #fff; border-radius: 10px; font-size: 10px; min-width: 18px; height: 18px; line-height: 18px; padding: 0 5px; text-align: center; font-weight: 700; }

/* карточки и элементы */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; margin: 0 0 10px; }
.h2 { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 20px 4px 8px; display: flex; align-items: center; gap: 8px; }
.h2 .n { background: var(--soft); color: var(--ink); border-radius: 10px; padding: 1px 8px; font-size: 12px; }
.h2.red { color: var(--red); } .h2.amber { color: #b57d0a; } @media (prefers-color-scheme: dark) { .h2.amber { color: var(--amber); } }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 12px; } .b { font-weight: 700; } .center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; } .grow { flex: 1; min-width: 0; } .wrap { flex-wrap: wrap; } .gap6 { gap: 6px; }
.ell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pre { white-space: pre-wrap; word-break: break-word; }

.contact { display: flex; gap: 12px; align-items: center; padding: 12px; cursor: pointer; }
.contact:active { transform: scale(.992); }
.av { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-weight: 800; font-size: 18px; flex: none; position: relative; }
.av.supplier { background: var(--brand-soft); color: var(--brand); } .av.buyer { background: var(--blue-soft); color: var(--blue); }
.av .st { position: absolute; right: -4px; bottom: -4px; background: var(--card); border-radius: 8px; font-size: 9px; letter-spacing: -1px; color: var(--amber); padding: 0 2px; line-height: 12px; box-shadow: 0 0 0 1px var(--line); }
.cname { font-weight: 700; font-size: 16px; }
.cmeta { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.cnote { font-size: 13px; color: var(--muted); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.acts { display: flex; flex-direction: column; gap: 8px; }
.rb { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: var(--brand-ink); flex: none; box-shadow: 0 2px 6px rgba(31, 122, 77, .35); }
.rb.alt { background: var(--soft); color: var(--ink); box-shadow: none; }
.rb:active { transform: scale(.94); }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--gray-soft); color: var(--muted); white-space: nowrap; }
.pill.g-new { background: var(--blue-soft); color: var(--blue); } .pill.g-retry { background: var(--amber-soft); color: #9a6a05; } .pill.g-active { background: var(--brand-soft); color: var(--brand); } .pill.g-lost { background: var(--red-soft); color: var(--red); }
@media (prefers-color-scheme: dark) { .pill.g-retry { color: var(--amber); } }
.pill.red { background: var(--red-soft); color: var(--red); } .pill.amber { background: var(--amber-soft); color: #9a6a05; } .pill.green { background: var(--brand-soft); color: var(--brand); } .pill.blue { background: var(--blue-soft); color: var(--blue); }
.late { color: var(--red); font-weight: 600; }

.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; gap: 2px; margin: 4px 0 10px; }
.seg button { flex: 1; padding: 8px 6px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 6px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { padding: 8px 13px; border-radius: 20px; background: var(--card); border: 1.5px solid var(--line); font-size: 14px; font-weight: 600; white-space: nowrap; flex: none; }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chip.on.red { background: var(--red); border-color: var(--red); color: #fff; }
.chip.on.amber { background: var(--amber); border-color: var(--amber); color: #2b1d00; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 18px; border-radius: 14px; font-weight: 700; background: var(--brand); color: var(--brand-ink); min-height: 48px; }
.btn:active { background: var(--brand-2); }
.btn.block { display: flex; width: 100%; } .btn.alt { background: var(--soft); color: var(--ink); } .btn.ghost { background: transparent; color: var(--brand); border: 1.5px solid var(--line); }
.btn.danger { background: var(--red-soft); color: var(--red); } .btn.sm { padding: 8px 12px; min-height: 36px; font-size: 14px; border-radius: 11px; }
.fab { position: absolute; right: 16px; bottom: calc(var(--tab-h) + var(--sab) + 16px); width: 56px; height: 56px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; box-shadow: 0 6px 18px rgba(31, 122, 77, .4); z-index: 5; }
.fab svg { width: 26px; height: 26px; }

.field { display: block; margin: 0 0 12px; }
.field > span { display: block; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 0 2px 5px; }
.in { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); outline: none; min-height: 46px; appearance: none; -webkit-appearance: none; }
.in:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.in { min-height: 90px; resize: vertical; }
select.in { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.search { position: relative; margin: 2px 0 10px; }
.search svg { position: absolute; left: 12px; top: 12px; color: var(--muted); }
.search .in { padding-left: 42px; border-radius: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.kv > div > span { display: block; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; } .kv > div > b { font-size: 15px; }

/* сводка */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0 4px; }
.stat { background: var(--card); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 24px; line-height: 1.1; letter-spacing: -.02em; } .stat span { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat.red b { color: var(--red); } .stat.green b { color: var(--brand); } .stat.amber b { color: #b57d0a; }
.bar { height: 8px; border-radius: 6px; background: var(--soft); overflow: hidden; } .bar > i { display: block; height: 100%; background: var(--brand); border-radius: 6px; }
.banner { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: var(--r); background: var(--amber-soft); margin: 4px 0 10px; font-size: 14px; }
.banner.green { background: var(--brand-soft); } .banner.blue { background: var(--blue-soft); }
.empty { text-align: center; color: var(--muted); padding: 36px 10px; }
.empty .big { font-size: 40px; }
.menu { padding: 0; overflow: hidden; }
.menu button, .menu a { display: flex; align-items: center; gap: 14px; width: 100%; padding: 15px 16px; text-align: left; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; font-weight: 600; }
.menu > :last-child { border-bottom: 0; } .menu svg.i:first-child { color: var(--brand); } .menu .go { margin-left: auto; color: var(--muted); }
.toggle { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 16px; background: var(--line); position: relative; flex: none; transition: .2s; outline: none; }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: .2s; }
.toggle:checked { background: var(--brand); } .toggle:checked::after { left: 23px; }

/* шторки */
#sheets { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.sheet-wrap { position: fixed; inset: 0; pointer-events: auto; display: flex; align-items: flex-end; justify-content: center; }
.backdrop { position: absolute; inset: 0; background: rgba(8, 14, 10, .5); animation: fade .2s; }
.sheet { position: relative; width: 100%; max-width: 760px; max-height: 94vh; max-height: 94dvh; overflow-y: auto; background: var(--bg); border-radius: 22px 22px 0 0; padding: 0 16px calc(var(--sab) + 24px); box-shadow: 0 -10px 40px rgba(0, 0, 0, .25); }
.sheet.fresh { animation: up .26s cubic-bezier(.2, .8, .2, 1); }
.sheet.full { height: 94dvh; }
.sheet-h { position: sticky; top: 0; z-index: 3; background: var(--bg); display: flex; align-items: center; gap: 10px; padding: 14px 0 10px; }
.sheet-h::before { content: ''; position: absolute; top: 6px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 3px; background: var(--line); }
.sheet-h h3 { margin: 6px 0 0; font-size: 19px; flex: 1; min-width: 0; letter-spacing: -.01em; }
.sheet-h .x { width: 36px; height: 36px; border-radius: 50%; background: var(--soft); display: grid; place-items: center; margin-top: 6px; flex: none; }
.sticky-b { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 24%); padding: 20px 0 4px; z-index: 2; }
.sec { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 18px 2px 8px; }
.qa { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.qa button, .qa a { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); font-size: 12px; font-weight: 700; color: var(--ink); text-decoration: none; }
.qa .main { background: var(--brand); color: var(--brand-ink); }
.tl { border-left: 2px solid var(--line); margin-left: 6px; padding-left: 14px; }
.tl > div { position: relative; padding: 0 0 12px; font-size: 14px; } .tl > div::before { content: ''; position: absolute; left: -20px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); border: 2px solid var(--bg); }

@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* карта */
#map { position: absolute; inset: 0; z-index: 1; }
.map-top { position: absolute; z-index: 400; top: calc(var(--sat) + 8px); left: 10px; right: 10px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.map-top > * { pointer-events: auto; }
.map-chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.map-chips .chip { box-shadow: var(--shadow); border-color: transparent; }
.map-card { position: absolute; z-index: 400; left: 10px; right: 10px; bottom: calc(var(--tab-h) + var(--sab) + 10px); background: var(--card); border-radius: 18px; padding: 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .28); }
.map-radius { background: var(--card); border-radius: 14px; padding: 8px 14px; box-shadow: var(--shadow); font-size: 13px; }
.map-radius input { width: 100%; accent-color: var(--brand); }
.leaflet-container { font-family: inherit; background: #d8e2dc; }
.legend { display: flex; gap: 12px; font-size: 12px; font-weight: 600; background: var(--card); padding: 6px 12px; border-radius: 12px; box-shadow: var(--shadow); width: fit-content; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }

/* подбор */
.pair { display: flex; gap: 12px; align-items: center; }
.margin { text-align: right; flex: none; } .margin b { font-size: 18px; display: block; letter-spacing: -.02em; } .margin.pos b { color: var(--brand); } .margin.neg b { color: var(--red); }
.kanban { display: flex; gap: 10px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 8px; scroll-snap-type: x mandatory; }
.kcol { flex: 0 0 82%; max-width: 330px; scroll-snap-align: start; background: var(--soft); border-radius: 16px; padding: 10px; }
.kcol > .kh { font-weight: 800; font-size: 14px; padding: 2px 4px 8px; display: flex; justify-content: space-between; }
.kcol .card { margin-bottom: 8px; padding: 12px; }
.msg { max-width: 82%; padding: 9px 13px; border-radius: 16px; margin: 6px 0; background: var(--card); box-shadow: var(--shadow); width: fit-content; word-break: break-word; }
.msg.me { margin-left: auto; background: var(--brand); color: var(--brand-ink); }
.msg .who { font-size: 11px; font-weight: 700; opacity: .7; margin-bottom: 2px; }
.msg .ref { display: inline-block; background: rgba(0, 0, 0, .1); border-radius: 8px; padding: 2px 8px; font-size: 12px; font-weight: 700; margin-bottom: 4px; }
#toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--sab) + 24px); transform: translate(-50%, 20px); background: #1b2420; color: #fff; padding: 11px 18px; border-radius: 14px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: .25s; z-index: 100; max-width: 90vw; text-align: center; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
.hide { display: none !important; }
@media (min-width: 761px) { body { background: #dfdcd2; } #app { box-shadow: 0 0 40px rgba(0, 0, 0, .15); } }

/* вход и синхронизация */
.auth { position: fixed; inset: 0; z-index: 200; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 20px; overflow-y: auto; }
.auth-box { width: 100%; max-width: 380px; text-align: center; }
.auth-box h2 { margin: 12px 0 6px; font-size: 26px; letter-spacing: -.02em; }
.auth-box .field { text-align: left; }
.syncdot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.syncdot.ok { background: var(--brand); } .syncdot.sync { background: var(--amber); } .syncdot.err { background: var(--red); } .syncdot.offline { background: var(--muted); }

/* чат отдельной вкладкой */
.chatwrap { height: calc(94dvh - 20px); display: flex; flex-direction: column; }
#v-chat.view { padding-bottom: 8px; overflow: hidden; }
#v-chat .chatwrap { height: 100%; }
#tabbar button { font-size: 10.5px; }
#tabbar .badge { left: 52%; }

/* плашки и панели Netlify (видны только тем, кто вошёл в Netlify на этом устройстве) не должны закрывать приложение */
[id*="netlify" i], [class*="netlify" i], iframe[src*="netlify.com" i], netlify-drawer { display: none !important; visibility: hidden !important; pointer-events: none !important; }

/* компьютер: меню слева, окна по центру */
@media (min-width: 900px) {
  :root { --tab-h: 0px; }
  #app { max-width: 1180px; display: grid; grid-template-columns: 96px 1fr; grid-template-rows: auto 1fr; }
  #tabbar { grid-column: 1; grid-row: 1 / span 2; flex-direction: column; justify-content: flex-start; gap: 4px; padding: 16px 6px; border-top: 0; border-right: 1px solid var(--line); }
  #tabbar button { flex: none; padding: 12px 0; }
  #top { grid-column: 2; grid-row: 1; padding-top: 18px; }
  #main { grid-column: 2; grid-row: 2; min-height: 0; }
  .view { padding-left: max(24px, calc((100% - 780px) / 2)); padding-right: max(24px, calc((100% - 780px) / 2)); padding-bottom: 40px; }
  #v-map.view { padding: 0; }
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 22px; max-height: 88vh; max-width: 600px; }
  .chatwrap { height: 80vh; }
}

/* плашка «Powered by Netlify» (бесплатный тариф): оставляем под приложением свободную полосу, чтобы она ничего не закрывала */
body.nlbadge #app { bottom: 64px; }
body.nlbadge .sheet-wrap { bottom: 64px; }
body.nlbadge .backdrop { bottom: 0; }
body.nlbadge #toast { bottom: calc(var(--tab-h) + var(--sab) + 88px); }

.note-f{position:relative}
.mic-btn{position:absolute;right:0;top:-6px;width:40px;height:40px;border-radius:50%;border:0;background:#e5394b;color:#fff;display:grid;place-items:center;box-shadow:0 2px 8px rgba(229,57,75,.4);cursor:pointer}
.mic-btn svg{width:20px;height:20px;stroke:#fff}
.mic-btn.rec{animation:micp 1s infinite}
@keyframes micp{0%{box-shadow:0 0 0 0 rgba(229,57,75,.7)}100%{box-shadow:0 0 0 14px rgba(229,57,75,0)}}

/* компактный список: контакт занимает одну-две строки */
.card.contact.cmp { padding: 7px 10px; margin: 0 0 5px; gap: 10px; border-radius: 12px; }
.cmp .av { width: 34px; height: 34px; border-radius: 10px; font-size: 15px; }
.cmp .av .st { display: none; }
.cmp .cname { font-size: 15px; line-height: 1.2; }
.cmp .cmeta { font-size: 12px; margin-top: 1px; flex-wrap: nowrap; overflow: hidden; white-space: nowrap; }
.cmp .cmeta .pill { padding: 0 6px; font-size: 11px; flex: none; }
.cmp .acts { flex-direction: row; gap: 6px; }
.cmp .acts .rb { width: 34px; height: 34px; }
.cmp .acts .rb svg.i { width: 18px; height: 18px; }
.cmp .cst { color: var(--amber); font-size: 11px; letter-spacing: -1px; flex: none; }

body.notop #top .rb { display: none; }
.drawer { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
.drawer.on { pointer-events: auto; }
.dr-back { position: absolute; inset: 0; background: rgba(8, 14, 10, .5); opacity: 0; transition: opacity .2s; }
.drawer.on .dr-back { opacity: 1; }
.dr-panel { position: absolute; top: 0; bottom: 0; left: 0; width: min(300px, 82vw); background: var(--card); box-shadow: var(--shadow); transform: translateX(-100%); transition: transform .2s; padding: calc(var(--sat) + 14px) 10px 20px; overflow-y: auto; }
.drawer.on .dr-panel { transform: none; }
.dr-head { display: flex; flex-direction: column; padding: 4px 10px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; font-size: 18px; }
.dr-panel > button { display: flex; align-items: center; gap: 14px; width: 100%; padding: 13px 10px; border-radius: 12px; font-weight: 600; text-align: left; }
.dr-panel > button:active { background: var(--soft); }
