:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f1f4f6;
  --text: #1f2a32;
  --muted: #66737f;
  --line: #d9e0e6;
  --brand: #227c6f;
  --brand-2: #b84c2f;
  --warn: #a36b00;
  --danger: #b3261e;
  --ok: #267044;
  --shadow: 0 10px 24px rgba(31, 42, 50, .08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  min-height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
}

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

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

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

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

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

.login-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-box {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-box h1 {
  font-size: 22px;
  margin: 0 0 6px;
}

.login-box p {
  color: var(--muted);
  margin: 0 0 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}

.form-grid.wide {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.field label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 5px;
}

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

.sidebar {
  background: #263238;
  color: #e8eef1;
  border-right: 1px solid #182126;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-bar {
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}

.brand-bar strong {
  display: block;
  font-size: 17px;
}

.brand-bar span {
  color: #b4c0c8;
  font-size: 12px;
}

.nav {
  overflow: auto;
  padding: 10px;
}

.nav-group {
  margin-bottom: 10px;
}

.nav-title {
  color: #9fb0bb;
  font-size: 11px;
  text-transform: uppercase;
  padding: 8px 8px 4px;
}

.nav button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #e8eef1;
  border: 0;
  border-radius: 6px;
  min-height: 34px;
}

.nav button.active,
.nav button:hover {
  background: rgba(255, 255, 255, .1);
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 58px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar h2 {
  margin: 0;
  font-size: 18px;
}

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

.content {
  padding: 18px;
  min-width: 0;
}

.band {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.band h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.metric .value {
  font-size: 26px;
  font-weight: 700;
}

.metric .label {
  color: var(--muted);
  margin-top: 4px;
}

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

.toolbar .left,
.toolbar .right {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

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

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  vertical-align: top;
  max-width: 360px;
  overflow-wrap: anywhere;
}

th {
  color: var(--muted);
  background: var(--panel-2);
  font-weight: 600;
  font-size: 12px;
}

tr:last-child td {
  border-bottom: 0;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: var(--panel-2);
}

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  min-height: 22px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #fff;
  white-space: nowrap;
}

.status.ok {
  color: var(--ok);
  border-color: #b9dac6;
}

.status.warn {
  color: var(--warn);
  border-color: #edd39a;
}

.status.danger {
  color: var(--danger);
  border-color: #e5b8b3;
}

.small {
  font-size: 12px;
}

.empty {
  color: var(--muted);
  padding: 18px;
}

.category-manager {
  padding: 0;
}

.category-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: 660px;
}

.category-tree-pane {
  border-right: 1px solid var(--line);
  min-width: 0;
}

.category-detail-pane {
  min-width: 0;
  max-height: 660px;
  overflow: auto;
}

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

.category-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.category-search input {
  width: 100%;
}

.category-tree-list {
  padding: 8px;
  max-height: 590px;
  overflow: auto;
}

.category-tree-row {
  width: 100%;
  display: grid;
  grid-template-columns: auto 18px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  min-height: 34px;
  padding: 5px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
}

.category-tree-row:hover,
.category-tree-row.active {
  background: #e8f3f1;
  color: var(--primary);
}

.category-tree-row.active {
  font-weight: 700;
}

.category-tree-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-tree-meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.category-detail-body {
  padding: 16px;
}

.category-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.category-stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.category-stat .label,
.category-detail-row .label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.category-stat .value {
  font-size: 20px;
  font-weight: 700;
}

.category-path {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  margin-bottom: 14px;
}

.category-path span::after {
  content: "/";
  margin-left: 6px;
  color: var(--muted);
}

.category-path span:last-child::after {
  content: "";
  margin: 0;
}

.category-path .current {
  color: var(--text);
  font-weight: 700;
}

.category-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 14px;
  align-items: start;
}

.category-child-table table {
  min-width: 640px;
}

.category-child-table code {
  display: inline-block;
  max-width: 330px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-level {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--primary);
  border: 1px solid #b9dac6;
  background: #f7fcfa;
  white-space: nowrap;
}

.category-side-detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
}

.category-detail-row {
  margin-bottom: 12px;
}

