:root {
  --bg-canvas: #f3f6f4;
  --bg-surface: #ffffff;
  --bg-subtle: #eaf0ec;
  --bg-hover: #f7faf8;
  --border-card: rgba(11, 38, 32, 0.08);
  --border-input: rgba(11, 38, 32, 0.14);
  --text-main: #0d211c;
  --text-muted: #5b716a;
  --text-soft: #81948e;
  --rail-bg: #0b2620;
  --rail-grad: linear-gradient(180deg, #0b2620 0%, #13332c 100%);
  --accent-mint: #10b981;
  --accent-mint-glow: #6ee7b7;
  --accent-orange: #f97316;
  --accent-orange-hover: #ea580c;
  --shadow-card: 0 8px 28px -8px rgba(11, 38, 32, 0.08), 0 2px 6px rgba(11, 38, 32, 0.03);
  --shadow-card-hover: 0 18px 38px -12px rgba(11, 38, 32, 0.16);
}

[data-theme="dark"] {
  --bg-canvas: #071612;
  --bg-surface: #0f241e;
  --bg-subtle: #143028;
  --bg-hover: #17362d;
  --border-card: rgba(110, 231, 183, 0.12);
  --border-input: rgba(110, 231, 183, 0.2);
  --text-main: #ecfdf5;
  --text-muted: #9cc2b5;
  --text-soft: #6f988b;
  --rail-bg: #05120f;
  --rail-grad: linear-gradient(180deg, #05120f 0%, #0b2620 100%);
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.45);
  --shadow-card-hover: 0 20px 40px -12px rgba(0, 0, 0, 0.65);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-canvas);
  color: var(--text-main);
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* Scrollbars gọn đẹp */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(16, 185, 129, 0.28);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(16, 185, 129, 0.5);
}

/* Bento Card V22 */
.v22-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: 20px;
  box-shadow: var(--shadow-card);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.22s ease, border-color 0.22s ease;
}

.v22-card-lift:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-card-hover);
  border-color: rgba(16, 185, 129, 0.28);
}

.v22-glass {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.65);
}

[data-theme="dark"] .v22-glass {
  background: rgba(15, 36, 30, 0.82);
  border: 1px solid rgba(110, 231, 183, 0.16);
}

.v22-hero {
  background: linear-gradient(125deg, #0b2620 0%, #133930 58%, #16493d 100%);
  border-radius: 22px;
  color: #ffffff;
  position: relative;
  overflow: hidden;
  box-shadow: 0 14px 32px -12px rgba(11, 38, 32, 0.45);
}

.v22-hero::after {
  content: '';
  position: absolute;
  width: 240px;
  height: 240px;
  right: -40px;
  top: -80px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(52, 211, 153, 0.26) 0%, transparent 70%);
  pointer-events: none;
}

/* Icon Rail Sidebar V22 */
.v22-rail {
  background: var(--rail-grad);
  border-radius: 24px;
  box-shadow: 0 18px 40px -14px rgba(11, 38, 32, 0.55);
}

.v22-rail-btn {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(226, 247, 239, 0.65);
  transition: all 0.2s ease;
  cursor: pointer;
}

.v22-rail-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.v22-rail-btn.active {
  color: #07221b;
  background: radial-gradient(circle at center, #a7f3d0 0%, #34d399 100%);
  box-shadow: 0 0 22px rgba(110, 231, 183, 0.65);
  border-radius: 999px;
}

.v22-rail-btn .v22-tooltip {
  position: absolute;
  left: 56px;
  background: #0b2620;
  color: #ecfdf5;
  padding: 6px 11px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-6px);
  transition: all 0.16s ease;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(110, 231, 183, 0.2);
  z-index: 60;
}

.v22-rail-btn:hover .v22-tooltip {
  opacity: 1;
  transform: translateX(0);
}

/* Nút bấm V22 */
.v22-btn-orange {
  background: linear-gradient(135deg, #fb923c 0%, #f97316 100%);
  color: #ffffff;
  font-weight: 700;
  border-radius: 999px;
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow: 0 8px 18px -6px rgba(249, 115, 22, 0.55);
}
.v22-btn-orange:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
  box-shadow: 0 12px 24px -6px rgba(249, 115, 22, 0.65);
}

