:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --text: #172026;
  --muted: #66737d;
  --line: #d9e0e5;
  --panel: #ffffff;
  --accent: #176b87;
  --danger: #b42318;
  --danger-hover: #912018;
  --focus: #f3b23a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 17px;
  margin-bottom: 16px;
}

h3 {
  font-size: 14px;
}

p {
  color: var(--muted);
  margin-top: 5px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.1fr);
  gap: 16px;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.wide-panel {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: #2a363f;
  font-size: 14px;
  font-weight: 700;
}

.field-label {
  margin-bottom: 7px;
  color: #2a363f;
  font-size: 14px;
  font-weight: 700;
}

.branch-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#branchesSummary {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.check-list {
  max-height: 380px;
  overflow: auto;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(16 24 32 / 52%);
}

.modal {
  width: min(760px, 100%);
  max-height: min(720px, calc(100vh - 36px));
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--panel);
  border-radius: 8px;
  border: 1px solid var(--line);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
}

.branches-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 8px;
  overflow: auto;
  padding: 4px;
}

.branches-column {
  min-width: 0;
}

.branches-grid .check-row {
  min-height: 16px;
  padding: 0;
  line-height: 1.1;
}

.branches-grid .check-row span {
  line-height: 1.1;
}

.modal-actions {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 18px;
  margin: 0;
  padding: 1px 3px;
  border-bottom: 1px solid var(--line);
  font-weight: 400;
  cursor: pointer;
}

.check-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.check-row:last-child {
  border-bottom: 0;
}

.check-row:hover {
  background: #eef3f5;
}

.muted-row {
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  font: inherit;
  color: var(--text);
  background: #fff;
}

textarea {
  min-height: 220px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

select[multiple] {
  min-height: 190px;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.hidden {
  display: none;
}

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

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  border-color: var(--accent);
}

button.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

button.danger:hover {
  border-color: var(--danger-hover);
  background: var(--danger-hover);
}

button.compact {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.output-panel {
  margin-top: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin-bottom: 0;
}

#productSummary,
#selectedProductsSummary {
  color: var(--muted);
  font-size: 13px;
}

.compact-head {
  margin: 18px 0 8px;
}

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

.split-tables > * {
  min-width: 0;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
  background: #fff;
}

.mini-table table {
  min-width: 620px;
}

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

th {
  background: #eef3f5;
  color: #2a363f;
  font-weight: 700;
}

td small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

td code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

td:first-child,
th:first-child {
  width: 42px;
  text-align: center;
}

input[type="checkbox"] {
  width: 12px;
  height: 12px;
  padding: 0;
}

.primary-actions {
  justify-content: flex-start;
  margin-bottom: 14px;
}

.warn-row {
  background: #fff7ed;
}

.deleted-row {
  background: #fef3f2;
}

.multi-row {
  background: #f0f9ff;
}

.balance-field {
  max-width: 220px;
  margin-top: 14px;
}

pre {
  min-height: 160px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border-radius: 6px;
  background: #101820;
  color: #e8eef2;
  font-size: 13px;
  line-height: 1.5;
}

@media (max-width: 820px) {
  .shell {
    width: 100%;
    max-width: 100vw;
    padding: 10px;
    overflow-x: hidden;
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
    margin-bottom: 10px;
  }

  h1 {
    font-size: 22px;
  }

  h2 {
    font-size: 16px;
    margin-bottom: 12px;
  }

  .layout {
    width: 100%;
    min-width: 0;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .panel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 12px;
    border-radius: 6px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .split-tables {
    width: 100%;
    min-width: 0;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .check-list {
    max-height: 310px;
  }

  .check-row {
    min-height: 20px;
    padding: 1px 3px;
    font-size: 12px;
  }

  .modal-backdrop {
    padding: 8px;
    align-items: stretch;
  }

  .modal {
    width: 100%;
    max-height: calc(100vh - 16px);
  }

  .modal-head {
    padding: 10px 12px;
  }

  .branches-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0 6px;
    padding: 4px;
  }

  .modal-actions {
    padding: 10px 12px;
  }

  input[type="checkbox"] {
    flex: 0 0 auto;
  }

  input,
  select,
  textarea {
    min-height: 42px;
    font-size: 16px;
  }

  .actions {
    justify-content: stretch;
    gap: 8px;
  }

  button {
    flex: 1 1 140px;
    min-height: 42px;
    padding: 0 10px;
    font-size: 14px;
  }

  button.compact {
    min-height: 34px;
  }

  .table-wrap {
    width: 100%;
    max-width: calc(100vw - 44px);
    border-radius: 6px;
  }

  table {
    min-width: 760px;
  }

  .mini-table table {
    min-width: 640px;
  }

  th,
  td {
    padding: 8px 9px;
    font-size: 12px;
  }

  pre {
    max-height: 260px;
    font-size: 12px;
  }
}
