:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2230;
  --muted: #667085;
  --border: #e3e6ec;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --head-bg: #eef2f8;
  --row-alt: #fafbfc;
  --hit: #fff3bf;
  --danger: #c62828;
  --ok: #1b7f3b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --border: #2a303c;
    --accent: #4c8dff;
    --head-bg: #1f2531;
    --row-alt: #1a1f28;
    --hit: #4a3f12;
    --danger: #ff6b6b;
    --ok: #4cc77a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
[hidden] { display: none !important; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }

header.top {
  display: flex; flex-wrap: wrap; gap: 12px 24px;
  align-items: flex-end; justify-content: space-between;
  margin-bottom: 16px;
}
h1 { font-size: 1.6rem; margin: 0 0 4px; }
.updated { color: var(--muted); font-size: .95rem; }
.updated strong { color: var(--text); font-weight: 600; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 9px 14px; border-radius: 8px; font: inherit;
  font-size: .95rem; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.search {
  flex: 1 1 260px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
.count { color: var(--muted); font-size: .9rem; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tab {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 14px; font: inherit; font-size: .9rem; cursor: pointer;
}
.tab.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.table-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  overflow: auto; max-height: 75vh;
}
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
thead th {
  position: sticky; top: 0; background: var(--head-bg); font-weight: 600;
  white-space: nowrap; z-index: 1;
}
tbody tr:nth-child(even) td { background: var(--row-alt); }
td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
mark { background: var(--hit); color: inherit; border-radius: 2px; }

.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

.notice {
  background: var(--surface); border: 1px solid var(--accent); border-radius: 8px;
  padding: 10px 14px; margin-bottom: 12px; display: flex; gap: 12px; align-items: center;
  justify-content: space-between; flex-wrap: wrap;
}

footer { color: var(--muted); font-size: .85rem; margin-top: 16px; text-align: center; }

/* admin */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 20px; margin-bottom: 16px;
}
.card h2 { font-size: 1.1rem; margin: 0 0 12px; }
.login { max-width: 380px; margin: 10vh auto; }
.login input {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; margin-bottom: 12px;
}
.drop {
  display: block; border: 2px dashed var(--border); border-radius: 10px; padding: 28px 16px;
  text-align: center; color: var(--muted); cursor: pointer;
}
.drop.over { border-color: var(--accent); color: var(--text); }
.error { color: var(--danger); min-height: 1.4em; margin: 0 0 8px; }
.hint { color: var(--muted); font-size: .9rem; margin: 6px 0 0; }

.editor td, .editor th { min-width: 80px; }
.editor [contenteditable] { outline: none; }
.editor [contenteditable]:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.editor td.row-tools { min-width: 0; width: 1%; padding: 4px; white-space: nowrap; }
.editor td.row-tools button {
  border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 2px 6px;
}
.editor td.row-tools button:hover { color: var(--danger); }
.dirty-dot { color: var(--danger); font-weight: 700; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  opacity: 0; transition: .2s; pointer-events: none; z-index: 10; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--danger); color: #fff; }

@media (max-width: 600px) {
  h1 { font-size: 1.3rem; }
  th, td { padding: 6px 8px; font-size: .88rem; }
  .table-box { max-height: none; }
}

/* ---------- cart ---------- */
.muted { color: var(--muted); }
.cart-col {
  position: sticky; right: 0; background: var(--surface); text-align: right;
  white-space: nowrap; box-shadow: -1px 0 0 var(--border);
}
thead th.cart-col { background: var(--head-bg); z-index: 2; }
tbody tr:nth-child(even) td.cart-col { background: var(--row-alt); }
.btn.add { padding: 5px 10px; font-size: .9rem; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--accent); border-radius: 8px; overflow: hidden; }
.stepper button {
  border: 0; background: var(--accent); color: var(--accent-text); width: 30px; height: 30px;
  font-size: 1.1rem; cursor: pointer; line-height: 1;
}
.stepper input {
  width: 52px; height: 30px; border: 0; text-align: center; font: inherit; background: var(--surface);
  color: var(--text); -moz-appearance: textfield;
}
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

body.has-cart .wrap { padding-bottom: 96px; }
.cart-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgba(0,0,0,.08);
}
.cart-bar-inner {
  max-width: 1200px; margin: 0 auto; padding: 12px 16px; display: flex; gap: 12px;
  align-items: center; justify-content: space-between; flex-wrap: wrap;
}

