:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --line: #d8e1ea;
  --line-strong: #b6c5d4;
  --text: #142033;
  --muted: #5f6f7e;
  --green: #1c5f99;
  --green-dark: #0d3f6c;
  --green-soft: #e9f3fb;
  --accent: #f2b735;
  --accent-soft: #fff7e2;
  --charcoal: #343436;
  --red: #b3261e;
  --red-soft: #fdecea;
  --yellow-soft: #fff7d6;
  --shadow: 0 10px 24px rgba(24, 32, 28, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  box-sizing: border-box;
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 18px 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 72px;
}

.brand-logo {
  width: 76px;
  height: 76px;
  object-fit: contain;
  padding: 3px;
  border-radius: 8px;
  background: #fff;
}

.brand strong {
  display: block;
  font-size: 18px;
  color: var(--charcoal);
}

.brand span,
.panel-header span,
.muted-text {
  color: var(--muted);
}

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

.nav-button {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

.nav-button:hover,
.nav-button.active {
  background: var(--green-soft);
  border-color: #c7e2d3;
  color: var(--green-dark);
}

.sidebar-note {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
}

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

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

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

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

h2 {
  font-size: 18px;
  line-height: 1.25;
}

h3 {
  font-size: 16px;
  line-height: 1.3;
}

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

.topbar-actions,
.table-tools,
.form-actions,
.export-actions,
.action-stack {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button,
.secondary-link,
.link-button {
  min-height: 36px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  padding: 8px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.primary-button {
  background: linear-gradient(180deg, #2b75b5, #164f86);
  border-color: #164f86;
  color: #fff;
}

.primary-button:hover {
  background: linear-gradient(180deg, #236aa7, #123f6c);
}

.secondary-button,
.secondary-link {
  background: #fff;
  color: var(--green-dark);
}

.secondary-button:hover,
.secondary-link:hover,
.ghost-button:hover,
.icon-button:hover {
  background: var(--green-soft);
}

.ghost-button {
  background: transparent;
  color: var(--muted);
}

.icon-button {
  width: 38px;
  padding: 8px;
  background: #fff;
  color: var(--text);
  font-size: 18px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 88px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
  color: var(--charcoal);
}

.metric.warning {
  background: var(--yellow-soft);
  border-color: #eadb9b;
}

.dashboard-grid,
.import-grid,
.refs-grid {
  display: grid;
  gap: 16px;
}

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

.import-grid {
  grid-template-columns: minmax(280px, 520px);
}

.refs-grid {
  grid-template-columns: repeat(3, minmax(320px, 1fr));
  align-items: start;
}

.refs-panel {
  display: grid;
  gap: 18px;
  padding: 16px;
}

.refs-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.ref-tab-button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--green-dark);
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
}

.ref-tab-button.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.ref-tab-panel,
.warehouse-tab-panel {
  display: none;
}

.ref-tab-panel.active,
.warehouse-tab-panel.active {
  display: grid;
  gap: 14px;
}

.warehouse-accordion {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.warehouse-accordion-item {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.warehouse-tab-button {
  display: grid;
  width: 100%;
  grid-template-columns: minmax(0, 1fr) auto 34px;
  gap: 12px;
  align-items: center;
  min-height: 62px;
  padding: 12px 14px;
  border: 0;
  background: #fff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.warehouse-tab-button:hover,
.warehouse-tab-button.active {
  background: #f7fbff;
}

.warehouse-tab-main {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.warehouse-tab-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--green-dark);
  font-size: 16px;
  font-weight: 800;
}

.warehouse-tab-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.warehouse-tab-count {
  min-width: 24px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #7b5612;
  text-align: center;
  font-size: 13px;
  font-weight: 800;
}

.warehouse-arrow {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: var(--green-dark);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fbff;
  font-size: 18px;
  transition: transform 140ms ease, background 140ms ease;
}

.warehouse-accordion-item.active .warehouse-arrow {
  transform: rotate(180deg);
  background: var(--green-soft);
}

.warehouse-tab-panel {
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
}

.panel,
.filter-grid {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
  min-width: 0;
}

.panel-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

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

.bar-list,
.compact-list {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(70px, 110px);
  align-items: center;
  gap: 10px;
}

.count-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 30px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
}

.count-row:last-child {
  border-bottom: none;
}

.bar-track {
  height: 8px;
  background: #edf0ee;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--green);
}

.list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.list-item:last-child {
  border-bottom: none;
}

.list-item strong {
  overflow-wrap: anywhere;
}

.list-item span,
.small-muted {
  color: var(--muted);
  font-size: 13px;
}

.photo-panel img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.filter-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) repeat(5, minmax(130px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  margin-bottom: 16px;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 76px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(19, 122, 67, 0.13);
}

.multi-select {
  position: relative;
}

.multi-select-button {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22px;
  gap: 8px;
  align-items: center;
  text-align: left;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  cursor: pointer;
}

.multi-select-button span:first-child {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.multi-select.open .multi-select-button,
.multi-select-button:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(19, 122, 67, 0.13);
  outline: none;
}

.select-arrow {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 18px;
}

.multi-select-menu {
  display: none;
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow: auto;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.multi-select.open .multi-select-menu {
  display: grid;
  gap: 2px;
}

.multi-option {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 32px;
  padding: 6px 8px;
  color: var(--text);
  border-radius: 5px;
  cursor: pointer;
}

.multi-option:hover {
  background: var(--green-soft);
}

.multi-option input {
  width: 16px;
  min-height: 16px;
  padding: 0;
}

.filter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.table-panel {
  padding: 0;
  overflow: hidden;
}

.table-panel .panel-header {
  padding: 16px 16px 0;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7faf8;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

td {
  line-height: 1.35;
}

.object-cell {
  min-width: 320px;
  max-width: 560px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #edf0ee;
  color: #44504b;
  font-size: 13px;
  white-space: nowrap;
}

.badge.green {
  color: var(--green-dark);
  background: var(--green-soft);
}

.badge.red {
  color: var(--red);
  background: var(--red-soft);
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-actions button,
.row-actions a {
  min-width: 34px;
  min-height: 32px;
  padding: 6px 8px;
  border-radius: 5px;
}

.edit-form {
  max-width: 980px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
}

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

.checkbox-line {
  grid-column: 1 / -1;
  grid-template-columns: 18px auto;
  align-items: center;
  color: var(--text);
}

.checkbox-line input {
  width: 16px;
  min-height: 16px;
}

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

.upload-form,
.inline-form {
  display: grid;
  gap: 8px;
}

.upload-form {
  grid-template-columns: minmax(0, 1fr) auto;
}

.inline-form {
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) auto;
  margin-bottom: 12px;
}

.inline-form .primary-button {
  min-width: 44px;
  padding-inline: 12px;
}

#company-form {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
}

#warehouse-form {
  grid-template-columns: minmax(190px, 0.75fr) minmax(260px, 1fr) auto;
}

#warehouses-list {
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

.warehouse-create-card {
  display: grid;
  gap: 12px;
  align-items: end;
  padding: 14px;
  margin: 6px 0 0;
  border: 1px solid #c7d9e9;
  border-radius: 8px;
  background: linear-gradient(180deg, #f7fbff 0%, #ffffff 100%);
}

.warehouse-create-copy,
.warehouse-card-heading,
.shelf-add-copy {
  display: grid;
  gap: 3px;
  align-self: center;
}

.warehouse-create-copy strong,
.warehouse-card-heading strong,
.shelf-add-copy strong,
.shelf-section-header strong {
  color: var(--text);
  font-size: 16px;
}

.section-kicker {
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.add-button {
  min-width: 164px;
}

.button-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-weight: 800;
}

.ref-edit-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(160px, 1.3fr) minmax(70px, 0.5fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

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

.ref-card label {
  min-width: 0;
}

.ref-card input,
.ref-card select {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.company-ref-row {
  grid-template-columns: minmax(0, 1fr) 86px;
  align-items: end;
}

.company-ref-row .wide {
  grid-column: 1 / -1;
}

.company-ref-row .ref-save-button {
  grid-column: 1 / -1;
  justify-self: end;
  min-width: 126px;
}

.region-edit-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.region-edit-row input {
  font-weight: 600;
}

.log-output {
  margin: 14px 0 0;
  min-height: 180px;
  max-height: 360px;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
  background: #101815;
  color: #d8f0e1;
  border-radius: 6px;
  font: 13px Consolas, monospace;
}

.tall-list {
  max-height: 520px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
}

.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 10;
  width: min(560px, 100vw);
  height: 100vh;
  padding: 18px;
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 32px rgba(24, 32, 28, 0.14);
  transform: translateX(105%);
  transition: transform 160ms ease;
  overflow: auto;
}

.detail-panel.open {
  transform: translateX(0);
}

.close-button {
  position: sticky;
  top: 0;
  margin-left: auto;
  z-index: 2;
}

.detail-title {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
}

.detail-title strong {
  font-size: 30px;
  line-height: 1.1;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.kv {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.kv span:first-child {
  color: var(--muted);
}

.history {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.history-item {
  border-left: 3px solid var(--green);
  padding: 8px 10px;
  background: #f7faf8;
  border-radius: 0 6px 6px 0;
}

.location-editor {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
  margin: 12px 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 20;
  transform: translateX(-50%) translateY(120%);
  visibility: hidden;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 14px;
  background: #18201c;
  color: #fff;
  border-radius: 6px;
  box-shadow: var(--shadow);
  transition: transform 160ms ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  visibility: visible;
}

.toast:empty {
  display: none;
}

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

.warehouse-ref-card {
  display: grid;
  gap: 14px;
  padding-top: 14px;
  border: 0;
  border-radius: 0;
  background: #fff;
}

.warehouse-ref-card + .warehouse-ref-card {
  margin-top: 2px;
}

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

.warehouse-title-row,
.shelf-line,
.shelf-add-row {
  display: grid;
  gap: 8px;
  align-items: end;
}

.warehouse-title-row {
  grid-template-columns: minmax(180px, 0.65fr) minmax(260px, 1fr) auto;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.warehouse-card-heading span:last-child {
  color: var(--muted);
  font-size: 13px;
}

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

.shelf-count-pill {
  min-width: 34px;
  padding: 4px 9px;
  text-align: center;
  color: #7b5612;
  background: var(--accent-soft);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.shelf-line {
  grid-template-columns: 78px minmax(0, 1fr) auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
}

.shelf-line-marker {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  color: var(--green-dark);
  background: var(--green-soft);
  border-radius: 6px;
  font-weight: 700;
}

.shelf-add-row {
  grid-template-columns: minmax(160px, 0.55fr) minmax(220px, 1fr) auto;
  padding: 12px;
  border: 1px dashed #b6c5d4;
  border-radius: 8px;
  background: #f8fbff;
}

.warehouse-title-row .ref-save-button,
.shelf-line .ref-save-button {
  justify-self: end;
  min-width: 126px;
}

.shelf-add-row .primary-button {
  min-width: 164px;
  padding-inline: 12px;
}

#import .import-grid {
  grid-template-columns: minmax(0, 520px);
}

@media (max-width: 1180px) {
  .filter-grid,
  .refs-grid,
  .import-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-actions {
    grid-column: 1 / -1;
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .nav-button {
    text-align: center;
    padding: 8px 6px;
  }

  .workspace {
    padding: 14px;
  }

  .topbar,
  .row-header {
    flex-direction: column;
    align-items: stretch;
  }

  .metrics,
  .dashboard-grid,
  .filter-grid,
  .form-grid,
  .refs-grid,
  .import-grid,
  .upload-form,
  .inline-form,
  .ref-edit-row,
  .company-ref-row,
  .region-edit-row,
  .warehouse-title-row,
  .shelf-line,
  .shelf-add-row,
  #company-form,
  #warehouse-form,
  .location-editor {
    grid-template-columns: 1fr;
  }

  .add-button,
  .warehouse-title-row .ref-save-button,
  .shelf-line .ref-save-button,
  .shelf-add-row .primary-button {
    width: 100%;
  }

  .detail-panel {
    width: 100vw;
  }
}
