/* ============================================================
   Warehouse workspace styles
   Magnolia DS v1.0 — CHANNEL palette (Bloomberg Light)
   Trader terminal trên giấy · navy + cyan + amber · JetBrains Mono cho KPI/title
   ============================================================ */

#workspace-warehouse {
  display: none;
  padding: 24px 32px;
  max-width: none;
  margin: 0;
  background: var(--bg-card, #ffffff);

  /* DS tokens (--p-* per spec) */
  --p-page: #ffffff;
  --p-card: #ffffff;
  --p-border: #e3e8ee;
  --p-text: #0a2540;
  --p-muted: #697386;
  --p-primary: #0a2540;          /* Bloomberg navy */
  --p-primary-light: #425466;
  --p-secondary: #0891b2;        /* Deep cyan */
  --p-secondary-light: #22d3ee;
  --p-warm: #d97706;             /* Amber */
  --p-warm-light: #ffaa00;       /* Signature Bloomberg amber */
  --p-neutral: #cfd7df;

  /* Legacy aliases */
  --bg: #ffffff;
  --bg-soft: #f6f9fb;
  --bg-card: #ffffff;
  --bg-hover: #f6f9fb;
  --text: #0a2540;
  --text-muted: #697386;
  --text-soft: #94a4b6;
  --accent: #0a2540;
  --accent-2: #0891b2;
  --accent-soft: #e0f2fe;
  --border: #e3e8ee;
  --border-soft: #f1f5f9;
}
/* Kho vận = app độc lập: nav dọc bên trái (kế thanh tổng) + vùng nội dung bên phải. */
#workspace-warehouse.active {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas:
    "whhead"
    "filter"
    "content";
  column-gap: 14px;
  height: calc(100vh - 48px);
}

/* JetBrains Mono cho KPI/title/labels per Channel domain spec */
#workspace-warehouse .wh-kpi-value,
#workspace-warehouse .wh-kpi-label,
#workspace-warehouse .wh-card-title,
#workspace-warehouse .wh-tab-btn,
#workspace-warehouse code,
#workspace-warehouse .num {
  font-family: 'JetBrains Mono', 'Cascadia Code', Consolas, 'Courier New', monospace;
  letter-spacing: 0;
}

/* Header (góc trên-trái, đầu cột nav) ----------------------- */
.wh-header {
  grid-area: whhead;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0 10px 12px 0;
  border-bottom: 1px solid var(--border);
}
.wh-header h1 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.wh-global-filter { grid-area: filter; }
.wh-header .wh-sync-badge {
  font-size: 13px;
  padding: 4px 12px;
  border-radius: 14px;
  background: var(--bg-soft);
  color: var(--text-muted);
}
.wh-header .wh-sync-badge.alert {
  background: #fee2e2;
  color: var(--danger);
  font-weight: 600;
}

/* Nav dọc (cột trái) --------------------------------------- */
.wh-tabs {
  /* NGUỒN ẨN cho app-tabrail mirror ra rail trái — 0x0, KHÔNG display:none (giữ vis() chạy được), KHÔNG chiếm chỗ */
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  padding: 0;
  margin: 0;
  border: none;
}
.wh-tab-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  transition: all .14s ease;
}
/* Icon đầu mỗi tab — neo thị giác, dễ nhận */
.wh-tab-btn::before {
  content: '•';
  font-size: 15px;
  width: 20px;
  text-align: center;
  flex: none;
  filter: grayscale(0.55);
  transition: filter .14s ease;
}
.wh-tab-btn:hover {
  color: var(--text);
  background: var(--bg-soft);
  transform: translateX(2px);
}
.wh-tab-btn:hover::before { filter: grayscale(0); }
.wh-tab-btn.active {
  color: #fff;
  background: var(--accent);
  border-left-color: transparent;
  font-weight: 700;
  box-shadow: 0 2px 9px rgba(0, 0, 0, .2);
}
.wh-tab-btn.active::before { filter: none; }

