* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f4f5f7;
  color: #1a1a1a;
}

.login-box {
  max-width: 360px;
  margin: 15vh auto;
  padding: 32px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  text-align: center;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  background: #d33b3b;
  color: #fff;
}
.topbar-title { font-weight: 700; font-size: 1.1rem; }
.topbar-info { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pill {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.85rem;
  color: #fff;
}
.pill.link { text-decoration: none; }
select.pill, input.pill { color: #1a1a1a; background: #fff; }

/* Whole-app layout: category sidebar flush against the left edge (below the
   full-width topbar), tabs + tab content filling the rest - no centered
   "main" column, so there is no dead gap on wide desktop screens. */
.app-layout { display: flex; align-items: flex-start; }

.category-sidebar {
  width: 200px;
  flex: none;
  background: #fff;
  padding: 8px;
  border-right: 1px solid #e0e0e0;
  position: sticky;
  top: 0;
  align-self: flex-start;
  max-height: 100vh;
  overflow-y: auto;
}
.category-group { margin-bottom: 8px; }
.category-group-title { font-weight: 600; padding: 6px 8px; color: #333; display: flex; align-items: center; gap: 6px; }
.category-group-toggle {
  width: 20px;
  height: 20px;
  flex: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #444;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  font-size: 0.9rem;
}
.catalog-updated-at { padding: 2px 8px 10px; font-size: 0.72rem; color: #999; }

.category-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: #444;
}
.category-item.active { background: #fdeaea; color: #d33b3b; font-weight: 600; }

.app-main { flex: 1; min-width: 0; }

.tabs {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 8px 16px 0;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  flex-wrap: wrap;
}
.tab-btn {
  border: none;
  background: none;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.95rem;
  border-bottom: 3px solid transparent;
  color: #555;
}
.tab-btn.active { color: #d33b3b; border-bottom-color: #d33b3b; font-weight: 600; }
/* Only the Print button claims the auto margin, so it - and Tải Excel right
   after it in the DOM, with no auto margin of its own - both land flush
   against the toolbar's right edge instead of getting pushed apart by an
   auto margin each. */
.tab-print-btn { margin-left: auto; margin-top: 6px; }
.tab-export-btn { margin-top: 6px; }

main { padding: 16px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.sku-list-toolbar { max-width: 280px; margin-bottom: 8px; display: flex; gap: 8px; }
.sku-list-toolbar select { padding: 6px 8px; border-radius: 6px; border: 1px solid #ccc; }
.sku-list-toolbar input#sku-search { flex: 1; min-width: 0; padding: 6px 8px; border-radius: 6px; border: 1px solid #ccc; }

.list-toolbar { max-width: 460px; margin-bottom: 8px; display: flex; gap: 8px; }
.list-toolbar select { padding: 6px 8px; border-radius: 6px; border: 1px solid #ccc; }
.list-toolbar input.list-search { flex: 1; min-width: 0; padding: 6px 8px; border-radius: 6px; border: 1px solid #ccc; }

.dat-hang-layout { display: flex; gap: 16px; align-items: flex-start; }
.sku-list {
  min-width: 220px;
  max-width: 280px;
  background: #fff;
  border-radius: 8px;
  max-height: 70vh;
  overflow-y: auto;
}
.sku-list-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  border-bottom: 1px solid #f0f0f0;
  padding: 10px 12px;
  cursor: pointer;
  color: #333;
}
.sku-list-item .sku-code { display: block; font-size: 0.75rem; color: #999; }
.sku-list-item .sku-supplier { display: block; font-size: 0.8rem; color: #888; }
.sku-list-item.active { background: #fdeaea; color: #d33b3b; font-weight: 600; }
.out-of-stock-tag {
  display: inline-block;
  background: #856404;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
}

.product-detail {
  flex: 1;
  background: #fff;
  border-radius: 10px;
  padding: 16px;
}
.product-detail .hint { color: #888; }
.product-detail img.product-photo {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 10px;
  background: #eee;
}
.product-detail textarea {
  width: 100%;
  min-height: 60px;
  margin: 8px 0;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #ccc;
}

.data-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; }
.data-table th, .data-table td { padding: 8px 10px; border-bottom: 1px solid #eee; text-align: left; font-size: 0.9rem; }
.data-table th { background: #fafafa; }
.data-table tr.filter-row th { padding: 4px 6px; background: #fff; }
.col-sort { width: auto; display: inline-block; margin-left: 4px; padding: 1px 2px; font-size: 0.8rem; border: 1px solid #ccc; border-radius: 4px; }
.data-table tr.filter-row input, .data-table tr.filter-row select {
  width: 100%;
  box-sizing: border-box;
  padding: 4px 6px;
  font-size: 0.82rem;
  font-weight: normal;
  border: 1px solid #ccc;
  border-radius: 4px;
}
.col-mart { display: none; }
.show-mart .col-mart { display: table-cell; }
/* A SKU/Mart line with a confirmed chia of 0 ("=> Hết hàng") - light red row
   background so it stands out at a glance among many rows. */
.data-table tr.row-het-hang { background: #fdeaea; }
.warn-text { color: #d33b3b; font-weight: 600; }

.qty-stepper { display: flex; align-items: center; gap: 6px; }
.qty-stepper button { width: 28px; height: 28px; border-radius: 6px; border: 1px solid #ccc; background: #fff; cursor: pointer; }
.qty-stepper input { width: 60px; text-align: center; padding: 4px; border: 1px solid #ccc; border-radius: 6px; }

.btn { padding: 10px 18px; border-radius: 8px; border: 1px solid #ccc; background: #fff; cursor: pointer; margin-top: 12px; }
.btn-primary { background: #2e8b57; color: #fff; border-color: #2e8b57; }

.confirm-allocation-row { display: flex; align-items: center; gap: 10px; }
#btn-confirm-allocation { background: #999; color: #fff; border-color: #999; }
#btn-confirm-allocation.confirmed { background: #2e8b57; color: #fff; border-color: #2e8b57; }

.lock-banner { background: #fff3cd; color: #856404; padding: 10px; border-radius: 8px; margin-bottom: 10px; }

.unlock-controls { display: flex; gap: 8px; align-items: center; }
.unlock-controls select { padding: 6px 10px; border-radius: 6px; border: 1px solid #ccc; }
.lock-toggle-btn { margin-top: 0; padding: 6px 14px; }
.lock-toggle-btn.active { font-weight: 600; }
#btn-unlock.active { background: #2e8b57; color: #fff; border-color: #2e8b57; }

/* Tổng/Mart picker and Mở khóa controls (Trưởng Bộ phận only, hidden
   otherwise) share one row, left-aligned - the picker comes first so it
   still shows up on its own, flush left, for anyone who can't see the
   unlock controls. */
.nguon-hang-toolbar { display: flex; justify-content: flex-start; align-items: center; gap: 16px; margin-bottom: 12px; flex-wrap: wrap; }
.nguon-hang-pill-select { padding: 6px 10px; border-radius: 6px; border: 1px solid #ccc; font-size: 0.9rem; }

.xac-nhan-toggle { display: flex; gap: 6px; }
.xn-btn { padding: 4px 10px; border-radius: 6px; border: 1px solid #ccc; background: #fff; cursor: pointer; font-size: 0.85rem; }
.xn-btn.active.xn-da-dat { background: #2e8b57; color: #fff; border-color: #2e8b57; font-weight: 600; }
.xn-btn.active.xn-het-hang { background: #d33b3b; color: #fff; border-color: #d33b3b; font-weight: 600; }
/* Đã đặt/Hết hàng confirmed earlier, but dat/chia has since changed - see
   get_daily_summary()'s xac_nhan_dat_stale. Overrides the green/red above. */
.xn-btn.active.stale { background: #8b5e34; border-color: #8b5e34; color: #fff; }

.print-only-title { display: none; }

@media print {
  .topbar, .tabs, .category-sidebar, .nguon-hang-toolbar,
  .list-toolbar, #btn-confirm-allocation { display: none !important; }
  .app-layout, .app-main, main { padding: 0; margin: 0; }
  .print-only-title { display: block; margin: 0 0 10px; }
}

@media (max-width: 900px) {
  .app-layout { flex-direction: column; }
  .category-sidebar {
    width: 100%;
    max-height: none;
    position: static;
    display: flex;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid #e0e0e0;
  }
  .category-group { margin-bottom: 0; margin-right: 12px; flex: none; }
  .dat-hang-layout { flex-direction: column; }
  .sku-list { max-width: 100%; max-height: 220px; }
  .data-table { display: block; overflow-x: auto; }
}