dialog.cart {
  width: min(920px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 0;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
}
dialog.cart::backdrop { background: rgba(0,0,0,.45); }
.cart-head {
  display: flex; justify-content: space-between; align-items: center; padding: 14px 20px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 3;
}
.cart-head h2 { margin: 0; font-size: 1.2rem; }
.cart-body { padding: 16px 20px 20px; }
.cart-table { max-height: none; margin-bottom: 16px; }
.cart-table td { vertical-align: middle; }
.cart-table tfoot td { border-bottom: 0; font-size: 1.05rem; }
.price-sm { display: none; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 4px 8px; }
.icon-btn:hover { color: var(--danger); }
.cart-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin-bottom: 8px; }
.cart-form label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
.cart-form .wide { grid-column: 1 / -1; }
.cart-form input, .cart-form textarea, .settings input, .settings textarea {
  padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font: inherit; width: 100%;
}
.cart-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.contacts {
  margin-top: 16px; padding: 12px 14px; border-radius: 8px; background: var(--head-bg); font-size: .95rem;
}
.contacts a { color: var(--accent); }

.print-only { display: none; }
@media print {
  .screen-only, #toast { display: none !important; }
  .print-only { display: block !important; color: #000; font-size: 12pt; }
  #printArea h1 { font-size: 18pt; margin: 0 0 8pt; }
  #printArea table { width: 100%; border-collapse: collapse; margin: 12pt 0; }
  #printArea th, #printArea td { border: 1px solid #999; padding: 4pt 6pt; position: static; background: none; }
  #printArea .num { text-align: right; white-space: nowrap; }
}

@media (max-width: 600px) {
  .hide-sm { display: none; }
  .cart-form { grid-template-columns: 1fr; }
  dialog.cart { width: 100%; max-width: 100%; max-height: 100%; height: 100%; border-radius: 0; margin: 0; }
  .cart-body { padding: 12px 12px 24px; }
  /* price table: keep prices visible, order column scrolls with the row */
  .cart-col { position: static; box-shadow: none; }
  .stepper button { width: 28px; height: 28px; }
  .stepper input { width: 36px; height: 28px; }
  /* cart: hide № and price columns, price is shown under the name instead */
  .cart-table th:nth-child(1), .cart-table td:nth-child(1),
  .cart-table th:nth-child(3), .cart-table td:nth-child(3) { display: none; }
  .cart-table th, .cart-table td { padding: 6px; }
  .price-sm { display: block !important; }
}

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.sent { text-align: center; padding: 24px 8px; }
.sent-icon { font-size: 3rem; }
.sent h3 { margin: 8px 0 12px; font-size: 1.3rem; }

/* admin: orders */
.orders td, .orders th { white-space: nowrap; }
.orders tbody tr.order-row { cursor: pointer; }
.orders tbody tr.order-row:hover td { background: var(--head-bg); }
.orders td.client { white-space: normal; min-width: 160px; }
.orders tr.details > td { background: var(--bg) !important; white-space: normal; padding: 12px 16px; }
.orders tr.details table { background: var(--surface); margin: 8px 0 12px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.badge.new { background: #ffe8a3; color: #6b4e00; }
.badge.done { background: #d5f0dc; color: #1b5e2f; }
.count-badge { background: var(--danger); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: .85rem; margin-left: 6px; }
.order-new td:first-child { box-shadow: inset 3px 0 0 var(--danger); }

/* ---------- branded header ---------- */
.brand { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.logo { height: 64px; width: auto; border-radius: 8px; background: #fff; padding: 4px 8px; }
.head-contacts { font-size: .9rem; margin-top: 2px; }
.head-contacts a, .contacts a { color: var(--accent); }

/* category tabs: one scrollable line */
.scroll-tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
.scroll-tabs .tab { white-space: nowrap; flex: 0 0 auto; }
.tabs.dim .tab.active { background: var(--surface); color: var(--text); border-color: var(--border); }

/* ---------- price table ---------- */
.price-box { max-height: none; overflow: visible; }
.price-table td, .price-table th { vertical-align: middle; }
.price-table tbody tr:nth-child(even) td { background: none; }
.price-table tr.group td {
  background: var(--head-bg); font-weight: 700; font-size: 1.02rem; padding: 12px; border-top: 2px solid var(--border);
}
.price-table tr.group.sheet-title td { background: var(--accent); color: var(--accent-text); }
.price-table tr.subhead th {
  background: var(--surface); color: var(--muted); font-size: .82rem; font-weight: 600; white-space: normal;
  border-bottom: 2px solid var(--border); position: static;
}
.price-table tr.item:hover td { background: var(--row-alt); }
.price-table td.name-col { min-width: 220px; font-weight: 500; }
.price-table td.price-col { white-space: nowrap; }
.price-table td.price-col.base { font-weight: 700; }
.price-table .photo-col { width: 84px; padding: 4px 8px; }
.price-table .cart-col { position: static; box-shadow: none; text-align: right; min-width: 150px; }
.price-table tr.unavailable td:not(.cart-col):not(.photo-col) { color: var(--muted); }
.thumb {
  width: 72px; height: 52px; object-fit: contain; border-radius: 6px; background: #fff;
  border: 1px solid var(--border); cursor: zoom-in; display: block;
}
.na { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.order-ctl { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.variant-line { display: flex; gap: 6px; }
.variant-line select {
  padding: 5px 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-size: .9rem;
}
.variant-line select.need { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(198,40,40,.2); }
.in-cart { font-size: .8rem; color: var(--ok); max-width: 220px; text-align: right; }

/* photo viewer */
dialog.photo-view {
  border: 0; border-radius: 12px; padding: 12px; max-width: min(900px, calc(100% - 32px));
  background: var(--surface); color: var(--text);
}
dialog.photo-view::backdrop { background: rgba(0,0,0,.7); }
dialog.photo-view form { text-align: right; margin-bottom: 8px; }
dialog.photo-view img { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; border-radius: 8px; background: #fff; cursor: zoom-out; }
dialog.photo-view p { text-align: center; margin: 10px 0 0; }

/* cart extras */
.cart-item { display: flex; gap: 10px; align-items: flex-start; }
.cart-thumb { width: 48px; height: 36px; object-fit: contain; border-radius: 4px; background: #fff; border: 1px solid var(--border); flex: 0 0 auto; }
.tier-next { display: block; color: var(--ok); font-size: .8rem; }

/* ---------- phones: product cards ---------- */
@media (max-width: 700px) {
  .logo { height: 48px; }
  .price-table, .price-table tbody { display: block; }
  .price-table tr.subhead { display: none; }
  .price-table tr.group { display: block; }
  .price-table tr.group td { display: block; }
  .price-table tr.item {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 2px 14px; position: relative;
    padding: 12px 12px 12px 96px; min-height: 88px; border-bottom: 1px solid var(--border);
  }
  .price-table tr.item.no-photo { padding-left: 12px; }
  .price-table tr.item td { display: block; border: 0; padding: 0; background: none !important; }
  .price-table tr.item td.empty-cell { display: none; }
  .price-table tr.item td.photo-col { position: absolute; left: 12px; top: 12px; width: 72px; padding: 0; }
  .price-table tr.item td.name-col { flex: 1 0 100%; font-weight: 600; min-width: 0; }
  .price-table tr.item td:not(.name-col):not(.photo-col):not(.price-col):not(.cart-col) {
    flex: 1 0 100%; font-size: .88rem; color: var(--muted); text-align: left;
  }
  .price-table tr.item td:not(.name-col):not(.photo-col):not(.price-col):not(.cart-col)[data-label]::before {
    content: attr(data-label) ": ";
  }
  .price-table tr.item td.price-col { display: flex; flex-direction: column; text-align: left; margin-top: 4px; }
  .price-table tr.item td.price-col::before { content: attr(data-label); font-size: .72rem; color: var(--muted); font-weight: 400; }
  .price-table tr.item td.price-col.base { font-size: 1.05rem; }
  .price-table tr.item td.cart-col { flex: 1 0 100%; text-align: left; margin-top: 8px; min-width: 0; }
  .order-ctl { align-items: flex-start; }
  .in-cart { text-align: left; }
  .cart-thumb { display: none; }
}

/* admin editor */
.editor tr.edit-head td { background: var(--head-bg) !important; font-weight: 600; }
.editor tr.edit-title td { background: var(--accent) !important; color: var(--accent-text); font-weight: 700; }
.photo-edit { display: flex; align-items: center; gap: 6px; }
.photo-edit img { width: 56px; height: 40px; object-fit: contain; background: #fff; border: 1px solid var(--border); border-radius: 4px; }
.photo-edit .btn { padding: 4px 8px; font-size: .8rem; white-space: nowrap; }
.editor td.row-tools button:first-child:hover { color: var(--ok); }
@media (max-width: 600px) {
  .price-table .hide-sm { display: inline; }
}