.wh-tab-btn[data-wh-tab="dashboard"]::before    { content: '📊'; }
.wh-tab-btn[data-wh-tab="inventory"]::before    { content: '📦'; }
.wh-tab-btn[data-wh-tab="import"]::before       { content: '📥'; }
.wh-tab-btn[data-wh-tab="export"]::before       { content: '📤'; }
.wh-tab-btn[data-wh-tab="promo"]::before        { content: '🎁'; }
.wh-tab-btn[data-wh-tab="transfer"]::before     { content: '🔄'; }
.wh-tab-btn[data-wh-tab="exchange"]::before     { content: '🔁'; }
.wh-tab-btn[data-wh-tab="destroy"]::before      { content: '🗑️'; }
.wh-tab-btn[data-wh-tab="samples"]::before      { content: '🧪'; }
.wh-tab-btn[data-wh-tab="kegs"]::before         { content: '🛢️'; }
.wh-tab-btn[data-wh-tab="transactions"]::before { content: '🕐'; }
.wh-tab-btn[data-wh-tab="misa"]::before         { content: '🔗'; }
.wh-tab-btn[data-wh-tab="co2"]::before          { content: '🧯'; }
.wh-tab-btn[data-wh-tab="tech"]::before         { content: '🔧'; }
.wh-tab-btn[data-wh-tab="issue"]::before        { content: '🚚'; }
.wh-tab-btn[data-wh-tab="assets"]::before       { content: '📍'; }
.wh-tab-btn[data-wh-tab="settings"]::before     { content: '⚙️'; }
.wh-content { grid-area: content; overflow-y: auto; overflow-x: hidden; min-width: 0; padding-bottom: 24px; }
.wh-tab-content { display: none; }
.wh-tab-content.active { display: block; }

/* KPI grid ------------------------------------------------- */
.wh-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.wh-kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, transform .15s;
}
.wh-kpi-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.wh-kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
}
.wh-kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
  line-height: 1.1;
}
.wh-kpi-sub {
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 4px;
}
.wh-kpi-card.accent .wh-kpi-value { color: var(--accent); }
.wh-kpi-card.teal   .wh-kpi-value { color: var(--cs); }
.wh-kpi-card.orange .wh-kpi-value { color: var(--ca); }
.wh-kpi-card.indigo .wh-kpi-value { color: var(--total); }

/* Section card --------------------------------------------- */
.wh-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.wh-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.wh-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
.wh-card-actions { display: flex; gap: 8px; }

/* Tables --------------------------------------------------- */
.wh-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.wh-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg-soft);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: inset 0 -1px 0 var(--border);
}
.wh-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.wh-table tr:hover td { background: var(--bg-hover); }
.wh-table .num {
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
  text-align: right;
  white-space: nowrap;
}
.wh-table .num.zero { color: var(--text-soft); }
.wh-table .num.neg { color: var(--danger); }

/* Hộp cuộn cho bảng — cuộn cả ngang/dọc, header sticky giữ nguyên */
.wh-scroll { overflow: auto; max-height: calc(100vh - 300px); }

/* Phân quyền: tab chỉ-xem → ẩn mọi nút sửa/xoá/tạo (.wh-edit-only) + banner */
.wh-tab-content.wh-readonly .wh-edit-only { display: none !important; }
.wh-tab-content.wh-readonly::before {
  content: "👁️ Chế độ chỉ xem — bạn không có quyền chỉnh sửa phần này";
  display: block;
  background: #fef9c3; color: #854d0e;
  padding: 8px 14px; border-radius: 6px; margin-bottom: 12px;
  font-size: 13px; font-weight: 500;
}

/* Header nhóm (Tháng → Ngày → Đơn) cũng ghim, xếp tầng dưới hàng tên cột */
.wh-table thead th { box-sizing: border-box; height: 44px; }
.wh-table tr.wh-grp-month td { box-sizing: border-box; height: 34px; position: sticky; top: 44px; z-index: 4; }
.wh-table tr.wh-grp-wh td { box-sizing: border-box; height: 30px; position: sticky; top: 78px; z-index: 3; }
.wh-table tr.wh-grp-order td { box-sizing: border-box; position: sticky; top: 108px; z-index: 2; }

/* Chart container ------------------------------------------ */
.wh-chart-wrap {
  position: relative;
  height: 280px;
}

