/* Smart Inventory — design system ported from the legacy Apps Script UI.
   Custom CSS only (no framework), CSS variables, responsive. */

:root {
  --bg: #f5f7fb;
  --card: #fff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --success: #059669;
  --success-light: #d1fae5;
  --border: #e5e7eb;
  --sidebar: #111827;
  --sidebar-muted: #9ca3af;
  --shadow: 0 10px 30px rgba(15, 23, 42, .08);
  --radius: 16px;
  --control-border: #d7deea;
  --control-bg: #fff;
  --control-shadow: 0 1px 2px rgba(15, 23, 42, .04), inset 0 1px 0 rgba(255, 255, 255, .6);
  --control-height: 44px;
  --sidebar-width: 260px;
}

* { box-sizing: border-box; }

html,
body {
  max-width: 100%;
}

body {
  margin: 0;
  font-family: "Google Sans Flex", Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

input::placeholder,
textarea::placeholder {
  color: #9ca3af;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: #e5e7eb;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  width: 100%;
  min-width: 0;
  transition: width .22s ease, padding .22s ease, transform .22s ease;
}
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 18px; min-width: 0; }
.brand .logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
  flex: 0 0 auto;
}
.brand-copy { min-width: 0; }
.brand .brand-name { font-weight: 700; font-size: 16px; color: #fff; }
.brand .brand-sub { font-size: 12px; color: var(--sidebar-muted); }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  color: #d1d5db;
  font-size: 14px;
  min-width: 0;
}
.nav-button {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
}
.nav-link-icon {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.nav-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}
.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-link:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link.disabled { color: #6b7280; cursor: not-allowed; }
.nav-spacer { flex: 1; }

/* Level-2 sidebar items — bấm mục cha (vd Quản lý bán hàng) để xổ ra / thu lại.
   Chiều cao chạy bằng grid-template-rows 0fr → 1fr nên mượt mà không cần biết
   trước cao bao nhiêu. Hiệu ứng chỉ bật khi sidebar có .nav-animate (sau lúc tải). */
.nav-group { position: relative; }
.nav-caret { margin-left: auto; width: 14px; height: 14px; opacity: .55; }
.nav-children {
  display: grid; grid-template-rows: 0fr; opacity: 0;
  padding-left: 34px;
}
.nav-children-inner {
  display: flex; flex-direction: column; gap: 2px;
  min-height: 0; overflow: hidden;
}
.nav-children-inner > :first-child { margin-top: 4px; }
.nav-children-inner > :last-child { margin-bottom: 6px; }
.nav-group.is-open .nav-children { grid-template-rows: 1fr; opacity: 1; }
.nav-group.is-open .nav-caret { transform: rotate(90deg); opacity: .85; }
.sidebar.nav-animate .nav-children { transition: grid-template-rows .24s ease, opacity .2s ease; }
.sidebar.nav-animate .nav-caret { transition: transform .24s ease, opacity .2s ease; }
.nav-child {
  display: block; padding: 7px 10px; border-radius: 10px;
  color: var(--sidebar-muted); font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: background-color .15s ease, color .15s ease;
}
.nav-child:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav-child.active { background: rgba(37, 99, 235, .35); color: #fff; }

/* Sidebar thu gọn (chỉ icon): mục con là menu nổi khi rê chuột / focus. */
body.sidebar-collapsed .nav-caret { display: none; }
body.sidebar-collapsed .nav-group .nav-children {
  position: absolute; left: 100%; top: 0; z-index: 60;
  min-width: 190px; margin-left: 8px; padding: 8px;
  background: var(--sidebar); border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 12px; box-shadow: var(--shadow);
  grid-template-rows: 1fr; opacity: 0; visibility: hidden; pointer-events: none;
  transform: translateX(-6px);
  transition: opacity .16s ease, transform .16s ease, visibility 0s linear .16s;
}
body.sidebar-collapsed .nav-children-inner { overflow: visible; }
body.sidebar-collapsed .nav-children-inner > :first-child,
body.sidebar-collapsed .nav-children-inner > :last-child { margin: 0; }
body.sidebar-collapsed .nav-group:hover .nav-children,
body.sidebar-collapsed .nav-group:focus-within .nav-children {
  opacity: 1; visibility: visible; pointer-events: auto; transform: none;
  transition: opacity .16s ease, transform .16s ease, visibility 0s;
}

@media (prefers-reduced-motion: reduce) {
  .sidebar.nav-animate .nav-children,
  .sidebar.nav-animate .nav-caret,
  body.sidebar-collapsed .nav-group .nav-children { transition: none; }
}

.sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, .08);
  background: rgba(255, 255, 255, .06);
  color: #fff;
  cursor: pointer;
  flex: 0 0 auto;
}
.sidebar-toggle:hover {
  background: rgba(255, 255, 255, .12);
}
.collapse-icon {
  transition: transform .2s ease;
}

.main {
  padding: 24px;
  min-width: 0;
  overflow-x: hidden;
}

body.sidebar-collapsed {
  --sidebar-width: 92px;
}
body.sidebar-collapsed .sidebar {
  padding-inline: 12px;
  /* Không cắt menu nổi của mục con (overflow-y:auto cũng ép overflow-x cắt).
     Sidebar chỉ còn icon nên vẫn vừa màn hình mà không cần cuộn. */
  overflow: visible;
}
body.sidebar-collapsed .brand {
  padding-right: 0;
}
body.sidebar-collapsed .brand-copy,
body.sidebar-collapsed .nav-label {
  width: 0;
  opacity: 0;
  overflow: hidden;
}
body.sidebar-collapsed .sidebar-head {
  flex-direction: column;
  align-items: stretch;
}
body.sidebar-collapsed .brand {
  justify-content: center;
  padding-bottom: 10px;
}
body.sidebar-collapsed .sidebar-toggle,
body.sidebar-collapsed .nav-link {
  justify-content: center;
}
body.sidebar-collapsed .collapse-icon {
  transform: rotate(180deg);
}

