:root {
  --navy: #17457f; --navy-2: #0f3463; --blue: #2f8fdb; --blue-soft: #e8f2fc;
  --green: #3fa45b; --green-soft: #e7f6eb; --red: #e5484d; --red-soft: #fdecec;
  --orange: #e8811c; --orange-soft: #fdf1e3; --violet: #7c5cd6; --violet-soft: #f0ebfc;
  --bg: #f3f6fb; --card: #fff; --line: #e3e9f2; --text: #17243a; --muted: #6b7a90;
  --r: 16px; --shadow: 0 1px 2px rgba(20,40,80,.05), 0 4px 16px rgba(20,40,80,.06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
body.noscroll { overflow: hidden; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.green { color: var(--green); } .red { color: var(--red); }

/* ---------- Кнопки и поля ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 46px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line); background: #fff; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--red); border-color: #f5c9ca; }
.btn.danger-fill { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 38px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--bg); }
.icon-btn.del { color: var(--red); }

label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.inp, select.inp, textarea.inp { width: 100%; height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; font-size: 16px; outline: none; }
textarea.inp { height: 84px; padding: 12px 14px; resize: vertical; }
.inp:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47,143,219,.15); }
.inp-unit { position: relative; }
.inp-unit .inp { padding-right: 52px; }
.inp-unit em { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: 14px; pointer-events: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; font-weight: 600; margin-bottom: 12px; }
.check input { width: 22px; height: 22px; accent-color: var(--navy); }

/* ---------- Логин ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 0%, #e3f0fc, transparent 50%), radial-gradient(circle at 100% 100%, #e5f5e8, transparent 50%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 24px; padding: 18px 24px 26px; box-shadow: var(--shadow); }
.login-logo { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; object-position: center 55%; mix-blend-mode: multiply; margin-bottom: 4px; }
.login-err { color: var(--red); font-size: 14px; min-height: 20px; margin-bottom: 6px; }

/* ---------- Каркас ---------- */
.app { display: flex; min-height: 100vh; }
.side { display: none; }
.main { flex: 1; min-width: 0; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 6px; padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top));
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); min-height: 58px; }
.topbar h1 { font-size: 18px; flex: 1; padding-left: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; margin-right: 6px; }
.sync.busy { background: var(--orange); } .sync.err { background: var(--red); } .sync.local { display: none; }
.content { padding: 14px; max-width: 1240px; margin: 0 auto; }
.page-head { display: none; }

.tabbar { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255,255,255,.96); backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; font-size: 11px; font-weight: 600; color: var(--muted); border-radius: 12px; }
.tabbar a .ti { width: 52px; height: 30px; display: grid; place-items: center; border-radius: 15px; }
.tabbar a.on { color: var(--navy); }
.tabbar a.on .ti { background: var(--blue-soft); }

.fab { position: fixed; z-index: 29; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); height: 56px; padding: 0 22px 0 18px; border-radius: 18px; border: 0;
  background: var(--navy); color: #fff; font-weight: 700; display: flex; align-items: center; gap: 8px; box-shadow: 0 8px 24px rgba(23,69,127,.35); cursor: pointer; }

