/* ===========================================================
   Прайс-лист — дизайн-система
   Тема: складской журнал/ведомость. Данные — главный герой.
   =========================================================== */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #F1F0EC;
  --surface: #FFFFFF;
  --surface-alt: #E9E7E0;
  --ink: #1E2124;
  --ink-soft: #5B5F63;
  --border: #DEDBD2;
  --primary: #1F2E3D;
  --primary-ink: #F1F0EC;
  --accent: #B5651D;
  --accent-ink: #FFFFFF;
  --link: #3E6B5C;
  --danger: #A23B2E;
  --radius: 6px;
  --shadow: 0 2px 10px rgba(30, 33, 36, 0.08);
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
}

button, input, select {
  font-family: inherit;
  font-size: inherit;
}

a { color: var(--link); }

.num, .price, .article-cell, td.price, input#searchInput {
  font-variant-numeric: tabular-nums;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--primary);
  color: var(--primary-ink);
  padding: 10px 16px;
  border-bottom: 3px solid var(--accent);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  font-size: 16px;
}

.icon-btn {
  background: transparent;
  border: 1px solid rgba(241, 240, 236, 0.35);
  color: var(--primary-ink);
  border-radius: var(--radius);
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(241, 240, 236, 0.12); }

.search-wrap { flex: 1 1 auto; min-width: 0; }

#searchInput {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(241, 240, 236, 0.25);
  background: rgba(241, 240, 236, 0.1);
  color: var(--primary-ink);
}
#searchInput::placeholder { color: rgba(241, 240, 236, 0.6); }
#searchInput:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  background: rgba(241, 240, 236, 0.16);
}

.btn-configurator {
  background: transparent;
  color: var(--primary-ink);
  border: 1px solid rgba(241, 240, 236, 0.35);
  border-radius: var(--radius);
  padding: 9px 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-configurator:hover { background: rgba(241, 240, 236, 0.12); }
.btn-configurator .short-label { display: none; }

.cart-btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius);
  padding: 9px 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cart-btn:hover { filter: brightness(1.06); }
#cartCount {
  background: rgba(255,255,255,0.25);
  border-radius: 999px;
  padding: 1px 8px;
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ---------- Layout ---------- */
.layout {
  display: flex;
  align-items: flex-start;
  max-width: 1400px;
  margin: 0 auto;
}

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-height: calc(100vh - 58px);
  position: sticky;
  top: 58px;
  overflow-y: auto;
  max-height: calc(100vh - 58px);
}

.sidebar-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.category-tree { padding: 10px 0 40px; }

.cat-item { }
.cat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  color: var(--ink);
}
.cat-row:hover { background: var(--surface-alt); }
.cat-row.active {
  border-left-color: var(--accent);
  background: var(--surface-alt);
  font-weight: 600;
}
.cat-toggle {
  width: 16px;
  flex-shrink: 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: 11px;
  transform: rotate(0deg);
  transition: transform .15s;
}
.cat-item.open > .cat-row .cat-toggle { transform: rotate(90deg); }
.cat-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
}
.cat-children { display: none; }
.cat-item.open > .cat-children { display: block; }
.cat-item .cat-item .cat-row { padding-left: 30px; }
.cat-item .cat-item .cat-item .cat-row { padding-left: 46px; }

.cat-root-all .cat-row { font-weight: 700; }

