:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #111827;
  --muted: #5f6b7a;
  --line: #e1e7ef;
  --blue: #2563eb;
  --blue-soft: #eef5ff;
  --blue-dark: #1d4ed8;
  --green: #15803d;
  --amber: #b45309;
  --red: #b42318;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px 10px;
  border-right: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

.brand {
  display: grid;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 14px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid #d6e4ff;
  border-radius: 10px;
  background: var(--blue-soft);
  color: var(--blue-dark);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 14px;
}

.brand span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #374151;
  text-align: left;
  font-size: 16px;
  font-weight: 750;
}

.nav-item::before {
  content: none;
}

.nav-item:hover,
.nav-item.active {
  border-color: #c9dcff;
  background: var(--blue-soft);
  color: var(--blue-dark);
}

.sidebar-note {
  margin-top: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}

.sidebar-note span,
.sidebar-note strong {
  display: block;
}

.sidebar-note span {
  color: var(--muted);
  font-size: 11px;
}

.sidebar-note strong {
  margin-top: 4px;
  font-size: 12px;
}

.main {
  min-width: 0;
  padding: 12px 28px 26px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 25px;
  font-weight: 780;
}

h2 {
  font-size: 18px;
  font-weight: 750;
}

.topbar-actions,
.filters,
.toolbar,
.sub-toolbar,
.detail-tabs,
.row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.local-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid #c9dcff;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 750;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  min-height: 38px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.primary-button {
  padding: 0 16px;
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 700;
}

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

.secondary-button {
  padding: 0 14px;
  font-weight: 650;
}

.icon-button {
  width: 42px;
  font-size: 18px;
}

.toolbar {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.toolbar .primary-button,
.toolbar .secondary-button,
.row-actions button,
.chip-button,
.detail-tabs button {
  min-height: 34px;
  padding: 0 12px;
}

.section {
  display: none;
}

.section.active {
  display: block;
}

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

.metric-card,
.panel,
.settings-grid article {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-card {
  position: relative;
  min-height: 112px;
  padding: 18px 56px 18px 16px;
}

.metric-card::after {
  content: "";
  position: absolute;
  top: 22px;
  right: 16px;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 1px #d8e6ff;
}

.metric-card span,
.metric-card small,
.settings-grid span {
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 6px 0 5px;
  font-size: 25px;
  line-height: 1.1;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 18px;
}

.panel {
  padding: 18px;
}

.inner-panel {
  box-shadow: none;
}

.workspace-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  align-items: start;
  gap: 18px;
}

.product-workbench {
  min-width: 0;
}

.dense-header {
  align-items: flex-start;
}

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

.timeline {
  display: grid;
  gap: 18px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 12px;
}

.timeline-item > span {
  width: 12px;
  height: 12px;
  margin-top: 5px;
  border-radius: 999px;
  background: #aab8ca;
}

.timeline-item.complete > span {
  background: var(--green);
}

.timeline-item.active > span {
  background: var(--blue);
}

.timeline-item p,
.scope-list,
.settings-grid p,
.import-result p {
  color: var(--muted);
}

.timeline-item p {
  margin: 4px 0 0;
}

.scope-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 18px;
}

input,
select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}

input {
  min-width: 260px;
  padding: 0 12px;
}

select {
  padding: 0 12px;
}

.filter-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1.4fr) repeat(3, minmax(160px, 0.7fr));
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}

.filter-grid label {
  display: grid;
  gap: 6px;
}

.filter-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filter-grid input,
.filter-grid select {
  width: 100%;
  min-width: 0;
}

.sub-toolbar {
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.chip-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-weight: 650;
}

.chip-button.active {
  border-color: #c9dcff;
  background: var(--blue-soft);
  color: var(--blue-dark);
}

.sub-toolbar span {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

#customers {
  margin: 0 -18px -18px;
}

#customers .panel {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 86px);
  padding: 8px 3px 3px;
  overflow: hidden;
}

#customers .panel-header {
  display: grid;
  grid-template-columns: minmax(260px, 420px) minmax(0, 1fr);
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.customer-search-wrap {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

#customer-search {
  min-width: 0;
  width: 100%;
  min-height: 32px;
  padding: 0 10px;
}