/* ---------- Header ---------- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-header h1 { font-size: 26px; margin: 0; }
.page-header .subtitle { color: var(--muted); font-size: 13px; }
.user-box { display: flex; align-items: center; gap: 12px; }
.user-pill {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 14px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px; font-size: 13px;
}
.role-chip {
  background: var(--primary); color: #fff; border-radius: 999px;
  padding: 2px 10px; font-size: 12px;
}

/* ---------- Cards & stats ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 20px;
  min-width: 0;
}
.card h2 { font-size: 18px; margin: 0 0 14px; }
.card h3 { font-size: 15px; margin: 0 0 10px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
  min-width: 0;
}
.stat-card .label { color: var(--muted); font-size: 13px; }
.stat-card .value { font-size: 26px; font-weight: 700; margin-top: 6px; }

/* ---------- Tables ---------- */
.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
table.data {
  width: max-content;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 100%;
}
table.data th, table.data td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: top;
}
table.data thead th { background: #f9fafb; color: var(--muted); font-weight: 600; }
table.data tbody tr:hover { background: #f9fafb; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--success-light); color: var(--success); }
.badge.info { background: #dbeafe; color: #1d4ed8; }
.badge.warning { background: var(--warning-light); color: var(--warning); }
.badge.danger { background: var(--danger-light); color: var(--danger); }
.badge.muted { background: #f3f4f6; color: var(--muted); }

/* ---------- Alert list ---------- */
.alert-item {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: #fff;
}
.alert-item.ok {
  border-left-color: var(--success);
  background: linear-gradient(90deg, rgba(5, 150, 105, .08), rgba(5, 150, 105, .02) 18%, #fff 42%);
}
.alert-item.warning {
  border-left-color: var(--warning);
  background: linear-gradient(90deg, rgba(217, 119, 6, .10), rgba(217, 119, 6, .03) 18%, #fff 42%);
}
.alert-item.danger {
  border-left-color: var(--danger);
  background: linear-gradient(90deg, rgba(220, 38, 38, .10), rgba(220, 38, 38, .03) 18%, #fff 42%);
}
.alert-item .title { font-weight: 600; }
.alert-item .desc { color: var(--muted); font-size: 13px; }

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  min-width: 0;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); }
.field input,
.field select,
.field textarea {
  width: 100%;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
select,
textarea {
  display: block;
  width: 100%;
  min-height: var(--control-height);
  padding: 10px 12px;
  border: 1px solid var(--control-border);
  border-radius: 12px;
  background: var(--control-bg);
  box-shadow: var(--control-shadow);
  transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #6b7280 50%),
    linear-gradient(135deg, #6b7280 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 12px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .14), var(--control-shadow);
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
}

.toolbar-form {
  flex: 1;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  min-width: 0;
}

.toolbar-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  min-width: 0;
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--control-height);
  color: var(--muted);
  font-size: 13px;
}

.toolbar-submit {
  align-self: end;
}

.toolbar-search {
  min-width: 240px;
  flex: 2 1 280px;
}

.card-form {
  max-width: 980px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
}

/* ---------- Single-row filter bar (dashboards) ---------- */
/* All controls stay on ONE line; the bar scrolls horizontally if too narrow. */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 4px;
}
.filter-bar .field { flex: 1 0 auto; min-width: 136px; gap: 4px; }
.filter-bar .field.field-date { flex: 0 0 auto; min-width: 160px; }
.filter-bar .field.field-wide { flex: 1 0 auto; min-width: 200px; }
.filter-bar .field label { font-size: 12px; white-space: nowrap; }
.filter-bar .field input,
.filter-bar .field textarea { min-height: 36px; padding: 8px 12px; }
/* keep room on the right for the dropdown chevron (global select uses 34px) */
.filter-bar .field select { min-height: 36px; padding: 8px 34px 8px 12px; text-overflow: ellipsis; }
.filter-bar .filter-actions { display: flex; flex: 0 0 auto; gap: 8px; align-items: center; }

/* ---------- Searchable <select> (js-searchable) ---------- */
.ss-wrap { position: relative; width: 100%; }
/* only selects the JS actually wrapped are hidden; short ones stay native */
/* Ẩn <select> gốc nhưng vẫn cho trình duyệt focus được: nếu display:none thì
   một select `required` sẽ chặn submit với "invalid form control ... is not
   focusable" mà không hiện thông báo nào. */
.ss-wrap select {
  position: absolute; left: 0; bottom: 0; width: 100%; height: 1px;
  opacity: 0; pointer-events: none; border: 0; padding: 0; margin: 0;
}
.ss-panel {
  z-index: 60;
  max-height: 280px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 4px;
}
.ss-option {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ss-option:hover, .ss-option.active { background: var(--bg); }
.ss-option.current { font-weight: 600; color: var(--primary); }
.ss-empty { padding: 10px; color: var(--muted); font-size: 13px; }

/* ---------- KPI stat-cards forced onto a single scrollable row ---------- */
.stats-oneline {
  display: flex;
  flex-wrap: nowrap;
  gap: 12px;
  overflow-x: auto;
  margin-bottom: 20px;
  padding-bottom: 4px;
}
.stats-oneline .stat-card { flex: 1 1 0; min-width: 128px; padding: 12px 14px; }
.stats-oneline .stat-card .label { font-size: 12px; white-space: nowrap; }
.stats-oneline .stat-card .value { font-size: 18px; margin-top: 4px; white-space: nowrap; }

/* ---------- Buttons / toolbar ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar > * {
  min-width: 0;
}
.toolbar-form > .field,
.toolbar-form > input,
.toolbar-form > select {
  flex: 1 1 180px;
  min-width: min(240px, 100%);
}
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--control-height);
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: #eef2ff;
  color: var(--primary);
  box-shadow: 0 8px 18px rgba(37, 99, 235, .08);
  transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease, border-color .18s ease;
}
.btn:hover {
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 12px 20px rgba(15, 23, 42, .1);
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .18);
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: #fff; border-color: var(--border); color: var(--text); box-shadow: none; }
.btn.danger { background: var(--danger); color: #fff; }

.field-error {
  color: var(--danger);
  font-size: 12px;
}

/* Cảnh báo không chặn lưu (vd. vượt tồn kho lúc lập đơn). */
.field-warning {
  color: var(--warning);
  font-size: 12px;
}

.pos-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr);
  gap: 20px;
  margin-bottom: 20px;
}

.pos-panel {
  background: linear-gradient(135deg, #fff, #f8fbff);
}

.pos-form-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: end;
}

.pos-checkbox-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}

.checkbox-inline input {
  margin: 0;
}

.pos-product-info .title {
  margin-bottom: 6px;
}

.panel-note {
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.pos-cart-card {
  margin-top: 16px;
  padding: 18px;
  background: rgba(255, 255, 255, .85);
}

.pos-cart-summary {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

.pos-cart-summary strong {
  font-size: 18px;
  color: var(--text);
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  min-width: 0;
}

.table-search {
  min-width: 240px;
  max-width: 100%;
}

table.data input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
table.data select,
table.data textarea {
  min-height: 40px;
  padding: 8px 10px;
  min-width: 120px;
}

.ai-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 60;
}

.ai-panel {
  display: none;
  position: fixed;
  right: 22px;
  bottom: 88px;
  width: 340px;
  max-width: 92vw;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  z-index: 60;
  overflow: hidden;
}

.ai-panel-head {
  background: var(--sidebar);
  color: #fff;
  padding: 12px 14px;
}

.ai-panel-head .subtitle {
  font-size: 12px;
  color: #9ca3af;
}

.ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px 0;
}

.ai-chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.ai-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.ai-messages {
  padding: 12px;
  max-height: 300px;
  min-height: 120px;
  overflow-y: auto;
  font-size: 13px;
}

.ai-composer {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
}

.ai-input {
  flex: 1;
}

.ai-message {
  margin: 6px 0;
  padding: 8px 10px;
  border-radius: 12px;
  white-space: pre-wrap;
}

.ai-message.me {
  background: #eef2ff;
}

.ai-message.bot {
  background: #f3f4f6;
}

.content-grid,
.stats-grid {
  display: grid !important;
  gap: 20px !important;
}

.content-grid {
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)) !important;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)) !important;
  gap: 20px !important;
}