/* ---------- Content ---------- */
.content {
  flex: 1 1 auto;
  min-width: 0;
  padding: 16px 20px 60px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.breadcrumbs {
  font-size: 14px;
  color: var(--ink-soft);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.breadcrumbs b { color: var(--ink); }

.sort-wrap select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

.results-info {
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

/* ---------- Product table ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table.product-table {
  width: 100%;
  border-collapse: collapse;
}

.product-table thead th {
  text-align: left;
  font-size: 12px;
  text-transform: none;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 10px 14px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}
.product-table thead th.num { text-align: right; }

.product-table tbody tr {
  border-bottom: 1px solid var(--border);
}
.product-table tbody tr:last-child { border-bottom: none; }
.product-table tbody tr:hover { background: #FAF9F6; }

.product-table td {
  padding: 10px 14px;
  vertical-align: middle;
}

td.article-cell {
  font-family: var(--font-mono);
  color: var(--ink-soft);
  white-space: nowrap;
  font-size: 13px;
}

td.name-cell a {
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}
td.name-cell a:hover { color: var(--link); text-decoration: underline; }

td.price {
  font-family: var(--font-mono);
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

td.action-cell { text-align: right; white-space: nowrap; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { background: var(--surface-alt); }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-accent:hover { filter: brightness(1.06); }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.15); }

.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }

.empty-state {
  padding: 50px 20px;
  text-align: center;
  color: var(--ink-soft);
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.pagination button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  min-width: 34px;
  height: 34px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 13px;
}
.pagination button.active {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: var(--primary);
}
.pagination button:disabled { opacity: .4; cursor: default; }

/* ---------- Overlays / drawers / modal ---------- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 24, 0.45);
  z-index: 45;
}
.sidebar-overlay.show { display: block; }

.cart-drawer {
  position: fixed;
  top: 0;
  right: -420px;
  width: 400px;
  max-width: 92vw;
  height: 100%;
  background: var(--surface);
  z-index: 60;
  display: flex;
  flex-direction: column;
  box-shadow: -6px 0 24px rgba(0,0,0,0.18);
  transition: right .2s ease;
}
.cart-drawer.open { right: 0; }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

.cart-items {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 16px;
}

.cart-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.cart-item .ci-name { font-size: 13.5px; }
.cart-item .ci-article { font-family: var(--font-mono); color: var(--ink-soft); font-size: 12px; }
.cart-item .ci-price { font-family: var(--font-mono); text-align: right; font-weight: 600; }
.ci-qty-row { display: flex; align-items: center; gap: 8px; grid-column: 1 / -1; }
.qty-btn {
  width: 26px; height: 26px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-mono);
}
.qty-value { font-family: var(--font-mono); min-width: 24px; text-align: center; }
.ci-remove {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 13px;
  text-decoration: underline;
}

.drawer-foot {
  border-top: 1px solid var(--border);
  padding: 14px 16px 18px;
}
.cart-total-row {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 12px;
}
.cart-total-row span:last-child { font-family: var(--font-mono); }

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 70;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 14px;
  overflow-y: auto;
  background: rgba(20,22,24,0.5);
}
.modal.open { display: flex; }
.modal-box {
  background: var(--surface);
  border-radius: 8px;
  width: 100%;
  max-width: 560px;
  padding: 22px;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: none; border: none;
  font-size: 18px; cursor: pointer;
  color: var(--ink-soft);
}
.modal-box h2 {
  margin: 0 0 16px;
  font-size: 19px;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 5px; }
.field input, .field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--link); outline-offset: 1px; }
.field-error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }

.order-success {
  text-align: center;
  padding: 10px 0 4px;
}
.order-success .order-number {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  margin: 10px 0;
}
.order-tg-instruction {
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.order-tg-instruction a { color: var(--link); font-weight: 600; }

/* Product card modal */
.pm-article { font-family: var(--font-mono); color: var(--ink-soft); font-size: 13px; margin-bottom: 4px; }
.pm-name { font-size: 18px; font-weight: 600; margin: 0 0 10px; }
.pm-price { font-family: var(--font-mono); font-size: 24px; font-weight: 700; color: var(--accent); margin-bottom: 16px; }
.pm-photo {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--surface-alt);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  font-size: 13px;
  margin-bottom: 14px;
  overflow: hidden;
}
.pm-photo img { width: 100%; height: 100%; object-fit: cover; }
.pm-desc { font-size: 14px; margin-bottom: 14px; }
.pm-specs { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 13.5px; }
.pm-specs td { padding: 6px 0; border-bottom: 1px solid var(--border); }
.pm-specs td:first-child { color: var(--ink-soft); width: 46%; }
.pm-ai-hint { font-size: 12.5px; color: var(--ink-soft); margin-top: 6px; }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--primary);
  color: var(--primary-ink);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.only-mobile { display: none; }

/* ---------- Конфигуратор ПК ---------- */
.configurator-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 20px 60px;
}
.configurator-intro h1 { font-size: 21px; margin: 0 0 6px; }
.configurator-intro p { color: var(--ink-soft); margin: 0 0 20px; max-width: 640px; }

