:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef3f6;
  --text: #17212b;
  --muted: #697783;
  --line: #dce3e8;
  --blue: #1769e0;
  --green: #1d8f61;
  --amber: #b77700;
  --red: #c73838;
  --shadow: 0 14px 36px rgba(27, 39, 51, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  background: var(--blue);
  color: #fff;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  cursor: wait;
  opacity: .65;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  background: #202833;
  color: #fff;
  padding: 28px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #fff;
  color: #202833;
  font-weight: 900;
}

.brand span {
  display: block;
  margin-top: 2px;
  color: #aab6c2;
  font-size: 13px;
}

.sidebar-bottom {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.company-select {
  gap: 6px;
  color: #aab6c2;
}

.company-select select {
  min-height: 42px;
  border-color: rgba(255, 255, 255, .2);
  background: #18212b;
  color: #dce4ec;
  font-weight: 700;
}

.company-select select:focus {
  outline: 2px solid rgba(23, 105, 224, .45);
  outline-offset: 2px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav a {
  border-radius: 7px;
  color: #dce4ec;
  padding: 11px 12px;
  text-decoration: none;
}

.nav a.active,
.nav a:hover {
  background: rgba(255, 255, 255, .1);
  color: #fff;
}

.ghost-button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, .2);
}

.workspace {
  min-width: 0;
  padding: 30px;
}

.login-panel,
.app-panel {
  display: none;
}

body[data-authenticated="0"] .login-panel,
body[data-authenticated="1"] .app-panel {
  display: block;
}

body[data-authenticated="0"] .sidebar {
  display: none;
}

body[data-authenticated="0"] .shell {
  grid-template-columns: 1fr;
}

.login-panel {
  min-height: calc(100vh - 60px);
  place-content: center;
}

.login-card {
  display: grid;
  gap: 18px;
  width: min(440px, 100%);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 28px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: 30px;
}

h2 {
  margin-bottom: 6px;
  font-size: 20px;
}

p {
  color: var(--muted);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.topbar-actions,
.form-footer,
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.secondary-button {
  background: #e7edf3;
  color: #1c2b38;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(320px, .8fr);
  gap: 18px;
  margin-bottom: 18px;
}

#products {
  margin-bottom: 18px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px;
}

.search-row {
  max-width: 460px;
  margin-top: 14px;
}