.content-grid > *,
.stats-grid > * {
  min-width: 0;
  align-self: start;
}

.chart-card {
  overflow: hidden;
}

.chart-card h3 {
  margin-bottom: 14px;
}

.chart-frame {
  position: relative;
  width: 100%;
  height: 280px;
  min-height: 280px;
}

.chart-frame.donut {
  height: 300px;
  min-height: 300px;
}

.chart-frame.tall {
  height: 320px;
  min-height: 320px;
}

.chart-frame canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 11px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--primary);
}

/* ---------- Utilities (muted text, card subtitles, stat cards) ---------- */
.muted { color: var(--muted); }

.card > .subtitle,
.card .subtitle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: -4px 0 14px;
}

.stat-label { color: var(--muted); font-size: 13px; }
.stat-value {
  display: block;
  margin-top: 6px;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: break-word;
}

/* ---------- Advanced analytics dashboard ---------- */
/* Wider cards + wrap long descriptive text so the table-heavy analytics
   cards never overflow (the columns hold long Vietnamese recommendations). */
.analytics-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr)) !important;
  align-items: start;
}
.analytics-grid table.data {
  width: 100%;
  min-width: 0;
  table-layout: auto;
}
.analytics-grid table.data th,
.analytics-grid table.data td {
  white-space: normal;
  overflow-wrap: break-word;
}
.analytics-grid table.data td .muted {
  display: block;
  margin-top: 2px;
  font-size: 12px;
}

.ocr-workbench {
  display: grid;
  gap: 20px;
}

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

.ocr-stage-card {
  margin-bottom: 0;
  background:
    radial-gradient(circle at top right, rgba(37, 99, 235, .08), transparent 34%),
    linear-gradient(180deg, #fff, #fbfdff);
}

.ocr-stage-card h3 {
  margin-bottom: 8px;
}

.ocr-form-shell {
  margin-bottom: 0;
}

.ocr-batch-banner {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 0;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, .08), rgba(37, 99, 235, .02)),
    #fff;
}

.ocr-batch-banner h2 {
  margin: 0 0 6px;
}

.ocr-batch-banner-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ocr-intake-card {
  margin-bottom: 18px;
  background:
    linear-gradient(180deg, #fbfdff, #f6faff);
}

.ocr-intake-head {
  align-items: flex-start;
}

.ocr-intake-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, .85fr);
  gap: 18px;
}