.v22-btn-mint {
  background: linear-gradient(135deg, #34d399 0%, #10b981 100%);
  color: #06281e;
  font-weight: 700;
  border-radius: 999px;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  box-shadow: 0 8px 18px -6px rgba(16, 185, 129, 0.45);
}
.v22-btn-mint:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px -6px rgba(16, 185, 129, 0.6);
}

.v22-btn-dark {
  background: #0b2620;
  color: #ecfdf5;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid rgba(16, 185, 129, 0.25);
  transition: background 0.15s ease, transform 0.15s ease;
}
[data-theme="dark"] .v22-btn-dark {
  background: #174136;
  border-color: rgba(110, 231, 183, 0.3);
}
.v22-btn-dark:hover:not(:disabled) {
  background: #143f35;
  transform: translateY(-1px);
}

.v22-btn-ghost {
  background: var(--bg-subtle);
  color: var(--text-main);
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid var(--border-card);
  transition: background 0.15s ease;
}
.v22-btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
}

/* Input chuẩn ERP */
.v22-input, .v22-select {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-input);
  border-radius: 12px;
  padding: 7px 11px;
  font-size: 13px;
  min-width: 0;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.v22-select {
  height: 35px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.v22-input:focus, .v22-select:focus {
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.16);
}

.v22-cell-input {
  width: 100%;
  min-width: 0;
  background: transparent;
  color: var(--text-main);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 4px 6px;
  font-size: 12.5px;
  outline: none;
  transition: border-color 0.14s ease, background-color 0.14s ease;
}
.v22-cell-input[type="number"]::-webkit-inner-spin-button,
.v22-cell-input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.v22-cell-input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}
.v22-cell-input:hover {
  background: var(--bg-subtle);
}
.v22-cell-input:focus {
  background: var(--bg-surface);
  border-color: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.18);
}

/* Segmented Tick Bar V22 */
.v22-tickbar {
  display: grid;
  grid-template-columns: repeat(24, minmax(0, 1fr));
  gap: 3px;
  align-items: center;
  height: 22px;
}
.v22-tick {
  height: 16px;
  border-radius: 999px;
  background: var(--bg-subtle);
  transition: transform 0.2s ease, background-color 0.2s ease;
}
.v22-tick.filled {
  background: linear-gradient(180deg, #34d399 0%, #059669 100%);
  height: 20px;
}
.v22-tick.orange {
  background: linear-gradient(180deg, #fb923c 0%, #ea580c 100%);
  height: 20px;
}

/* ERP Data Table mật độ cao */
.v22-table-wrap {
  overflow: auto;
  border-radius: 16px;
  border: 1px solid var(--border-card);
  background: var(--bg-surface);
}
.v22-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
}
.v22-table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-card);
  white-space: nowrap;
}
.v22-table tbody td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-card);
  vertical-align: middle;
}
.v22-table tbody tr:hover td {
  background: var(--bg-hover);
}
.v22-table tbody tr.row-selected td {
  background: rgba(16, 185, 129, 0.12);
}

/* Multi-Tab Bar */
.v22-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}
.v22-tab:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}
.v22-tab.active {
  background: var(--bg-surface);
  color: var(--text-main);
  border-color: var(--border-card);
  box-shadow: 0 4px 12px -4px rgba(11, 38, 32, 0.12);
}

/* Animation fade-in */
@keyframes v22FadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.v22-fade-in {
  animation: v22FadeIn 0.22s ease-out;
}

/* Ngăn phụ Menu 2-3 cấp (Phương án A: Dual-Panel Icon Rail + Sub-Drawer) */
.v22-subdrawer {
  width: 268px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border-card);
  box-shadow: 0 20px 44px -14px rgba(11, 38, 32, 0.24);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: v22DrawerIn 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="dark"] .v22-subdrawer {
  background: rgba(11, 30, 25, 0.95);
  border-color: rgba(110, 231, 183, 0.18);
  box-shadow: 0 22px 48px -12px rgba(0, 0, 0, 0.65);
}

@keyframes v22DrawerIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

.v22-tree-l2-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 12px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-main);
  transition: background-color 0.14s ease;
  cursor: pointer;
  text-align: left;
}
.v22-tree-l2-btn:hover {
  background: var(--bg-subtle);
}

.v22-tree-children {
  margin-left: 14px;
  padding-left: 10px;
  border-left: 1.5px solid var(--border-input);
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 2px;
  margin-bottom: 6px;
}