.configurator-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}

.slots-wrap {
  display: grid;
  gap: 12px;
}

.slot-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.slot-card.filled { border-left: 3px solid var(--accent); }

.slot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.slot-title { font-weight: 600; margin-right: 8px; }
.slot-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.slot-badge.required { background: #EAF3EC; color: #3E6B5C; }
.slot-badge.optional { background: var(--surface-alt); color: var(--ink-soft); }
.slot-empty-note { color: var(--ink-soft); font-size: 13px; }

.slot-selected {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.slot-selected-info { flex: 1 1 220px; min-width: 0; }
.slot-selected-name { font-size: 14px; margin-bottom: 2px; }
.slot-selected-meta { font-size: 12.5px; color: var(--ink-soft); font-family: var(--font-mono); }
.slot-actions { display: flex; gap: 8px; }

.config-summary { position: sticky; top: 74px; }
.config-summary-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.config-summary-box h2 { font-size: 16px; margin: 0 0 10px; }
.summary-list { margin-bottom: 10px; max-height: 320px; overflow-y: auto; }
.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.summary-row-price { font-family: var(--font-mono); white-space: nowrap; }

/* модалка выбора компонента */
.picker-box { max-width: 640px; }
.picker-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.picker-toolbar input {
  flex: 1 1 auto;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.picker-toolbar select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.picker-list { max-height: 50vh; overflow-y: auto; margin-bottom: 10px; }
.picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--border);
}
.picker-row-info { flex: 1 1 auto; min-width: 0; }
.picker-row-name { font-size: 13.5px; }
.picker-row-meta { font-size: 12px; color: var(--ink-soft); font-family: var(--font-mono); }
.picker-row-price { font-family: var(--font-mono); font-weight: 600; white-space: nowrap; }

@media (max-width: 900px) {
  .configurator-layout { grid-template-columns: 1fr; }
  .config-summary { position: static; }
}

/* ---------- Responsive: mobile ---------- */
@media (max-width: 900px) {
  .brand { display: none; }
  .only-mobile { display: inline-flex; }
  .btn-configurator .full-label { display: none; }
  .btn-configurator .short-label { display: inline; }
  .btn-configurator { padding: 9px 11px; font-size: 16px; }

  .sidebar {
    position: fixed;
    top: 0; left: -320px;
    width: 300px;
    height: 100%;
    z-index: 55;
    transition: left .2s ease;
  }
  .sidebar.open { left: 0; }
  .sidebar-head { display: flex; }

  .content { padding: 12px 10px 70px; }

  .table-wrap { border: none; background: transparent; }
  table.product-table thead { display: none; }
  table.product-table, table.product-table tbody, table.product-table tr, table.product-table td {
    display: block;
    width: 100%;
  }
  .product-table tbody tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    padding: 10px 12px;
  }
  .product-table td { padding: 3px 0; border-bottom: none; }
  td.article-cell { font-size: 12px; }
  td.name-cell a { font-size: 14px; }
  td.price { text-align: left; font-size: 16px; margin-top: 4px; }
  td.action-cell { text-align: left; margin-top: 8px; }
  .btn-block-mobile { width: 100%; }

  .cart-drawer { width: 100%; max-width: 100%; }
}