.category-detail-row .value {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.category-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(720px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform .16s ease;
  z-index: 20;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-head {
  height: 58px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.drawer-body {
  overflow: auto;
  padding: 16px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.preview-field {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 12px;
  min-height: 74px;
}

.preview-field .label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.preview-field .value {
  font-weight: 600;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.preview-actions {
  margin: 16px 0 0;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #1f2a32;
  color: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  max-width: 420px;
  z-index: 40;
  box-shadow: var(--shadow);
}

.scan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.scan-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.scan-panel h4 {
  margin: 0 0 10px;
}

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

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}


.inline-check,
.role-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

.inline-check input,
.role-check input {
  width: 16px;
  height: 16px;
}

.subject-editor-overlay,
.gtin-import-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.45);
}

.subject-editor-panel,
.gtin-import-panel {
  width: min(880px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.24);
}

.gtin-import-panel {
  width: min(620px, 100%);
}

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

.subject-editor-body {
  padding: 16px;
}

.subject-editor-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.subject-role-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.subject-role-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 8px;
}

.gtin-summary {
  display: flex;
  gap: 24px;
  padding: 12px 4px;
  color: var(--muted);
}

.wms-overview-section {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px;
  min-width: 0;
}

.wms-overview-section + .wms-overview-section,
.wms-overview-split {
  margin-top: 14px;
}

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

.wms-section-title h3 {
  margin: 0;
  font-size: 17px;
}

.wms-metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  border: 1px solid var(--line);
}

.wms-metric {
  display: grid;
  gap: 8px;
  min-height: 78px;
  padding: 14px;
  border-right: 1px solid var(--line);
}

.wms-metric:last-child {
  border-right: 0;
}

.wms-metric span {
  color: var(--muted);
}

.wms-metric strong {
  font-size: 22px;
}

.warehouse-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 10px;
}

.warehouse-overview-card {
  display: grid;
  gap: 14px;
  text-align: left;
  background: var(--panel-2);
  border-color: var(--line);
  color: inherit;
}

.warehouse-card-head,
.warehouse-card-stock,
.warehouse-card-flow {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.warehouse-card-head span,
.warehouse-card-stock span {
  color: var(--muted);
}

.warehouse-card-stock > div {
  display: grid;
  gap: 4px;
}

.warehouse-card-flow .in { color: #087f5b; }
.warehouse-card-flow .out { color: #c2410c; }

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

.wms-overview-split .wms-overview-section {
  margin-top: 0;
}

.distribution-list,
.alert-list,
.top-sku-list {
  display: grid;
  gap: 10px;
}

.distribution-row {
  display: grid;
  grid-template-columns: minmax(90px, 150px) minmax(100px, 1fr) 80px;
  align-items: center;
  gap: 10px;
}

.distribution-track {
  height: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.distribution-track span {
  display: block;
  height: 100%;
  background: #2f80ed;
}

.wms-alert-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.wms-alert-column {
  border-left: 3px solid var(--line);
  padding-left: 12px;
}

.wms-alert-column.low { border-left-color: #e8590c; }
.wms-alert-column.high { border-left-color: #d6336c; }

.alert-row,
.top-sku-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.trend-chart {
  height: 220px;
  display: grid;
  grid-template-columns: repeat(30, minmax(5px, 1fr));
  align-items: end;
  gap: 3px;
  padding-top: 10px;
  border-bottom: 1px solid var(--line);
}

.trend-day {
  height: 100%;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 1px;
}

.trend-bar {
  width: 42%;
  min-height: 2px;
}

.trend-bar.inbound { background: #2f80ed; }
.trend-bar.outbound { background: #f59f00; }

.trend-legend {
  color: var(--muted);
}

.top-sku-row {
  min-height: 42px;
  border-bottom: 1px solid var(--line);
}

.top-sku-row > div {
  display: grid;
  min-width: 0;
}

.top-sku-row .rank {
  width: 24px;
  color: var(--brand);
  font-weight: 700;
}

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

  .sidebar {
    min-height: auto;
  }

  .nav {
    display: flex;
    overflow-x: auto;
    gap: 8px;
  }

  .nav-group {
    min-width: 190px;
  }

  .topbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    padding: 12px;
  }

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

  .product-entry-head {
    height: auto;
    padding: 12px;
    align-items: flex-start;
    flex-direction: column;
  }

  .product-entry-main {
    padding: 12px;
  }

  .section-title-row,
  .sku-card-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .sku-preview-code {
    max-width: 100%;
  }

  .category-picker-field {
    grid-column: 1 / -1;
  }

  .category-picker-filters {
    grid-template-columns: 1fr;
  }

  .packaging-row,
  .linked-row,
  .wms-metric-grid,
  .wms-overview-split,
  .wms-alert-grid {
    grid-template-columns: 1fr;
  }

  .wms-metric {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .wms-metric:last-child {
    border-bottom: 0;
  }
}

@media (max-width: 980px) {
  .category-layout,
  .category-split {
    grid-template-columns: 1fr;
  }

  .category-tree-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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