/* Buttons -------------------------------------------------- */
.wh-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.wh-btn:hover {
  background: var(--bg-soft);
  border-color: var(--text-muted);
}
.wh-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.wh-btn.primary:hover { background: #d97706; }
.wh-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* Placeholder for non-Phase 1 tabs ------------------------- */
.wh-placeholder {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.wh-placeholder-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: .5;
}
.wh-placeholder h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 8px;
}
.wh-placeholder p { font-size: 14px; margin: 0; }
.wh-placeholder .wh-placeholder-eta {
  display: inline-block;
  margin-top: 12px;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--bg-soft);
  color: var(--text-muted);
  font-size: 12px;
}

/* Empty state for tables/charts ---------------------------- */
.wh-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-soft);
  font-size: 13px;
}
.wh-empty-hint {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 12px;
  background: var(--bg-soft);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

/* Loading shimmer ------------------------------------------ */
.wh-loading {
  color: var(--text-soft);
  font-style: italic;
  padding: 12px;
}

/* Error box ------------------------------------------------ */
.wh-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}
.wh-error code {
  background: var(--bg-card, #fff);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
}

/* Status pill --------------------------------------------- */
.wh-status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-left: 8px;
  vertical-align: middle;
}

/* Modal --------------------------------------------------- */
.wh-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 20px 20px;
  overflow-y: auto;
}
.wh-modal[hidden] { display: none; }
.wh-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
}
/* Modal nhập kho có nhiều cột (Mã SP/Tên/ĐVT/SL/giá/...) → rộng hơn cho thoáng */
#wh-if-modal .wh-modal-content { max-width: 1040px; }

/* Ô ghi chú từng dòng: rộng, không khung, wrap để thấy full text */
.wh-if-note {
  width: 100%;
  border: none;
  background: transparent;
  resize: none;
  overflow: hidden;
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
  padding: 6px 4px;
  min-height: 30px;
  white-space: pre-wrap;
  word-break: break-word;
}
.wh-if-note:focus { outline: none; background: var(--bg-soft, #f8fafc); border-radius: 4px; }

.wh-modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: 12px;
  width: 100%;
  max-width: 900px;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
  z-index: 1;
}
.wh-modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.wh-modal-header h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}
.wh-modal-close {
  background: transparent;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.wh-modal-close:hover { background: var(--bg-soft); color: var(--text); }
.wh-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}
.wh-modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Forms --------------------------------------------------- */
.wh-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr 160px;
  gap: 14px;
  margin-bottom: 14px;
}
.wh-form-field {
  display: flex;
  flex-direction: column;
  min-width: 0; /* cho phép co trong grid — select option dài (tên outlet) không đẩy tràn modal */
}
.wh-form-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.wh-form-field input,
.wh-form-field select,
.wh-form-field textarea {
  width: 100%;
  box-sizing: border-box; /* fill đúng ô grid, không tràn vì padding/border */
  padding: 7px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card, #fff);
  color: var(--text);
  font-family: inherit;
}
.wh-form-field input:focus,
.wh-form-field select:focus,
.wh-form-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, .12);
}
.wh-form-divider {
  margin: 20px 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 6px;
}
.num-input {
  padding: 5px 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 5px;
  text-align: right;
  width: 100%;
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
}
.num-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Detail grid --------------------------------------------- */
.wh-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-soft);
  border-radius: 8px;
  margin-bottom: 12px;
}
.wh-detail-grid > div { display: flex; flex-direction: column; }
.wh-detail-grid label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 3px;
}
.wh-detail-grid strong { font-size: 14px; color: var(--text); }
.wh-detail-notes {
  padding: 10px 14px;
  background: #fffbeb;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 13px;
}
.wh-detail-notes label {
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 4px;
}