.v22-tree-leaf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 9px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.14s ease;
  cursor: pointer;
  text-align: left;
}
.v22-tree-leaf:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}
.v22-tree-leaf.active {
  background: #0b2620;
  color: #ecfdf5;
  box-shadow: 0 6px 16px -6px rgba(11, 38, 32, 0.5);
}
[data-theme="dark"] .v22-tree-leaf.active {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #051c16;
}
.v22-tree-leaf .v22-fav-btn {
  opacity: 0;
  transition: opacity 0.14s ease;
}
.v22-tree-leaf:hover .v22-fav-btn,
.v22-tree-leaf .v22-fav-btn.starred {
  opacity: 1;
}

/* Sticky Left/Right Columns cho lưới Nhập đơn tốc độ cao */
.v22-table th.v22-sticky-l0,
.v22-table td.v22-sticky-l0 {
  position: sticky;
  left: 0;
  width: 60px;
  min-width: 60px;
  max-width: 60px;
  z-index: 14;
  background: var(--bg-surface);
}
.v22-table th.v22-sticky-l1,
.v22-table td.v22-sticky-l1 {
  position: sticky;
  left: 60px;
  min-width: 132px;
  z-index: 14;
  background: var(--bg-surface);
  box-shadow: 6px 0 12px -6px rgba(11, 38, 32, 0.16);
}
.v22-table th.v22-sticky-r1,
.v22-table td.v22-sticky-r1 {
  position: sticky;
  right: 54px;
  min-width: 102px;
  z-index: 14;
  background: var(--bg-surface);
  box-shadow: -6px 0 12px -6px rgba(11, 38, 32, 0.16);
}
.v22-table th.v22-sticky-r0,
.v22-table td.v22-sticky-r0 {
  position: sticky;
  right: 0;
  width: 54px;
  min-width: 54px;
  max-width: 54px;
  z-index: 14;
  background: var(--bg-surface);
}
.v22-table thead th.v22-sticky-l0,
.v22-table thead th.v22-sticky-l1,
.v22-table thead th.v22-sticky-r1,
.v22-table thead th.v22-sticky-r0 {
  z-index: 22;
  background: var(--bg-subtle);
}
.v22-table tbody tr:hover td.v22-sticky-l0,
.v22-table tbody tr:hover td.v22-sticky-l1,
.v22-table tbody tr:hover td.v22-sticky-r1,
.v22-table tbody tr:hover td.v22-sticky-r0 {
  background: var(--bg-hover);
}
.v22-table tbody tr.row-highlight td {
  background: rgba(16, 185, 129, 0.16) !important;
}
.v22-table tbody tr.row-found-lactuyen td {
  background: rgba(250, 204, 21, 0.34) !important;
  font-weight: 600;
}
.v22-table tbody tr.row-found-lactuyen td:first-child {
  box-shadow: inset 4px 0 0 #f97316;
}
[data-theme="dark"] .v22-table tbody tr.row-found-lactuyen td {
  background: rgba(245, 158, 11, 0.28) !important;
}
.v22-table tbody tr.row-highlight td.v22-sticky-l0,
.v22-table tbody tr.row-highlight td.v22-sticky-l1,
.v22-table tbody tr.row-highlight td.v22-sticky-r1,
.v22-table tbody tr.row-highlight td.v22-sticky-r0 {
  background: #dcfce7 !important;
}
[data-theme="dark"] .v22-table tbody tr.row-highlight td.v22-sticky-l0,
[data-theme="dark"] .v22-table tbody tr.row-highlight td.v22-sticky-l1,
[data-theme="dark"] .v22-table tbody tr.row-highlight td.v22-sticky-r1,
[data-theme="dark"] .v22-table tbody tr.row-highlight td.v22-sticky-r0 {
  background: #123b2e !important;
}

/* Ngăn Danh sách Chứng từ gắn song song bên trái Form (Nhập đơn) */
.v22-batch-drawer {
  width: 100%;
  border-radius: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: v22DrawerIn 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

/* In ấn Bill A5 / Bảng kê / Phiếu thu */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  #app, #toast-root, #modal-root {
    display: none !important;
  }
  #print-root {
    display: block !important;
    padding: 8mm;
    font-family: Arial, sans-serif;
  }
}
