/* ==========================================================================
   WEBAPP V3 DESIGN SYSTEM — fork nguyên văn từ WEBAPP_V2/public/styles/main.css
   (đã được user duyệt dark/light theme, touch cards, v.v.) — KHÔNG đổi gì ở đây,
   chỉ đổi phần JS/backend gọi API. CSS này CHƯA đầy đủ cho mọi màn hình (ordering/
   fulfillment/inventory/catalog/b2b còn thiếu nhiều class — ghi chú gốc bên dưới),
   sẽ bổ sung dần đúng phạm vi từng phase khi build view tương ứng.
   ========================================================================== */

:root {
  /* Colors Palette - Tailored HSL & Dark Slate */
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #0f172a;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --border-light: #e2e8f0;
  --border-strong: #cbd5e1;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;

  --success: #16a34a;
  --success-hover: #15803d;
  --success-soft: #f0fdf4;

  --warning: #d97706;
  --warning-hover: #b45309;
  --warning-soft: #fffbeb;

  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;

  --accent-gold: #f59e0b;

  /* Status Colors */
  --st-draft-bg: #f1f5f9; --st-draft-fg: #475569; --st-draft-border: #cbd5e1;
  --st-pending-bg: #fef3c7; --st-pending-fg: #b45309; --st-pending-border: #fde68a;
  --st-approved-bg: #e0f2fe; --st-approved-fg: #0369a1; --st-approved-border: #bae6fd;
  --st-done-bg: #dcfce7; --st-done-fg: #15803d; --st-done-border: #bbf7d0;
  --st-cancel-bg: #ffe4e6; --st-cancel-fg: #be123c; --st-cancel-border: #fecdd3;

  /* Shadows & Radius */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  /* Fonts */
  --font-heading: 'Montserrat', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="dark"] {
  --bg-app: #0b1329;
  --bg-card: #1e293b;
  --bg-sidebar: #070d19;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;

  --border-light: #334155;
  --border-strong: #475569;

  --primary-soft: #1e3a8a;
  --success-soft: #14532d;
  --warning-soft: #78350f;
  --danger-soft: #7f1d1d;
}

/* Reset & Base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* Layout Wrapper */
.app-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Top Header */
.top-header {
  height: 60px;
  background-color: var(--bg-sidebar);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 2px solid var(--accent-gold);
  z-index: 100;
  flex-shrink: 0;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  font-size: 24px;
}

.brand-title {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.5px;
  display: block;
}

.brand-subtitle {
  font-size: 10px;
  color: var(--accent-gold);
  font-weight: 700;
  display: block;
}

/* Branch Select Dropdown */
.branch-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.1);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.2);
}

.branch-label {
  font-size: 12px;
  color: var(--text-muted);
}

.branch-select {
  background: transparent;
  color: #ffffff;
  border: none;
  font-weight: 700;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.branch-select option {
  background-color: var(--bg-sidebar);
  color: #ffffff;
}

/* Realtime Status Dot */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #86efac;
  font-weight: 600;
}

.status-indicator .dot {
  width: 8px;
  height: 8px;
  background-color: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 8px #22c55e;
}

/* User Profile Badge */
.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.1);
  padding: 4px 10px;
  border-radius: 20px;
}

.avatar-circle {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--accent-gold), var(--warning-hover));
  color: #000;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
}

.user-name {
  font-size: 12px;
  font-weight: 700;
  display: block;
}

.user-role {
  font-size: 10px;
  color: var(--text-muted);
  display: block;
}

.logout-btn {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Global Draft Banner */
.orphan-draft-banner {
  background: linear-gradient(90deg, #f59e0b, #d97706);
  color: #0f172a;
  padding: 8px 16px;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
  z-index: 90;
}

/* Main Body Layout */
.main-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar Nav */
.sidebar-nav {
  width: 240px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}

.nav-item svg {
  width: 20px;
  height: 20px;
}

.nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: #ffffff;
}

.nav-item.active {
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.4);
}

/* Content Area */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background-color: var(--bg-app);
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

.view-header {
  margin-bottom: 20px;
}

.view-header h2 {
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 800;
  color: var(--text-main);
}

.view-desc {
  font-size: 13px;
  color: var(--text-muted);
}

/* Stats Cards Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.stat-card.blue { border-left: 4px solid var(--primary); }
.stat-card.yellow { border-left: 4px solid var(--warning); }
.stat-card.green { border-left: 4px solid var(--success); }
.stat-card.purple { border-left: 4px solid #9333ea; }

.stat-icon {
  font-size: 32px;
}

.stat-value {
  font-family: var(--font-heading);
  font-size: 24px;
  font-weight: 800;
  display: block;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Touch Cards & Products Grid */