.stock-summary {
  display: grid;
  grid-template-columns: repeat(7, minmax(110px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.stock-summary.orders-summary {
  grid-template-columns: repeat(5, minmax(120px, 1fr));
}

.market-tabs {
  display: inline-flex;
  gap: 6px;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 4px;
}

.market-tabs button {
  min-height: 34px;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 0 18px;
  font-weight: 400;
}

.market-tabs button.active {
  background: var(--blue);
  color: #fff;
}

.section-title {
  margin: 18px 0 0;
  font-size: 16px;
  font-weight: 400;
}

.stock-summary div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px;
}

.stock-summary span,
.stock-summary strong {
  display: block;
  font-weight: 400;
}

.stock-summary span {
  color: var(--muted);
  font-size: 13px;
}

.stock-summary strong {
  margin-top: 6px;
  color: var(--text);
  font-size: 20px;
}

.wide {
  min-width: 0;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 14px;
}

.table-wrap.compact table {
  min-width: 620px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1120px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.row-number {
  width: 44px;
  color: var(--muted);
}

.table-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.product-cell {
  display: grid;
  grid-template-columns: 52px 72px minmax(260px, 1fr);
  align-items: center;
  gap: 12px;
  min-width: 420px;
}

.product-cell .product-name,
.product-cell span {
  display: block;
}

.product-name {
  color: var(--text);
  font-weight: 400;
}

.product-code {
  margin-top: 4px;
  color: #334454;
  font-size: 13px;
  font-weight: 400;
}

.product-code.muted {
  color: var(--muted);
  font-weight: 400;
}

.product-thumb {
  width: 52px;
  height: 68px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafb;
  object-fit: cover;
}

.product-thumb.hidden {
  display: block;
}

.product-thumb.placeholder {
  display: block;
}

.small-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.stock-value,
.cell-value {
  min-width: 54px;
  min-height: 34px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 0 10px;
  font-weight: 400;
}

.cell-value {
  min-width: 72px;
}

.supplier-stock {
  display: inline-flex;
  min-width: 54px;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: #eefbf4;
  color: var(--green);
  padding: 0 10px;
}

.supplier-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.supplier-stock.forced {
  background: #f8e3e3;
  color: var(--red);
}

.supplier-zero-button.active {
  border-color: #e5b8b8;
  background: #f8e3e3;
  color: var(--red);
}

.danger-button {
  background: #f4e7e7;
  color: var(--red);
}

.stack-form,
.marketplace-fields {
  display: grid;
  gap: 13px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-row.single {
  grid-template-columns: 1fr;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 12px;
}

.settings-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 16px;
}

.settings-card h3 {
  margin: 0;
}

.warehouse-list {
  display: grid;
  gap: 8px;
}

.warehouse-option {
  display: grid;
  gap: 3px;
  height: auto;
  min-height: 52px;
  justify-items: start;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px;
  text-align: left;
}

.warehouse-option span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge-row {
  display: grid;
  gap: 6px;
  justify-items: start;
}

.order-items {
  display: grid;
  gap: 6px;
}

.order-items span,
.order-items small {
  display: block;
  font-weight: 400;
}

.order-items small {
  color: var(--muted);
  font-size: 12px;
}

.pick-list {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.pick-list-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.pick-list h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 400;
}

.pick-list p {
  margin: 5px 0 0;
  color: var(--muted);
}

.assembly-progress {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  background: #f8fafc;
  padding: 12px 0;
}

.assembly-progress div {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
}

.assembly-progress span {
  color: var(--muted);
  font-size: 12px;
}

.assembly-progress strong {
  font-size: 18px;
}

.assembly-list {
  display: grid;
  gap: 10px;
  padding: 14px 0 18px;
}

.assembly-card {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.assembly-card-main {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.assembly-cell,
.assembly-quantity,
.assembly-sticker {
  display: grid;
  gap: 2px;
  border-radius: 8px;
  background: #eef4ff;
  padding: 8px 10px;
}

.assembly-quantity {
  background: #fff7dc;
}

.assembly-sticker {
  background: #eaf6f0;
}

.assembly-cell span,
.assembly-quantity span,
.assembly-sticker > span {
  color: var(--muted);
  font-size: 11px;
}

.assembly-cell strong,
.assembly-quantity strong,
.assembly-sticker strong {
  font-size: 26px;
  line-height: 1.05;
}

.assembly-sticker-main {
  grid-template-columns: minmax(76px, 0.7fr) minmax(76px, 0.7fr) minmax(130px, 1.4fr);
}

.assembly-sticker-card {
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
}

.assembly-sticker .sticker-tail {
  font-size: 44px !important;
}

.assembly-sticker .sticker-prefix,
.assembly-sticker .sticker-suffix {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.assembly-product {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.assembly-product span {
  font-size: 17px;
  line-height: 1.25;
}

.assembly-product small {
  color: var(--muted);
  font-size: 12px;
}

.label-match-card {
  grid-template-columns: minmax(140px, 230px) minmax(0, 1fr);
}

.label-match-code {
  display: grid;
  gap: 5px;
  border-radius: 8px;
  background: #eef4ff;
  padding: 10px 12px;
}

.label-match-code span {
  color: var(--muted);
  font-size: 11px;
}

.label-match-code strong {
  overflow-wrap: anywhere;
  font-size: 21px;
  line-height: 1.1;
}

.sticker-match-code strong {
  display: block;
}

.sticker-value {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0;
}

.sticker-prefix {
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.sticker-tail {
  color: var(--blue);
  font-size: 58px !important;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 0.9;
}

.sticker-suffix {
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.sticker-value-ozon {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: start;
  align-items: end;
  column-gap: 0;
  row-gap: 2px;
  max-width: 100%;
}

.sticker-value-ozon .sticker-prefix {
  font-size: 14px;
  line-height: 0.95;
  white-space: nowrap;
}

.sticker-value-ozon .sticker-tail {
  display: inline-block;
  border-radius: 2px;
  background: #1f2937;
  color: #fff;
  font-size: 36px !important;
  line-height: 0.95;
  padding: 0 4px 2px;
}

.sticker-value-ozon .sticker-suffix {
  grid-column: 1 / -1;
  font-size: 14px;
  letter-spacing: 0;
}

.label-match-items {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}

.label-match-items div {
  display: grid;
  gap: 2px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.label-match-items span {
  font-size: 15px;
  line-height: 1.2;
}

.label-match-items small {
  color: var(--muted);
  font-size: 12px;
}

.assembly-page {
  background: #f8fafc;
}

.assembly-page-shell {
  width: min(920px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--surface);
}

.assembly-page-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 14px 16px;
}

.assembly-page-header span {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.assembly-page-header h1 {
  margin: 3px 0 0;
  font-size: 24px;
}

.assembly-back-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border-radius: 7px;
  background: #e8edf2;
  color: var(--text);
  padding: 0 14px;
  text-decoration: none;
  font-weight: 700;
}

.assembly-page-auth,
.assembly-page-content {
  padding: 16px;
}

.assembly-page-content,
.assembly-authenticated .assembly-page-auth {
  display: none;
}

.assembly-authenticated .assembly-page-content {
  display: block;
}

.assembly-page-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.assembly-page .login-card {
  max-width: none;
}

.assembly-page .assembly-progress {
  margin-top: 12px;
}

.cell-pill,
.cell-inline {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 0 9px;
  font-weight: 400;
}

.cell-inline {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: #e8edf2;
  color: #344554;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 400;
}

.badge.success {
  background: #def3e9;
  color: var(--green);
}

.badge.warning {
  background: #fff2d6;
  color: var(--amber);
}

.badge.danger {
  background: #f8e3e3;
  color: var(--red);
}

.marketplace-badge.ozon {
  background: #e2efff;
  color: #1255b8;
}

.marketplace-badge.wildberries {
  background: #f0e4ff;
  color: #7a2bc4;
}

.marketplace-badge.yandex {
  background: #fff2b8;
  color: #7c5c00;
}

.form-message {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.exchange-form {
  margin-top: 14px;
}

.source-switch {
  display: inline-flex;
  width: fit-content;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.source-switch label {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
}

.source-switch label:has(input:checked) {
  background: var(--blue);
  color: #fff;
}

.source-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.exchange-source-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, .35fr);
  gap: 12px;
}

.threshold-panel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 14px;
}

.threshold-panel h3,
.preview-panel h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 400;
}

.threshold-panel p {
  margin: 5px 0 0;
  color: var(--muted);
}

.threshold-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.threshold-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.exchange-status {
  margin-top: 14px;
}

.exchange-status-card {
  display: grid;
  gap: 6px;
  max-width: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 14px;
}

.exchange-status-card span,
.exchange-status-card small {
  color: var(--muted);
}

.exchange-status-card strong {
  font-weight: 600;
}

.exchange-status-card.success {
  border-color: #bfe7d2;
  background: #eefbf4;
}

.exchange-status-card.warning {
  border-color: #f2d9a6;
  background: #fff8e8;
}

.exchange-report {
  display: grid;
  gap: 12px;
  max-width: 860px;
  margin-top: 14px;
}

.exchange-report h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 400;
}

.exchange-report-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.exchange-report-grid div,
.selected-file {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.exchange-report-grid span,
.selected-file span,
.selected-file small {
  color: var(--muted);
}

.exchange-report-grid strong,
.selected-file strong {
  font-weight: 400;
}

.exchange-preview {
  margin-top: 16px;
}

.preview-panel {
  display: grid;
  gap: 12px;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-header span {
  color: var(--muted);
}

.preview-panel table {
  min-width: 900px;
}

.preview-panel td {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stock-dialog {
  width: min(520px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 0;
}

.stock-dialog::backdrop {
  background: rgba(23, 33, 43, .42);
}

.stock-form {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.log-list {
  display: grid;
  gap: 10px;
}

.log-list.compact {
  margin-top: 14px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
}

.log-item {
  display: grid;
  gap: 4px;
  border-left: 3px solid var(--line);
  background: #f8fafb;
  padding: 10px 12px;
}

.log-item.success {
  border-left-color: var(--green);
}

.log-item.warning {
  border-left-color: var(--amber);
}

.log-time {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

@media (max-width: 1100px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .content-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .workspace {
    padding: 18px;
  }

  .topbar,
  .panel-header,
  .topbar-actions,
  .form-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .exchange-report-grid {
    grid-template-columns: 1fr;
  }

  .threshold-grid {
    grid-template-columns: 1fr;
  }

  .exchange-source-row {
    grid-template-columns: 1fr;
  }

  .assembly-progress {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .assembly-card {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
  }

  .label-match-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .assembly-card-main {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .assembly-sticker-main {
    grid-template-columns: minmax(74px, 0.65fr) minmax(74px, 0.65fr) minmax(132px, 1.3fr);
  }

  .assembly-product {
    padding-left: 0;
  }

  .assembly-product span {
    font-size: 18px;
  }

  .assembly-page-shell {
    width: 100%;
  }

  .assembly-page-header h1 {
    font-size: 22px;
  }
}
