:root {
  --bg: #f6f2ec; --surface: #fff; --ink: #1f1b17; --muted: #7b7168; --line: #e7e0d5;
  --gold: #a07c36; --gold-soft: #f3ead7; --night: #1f1b17; --night-2: #2c2620;
  --ok: #2f7d53; --ok-bg: #e3f2e9; --bad: #b3402f; --bad-bg: #f8e4df; --warn: #9a6a12; --warn-bg: #f8edd3;
  --info: #2c5f8a; --info-bg: #e2edf6; --off: #6f6a64; --off-bg: #ebe8e3; --ship: #6a4a94; --ship-bg: #ece4f5;
  --radius: 10px; --serif: Georgia, "Times New Roman", serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
h1 { font: 600 24px/1.2 var(--serif); margin: 0; letter-spacing: .01em; }
h2 { font: 600 13px/1.2 system-ui, sans-serif; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 12px; }
small, .muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* layout */
.side { position: fixed; inset: 0 auto 0 0; width: 220px; background: var(--night); color: #e9e1d4; padding: 22px 12px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; z-index: 30; }
.brand { font: 400 19px var(--serif); letter-spacing: .04em; text-decoration: none; color: inherit; }
.brand b { font-weight: 600; color: #d8b877; }
.side .brand { padding: 0 10px 18px; display: block; }
.side .brand small { display: block; font: 11px system-ui, sans-serif; letter-spacing: .25em; color: #8d8274; margin-top: 2px; }
.side a:not(.brand) { padding: 9px 10px; border-radius: 8px; text-decoration: none; color: #cfc6b8; }
.side a:not(.brand):hover { background: var(--night-2); color: #fff; }
.side a.on { background: var(--night-2); color: #fff; box-shadow: inset 3px 0 0 #d8b877; }
.side .who { margin-top: auto; padding: 14px 10px 0; font-size: 13px; color: #8d8274; border-top: 1px solid #3a322a; }
.side .who a { padding: 0 !important; color: #cfc6b8; }
.topbar { display: none; }
main { margin-left: 220px; padding: 28px 32px 60px; max-width: 1500px; }

.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.head .grow { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 18px 0; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi span { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi b { display: block; font: 600 24px/1.3 var(--serif); font-variant-numeric: tabular-nums; }
.kpi small { font-size: 12px; }
.kpi.accent { background: var(--night); border-color: var(--night); color: #f4ecdd; }
.kpi.accent span, .kpi.accent small { color: #b9ad9b; }
.kpi.accent b { color: #e3c485; }

/* tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fbf9f5; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fcfaf6; }
td a.main { font-weight: 600; text-decoration: none; }
td a.main:hover { color: var(--gold); }
tfoot td { font-weight: 600; background: #fbf9f5; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--gold-soft); display: block; }
.thumb.lg { width: 100%; height: auto; aspect-ratio: 1; }
.thumb.ph { display: grid; place-items: center; color: var(--gold); font: 600 15px var(--serif); }
.item { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.item:last-child { margin-bottom: 0; }
.item .thumb { width: 30px; height: 30px; border-radius: 6px; flex: none; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-new { background: var(--gold-soft); color: #7a5c20; } .b-ok { background: var(--ok-bg); color: var(--ok); }
.b-gold { background: var(--night); color: #e3c485; } .b-bad { background: var(--bad-bg); color: var(--bad); }
.b-warn { background: var(--warn-bg); color: var(--warn); } .b-info { background: var(--info-bg); color: var(--info); }
.b-off { background: var(--off-bg); color: var(--off); } .b-ship { background: var(--ship-bg); color: var(--ship); }

.b-alert { background: #b3402f; color: #fff; }
tr.todo td { background: #fdf6e7; }
tr.todo td:first-child { box-shadow: inset 4px 0 0 #c9892b; }
tbody tr.todo:hover td { background: #fbefd6; }
.seg { display: inline-flex; background: #ece6dc; border-radius: 10px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.seg a { padding: 8px 18px; border-radius: 7px; text-decoration: none; font-weight: 600; color: var(--muted); }
.seg a.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(31, 27, 23, .15); }
.pill { display: inline-block; min-width: 20px; padding: 1px 7px; margin-left: 6px; border-radius: 99px; background: #b3402f; color: #fff; font-size: 12px; font-weight: 700; text-align: center; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.callbar { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* forms */
label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid #d8cfc1; border-radius: 8px; background: #fff; color: var(--ink); font: inherit; min-height: 36px; }
input[type=checkbox] { display: inline-block; width: auto; min-height: 0; margin: 0 6px 0 0; vertical-align: middle; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #d8b877; outline-offset: 0; border-color: var(--gold); }
.form { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; }
.c2 { grid-column: span 2; } .c3 { grid-column: span 3; } .c4 { grid-column: span 4; } .c6 { grid-column: span 6; } .c8 { grid-column: span 8; } .c12 { grid-column: span 12; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters input, .filters select { width: auto; margin: 0; }
.filters input[type=search] { min-width: 220px; flex: 1; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; min-height: 36px; border-radius: 8px; border: 1px solid #d8cfc1; background: #fff; color: var(--ink); font: 600 13px system-ui, sans-serif; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--gold); }
.btn.primary { background: var(--night); border-color: var(--night); color: #f4ecdd; }
.btn.primary:hover { background: #000; }
.btn.danger { color: var(--bad); }
.btn[disabled] { opacity: .4; cursor: default; pointer-events: none; }
.btn.sm { padding: 4px 9px; min-height: 28px; font-size: 12px; }
.inline { display: inline; }
select.mini { width: auto; min-height: 28px; padding: 2px 6px; margin: 0; font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a { padding: 6px 12px; border-radius: 99px; text-decoration: none; border: 1px solid var(--line); background: #fff; font-weight: 600; font-size: 13px; }
.tabs a.on { background: var(--night); border-color: var(--night); color: #f4ecdd; }
.tabs a i { font-style: normal; opacity: .6; margin-left: 4px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 600; }
.flash-ok { background: var(--ok-bg); color: var(--ok); } .flash-bad { background: var(--bad-bg); color: var(--bad); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* order item rows */
.items-edit .row { display: grid; grid-template-columns: 2.2fr 2fr 1fr 1fr .6fr 1fr 1.4fr auto; gap: 8px; align-items: end; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.items-edit .row input, .items-edit .row select { margin-top: 2px; }

.psearch { position: relative; }
.psearch-list { position: absolute; z-index: 15; top: 100%; left: 0; width: max(100%, 380px); max-width: 92vw; max-height: 320px; overflow-y: auto; margin-top: 4px; background: #fff; border: 1px solid #d8cfc1; border-radius: 10px; box-shadow: 0 12px 30px rgba(31, 27, 23, .16); padding: 4px; }
.psearch-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border: 0; background: none; border-radius: 7px; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.psearch-item.on, .psearch-item:hover { background: var(--gold-soft); }
.psearch-item img, .psearch-item .noimg { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; background: var(--gold-soft); flex: none; }
.psearch-item .t { flex: 1; min-width: 0; } .psearch-item small { display: block; }
.psearch-item .p { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.psearch-item .ok { color: var(--ok); } .psearch-item .no { color: var(--bad); }
.psearch-empty { padding: 10px; color: var(--muted); }
.check .checkline { display: flex; align-items: center; min-height: 36px; margin-top: 4px; color: var(--ink); font-size: 14px; font-weight: 400; cursor: pointer; }
input[readonly] { background: #f3efe8; color: var(--muted); }
tr.grand td { border-top: 2px solid var(--ink); font-size: 16px; }

.range { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--muted); }
.range[hidden] { display: none; }
.offers { display: flex; flex-direction: column; gap: 1px; margin: 4px 0 6px; font-size: 12px; color: var(--muted); }
.offers .cur { color: var(--ink); font-weight: 700; }

.best { display: inline-block; padding: 1px 7px; border-radius: 99px; background: #1f1b17; color: #e3c485; font-size: 11px; font-weight: 700; white-space: nowrap; }
.itemform { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.itemform label { flex: 1 1 150px; } .itemform .price { flex: 0 0 96px; } .itemform .wide { flex: 2 1 220px; }
.itemform .thumb { flex: none; align-self: center; }

.btn.icon { min-width: 30px; padding: 4px 8px; font-size: 15px; line-height: 1; }
tr.editrow td { background: #fbf9f5; }
tr.editrow[hidden] { display: none; }

label[hidden] { display: none; }

/* profit sharing chart */
.split { display: flex; gap: 2px; height: 34px; border-radius: 6px; overflow: hidden; }
.seg-part { min-width: 3px; }
.p-r1 { background: #2c2620; } .p-r2 { background: #7d6f60; }
.p-y1 { background: #b8892f; } .p-y2 { background: #e6cf9a; }
.split-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 8px 18px; margin-top: 12px; }
.split-legend div { display: grid; grid-template-columns: 12px 1fr; column-gap: 8px; align-items: center; }
.split-legend i { width: 12px; height: 12px; border-radius: 3px; grid-row: span 2; align-self: start; margin-top: 4px; }
.split-legend span { color: var(--muted); font-size: 13px; }
.split-legend b { font-variant-numeric: tabular-nums; }
.split-legend small { grid-column: 2; }
.cols { display: flex; align-items: stretch; gap: 10px; height: 200px; }
.colbar { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; text-decoration: none; }
.colbar .track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; margin-top: 18px; border-bottom: 1px solid var(--line); }
.colbar .fill { position: relative; display: block; width: 70%; max-width: 34px; min-height: 2px; background: #b8892f; border-radius: 4px 4px 0 0; }
.colbar:hover .fill { background: #2c2620; }
.colbar small { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); padding-bottom: 3px; font-variant-numeric: tabular-nums; color: var(--ink); font-size: 11px; white-space: nowrap; }
.colbar em { font-style: normal; font-size: 11px; color: var(--muted); padding-top: 4px; }
.track { margin-top: 6px; line-height: 1.5; }

/* bars */
.bars { display: flex; align-items: flex-end; gap: 14px; height: 170px; padding-top: 10px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; min-width: 0; }
.bars .pair { display: flex; align-items: flex-end; gap: 3px; height: 100%; width: 100%; justify-content: center; }
.bars .bar { width: 38%; max-width: 26px; border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .in { background: #c9a85f; } .bars .out { background: #3b332b; }
.bars small { font-size: 11px; white-space: nowrap; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }
.meter { height: 6px; border-radius: 3px; background: var(--off-bg); overflow: hidden; margin-top: 4px; }
.meter i { display: block; height: 100%; background: #c9a85f; }

/* catalog */
.catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.pcard { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-decoration: none; display: flex; flex-direction: column; }
.pcard:hover { border-color: var(--gold); }
.pcard .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.pcard b { font-size: 14px; }
.pcard .thumb { border-radius: 0; }
.pcard.inactive { opacity: .55; }
.stockline { display: flex; gap: 6px; flex-wrap: wrap; }

/* auth */
body.auth { display: grid; place-items: center; min-height: 100vh; background: var(--night); padding: 16px; }
.auth-card { background: #fff; padding: 30px; border-radius: 14px; width: 100%; max-width: 360px; display: grid; gap: 14px; }
.auth-card .brand { font-size: 22px; color: var(--ink); } .auth-card .brand b { color: var(--gold); }
.auth-card h1 { font-size: 18px; }

@media (max-width: 900px) {
  .topbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20; background: var(--night); color: #e9e1d4; padding: 10px 14px; }
  .burger { width: 38px; height: 38px; border: 0; background: var(--night-2); border-radius: 8px; display: grid; place-items: center; cursor: pointer; }
  .burger span, .burger span::before, .burger span::after { display: block; width: 18px; height: 2px; background: #e9e1d4; border-radius: 2px; position: relative; content: ""; }
  .burger span::before { position: absolute; top: -6px; } .burger span::after { position: absolute; top: 6px; }
  .side { transform: translateX(-100%); transition: transform .2s; width: 250px; }
  .nav-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45); }
  main { margin-left: 0; padding: 16px 14px 60px; }
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .c2, .c3, .c4 { grid-column: span 6; } .c6, .c8 { grid-column: span 12; }
  .items-edit .row { grid-template-columns: 1fr 1fr; }
  .items-edit .row .psearch, .items-edit .row .actions { grid-column: 1 / -1; }
  .hide-sm { display: none; }
  h1 { font-size: 21px; }
}
/* ---------- phones ---------- */
@media (max-width: 700px) {
  input, select, textarea { font-size: 16px; }              /* no zoom-in on focus */
  .btn { min-height: 42px; } .btn.sm { min-height: 36px; padding: 6px 12px; font-size: 13px; } select.mini { min-height: 36px; font-size: 14px; }
  main { padding: 14px 12px calc(70px + env(safe-area-inset-bottom)); }
  .card { padding: 14px; border-radius: 12px; }
  .head { gap: 8px; margin-bottom: 14px; }
  .head .btn { flex: 1 1 auto; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px; } .kpi b { font-size: 19px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px 12px; padding: 0 12px 4px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { flex: none; padding: 8px 14px; }
  .seg { display: flex; } .seg a { flex: 1; padding: 10px 8px; text-align: center; }
  .filters input[type=search] { min-width: 0; flex: 1 1 100%; }
  .filters select { flex: 1 1 auto; }
  .range { flex: 1 1 100%; } .range input { flex: 1; min-width: 0; width: auto; }
  .c2, .c3 { grid-column: span 6; } .c4, .c6, .c8 { grid-column: span 12; }
  .catalog { grid-template-columns: 1fr 1fr; gap: 10px; }
  .psearch-list { width: calc(100vw - 52px); max-width: none; }
  .itemform label, .itemform .price, .itemform .wide { flex: 1 1 100%; }
  .split-legend { grid-template-columns: 1fr 1fr; }
  .cols { gap: 4px; }

  /* list tables become stacked cards: one order, client or article per block */
  .tablewrap { overflow: visible; }
  .tablewrap table, .tablewrap tbody, .tablewrap tfoot, .tablewrap tr, .tablewrap td { display: block; width: 100%; }
  .tablewrap thead { display: none; }
  .tablewrap tr { display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .tablewrap td { grid-column: 1 / -1; min-width: 0; }
  .tablewrap td.num, .t-orders td:nth-child(1), .t-orders td:nth-child(2) { grid-column: auto; }   /* short values sit side by side */
  .tablewrap tr[hidden] { display: none; }
  .tablewrap tbody tr:last-child { border-bottom: 0; }
  .tablewrap td, .tablewrap td.num { padding: 4px 0; border: 0; text-align: left; white-space: normal; background: none !important; box-shadow: none !important; }
  .tablewrap td[data-label]:not([data-label=""])::before { content: attr(data-label); display: block; font-size: 10px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
  .tablewrap td.hide-sm { display: block; }
  .tablewrap td:empty { display: none; }
  .tablewrap tr.todo { background: #fdf6e7; box-shadow: inset 4px 0 0 #c9892b; }
  .tablewrap tfoot tr { background: #fbf9f5; font-weight: 600; }
  .tablewrap td.actions { padding-top: 8px; }
  .tablewrap td input { width: 100% !important; margin: 0 !important; text-align: left !important; }
  .callbar .btn, td.actions .btn { flex: 1 1 auto; }
  td.actions form.inline, .callbar form.inline { display: flex; flex: 1 1 auto; } td.actions form.inline .btn, .callbar form.inline .btn { width: 100%; }
}
@media print {
  .side, .topbar, .no-print, .flash { display: none !important; }
  main { margin: 0; padding: 0; }
  body { background: #fff; }
  .card { border: 0; padding: 0; }
}