/* ---------- Карточки ---------- */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-title h3 { font-size: 16px; }
.list-card { display: block; cursor: pointer; }
.list-card:active { background: #fafcff; }
.lc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.lc-top b { font-size: 16px; }
.lc-bot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 10px; }
.lc-bot b { font-size: 16px; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { opacity: .35; margin-bottom: 8px; }

.badge { display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: 13px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.st-new { background: var(--blue-soft); color: var(--blue); }
.st-process { background: var(--orange-soft); color: var(--orange); }
.st-payment { background: var(--violet-soft); color: var(--violet); }
.st-closed { background: var(--green-soft); color: var(--green); }
.st-cancel { background: #eef1f5; color: var(--muted); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; margin: 0 -14px; padding-left: 14px; padding-right: 14px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 38px; padding: 0 14px; border-radius: 19px; border: 1px solid var(--line); background: #fff; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--muted); }
.chip i { font-style: normal; font-size: 12px; background: var(--bg); border-radius: 10px; padding: 1px 7px; }
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip.on i { background: rgba(255,255,255,.2); }
.search { position: relative; margin-bottom: 12px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search .inp { padding-left: 42px; }
.seg { display: flex; background: #e8edf5; border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 14px; overflow-x: auto; }
.seg a, .seg button { flex: 1; text-align: center; padding: 9px 10px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); white-space: nowrap; border: 0; background: none; cursor: pointer; }
.seg .on { background: #fff; color: var(--navy); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* Строки внутри карточек */
.rows > div { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.rows > div:last-child { border-bottom: 0; }
.rows .total { font-size: 17px; font-weight: 800; border-bottom: 0; }
.kv { display: grid; grid-template-columns: 24px 1fr; gap: 10px 8px; align-items: start; }
.kv svg { color: var(--muted); margin-top: 1px; }
.item-line { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item-line:last-child { border-bottom: 0; }
.item-line .grow { flex: 1; min-width: 0; }
.addrow { display: grid; grid-template-columns: 1fr 110px auto; gap: 8px; margin-top: 10px; }
.addrow.three { grid-template-columns: 1fr 1fr auto; }
.addrow > * { min-width: 0; }
.addrow .inp { height: 44px; font-size: 15px; }
select.inp { min-width: 0; text-overflow: ellipsis; }
.grid2 > * { min-width: 0; }
.addrow .btn { height: 44px; }

.ord-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 4px; }
.ord-head h2 { font-size: 22px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.actions .btn { flex: 1 1 140px; }
.profit-box { border-radius: 14px; padding: 14px; background: var(--green-soft); display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-top: 8px; }
.profit-box b { font-size: 22px; color: var(--green); }
.profit-box.neg { background: var(--red-soft); } .profit-box.neg b { color: var(--red); }
.note { padding: 12px 14px; border-radius: 12px; background: var(--violet-soft); color: #4b3796; font-weight: 600; margin-bottom: 12px; }

/* Таблицы (компьютер) */
.tbl-wrap { background: #fff; border-radius: var(--r); box-shadow: var(--shadow); overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; padding: 12px 16px; border-bottom: 1px solid var(--line); background: #fafbfd; white-space: nowrap; }
.tbl td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: #f7faff; }
.tbl .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Отчёт */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi { background: #fff; border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; }
.kpi span { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi b { display: block; font-size: 19px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.accent { background: linear-gradient(135deg, var(--navy), var(--blue)); color: #fff; }
.kpi.accent span { color: rgba(255,255,255,.8); }
.charts { display: grid; gap: 12px; }
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.donut-wrap { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: center; }
.donut-leg > div { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.donut-leg > div:last-child { border-bottom: 0; }
.donut-leg i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.donut-leg .grow { flex: 1; }

/* ---------- Окна (sheet) ---------- */
.sheet { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.sheet-bg { position: absolute; inset: 0; background: rgba(12,24,44,.45); animation: fade .2s; }
.sheet-box { position: relative; width: 100%; height: 100%; background: var(--bg); display: flex; flex-direction: column; animation: up .25s cubic-bezier(.2,.8,.2,1); }
.sheet.small .sheet-box { height: auto; max-height: 90vh; border-radius: 22px 22px 0 0; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 18px; padding-top: calc(10px + env(safe-area-inset-top)); background: #fff; border-bottom: 1px solid var(--line); }
.sheet.small .sheet-head { padding-top: 10px; border-radius: 22px 22px 0 0; }
.sheet-head b { flex: 1; font-size: 17px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; }
.sheet-foot { display: flex; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); }
.sheet-foot:empty { display: none; }
.sheet-foot .btn { flex: 1; height: 50px; }
.steps { display: flex; gap: 8px; margin-bottom: 16px; }
.steps button { flex: 1; border: 0; background: #e8edf5; color: var(--muted); border-radius: 12px; padding: 10px; font-weight: 700; cursor: pointer; text-align: left; font-size: 14px; }
.steps button span { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: #fff; margin-right: 6px; font-size: 12px; }
.steps button.on { background: var(--navy); color: #fff; }
.steps button.on span { color: var(--navy); }
.svc { background: #fff; border-radius: 14px; padding: 14px; margin-bottom: 10px; border: 1px solid var(--line); }
.svc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.svc-head b { flex: 1; color: var(--muted); font-size: 13px; }
.svc .f { margin-bottom: 10px; }
.svc-sum { text-align: right; font-weight: 700; }
.add-svc { width: 100%; height: 50px; border: 2px dashed #bcd3ec; background: transparent; border-radius: 14px; color: var(--blue); font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 14px; }
.totals { background: #fff; border-radius: 14px; padding: 6px 14px; border: 1px solid var(--line); }
.dialog-text { font-size: 15px; margin-bottom: 4px; }

.toast { position: fixed; z-index: 200; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #17243a; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow); animation: up .2s; max-width: calc(100vw - 32px); }
.toast.err { background: var(--red); }

@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Накладная ---------- */
.invoice { background: #fff; color: #111; padding: 28px; border-radius: 12px; max-width: 800px; margin: 0 auto; font-size: 14px; }
.inv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; border-bottom: 3px solid var(--navy); padding-bottom: 14px; margin-bottom: 16px; }
.inv-brand { font-size: 28px; font-weight: 800; color: var(--navy); letter-spacing: -.5px; }
.inv-brand span { color: #5cb85c; }
.inv-no { text-align: right; }
.inv-no b { font-size: 18px; display: block; }
.inv-client { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin-bottom: 18px; }
.inv-client span { color: #666; }
.invoice table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.invoice th, .invoice td { border: 1px solid #ccc; padding: 8px 10px; }
.invoice th { background: #f1f5fa; text-align: left; font-size: 13px; }
.invoice td.n { text-align: right; white-space: nowrap; }
.inv-tot { margin-left: auto; width: 300px; max-width: 100%; }
.inv-tot div { display: flex; justify-content: space-between; padding: 4px 0; }
.inv-tot .big { font-size: 17px; font-weight: 800; border-top: 2px solid #111; margin-top: 4px; padding-top: 8px; }
.inv-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 46px; }
.inv-sign .line { border-bottom: 1px solid #111; height: 34px; margin-bottom: 4px; }
.inv-stamp { width: 110px; height: 110px; border: 2px dashed #aaa; border-radius: 50%; display: grid; place-items: center; color: #999; font-weight: 700; margin-top: 14px; }

@media (max-width: 600px) {
  .invoice { padding: 16px 12px; font-size: 12.5px; border-radius: 10px; }
  .inv-brand { font-size: 22px; }
  .inv-head { flex-direction: column; gap: 8px; }
  .inv-no { text-align: left; }
  .invoice th, .invoice td { padding: 6px 5px; }
  .inv-sign { gap: 14px; margin-top: 30px; }
  .inv-stamp { width: 84px; height: 84px; }
}

/* ---------- Компьютер ---------- */
@media (min-width: 900px) {
  .only-m { display: none !important; }
  .side { display: flex; flex-direction: column; width: 256px; flex: none; position: sticky; top: 0; height: 100vh; padding: 22px 14px; color: #fff;
    background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%); }
  .side-brand { font-size: 22px; font-weight: 800; padding: 0 10px 4px; letter-spacing: -.3px; }
  .side-brand span { color: #7fd38f; }
  .side-sub { font-size: 12px; opacity: .65; padding: 0 10px 22px; }
  .side nav a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; font-weight: 600; opacity: .8; margin-bottom: 2px; }
  .side nav a:hover { background: rgba(255,255,255,.08); opacity: 1; }
  .side nav a.on { background: #fff; color: var(--navy); opacity: 1; }
  .side-user { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 10px; border-top: 1px solid rgba(255,255,255,.15); }
  .side-user .av { width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.15); display: grid; place-items: center; font-weight: 800; }
  .side-user .grow { flex: 1; min-width: 0; font-size: 14px; } .side-user .grow div { opacity: .6; font-size: 12px; }
  .side-user .icon-btn { color: #fff; } .side-user .icon-btn:hover { background: rgba(255,255,255,.1); }
  .topbar, .tabbar, .fab { display: none !important; }
  .main { padding-bottom: 40px; }
  .content { padding: 28px 36px; }
  .page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
  .page-head h1 { font-size: 26px; flex: 1; }
  .chips { margin: 0; padding: 0 0 14px; flex-wrap: wrap; }
  .search { max-width: 360px; }
  .toolbar { display: flex; gap: 14px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
  .kpis { grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
  .kpi { padding: 18px 20px; } .kpi b { font-size: 24px; }
  .charts { grid-template-columns: 1.6fr 1fr; gap: 14px; }
  .ord-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
  .sheet { align-items: center; padding: 30px; }
  .sheet-box, .sheet.small .sheet-box { height: auto; max-height: 92vh; max-width: 640px; border-radius: 20px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.25); animation: pop .2s; }
  .sheet.small .sheet-box { max-width: 460px; }
  .sheet.wide .sheet-box { max-width: 880px; }
  .sheet-head, .sheet.small .sheet-head { padding-top: 10px; border-radius: 0; }
  .sheet-foot { justify-content: flex-end; } .sheet-foot .btn { flex: 0 0 auto; min-width: 140px; height: 46px; }
  .toast { bottom: 30px; }
  @keyframes pop { from { transform: scale(.96); opacity: 0; } }
}
@media (max-width: 899px) { .only-d { display: none !important; } }
@media (max-width: 380px) { .addrow { grid-template-columns: 1fr 90px auto; } .donut-wrap { grid-template-columns: 1fr; justify-items: center; } }

/* ---------- Печать ---------- */
@media print {
  @page { margin: 12mm; }
  body { background: #fff; }
  #root, .toast, .sheet-head, .sheet-foot, .sheet-bg { display: none !important; }
  .sheet { position: static; display: block; padding: 0; }
  .sheet-box { max-width: none !important; max-height: none !important; box-shadow: none !important; background: #fff; animation: none; height: auto; border-radius: 0; }
  .sheet-body { overflow: visible; padding: 0; }
  .invoice { padding: 0; max-width: none; }
}