/* Remove button (item row) -------------------------------- */
.wh-tv-rm {
  background: transparent;
  border: none;
  color: var(--text-soft);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
}
.wh-tv-rm:hover { background: #fee2e2; color: var(--danger); }

/* Product picker ------------------------------------------ */
.wh-pp { position: relative; }
.wh-pp-input {
  width: 100%;
  min-width: 110px;          /* không bóp đến mức không thấy chữ đang gõ */
  padding: 7px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-card, #fff);
  font-family: inherit;
}
.wh-pp-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, .12);
}
.wh-pp-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: auto;
  min-width: 480px;          /* popup to hẳn — hiện rõ mã + tên + ĐVT */
  max-width: 90vw;
  margin-top: 2px;
  background: var(--bg-card, #fff);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .1);
  max-height: 240px;
  overflow-y: auto;
  z-index: 10;
}
.wh-pp-item {
  display: grid;
  grid-template-columns: 120px 1fr 60px;
  gap: 10px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border-soft);
}
.wh-pp-item:last-child { border-bottom: none; }
.wh-pp-item:hover, .wh-pp-item.active { background: var(--bg-soft); }
.wh-pp-sku {
  font-weight: 600;
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--accent);
}
.wh-pp-name { color: var(--text); }
.wh-pp-fmt { color: var(--text-muted); font-size: 11px; text-align: right; }
.wh-pp-empty {
  padding: 14px;
  text-align: center;
  color: var(--text-soft);
  font-size: 13px;
}

/* Toast --------------------------------------------------- */
.wh-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #15803d;
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .2);
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
  transform: translateY(40px);
  opacity: 0;
  transition: transform .25s, opacity .25s;
}
.wh-toast.show { transform: translateY(0); opacity: 1; }

/* Mobile --------------------------------------------------- */
@media (max-width: 900px) {
  #workspace-warehouse { padding: 16px; }
  .wh-kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .wh-kpi-value { font-size: 22px; }
  .wh-header h1 { font-size: 20px; }
  .wh-table { font-size: 12px; }
  .wh-table th, .wh-table td { padding: 8px; }
  .wh-form-row { grid-template-columns: 1fr; gap: 10px; }
  .wh-modal { padding: 20px 10px; }
  .wh-modal-content { max-height: calc(100vh - 40px); }
  .wh-modal-body, .wh-modal-header, .wh-modal-footer { padding-left: 14px; padding-right: 14px; }
  .wh-pp-item { grid-template-columns: 90px 1fr; }
  .wh-pp-fmt { display: none; }
}
@media (max-width: 500px) {
  .wh-kpi-grid { grid-template-columns: 1fr; }
}

/* ── Tồn kho — card chọn kho + popup ─────────────────── */
.wh-inv-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
  gap: 14px;
}
.wh-inv-card {
  text-align: left;
  background: var(--bg-card, #fff);
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .1s;
  font: inherit;
}
.wh-inv-card:hover:not(.empty) {
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(0,0,0,.08);
  transform: translateY(-1px);
}
.wh-inv-card.empty { opacity: .55; cursor: default; }
.wh-inv-card-name { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.wh-inv-card-value { font-size: 20px; font-weight: 700; color: var(--accent); }
.wh-inv-card-value small { font-size: 12px; color: #94a3b8; font-weight: 500; }
.wh-inv-card-meta { font-size: 12px; color: #64748b; margin-top: 8px; line-height: 1.5; }
.wh-inv-card-hint { font-size: 11.5px; color: #94a3b8; margin-top: 10px; }
.wh-inv-card:hover:not(.empty) .wh-inv-card-hint { color: var(--accent); }
.wh-inv-modal-content { max-width: 1100px; width: 96vw; }

.wh-inv-group {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}
.wh-inv-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: #f8fafc;
  border-bottom: 1px solid #e5e7eb;
}
.wh-inv-group-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
}
.wh-inv-group-sub {
  font-size: 12.5px;
  color: #64748b;
  white-space: nowrap;
}
.wh-inv-group .wh-table { margin: 0; }
.wh-inv-subtotal td {
  font-weight: 700;
  background: #f8fafc;
  border-top: 2px solid #e5e7eb;
}
.wh-inv-fmt-banner td {
  background: #eef2ff;
  font-weight: 600;
  font-size: 12.5px;
  color: #4338ca;
  padding-top: 6px;
  padding-bottom: 6px;
}
.wh-inv-fmt-banner small { color: #6366f1; font-weight: 500; }
.wh-inv-empty {
  text-align: center;
  color: #94a3b8;
  font-style: italic;
  padding: 18px 0;
}

/* Kho vận: ẩn toàn bộ cột/giá trị tiền bạc — thủ kho không cần xem giá. Đảo ngược: bỏ display:none. */
.wh-money { display: none !important; }