.ocr-preview-box {
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 14px;
  background: #fff;
  min-height: 220px;
  display: grid;
  place-items: center;
}

.ocr-preview-image {
  max-width: 100%;
  max-height: 320px;
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .08);
}

.ocr-side-note {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  font-size: 13px;
}

.ocr-mapping-section {
  margin-top: 16px;
}

.ocr-mapping-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.ocr-mapping-table th,
.ocr-mapping-table td {
  vertical-align: middle;
}

.ocr-mapping-table select,
.ocr-mapping-table input {
  min-width: 140px;
  background-color: #fff;
}

.ocr-form-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.ocr-form-head h3 {
  margin: 0;
}

.ocr-form-head-note {
  max-width: 380px;
  color: var(--muted);
  font-size: 13px;
}

.ocr-form-grid {
  gap: 16px;
}

.ocr-submit-bar {
  margin-top: 20px;
  margin-bottom: 0;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.ocr-history-table td {
  vertical-align: middle;
}

.ocr-history-actions {
  display: grid;
  gap: 6px;
}

.ocr-batch-stats .stat-card {
  margin-bottom: 0;
}

.responsive-cards table.data td[data-label]::before {
  content: none;
}

/* ---------- Mobile ---------- */
.mobile-topbar { display: none; }
.hamburger {
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .12);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
}
.hamburger:hover {
  background: rgba(255, 255, 255, .14);
}
.hamburger svg {
  width: 22px;
  height: 22px;
}
.fab-icon {
  width: 24px;
  height: 24px;
}
.backdrop { display: none; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 260px; z-index: 50;
    transform: translateX(-110%); transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-head {
    flex-direction: row;
  }
  .sidebar-toggle {
    display: none;
  }
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px; padding: 12px 16px;
    background: var(--sidebar); color: #fff; position: sticky; top: 0; z-index: 40;
  }
  body.sidebar-collapsed {
    --sidebar-width: 260px;
  }
  body.sidebar-collapsed .brand-copy,
  body.sidebar-collapsed .nav-label {
    width: auto;
    opacity: 1;
  }
  body.sidebar-collapsed .nav-link {
    justify-content: flex-start;
  }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 45; }
}

