* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f5f7fb;
  color: #222;
  -webkit-text-size-adjust: 100%;
}

a {
  color: inherit;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid #e9edf4;
}

.factory-hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 20px 24px 8px;
}

.factory-hero.compact {
  padding-bottom: 0;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 13px;
  color: #5b6576;
}

.hero-copy {
  margin: 8px 0 0;
  color: #5b6576;
}

.hero-actions,
.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.card {
  background: #fff;
  border: 1px solid #e9edf4;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(10, 32, 68, 0.04);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  padding: 16px 24px;
}

.stats-grid .card {
  padding: 12px;
}

.stats-grid h3 {
  margin: 0;
  font-size: 14px;
  color: #5b6576;
}

.stats-grid p {
  margin: 8px 0 0;
  font-size: 24px;
  font-weight: bold;
}

.table-card,
.form-card,
.upload-box,
.factory-toast,
.empty-state,
.simple-form-card {
  margin: 0 24px 24px;
  padding: 16px;
  overflow: auto;
}

.factory-toast.success {
  border-color: #cde7d0;
  background: #f4fbf4;
}

.factory-toast.info {
  border-color: #d9e4ff;
  background: #f5f8ff;
}

.empty-state {
  text-align: center;
}

.upload-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.small-tip {
  margin-top: 8px;
  color: #6b7280;
  font-size: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 860px;
}

th,
td {
  border: 1px solid #e9edf4;
  padding: 8px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f4f7ff;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cfd8e6;
  border-radius: 10px;
  font-size: 16px;
  background: #fff;
}

button,
.btn {
  border: none;
  background: #2859ff;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  font-size: 14px;
  min-height: 44px;
  text-align: center;
}

.btn-large {
  padding: 14px 18px;
  font-size: 16px;
}

.btn-secondary {
  background: #edf2ff;
  color: #2859ff;
}

.btn-warning {
  background: #ffb020;
  color: #1f2937;
}

.btn.danger {
  background: #f44336;
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  width: 360px;
  padding: 24px;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sub {
  color: #6b7280;
  margin-bottom: 16px;
}

.tips {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px dashed #d3dbe8;
  font-size: 12px;
  color: #5b6576;
}

.product-cell {
  display: flex;
  gap: 8px;
  align-items: center;
}

.product-cell img,
.factory-item-image {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 10px;
  background: #f3f4f6;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.error {
  background: #fde8e8;
  border: 1px solid #f7b4b4;
  color: #9d1f1f;
  padding: 8px;
  border-radius: 8px;
  margin-bottom: 10px;
}

.red {
  color: #d32f2f;
}

.yellow {
  color: #e6a700;
}

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
}

.badge.ok {
  background: #2e7d32;
}

.badge.pending {
  background: #f59e0b;
}

.badge.reject {
  background: #e53935;
}

.audit-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.factory-filter-bar {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
}

.factory-form {
  padding-bottom: 96px;
}

.factory-card-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  padding: 8px 24px 24px;
}

.factory-item-card {
  padding: 16px;
}

.factory-item-head {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.factory-item-head h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.factory-meta {
  margin: 0;
  color: #6b7280;
}

.field-block {
  display: block;
  margin-bottom: 12px;
}

.field-block span,
.simple-form label span {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  color: #4b5563;
}

.factory-card-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  color: #6b7280;
  font-size: 13px;
}

.soft-tag {
  background: #fff7e6;
  color: #b26a00;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
}

.bottom-save-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 24px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid #e9edf4;
  backdrop-filter: blur(8px);
}

.simple-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 560px;
}

.simple-form-card {
  max-width: 760px;
}

.pending-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  padding: 0 24px 24px;
}

.pending-card {
  padding: 16px;
}