.customer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: flex-start;
}

#customers .table-wrap {
  flex: 1;
  max-height: none;
  overflow: auto;
  overscroll-behavior: contain;
}

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

.product-table {
  min-width: 1460px;
}

.customer-table {
  width: max-content;
  min-width: 100%;
  table-layout: fixed;
}

.customer-table th,
.customer-table td {
  padding: 6px 8px;
  border: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.25;
}

.customer-table th {
  position: relative;
  font-weight: 700;
  top: 0;
  z-index: 2;
  background: #f3f6fb;
}

.customer-table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.customer-table tbody tr {
  cursor: pointer;
}

.customer-table tbody td {
  user-select: none;
}

.customer-table tbody tr.row-selected {
  background: #eef5ff;
}

.customer-table th.is-hidden-col,
.customer-table td.is-hidden-col {
  display: none;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
}

.sort-icon {
  display: inline-block;
  width: 14px;
  color: #8ea1bc;
  font-size: 14px;
  line-height: 1;
}

.col-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 4;
}

.col-resizer::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3px;
  width: 1px;
  background: transparent;
}

.col-resizer:hover::before {
  background: #9db3d4;
}

.customer-table th:nth-child(1),
.customer-table td:nth-child(1) { width: 64px; }
.customer-table th:nth-child(2),
.customer-table td:nth-child(2) { width: 110px; }
.customer-table th:nth-child(3),
.customer-table td:nth-child(3) { width: 90px; }
.customer-table th:nth-child(4),
.customer-table td:nth-child(4) { width: 88px; }
.customer-table th:nth-child(5),
.customer-table td:nth-child(5) { width: 52px; }
.customer-table th:nth-child(6),
.customer-table td:nth-child(6) { width: 130px; }
.customer-table th:nth-child(7),
.customer-table td:nth-child(7) { width: 72px; }
.customer-table th:nth-child(8),
.customer-table td:nth-child(8) { width: 72px; }
.customer-table th:nth-child(9),
.customer-table td:nth-child(9) { width: 68px; }
.customer-table th:nth-child(10),
.customer-table td:nth-child(10) { width: 92px; }
.customer-table th:nth-child(11),
.customer-table td:nth-child(11) { width: 128px; }
.customer-table th:nth-child(12),
.customer-table td:nth-child(12) { width: 86px; }
.customer-table th:nth-child(13),
.customer-table td:nth-child(13) { width: 110px; }

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  background: var(--panel-soft);
  color: #4b5563;
  font-size: 12px;
  font-weight: 750;
}

td {
  font-size: 13px;
}

tbody tr:hover {
  background: #f8fbff;
}

.product-table tbody tr:has(.row-check:checked) {
  background: #eef5ff;
}

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

.row-actions button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 650;
}

.detail-panel {
  position: sticky;
  top: 20px;
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 16px;
  box-shadow: var(--shadow);
}

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

.product-preview {
  align-items: flex-start;
  justify-content: flex-start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}

.image-placeholder {
  display: grid;
  width: 74px;
  height: 74px;
  flex: 0 0 74px;
  place-items: center;
  border: 1px dashed #9fb1c7;
  border-radius: 12px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.product-preview strong,
.product-preview span {
  display: block;
}

.product-preview span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.detail-tabs {
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}

.detail-tabs button {
  flex: 1;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.detail-tabs button.active {
  background: #fff;
  color: var(--blue-dark);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}

.detail-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #edf2f7;
}

.detail-list dt {
  color: var(--muted);
  font-size: 13px;
}

.detail-list dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.detail-note {
  padding: 12px;
  border-radius: 12px;
  background: #fff8e8;
  color: #4f3608;
}

.detail-note p {
  margin: 6px 0 0;
  color: #6b4a0e;
}

.checkout-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 18, 34, 0.48);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(860px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.22);
}

.modal.modal-compact {
  width: min(360px, calc(100vw - 48px));
}

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

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

.modal-body {
  overflow: auto;
  padding: 18px;
}

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

.product-form label,
.stock-adjust label {
  display: grid;
  gap: 6px;
}

.product-form label.wide {
  grid-column: span 3;
}

.product-form span,
.stock-adjust span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.product-form input,
.stock-adjust input {
  width: 100%;
  min-width: 0;
}

