[hidden] { display: none !important; }
:root {
  --green: #2f6b2f; --green-2: #3f8a3f; --green-soft: #e6f1df; --red: #c63b33; --red-soft: #fbe7e5;
  --amber: #b26a00; --amber-soft: #fff3d6; --blue: #2a5f9e; --blue-soft: #e3eefa;
  --bg: #f6f8f3; --card: #fff; --text: #1d241b; --muted: #66705f; --line: #dde3d6; --radius: 12px;
  --nav-h: 64px; font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; line-height: 1.4; -webkit-text-size-adjust: 100%; }
a { color: var(--green); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Каркас ---------- */
.layout { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--green); color: #fff; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { background: none; border: 0; color: #fff; font-size: 24px; padding: 0 6px 0 0; cursor: pointer; }
.topbar select { background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; padding: 6px 8px; max-width: 48vw; }
.topbar select option { color: #000; }
.main { padding: 12px 12px 24px; max-width: 1200px; margin: 0 auto; }
.nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid var(--line); display: flex; }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; color: var(--muted); font-size: 12px; gap: 2px; }
.nav a .i { font-size: 22px; line-height: 1; }
.nav a.active { color: var(--green); font-weight: 600; }
.nav a.plus .i { background: var(--green); color: #fff; width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 28px; margin-top: -14px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.nav .brand { display: none; }

@media (min-width: 900px) {
  .layout { padding-bottom: 0; padding-left: 220px; }
  .nav { top: 0; right: auto; width: 220px; height: auto; flex-direction: column; justify-content: flex-start; border-top: 0; border-right: 1px solid var(--line); padding: 16px 0; }
  .nav .brand { display: block; padding: 0 20px 16px; font-weight: 700; color: var(--green); font-size: 18px; }
  .nav a { flex: 0; flex-direction: row; justify-content: flex-start; padding: 12px 20px; font-size: 15px; gap: 12px; }
  .nav a.active { background: var(--green-soft); }
  .nav a.plus .i { width: 28px; height: 28px; font-size: 20px; margin: 0; box-shadow: none; }
  .main { padding: 20px 24px 40px; }
  .hide-desktop { display: none !important; }
}
@media (max-width: 899px) { .hide-mobile { display: none !important; } }

/* ---------- Элементы ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2, .card h3 { margin: 0 0 10px; font-size: 17px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 520px) { .grid3 { grid-template-columns: 1fr 1fr; } }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 12px; } .mb0 { margin-bottom: 0; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

label.f { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label.f > span { display: block; margin-bottom: 4px; }
input[type=text], input[type=tel], input[type=number], input[type=password], input[type=date], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; background: #fff; font-size: 16px; min-height: 44px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green-2); outline-offset: -1px; border-color: transparent; }
.check { display: flex; gap: 10px; align-items: center; font-size: 15px; margin: 8px 0; color: var(--text); }
.check input { width: 22px; height: 22px; accent-color: var(--green); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 14px; min-height: 44px; cursor: pointer; text-decoration: none; color: var(--text); font-weight: 500; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--red); border-color: #f0c4c0; }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { flex: 1; border: 0; background: none; padding: 10px 8px; min-height: 44px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--green); color: #fff; font-weight: 600; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; -webkit-overflow-scrolling: touch; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; white-space: nowrap; cursor: pointer; font-size: 14px; }
.chip.on { background: var(--green); color: #fff; border-color: var(--green); }
.chip .n { opacity: .7; margin-left: 4px; }

.badge { display: inline-block; font-size: 12px; padding: 3px 8px; border-radius: 999px; background: #eef0eb; color: var(--muted); white-space: nowrap; font-weight: 600; }
.st-new { background: var(--blue-soft); color: var(--blue); }
.st-processing { background: #efe6fb; color: #6a3fa0; }
.st-confirmed { background: var(--green-soft); color: var(--green); }
.st-ready { background: var(--amber-soft); color: var(--amber); }
.st-shipped { background: #dff3f1; color: #19756c; }
.st-done { background: #eceeea; color: #555; }
.st-cancelled { background: var(--red-soft); color: var(--red); }
.pay-unpaid { background: #f1f1f1; color: #666; }
.pay-invoiced { background: var(--amber-soft); color: var(--amber); }
.pay-prepaid { background: var(--blue-soft); color: var(--blue); }
.pay-paid { background: var(--green-soft); color: var(--green); }
.warn { background: var(--amber-soft); color: #7a4a00; border-radius: 10px; padding: 10px 12px; margin: 8px 0; font-size: 14px; }
.err { background: var(--red-soft); color: var(--red); border-radius: 10px; padding: 10px 12px; margin: 8px 0; font-size: 14px; }

/* ---------- Список заказов ---------- */
.ocard { display: block; text-decoration: none; color: inherit; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.ocard .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.ocard .name { font-weight: 600; }
.ocard .num { font-size: 13px; color: var(--muted); }
.ocard .meta { font-size: 13px; color: var(--muted); margin-top: 4px; }
.ocard .sum { font-weight: 700; white-space: nowrap; }
.summary { font-size: 14px; color: var(--muted); margin: 4px 2px 10px; }
table.t { width: 100%; border-collapse: collapse; background: #fff; font-size: 14px; }
table.t th, table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.t th { background: #f2f5ee; font-weight: 600; position: sticky; top: 0; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #fafcf8; }
table.t td.num, table.t th.num { text-align: right; white-space: nowrap; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.bulkbar { position: sticky; bottom: 0; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-top: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; box-shadow: 0 -2px 10px rgba(0,0,0,.06); }

/* ---------- Форма заказа ---------- */
.vlist { display: grid; gap: 8px; }
@media (min-width: 700px) { .vlist { grid-template-columns: 1fr 1fr; } }
.vitem { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: #fff; }
.vitem.on { border-color: var(--green-2); background: #f6fbf3; }
.vitem .vh { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.vitem .vh b { font-size: 16px; }
.qty { display: flex; gap: 6px; align-items: center; }
.qty button { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 22px; cursor: pointer; flex: none; }
.qty input { text-align: center; font-weight: 700; font-size: 18px; }
.quick { display: flex; gap: 6px; margin-top: 6px; }
.quick button { flex: 1; border: 1px dashed var(--line); background: #fff; border-radius: 8px; padding: 6px 0; cursor: pointer; font-size: 14px; color: var(--muted); }
.totals { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 10; background: #fff; border: 1px solid var(--green-2); border-radius: var(--radius); padding: 10px 14px; box-shadow: 0 -2px 12px rgba(0,0,0,.08); }
@media (min-width: 900px) { .totals { bottom: 0; } }
.totals .big { font-size: 20px; font-weight: 700; }
.found { background: var(--green-soft); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 14px; }
.addr-opt { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 6px; cursor: pointer; background: #fff; }
.addr-opt input { margin-top: 3px; width: 20px; height: 20px; accent-color: var(--green); flex: none; }

/* ---------- Карточка заказа ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.money-row { display: flex; justify-content: space-between; padding: 4px 0; }
.money-row.total { font-weight: 700; font-size: 17px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; }
.hist { font-size: 13px; color: var(--muted); }
.hist div { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.statusflow { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Окна ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: #fff; width: 100%; max-width: 520px; border-radius: 16px 16px 0 0; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); max-height: 90vh; overflow: auto; }
@media (min-width: 600px) { .modal-bg { align-items: center; } .modal { border-radius: 16px; } }
.modal h3 { margin: 0 0 12px; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 200; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; text-align: center; }
#toast.show { opacity: .95; }
#toast.bad { background: var(--red); }

/* ---------- Вход ---------- */
.login { max-width: 360px; margin: 12vh auto; padding: 0 16px; }
.login .logo { text-align: center; margin-bottom: 20px; }
.login .logo img { width: 72px; height: 72px; }
.login h1 { font-size: 22px; text-align: center; margin: 8px 0 20px; }

/* ---------- Отчёты ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .l { font-size: 13px; color: var(--muted); }
.menu a { display: flex; justify-content: space-between; padding: 14px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--text); }
.menu a:last-child { border-bottom: 0; }

/* ---------- Печать ---------- */
@media print {
  .nav, .topbar, .no-print, #toast { display: none !important; }
  .layout { padding: 0 !important; }
  .main { padding: 0; max-width: none; }
  .card { border: 0; padding: 0; break-inside: avoid; }
  .assembly-item { border: 1px solid #999 !important; padding: 8px !important; margin-bottom: 8px; break-inside: avoid; }
  body { background: #fff; }
}

/* Мелкие правки раскладки */
.grid2 > *, .grid3 > * { min-width: 0; }
.money-row > :last-child { white-space: nowrap; padding-left: 10px; }
table.t input { padding: 8px; min-height: 38px; }
@media (min-width: 900px) { .topbar select { max-width: 320px; } }