.pending-head {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.pending-head h3 {
  margin: 0 0 6px;
}

.pending-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.pending-fields span {
  display: block;
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 4px;
}

.pending-form-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pending-edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.pending-edit-grid label span {
  display: block;
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 4px;
}

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

.grid-3,
.grid-4 {
  display: grid;
  gap: 12px;
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 12px;
}

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

.mobile-section-title {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mobile-sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: rgba(245, 247, 251, 0.96);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid #e9edf4;
  backdrop-filter: blur(8px);
}

.mobile-sticky-actions .pending-actions,
.mobile-sticky-actions .actions {
  width: 100%;
}

.mobile-sticky-actions .btn,
.mobile-sticky-actions button {
  flex: 1;
}

.preview-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.preview-card {
  padding: 14px;
}

.preview-card h4 {
  margin: 0 0 6px;
}

.mobile-sku-list {
  display: none;
  gap: 12px;
  margin-bottom: 12px;
}

.mobile-sku-card {
  border: 1px solid #e9edf4;
  border-radius: 12px;
  padding: 12px;
  background: #fbfcff;
}

.mobile-sku-card-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.mobile-sku-check {
  font-size: 13px;
  color: #4b5563;
}

.mobile-sku-check input {
  width: auto;
  margin-right: 6px;
}

.mobile-sku-meta {
  margin-bottom: 10px;
}

.mobile-sku-edit-grid label span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: #6b7280;
}

.batch-drawer {
  position: fixed;
  inset: 0;
  z-index: 60;
}

.batch-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.batch-drawer-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82vh;
  overflow: auto;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  padding: 16px;
}

.boss-mobile-panel {
  border: 1px solid #d9e4ff;
  background: linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
}

@media (max-width: 900px) {
  .stats-grid,
  .grid-2,
  .grid-3,
  .grid-4,
  .pending-fields,
  .pending-edit-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .factory-hero,
  .bottom-save-bar,
  .pending-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar,
  .factory-hero {
    padding: 14px 16px;
  }

  .topbar h1,
  .factory-hero h1 {
    margin: 0;
    font-size: 24px;
    line-height: 1.25;
  }

  .topbar p,
  .factory-hero p,
  .sub,
  .hero-copy {
    font-size: 13px;
  }

  .hero-actions,
  .actions,
  .pending-actions {
    width: 100%;
  }

  .hero-actions .btn,
  .actions .btn,
  .actions form,
  .pending-actions .btn,
  .pending-actions form,
  .pending-actions button {
    width: 100%;
  }

  .factory-card-list,
  .pending-grid {
    grid-template-columns: 1fr;
    padding-left: 16px;
    padding-right: 16px;
    gap: 12px;
  }

  .factory-filter-bar {
    grid-template-columns: 1fr;
  }

  .table-card,
  .form-card,
  .upload-box,
  .factory-toast,
  .empty-state,
  .simple-form-card {
    margin-left: 16px;
    margin-right: 16px;
    padding: 14px;
  }

  .table-card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    font-size: 12px;
  }

  th,
  td {
    padding: 7px;
    white-space: nowrap;
  }

  .bottom-save-bar {
    padding-left: 16px;
    padding-right: 16px;
  }

  .factory-card-footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .pending-head {
    align-items: flex-start;
  }

  .pending-head h3 {
    font-size: 16px;
  }

  .login-card {
    width: calc(100% - 32px);
    max-width: 420px;
    padding: 20px;
  }

  .sku-batch-tools {
    grid-template-columns: 1fr;
  }

  .batch-drawer-panel {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .mobile-sticky-actions {
    padding-left: 16px;
    padding-right: 16px;
  }
}

@media (max-width: 640px) {
  .stats-grid {
    padding: 12px 16px;
    gap: 10px;
  }

  .stats-grid .card {
    padding: 12px;
  }

  .stats-grid p {
    font-size: 20px;
  }

  .product-cell {
    min-width: 180px;
  }

  .pending-fields {
    gap: 8px;
  }

  .pending-fields div {
    padding: 10px;
    border: 1px solid #eef2f7;
    border-radius: 10px;
    background: #fafbff;
  }

  .mobile-sku-list {
    display: grid;
  }

  .desktop-sku-table {
    display: none;
  }

  .mobile-sku-card .pending-fields {
    grid-template-columns: 1fr 1fr;
  }

  .mobile-sku-card .pending-fields div {
    background: #fff;
  }
}