.modal-message {
  margin: 0;
  color: var(--muted);
}

.column-picker {
  display: grid;
  gap: 10px;
}

.column-picker .modal-message {
  grid-column: 1 / -1;
  margin-bottom: 2px;
  font-size: 12px;
}

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

.column-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
}

.column-item span {
  color: #111827;
  font-size: 13px;
  font-weight: 700;
}

.column-item input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  min-width: 14px;
  min-height: 14px;
  padding: 0;
  border: 1.5px solid #111827;
  border-radius: 3px;
  background: #fff;
  margin: 0;
  flex: 0 0 14px;
  display: inline-grid;
  place-content: center;
}

.column-item input[type="checkbox"]::after {
  content: "";
  width: 7px;
  height: 4px;
  border-left: 1.8px solid #111827;
  border-bottom: 1.8px solid #111827;
  transform: rotate(-45deg) scale(0);
  transform-origin: center;
  transition: transform 120ms ease;
}

.column-item input[type="checkbox"]:checked::after {
  transform: rotate(-45deg) scale(1);
}

.column-item input[type="checkbox"]:disabled {
  opacity: 0.55;
  border-color: #111827;
}

.column-item.is-required {
  border-color: #c9dcff;
  background: #eef5ff;
}

.row-action-menu {
  position: fixed;
  z-index: 30;
  min-width: 140px;
  display: grid;
  gap: 2px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 10px 32px rgba(15, 23, 42, 0.18);
}

.row-action-menu[hidden] {
  display: none;
}

.row-action-menu button {
  min-height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: #fff;
  color: #1f2937;
  text-align: left;
  font-size: 13px;
}

.row-action-menu button:hover {
  background: #eef5ff;
  color: var(--blue-dark);
}

.stock-adjust {
  display: grid;
  gap: 14px;
}

.barcode-card {
  display: grid;
  place-items: center;
  min-height: 160px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: repeating-linear-gradient(
    90deg,
    #111 0,
    #111 2px,
    #fff 2px,
    #fff 7px,
    #111 7px,
    #111 10px,
    #fff 10px,
    #fff 16px
  );
  color: #111;
}

.barcode-card span,
.barcode-card strong {
  padding: 4px 10px;
  background: #fff;
}

.image-manager {
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: 16px;
  align-items: start;
}

.image-placeholder.large {
  width: 128px;
  height: 128px;
  flex-basis: 128px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 700;
}

.status.ok {
  background: #e8f6f0;
  color: var(--green);
}

.status.warn {
  background: #fff4df;
  color: var(--amber);
}

.status.danger {
  background: #ffecec;
  color: var(--red);
}

.import-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(0, 1.1fr);
  gap: 18px;
}

.upload-box,
.import-result {
  min-height: 180px;
  border: 1px dashed #9fb1c7;
  border-radius: 12px;
  background: var(--panel-soft);
  padding: 22px;
}

.upload-box {
  display: grid;
  align-content: center;
  gap: 8px;
}

.upload-box input {
  min-width: 0;
  padding: 8px;
}

.upload-box span {
  color: var(--muted);
}

.import-result {
  border-style: solid;
  background: #fff;
}

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

.settings-grid article {
  padding: 16px;
  box-shadow: none;
}

.settings-grid strong,
.settings-grid span {
  display: block;
}

.settings-grid strong {
  margin-top: 6px;
  font-size: 18px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 118px minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    height: 100vh;
  }

  .nav-list {
    grid-template-columns: 1fr;
  }

  .metrics-grid,
  .two-column,
  .import-grid,
  .settings-grid,
  .workspace-layout,
  .filter-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }
}

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

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

  .topbar-actions {
    width: 100%;
  }

  .local-badge {
    justify-content: center;
    width: 100%;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .nav-list {
    grid-template-columns: 1fr;
  }

  input,
  select {
    min-width: 100%;
  }

  .product-form,
  .product-form label.wide,
  .image-manager {
    grid-template-columns: 1fr;
    grid-column: span 1;
  }

  #customers .panel-header {
    grid-template-columns: 1fr;
  }

  .customer-actions {
    justify-content: flex-start;
  }
}