@media (max-width: 760px) {
  .stats { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .main { padding: 16px; }
  .pos-layout { grid-template-columns: 1fr; }
  .content-grid,
  .stats-grid {
    grid-template-columns: 1fr !important;
  }
  .ocr-intake-grid {
    grid-template-columns: 1fr;
  }
  .ocr-batch-banner,
  .ocr-mapping-head,
  .ocr-form-head {
    flex-direction: column;
    align-items: stretch;
  }
  .ocr-batch-banner-actions {
    justify-content: flex-start;
  }
  .chart-frame {
    height: 220px;
    min-height: 220px;
  }
  .chart-frame.donut,
  .chart-frame.tall {
    height: 240px;
    min-height: 240px;
  }
  .toolbar-form {
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar-form > .field,
  .toolbar-form > input,
  .toolbar-form > select {
    min-width: 100%;
  }
  .toolbar-submit,
  .toolbar-search {
    min-width: 100%;
  }
  .responsive-cards table.data {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 10px;
  }
  .responsive-cards table.data thead {
    display: none;
  }
  .responsive-cards table.data tbody tr {
    display: block;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 6px 0;
    box-shadow: 0 6px 16px rgba(15, 23, 42, .06);
  }
  .responsive-cards table.data td[data-label] {
    display: grid;
    grid-template-columns: 118px minmax(0, 1fr);
    gap: 8px;
    border-bottom: 1px solid #eef2f7;
    padding: 9px 12px;
    word-break: break-word;
    white-space: normal;
  }
  .responsive-cards table.data td[data-label]:last-child {
    border-bottom: 0;
  }
  .responsive-cards table.data td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
    font-size: 12px;
  }

  table.data th,
  table.data td {
    white-space: normal;
  }
}

/* ---------- Order line editor & "Bù trừ" sub-orders (order form + POS) ---------- */
.card-icon {
  flex: 0 0 38px; width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center; background: #eff6ff; color: var(--primary);
}
.card-icon svg { width: 19px; height: 19px; }
.card-icon.warning { background: var(--warning-light); color: var(--warning); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.stack { grid-template-columns: minmax(0, 1fr); }
.span-full { grid-column: 1 / -1; }
.req { color: var(--danger); }

/* Ô chọn hàng: combobox tìm kiếm dùng chung với "Sản phẩm" ở phiếu kho. */
.lines-table .ss-wrap { min-width: 240px; }
.lines-table .ss-input { width: 100%; }
.lines-table select.line-product:not([data-ss-enhanced]) { width: 100%; min-width: 240px; }
.lines-table .col-qty input { max-width: 110px; min-width: 90px; }
/* Discount cells: % on top, amount underneath; Giảm SP input right-aligned under its header. */
.lines-table td.disc { text-align: right; vertical-align: middle; white-space: nowrap; }
.lines-table .pct-input { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
table.data.lines-table td.col-pd .pct-input input[type="number"] {
  width: 88px; min-width: 88px; max-width: 88px; text-align: right;
}
.lines-table .pct-sign { color: var(--muted); font-weight: 600; }
.lines-table .disc-rate { font-weight: 600; }
.lines-table .disc-amount { display: block; margin-top: 3px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.lines-table .disc-amount:empty { display: none; }
.lines-table th.num, .lines-table td.ro { text-align: right; white-space: nowrap; }
.lines-table td.ro, .lines-table td.col-actions { vertical-align: middle; }
.lines-table .auto { color: var(--muted); font-weight: 400; }
.lines-table .line-note { font-size: 11px; color: var(--success); margin-top: 3px; }
.lines-table .line-note:empty { display: none; }
.lines-table .stock-hint { font-size: 11px; margin-top: 3px; }
.lines-table .stock-hint.ok { color: var(--muted); }
.lines-table .stock-hint.danger { color: var(--danger); font-weight: 600; }
.lines-table input.stock-over { border-color: var(--danger); }
.lines-table tr.line-row.is-deleted td > *:not(.icon-btn) { opacity: .4; }
.lines-table tr.line-row.is-deleted .c-net { text-decoration: line-through; }
.line-editor-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.line-totals { display: flex; gap: 18px; flex-wrap: wrap; align-items: baseline; font-size: 13px; color: var(--muted); }
.line-totals strong { color: var(--text); margin-left: 4px; }
.line-totals .net strong { color: var(--primary); font-size: 16px; }
.line-editor .btn svg,
.offset-card .btn svg { width: 16px; height: 16px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border); background: #fff; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--danger); border-color: #fecaca; background: var(--danger-light); }
.icon-btn svg { width: 16px; height: 16px; }
tr.line-row.is-deleted .icon-btn { color: var(--primary); }

.offset-card.is-open { border-color: #fcd34d; }
.offset-toggle { position: relative; display: flex; align-items: center; gap: 14px; cursor: pointer; }
.offset-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch { flex: 0 0 46px; width: 46px; height: 26px; border-radius: 999px; background: #d1d5db; position: relative; transition: background .18s ease; }
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(15, 23, 42, .25); transition: transform .18s ease;
}
.offset-toggle input:checked + .switch { background: var(--warning); }
.offset-toggle input:checked + .switch::after { transform: translateX(20px); }
.offset-toggle input:focus-visible + .switch { box-shadow: 0 0 0 4px rgba(217, 119, 6, .22); }
.offset-toggle-text strong { display: block; font-size: 17px; }
.offset-toggle-text small { display: block; color: var(--muted); font-size: 13px; }
.offset-body { margin-top: 16px; }
.sub-orders { display: flex; flex-direction: column; gap: 16px; margin: 14px 0; }
.sub-order {
  border: 1px solid #fde68a; border-left: 4px solid var(--warning); border-radius: 14px;
  background: linear-gradient(180deg, #fffbeb, #fff 140px); padding: 16px; min-width: 0;
}
.sub-order .form-grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.sub-order.has-errors { border-color: #fecaca; border-left-color: var(--danger); }
.sub-order-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.sub-order-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sub-order-actions { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.sub-order-actions strong { color: var(--warning); font-size: 15px; margin-left: 4px; }
.sub-order-lines-title { margin: 18px 0 8px; font-size: 14px; }
.sub-order-deleted-bar { display: none; }
.sub-order.is-deleted { background: #f9fafb; border-color: var(--border); border-left-color: #9ca3af; }
.sub-order.is-deleted .sub-order-body,
.sub-order.is-deleted .sub-order-actions { display: none; }
.sub-order.is-deleted .sub-order-head { margin-bottom: 8px; }
.sub-order.is-deleted .sub-order-deleted-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.empty-sub-orders { padding: 18px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: 12px; margin: 14px 0; }
.pos-panel .offset-card { margin: 16px 0 0; box-shadow: none; }

@media (max-width: 1100px) {
  .form-grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .form-grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Sales order form (Quản lý bán hàng + Bán hàng tại quầy) ---------- */
.order-form .card-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.order-form .card-head h2 { margin: 0; }
.order-form .card-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.order-form .field textarea { min-height: 72px; }
.order-scope { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.order-panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; margin-bottom: 20px; }
.order-panels > .card { margin-bottom: 0; }
.check-row {
  display: flex; align-items: center; gap: 10px; min-height: var(--control-height);
  padding: 0 12px; border: 1px dashed var(--control-border); border-radius: 12px;
  cursor: pointer; font-size: 13px;
}
.form-actions-bar {
  position: sticky; bottom: 12px; z-index: 5; margin-bottom: 20px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; background: rgba(255, 255, 255, .96); backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 -6px 24px rgba(15, 23, 42, .08);
}
.form-actions-bar .btn svg { width: 16px; height: 16px; }
.form-actions-summary { display: flex; gap: 18px; flex-wrap: wrap; align-items: baseline; font-size: 13px; color: var(--muted); }
.form-actions-summary strong { color: var(--text); font-size: 15px; margin-left: 4px; }
.form-actions-summary .net strong { color: var(--primary); font-size: 18px; }
.form-actions-summary .danger strong { color: var(--danger); }
.form-actions-buttons { display: flex; gap: 10px; }
.pos-panels { display: grid; grid-template-columns: minmax(280px, .8fr) minmax(0, 1.4fr); gap: 20px; align-items: start; }
@media (max-width: 1100px) {
  .pos-panels { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .form-actions-buttons { width: 100%; }
  .form-actions-buttons .btn { flex: 1; justify-content: center; }
}
.order-form .btn svg { width: 16px; height: 16px; }

/* Inline validation (order form): red outline + message under the field. */
.order-form .is-invalid,
.order-form .ss-wrap.is-invalid .ss-input,
table.data.lines-table input.is-invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .12) !important;
}
.order-form .client-error { margin-top: 4px; font-size: 12px; font-weight: 600; white-space: normal; }
/* SKU không có giá ở ngày giao hàng (order-lines.js setNoPrice). */
.order-form .ss-wrap.no-price .ss-input,
.order-form select.no-price {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .12) !important;
}
.order-form .no-price-error { margin-top: 4px; font-size: 12px; font-weight: 600; white-space: normal; }

/* Hai bước: "Tiếp tục: chọn hàng hóa" dưới phần thông tin đơn. */
.order-step-next { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.order-step-next .subtitle { margin: 0; }

/* "Xem bù trừ": main order vs sub-orders (money + goods). */
.promo-card { border-color: #fde68a; }
.promo-editor .line-totals .net strong { color: var(--warning); }
.promo-editor .promo-hint { color: var(--muted); }
.offset-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.offset-actions .btn svg { width: 16px; height: 16px; }
.offset-preview { margin-top: 16px; }
.offset-preview-card { border: 1px solid var(--border); border-radius: 14px; padding: 16px; background: #fff; }
.offset-preview-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.offset-preview-note { margin: 6px 0 12px; font-size: 12px; color: var(--muted); }
.offset-preview-money { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
.offset-preview-stat { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; }
.offset-preview-stat .label { font-size: 12px; color: var(--muted); }
.offset-preview-stat .badge { align-self: flex-start; }
.offset-preview-goods th.num, .offset-preview-goods td.ro { text-align: right; }
.offset-preview-errors { margin: 6px 0 0; padding-left: 18px; color: var(--danger); font-size: 13px; }
.offset-preview-stale { display: none; margin: 10px 0 0; font-size: 12px; font-weight: 600; color: var(--warning); }
.offset-preview[data-stale] .offset-preview-stale { display: block; }
.offset-preview[data-stale] .offset-preview-card { opacity: .7; }

/* `hidden` phải luôn ẩn: các khối có `display` riêng (vd .modal-backdrop) sẽ
   đè mất quy tắc [hidden] mặc định của trình duyệt và popup hiện ngay khi mở
   trang, đóng cũng không được. */
[hidden] { display: none !important; }

/* ---------- Confirmation popup (static/js/confirm-dialog.js) ---------- */
body.modal-open { overflow: hidden; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 16px;
  background: rgba(15, 23, 42, .45);
  animation: modal-fade .15s ease-out;
}
.modal {
  width: min(460px, 100%);
  background: var(--card); border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
  padding: 24px; text-align: center;
  animation: modal-pop .18s ease-out;
}
.modal-icon {
  width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 50%;
  display: grid; place-items: center; background: #eff6ff; color: var(--primary);
}
.modal-icon.warning { background: var(--warning-light); color: var(--warning); }
.modal-icon.danger { background: var(--danger-light); color: var(--danger); }
.modal-icon svg { width: 26px; height: 26px; }
.modal-title { margin: 0 0 10px; font-size: 18px; }
.modal-body { color: var(--muted); font-size: 14px; }
.modal-body p { margin: 0 0 6px; }
.modal-body p:first-child { color: var(--text); font-weight: 600; }
.modal-actions { display: flex; justify-content: center; gap: 10px; margin-top: 20px; }
.modal-actions .btn { min-width: 132px; justify-content: center; }
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@media (max-width: 760px) {
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
}

/* ---------- Phiếu bù trừ: hai cột đơn giao hàng / đơn DMS + bộ chọn đơn ---------- */
.offset-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.offset-column { display: flex; flex-direction: column; gap: 12px; }
.offset-column .card-head { margin-bottom: 0; }
.offset-column h2 { display: flex; align-items: center; gap: 8px; }
.offset-column-total {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 10px 14px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border);
}
.offset-column-total span { color: var(--muted); font-size: 13px; }
.offset-column-total strong { font-size: 18px; }

.offset-item {
  border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
}
.offset-column:nth-child(2) .offset-item { border-left-color: var(--warning); }
.offset-item.is-cancelled { opacity: .6; border-left-color: var(--muted); }
.offset-item-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.offset-item-code { font-weight: 600; }
.offset-item-total { font-weight: 700; white-space: nowrap; }
.offset-item-customer { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.offset-item-customer i { width: 14px; height: 14px; color: var(--muted); }
.offset-item-goods { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.offset-item-goods li.promo { list-style: none; margin-left: -18px; }
.offset-item-actions { margin: 0; }
/* Toolbar của thẻ "Bù trừ với nhân viên bán hàng": badge + nút Xem bù trừ. */
.offset-view-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.offset-empty {
  padding: 18px; text-align: center; color: var(--muted); font-size: 13px;
  border: 1px dashed var(--border); border-radius: 10px;
}

.offset-picker { position: relative; }
.offset-picker-toggle { width: 100%; justify-content: center; }
.offset-picker-panel {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, .16); padding: 12px; max-height: 420px; overflow: auto;
}
.offset-picker-search { display: flex; align-items: center; gap: 8px; }
.offset-picker-search i { width: 16px; height: 16px; color: var(--muted); }
.offset-picker-search input { flex: 1; }
.offset-picker-hint { margin: 8px 0 10px; font-size: 12px; color: var(--muted); }
.offset-picker-list { display: flex; flex-direction: column; gap: 8px; }
.offset-candidate {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px; margin: 0; background: var(--bg);
}
.offset-candidate:hover { border-color: var(--primary); }
.offset-candidate-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.offset-candidate-total { font-weight: 700; white-space: nowrap; }
.offset-candidate-body { display: flex; flex-direction: column; gap: 4px; }
.offset-candidate-customer { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.offset-candidate-customer i { width: 14px; height: 14px; color: var(--muted); }
.offset-candidate-goods { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12px; }
.offset-candidate-goods li.promo { list-style: none; margin-left: -18px; }
.offset-candidate-add { align-self: flex-start; }
.offset-picker-empty { padding: 14px; text-align: center; color: var(--muted); font-size: 13px; }

@media (max-width: 1100px) {
  .offset-columns { grid-template-columns: 1fr; }
}

/* ---------- Nút "Thêm mới" có nhiều lựa chọn (vd: đơn giao hàng / đơn DMS) ---------- */
.create-menu { position: relative; }
.create-menu > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.create-menu > summary::-webkit-details-marker { display: none; }
.create-menu[open] > summary i { transform: rotate(180deg); }
.create-menu > summary i { width: 16px; height: 16px; transition: transform .15s ease; }
.create-menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 290px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 6px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, .16); display: flex; flex-direction: column; gap: 2px;
}
.create-menu-option {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 12px;
  border-radius: 8px; color: var(--text); text-decoration: none;
}
.create-menu-option:hover { background: var(--bg); }
.create-menu-option span { font-size: 12px; color: var(--muted); }

/* ---------- Popup nhập liệu (vd: "Hoàn 1 phần" trên trang đơn hàng) ---------- */
.modal-card {
  width: min(720px, 100%); max-height: 88vh; overflow: auto;
  background: var(--card); border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(15, 23, 42, .28); padding: 22px 24px;
  animation: modal-pop .18s ease-out; text-align: left;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.offset-candidate.is-blocked { opacity: .72; background: transparent; }
.offset-candidate.is-blocked:hover { border-color: var(--border); }
.offset-candidate-blocked { align-self: flex-start; }

/* Card ở trang phiếu bù trừ: tiêu đề bên trái, nút phụ nằm góc trên bên phải. */
.offset-column .card-head { display: flex; align-items: flex-start; gap: 12px; }
.offset-column .card-head h2 { margin: 0; }
.offset-column .card-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.card-head-action { margin-left: auto; white-space: nowrap; }

/* Dòng tiền tóm tắt của một đơn (thẻ trong phiếu + ứng viên trong bộ chọn). */
.offset-money {
  display: flex; flex-wrap: wrap; gap: 4px 14px;
  font-size: 12px; color: var(--muted);
  padding-top: 6px; border-top: 1px dashed var(--border);
}
.offset-money strong { color: var(--text); font-weight: 600; }
.offset-money-parts { flex-basis: 100%; }

/* ---------- Bộ lọc danh sách (kiểu Sapo) ---------- */
.list-toolbar {
  display: block;
}

.table-filter {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

/* Tab nhanh */
.table-filter-tabs {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

.table-filter-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.table-filter-tab:hover {
  color: var(--text);
  background: var(--bg);
}

.table-filter-tab.is-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.table-filter-tab-count {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.table-filter-tab.is-active .table-filter-tab-count {
  background: var(--primary);
  color: #fff;
}

/* Hàng tìm kiếm */
.table-filter-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.table-filter-head {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* Nút Import / Thêm mới đẩy sang mép phải cùng hàng với ô tìm kiếm. */
.table-filter-actions {
  margin-left: auto;
}

.table-filter-search {
  position: relative;
  flex: 1 1 280px;
  min-width: min(240px, 100%);
  display: flex;
  align-items: center;
}

.table-filter-search i {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

.table-filter-search input {
  width: 100%;
  padding-left: 36px;
}

.table-filter-toggle .table-filter-count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

/* Bảng "Bộ lọc khác" */
.table-filter-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  padding: 14px;
}

.table-filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.table-filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.table-filter-field > label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.table-filter-field select,
.table-filter-field input {
  width: 100%;
}

.table-filter-range {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.table-filter-range span {
  color: var(--muted);
  flex: none;
}

.table-filter-range input {
  flex: 1 1 0;
  min-width: 0;
}

.table-filter-panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Thẻ điều kiện đang áp */
.table-filter-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.table-filter-chips-label {
  color: var(--muted);
  font-size: 13px;
}

.table-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
}

.table-filter-chip:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.table-filter-chip i {
  width: 14px;
  height: 14px;
  color: var(--muted);
}

.table-filter-chip:hover i {
  color: var(--danger);
}

.table-filter-chip-clear {
  color: var(--primary);
  font-size: 13px;
  text-decoration: none;
}

.table-filter-chip-clear:hover {
  text-decoration: underline;
}

@media (max-width: 760px) {
  .table-filter-actions {
    margin-left: 0;
    width: 100%;
  }

  .table-filter-head .btn {
    flex: 1 1 auto;
    justify-content: center;
  }

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

/* ---------- Ghi nhận thanh toán cho đơn hàng ---------- */
.pay-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.pay-figure {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}

.pay-figure .label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.pay-figure strong {
  font-size: 20px;
  font-weight: 600;
}

.pay-figure.is-due {
  border-color: var(--danger);
  background: #fef2f2;
}

.pay-figure.is-due strong {
  color: var(--danger);
}

.pay-figure.is-clear strong {
  color: var(--success);
}

.pay-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.pay-amount {
  position: relative;
  display: flex;
  align-items: center;
}

.pay-amount input {
  width: 100%;
  padding-right: 34px;
  font-size: 20px;
  font-weight: 600;
  text-align: right;
}

.pay-currency {
  position: absolute;
  right: 12px;
  color: var(--muted);
  pointer-events: none;
}

.pay-fill {
  align-self: flex-start;
  margin-top: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
}

.pay-fill:hover {
  text-decoration: underline;
}

.pay-hint {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.pay-hint.is-clear {
  color: var(--success);
}

.pay-hint.is-over {
  color: var(--danger);
}

.pay-form .form-grid {
  margin-top: 14px;
}

.pay-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

@media (max-width: 900px) {
  .pay-layout {
    grid-template-columns: 1fr;
  }
}

/* ---------- Số dư bù trừ theo nhân viên ---------- */
.balance-table .num {
  text-align: right;
  white-space: nowrap;
}

.balance-money {
  font-weight: 600;
}

.balance-money.is-due {
  color: var(--danger);
}

.balance-money.is-owed {
  color: var(--warning);
}

.balance-net {
  margin-top: 4px;
  font-weight: 600;
}

.balance-headline {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.balance-headline strong {
  font-size: 20px;
}

/* ---------- Bộ lọc trong bộ chọn đơn của phiếu bù trừ ---------- */
.offset-picker-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px 10px;
  align-items: end;
  padding: 10px 0 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.offset-picker-filter {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.offset-picker-filter > span:first-child {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.offset-picker-filter select,
.offset-picker-filter input {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

.offset-picker-filter select {
  padding-right: 30px;
}

.offset-picker-range {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.offset-picker-range > span {
  color: var(--muted);
  flex: none;
}

.offset-picker-range input {
  flex: 1 1 0;
  min-width: 0;
}

.offset-picker-reset {
  align-self: end;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.offset-picker-reset:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.offset-picker-count {
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Popup xác nhận duyệt đơn (static/js/approve-check.js) ---------- */
.approve-messages {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
}

.approve-messages:empty {
  display: none;
}

.approve-check-table .num {
  text-align: right;
  white-space: nowrap;
}

.approve-check-table tr.is-short td {
  background: #fef2f2;
}

.approve-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.approve-actions .btn[disabled] {
  opacity: .55;
  cursor: not-allowed;
}

/* ---------- Xem trước Phiếu giao hàng (bám bố cục mẫu .xlsx) ---------- */
.delivery-note {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  font-size: 13px;
}

.dn-head {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 14px;
  align-items: start;
}

.dn-logo { width: 140px; height: auto; }
.dn-company strong { display: block; font-size: 14px; }
.dn-company div { color: var(--text); }
.dn-meta { text-align: right; white-space: nowrap; }

.dn-title {
  margin: 14px 0 12px;
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  letter-spacing: .5px;
}

.dn-info {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 10px;
}

.dn-info-main > div { margin-bottom: 2px; }
.dn-info-side { text-align: right; white-space: nowrap; }

/* Hàng MST · MĐD · Tên pháp nhân đặt theo đúng cột của mẫu (A · C · F). */
.dn-info-row { display: flex; }
.dn-mst { flex: 0 0 19%; }
.dn-mdd { flex: 0 0 26%; }
.dn-legal { flex: 1 1 auto; }

/* Mã SP tràn ra thay vì xuống dòng — giống cài đặt trong file .xlsx. */
.dn-sku { white-space: nowrap; }
.dn-blank { border-color: transparent !important; }
/* Ô trống ở đầu bảng cũng không tô nền — bảng khuyến mãi dừng ở cột THÀNH TIỀN. */
.dn-table thead th.dn-blank { background: transparent; }

/* Nhãn tổng tràn sang trái ra ngoài ô, đúng như Excel hiển thị. */
.dn-overflow-cell { position: relative; }
.dn-overflow-cell > span {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
}

.dn-table {
  width: 100%;
  border-collapse: collapse;
}

.dn-table th,
.dn-table td {
  border: 1px solid #94a3b8;
  padding: 4px 6px;
}

.dn-table thead th {
  background: #e2e8f0;
  font-size: 12px;
  text-align: center;
}

.dn-table .num { text-align: right; }
.dn-table thead .num { text-align: center; }
.dn-table tfoot th { text-align: right; }
.dn-empty { text-align: center; color: var(--muted); padding: 16px; }

.dn-sign-date { margin-top: 14px; text-align: right; font-style: italic; }

.dn-signs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 6px;
  text-align: center;
  font-weight: 600;
}

@media print {
  .no-print, .sidebar, .mobile-topbar, .page-header, .ai-fab, .ai-panel { display: none !important; }
  .main, .layout { margin: 0; padding: 0; }
  .delivery-note { border: 0; padding: 0; }
}

/* Bảng hàng khuyến mãi của phiếu giao hàng — tách khỏi khối tiền phải trả. */
/* Nhãn "Hàng khuyến mãi" là chữ thường, không khung — như ô A của file in. */
.dn-promo-title {
  margin: 14px 0 4px;
}

/* ---------- Nhập đơn hàng từ .xlsx ---------- */
/* Thẻ thu gọn: bấm tiêu đề để mở form nhập tệp. */
.order-import > summary { list-style: none; cursor: pointer; }
.order-import > summary::-webkit-details-marker { display: none; }
.order-import:not([open]) > summary { margin-bottom: 0; }
.order-import-chevron { margin-left: auto; flex: none; width: 18px; height: 18px; color: var(--muted); transition: transform .15s ease; }
.order-import[open] .order-import-chevron { transform: rotate(180deg); }
.order-import-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.order-import-form .btn:disabled { opacity: .5; cursor: not-allowed; }

.order-import-form input[type="file"] {
  flex: 1 1 280px;
  min-width: min(260px, 100%);
}

@media (max-width: 760px) {
  .order-import-form .btn { flex: 1 1 auto; justify-content: center; }
}

/* Nút cạnh nhau trong ô thao tác (Ghi thu · Ghi chi · Xem chi tiết). */
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