.products-grid, .inventory-products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.product-touch-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s, border-color 0.15s;
}

.product-touch-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.card-prod-code {
  font-size: 10px;
  font-weight: 800;
  color: var(--primary);
  text-transform: uppercase;
}

.card-prod-name {
  font-size: 13px;
  font-weight: 700;
  margin: 4px 0;
  line-height: 1.3;
}

.card-prod-alias {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

.card-prod-footer {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.unit-badge {
  font-size: 11px;
  background: var(--bg-app);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  color: var(--text-muted);
}

/* Touch Controls Button (+/-) */
.qty-stepper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.step-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text-main);
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
}

.step-btn:active {
  background: var(--primary);
  color: #fff;
}

.step-val {
  font-weight: 800;
  font-size: 13px;
  min-width: 20px;
  text-align: center;
}

/* Status Pills */
.st {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 12px;
  border: 1px solid transparent;
}

.st-draft { background: var(--st-draft-bg); color: var(--st-draft-fg); border-color: var(--st-draft-border); }
.st-pending { background: var(--st-pending-bg); color: var(--st-pending-fg); border-color: var(--st-pending-border); }
.st-approved { background: var(--st-approved-bg); color: var(--st-approved-fg); border-color: var(--st-approved-border); }
.st-done { background: var(--st-done-bg); color: var(--st-done-fg); border-color: var(--st-done-border); }
.st-cancel { background: var(--st-cancel-bg); color: var(--st-cancel-fg); border-color: var(--st-cancel-border); }

/* Buttons System */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 13px;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}

.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.success { background: var(--success); color: #fff; }
.btn.warning { background: var(--warning); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.secondary { background: var(--border-light); color: var(--text-main); }
.btn.full-width { width: 100%; }
.btn.large { padding: 12px 20px; font-size: 15px; }
.btn.small { padding: 4px 10px; font-size: 11px; }

/* Table Container & Tables */
.table-container {
  width: 100%;
  overflow-x: auto;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
}

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

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

th {
  background: var(--bg-app);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
}

/* Modals System */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; background: var(--bg-app); display: flex; justify-content: flex-end; gap: 8px; }

/* Utilities & Mobile Nav */
.hidden { display: none !important; }
.mobile-only { display: none; }
.desktop-only { display: flex; }

.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-light);
  justify-content: space-around;
  align-items: center;
  z-index: 90;
}

.mobile-bottom-nav .nav-item {
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  font-size: 10px;
}

@media (max-width: 768px) {
  .mobile-only { display: flex; }
  .desktop-only { display: none !important; }
  .sidebar-nav { display: none; }
  .mobile-bottom-nav { display: flex; }
  .content-area { padding-bottom: 80px; }
}

/* ==========================================================================
   Form / Card / Tab / Autocomplete / Utilities
   Ghi chú kế thừa từ WEBAPP_V2: các class này chỉ mới vá đúng phạm vi Hàng Hủy/
   Hàng Hoàn — CHƯA rà soát hết ~100 class còn thiếu cho các màn khác (Danh Mục/
   Phân Quyền/B2B/Nhà Cung Cấp) — sẽ bổ sung dần khi build đúng view đó ở phase
   tương ứng (xem plan phase 3-5), không cố gắng đoán trước khi chưa cần.
   ========================================================================== */

.card-widget {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.report-form h3 { margin: 0 0 14px; font-size: 15px; }

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

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); }

.form-control {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-app);
  color: var(--text-main);
  font-size: 13px;
  font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--primary); }
.form-control[readonly] { background: var(--border-light); color: var(--text-muted); }

/* Tab switcher - .tab-content KHÔNG chỉ là thẩm mỹ, thiếu display:none sẽ làm
   cả 2 tab (Hủy/Hoàn) hiện chồng lên nhau cùng lúc. */
.tab-switcher {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}
.tab-btn {
  padding: 10px 16px;
  border: none;
  background: none;
  font-weight: 700;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Product autocomplete (ô tìm sản phẩm) - dùng cho Hàng Hủy/Hàng Hoàn, và tái
   dùng được cho các form khác sau này cần tìm sản phẩm trên ~300 mặt hàng. */
.product-autocomplete { position: relative; }
.autocomplete-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  max-height: 260px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 50;
}
.autocomplete-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--primary-soft); }
.autocomplete-item .prod-code { color: var(--text-muted); font-size: 11px; }

.history-section h3 { font-size: 14px; margin: 0 0 10px; }
.empty-msg { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

.user-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-app);
  padding: 2px 8px;
  border-radius: 10px;
}

.card-actions { display: flex; justify-content: flex-end; gap: 8px; }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--border-light); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.mb-3 { margin-bottom: 16px; }
