:root {
  --bg: #f4f7fb;
  --bg-card: #ffffff;
  --sidebar: #1e3a5f;
  --sidebar-hover: #2a4d73;
  --sidebar-text: #c8d9ec;
  --sidebar-active: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --hoa: #7c3aed;
  --kha: #0891b2;
  --shared: #ea580c;
  --box: #ca8a04;
  --pack: #0284c7;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --radius: 10px;
  --input-h: 36px;
  --max-w: 1440px;
  --sidebar-width: 220px;
  --sidebar-collapsed-width: 68px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

html, body {
  overflow-x: hidden;
}

/* Sidebar — fixed full viewport height */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  background: var(--sidebar);
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.logo {
  padding: 1.15rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-shrink: 0;
}

.logo-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #7c3aed);
  color: #fff;
  font-weight: 800;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-text .logo-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  letter-spacing: -0.02em;
}

.logo small {
  display: block;
  font-size: 0.68rem;
  color: var(--sidebar-text);
  font-weight: 400;
  margin-top: 0.1rem;
}

.sidebar-toggle {
  position: absolute;
  right: -12px;
  top: 72px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  line-height: 1;
  box-shadow: var(--shadow);
  z-index: 101;
}

body.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .main {
  margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .logo-text,
body.sidebar-collapsed .nav-item span:not(.nav-icon) {
  display: none;
}

body.sidebar-collapsed .logo {
  justify-content: center;
  padding: 1rem 0.5rem;
}

body.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 0.72rem 0.5rem;
}

body.sidebar-collapsed .sidebar-toggle {
  transform: rotate(180deg);
}

.nav {
  padding: 0.65rem 0.55rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.72rem 0.85rem;
  margin-bottom: 3px;
  color: var(--sidebar-text);
  text-decoration: none;
  cursor: pointer;
  border-radius: 10px;
  font-size: 0.9375rem;
  line-height: 1.25;
  transition: background 0.15s, color 0.15s;
}

.nav-item .nav-icon {
  width: 20px;
  min-width: 20px;
  text-align: center;
  opacity: 0.9;
  font-size: 1.05rem;
  line-height: 1;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-active);
}

.hidden { display: none !important; }

.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--sidebar-active);
  font-weight: 600;
  box-shadow: inset 3px 0 0 rgba(96, 165, 250, 0.85);
}

/* Sidebar — card tỷ giá & thời gian */
.sidebar-footer {
  margin-top: auto;
  flex-shrink: 0;
  padding: 0 12px 16px;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
}

.sidebar-info-card {
  width: calc(100% - 0px);
  max-width: 100%;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 0.8rem 0.85rem;
  color: #c7d7ea;
  overflow: hidden;
  box-sizing: border-box;
}

.sidebar-info-title {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #c7d7ea;
  margin-bottom: 0.55rem;
  opacity: 0.95;
}

.sidebar-info-full .rate-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem;
  margin-bottom: 0.38rem;
  min-width: 0;
}

.sidebar-info-full .rate-label {
  font-size: 0.8125rem;
  color: #c7d7ea;
  font-weight: 600;
  flex-shrink: 0;
}

.sidebar-info-full .rate-value {
  display: flex;
  align-items: baseline;
  gap: 0.15rem;
  text-align: right;
  min-width: 0;
}

.sidebar-info-full .rate-line b {
  color: #ffffff;
  font-weight: 700;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.sidebar-info-full .rate-suf {
  color: #b9c9dc;
  font-size: 0.8125rem;
  font-weight: 500;
}

.sidebar-info-full .rate-line-shop .rate-label {
  color: #d4c4f5;
}

.sidebar-info-clock {
  margin: 0.55rem 0 0.65rem;
  text-align: center;
}

.time-display {
  font-variant-numeric: tabular-nums;
  font-size: 1.5rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.03em;
  line-height: 1.25;
}

.date-display {
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
  color: #b9c9dc;
  margin-top: 0.2rem;
  line-height: 1.35;
}

.sidebar-edit-rates {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 36px;
  margin-top: 0.15rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.sidebar-edit-rates:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.42);
  color: #ffffff;
}

.sidebar-info-mini {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  text-align: center;
}

.sidebar-info-mini .mini-line {
  font-size: 0.72rem;
  color: #c7d7ea;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sidebar-info-mini .mini-line b {
  color: #ffffff;
  font-weight: 700;
  font-size: 0.8125rem;
}

.sidebar-info-mini .mini-line.mini-time {
  color: #ffffff;
  font-weight: 700;
  font-size: 0.875rem;
  margin-top: 0.1rem;
}

body.sidebar-collapsed .sidebar-footer {
  padding: 0 8px 14px;
}

body.sidebar-collapsed .sidebar-info-card {
  padding: 0.55rem 0.35rem;
  border-radius: 10px;
}

body.sidebar-collapsed .sidebar-info-full {
  display: none;
}

body.sidebar-collapsed .sidebar-info-mini {
  display: flex;
}

body.sidebar-collapsed .sidebar-edit-rates {
  display: none;
}

.field-hint {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.jpy-helper {
  display: flex;
  flex-direction: column;
}

.unit-cost-field {
  display: flex;
  flex-direction: column;
}

.yen-addon {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px dashed var(--border);
}

.yen-addon-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.yen-addon input {
  width: 100px;
  max-width: 40%;
  height: 28px;
  padding: 0 0.4rem;
  font-size: 0.82rem;
}

.yen-addon .field-hint {
  flex: 1 1 100%;
  margin-top: 0;
}

/* Main — offset by sidebar width */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  min-width: 0;
  display: flex;
  justify-content: center;
}

.content-wrap {
  width: 100%;
  max-width: var(--max-w);
  padding: 1.25rem 1.5rem 2rem;
}

.page {
  display: none;
  animation: fadeIn 0.2s ease;
}

.page.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.page-header {
  margin-bottom: 1.25rem;
}

.page-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.page-header p {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

/* Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  background: var(--accent-soft);
}

.card-icon.green { background: #dcfce7; }
.card-icon.amber { background: #fef3c7; }
.card-icon.red { background: #fee2e2; }
.card-icon.purple { background: #ede9fe; }

.card-body { min-width: 0; flex: 1; }

.card .label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
  font-weight: 500;
}

.card .value {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  word-break: break-word;
}

.card.debt {
  border-color: #fecaca;
  background: linear-gradient(135deg, #fff 0%, #fef2f2 100%);
}

.card.debt .value {
  color: var(--danger);
  font-size: 1.45rem;
}

/* Panels */
.form-panel,
.info-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.form-panel h2,
.panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.85rem;
}

.formula-box {
  background: var(--accent-soft);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  font-size: 0.85rem;
  color: #1e40af;
  line-height: 1.65;
}

.settings-card {
  max-width: 420px;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.settings-field input {
  max-width: 140px;
}

.settings-help {
  margin: 0 0 0.75rem;
  padding-left: 1.2rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.6;
}

.settings-help strong {
  color: var(--text);
}

.settings-note {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.85rem;
  line-height: 1.5;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.form-grid label,
.toolbar label {
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  gap: 0.3rem;
}

input,
select,
textarea {
  height: var(--input-h);
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0 0.65rem;
  border-radius: 8px;
  font-size: 0.875rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea {
  height: auto;
  min-height: 72px;
  padding: 0.5rem 0.65rem;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* Buttons */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  height: var(--input-h);
  padding: 0 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s;
  white-space: nowrap;
}

button:hover,
.btn:hover {
  background: var(--accent-hover);
}

button.secondary,
.btn.secondary {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
}

button.secondary:hover {
  background: var(--bg);
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #b91c1c;
}

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

button.small,
.btn-icon {
  height: 28px;
  padding: 0 0.5rem;
  font-size: 0.75rem;
  border-radius: 6px;
}

.btn-icon {
  min-width: 28px;
  padding: 0;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 0.85rem;
  margin-bottom: 0.85rem;
  align-items: flex-end;
  padding: 0.85rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toolbar label input,
.toolbar label select {
  min-width: 120px;
}

/* Purchases — horizontal filter toolbar */
.purchase-filter-card {
  padding: 20px 22px;
  margin-bottom: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.purchase-filter-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1.4fr) 160px 150px 150px 150px minmax(160px, auto);
  gap: 14px;
  align-items: end;
}

.pur-filter-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.pur-filter-actions-end {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.pur-manage-lots-desktop-btn {
  display: none;
}

.pur-filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  margin: 0;
}

.pur-filter-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.2;
  letter-spacing: 0.02em;
}

.pur-filter-label-sr {
  visibility: hidden;
  height: 0;
  margin: 0;
  overflow: hidden;
}

.pur-filter-field input,
.pur-filter-field select {
  width: 100%;
  height: 44px;
  min-height: 44px;
  padding: 0 0.75rem;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  box-sizing: border-box;
}

.pur-filter-field input:focus,
.pur-filter-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.pur-check-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 44px;
  min-height: 44px;
  padding: 0 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 0.8125rem;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  box-sizing: border-box;
}

.pur-check-pill input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.pur-filter-check {
  align-self: end;
}

.pur-filter-btn {
  height: 44px;
  min-height: 44px;
  padding: 0 1.1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  align-self: end;
}

.pur-filter-btn-primary {
  background: var(--accent);
  color: #fff;
}

.pur-filter-btn-primary:hover {
  background: var(--accent-hover);
}

.pur-filter-btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}

.pur-filter-btn-secondary:hover {
  background: #f8fafc;
}

#page-purchases .page-header {
  margin-bottom: 0.65rem;
}

#page-purchases .page-header p {
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

#page-purchases .pur-list-meta {
  margin-top: 14px;
}

#page-purchases .pur-type-summary {
  margin-top: 0;
}

#page-purchases .pur-type-tabs {
  margin-top: 12px;
}

#page-purchases .pur-stat-chip {
  padding: 0.28rem 0.55rem;
  font-size: 0.75rem;
}

#page-purchases .pur-tab {
  padding: 0.32rem 0.6rem;
  font-size: 0.78rem;
}

#page-purchases .pur-table-wrap {
  width: 100%;
  margin-top: 12px;
  max-height: calc(100vh - 248px);
  overflow: auto;
}

#page-purchases .purchase-table {
  width: 100%;
  min-width: 0;
  table-layout: auto;
  border-collapse: collapse;
}

#page-purchases .purchase-table .col-sp {
  white-space: normal;
  word-break: break-word;
  width: 100%;
  min-width: 10rem;
}

#page-purchases .purchase-table .col-actions {
  width: 1%;
  white-space: nowrap;
}

#page-purchases .pur-row-menu-wrap {
  position: relative;
  display: inline-flex;
}

#page-purchases .pur-row-menu-btn {
  width: 38px;
  height: 38px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #fff;
  color: #475569;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.12s ease, border-color 0.12s ease;
}

#page-purchases .pur-row-menu-btn:hover,
#page-purchases .pur-row-menu-btn[aria-expanded="true"] {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #0f172a;
}

#page-purchases .pur-row-menu {
  min-width: 168px;
  padding: 4px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}

#page-purchases .pur-row-menu.hidden {
  display: none;
}

#page-purchases .pur-row-menu button {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: inherit;
  color: #0f172a;
  cursor: pointer;
}

#page-purchases .pur-row-menu button:hover:not(:disabled) {
  background: #f1f5f9;
}

#page-purchases .pur-row-menu button.danger {
  color: #b91c1c;
}

#page-purchases .pur-row-menu button.danger:hover:not(:disabled) {
  background: #fef2f2;
}

#page-purchases .pur-row-menu button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#page-purchases .purchase-table .col-receipt {
  white-space: nowrap;
}

#page-purchases .receipt-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

#page-purchases .receipt-link:hover {
  text-decoration: underline;
}

#page-purchases .purchase-table .qs-sold-out-cell {
  white-space: normal;
}

.pur-mobile-filter-btn {
  margin-top: 10px;
  margin-bottom: 10px;
}

@media (max-width: 900px) {
  .purchase-filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pur-filter-search {
    grid-column: 1 / -1;
  }

  .pur-filter-check {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .purchase-filter-card {
    padding: 16px;
  }

  .purchase-filter-grid {
    grid-template-columns: 1fr;
  }

  .pur-filter-search,
  .pur-filter-check {
    grid-column: auto;
  }

  .pur-filter-btn {
    width: 100%;
  }
}

/* Payments page → frontend/css/payments.css */

/* Tables */
.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 280px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

th,
td {
  padding: 0.55rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  box-shadow: 0 1px 0 var(--border);
}

tbody tr:hover td {
  background: #f8fafc;
}

td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.actions {
  display: flex;
  gap: 0.25rem;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge.box { background: #fef9c3; color: #854d0e; border: 1px solid #fde047; }
.badge.pack { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.badge.other { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }

.badge.status-dang_con { background: #dbeafe; color: #1d4ed8; }
.badge.status-moi_nhap { background: #dbeafe; color: #1d4ed8; }
.badge.status-dang_ban { background: #dbeafe; color: #1d4ed8; }
.badge.status-da_ban_het { background: #e2e8f0; color: #475569; }
.badge.status-da_hoan_tra { background: #ede9fe; color: #6d28d9; }
.badge.status-hoan_tra_mot_phan { background: #ffedd5; color: #c2410c; }
.badge.status-nhap { background: #f1f5f9; color: #64748b; }
.badge.status-da_chot { background: #dcfce7; color: #166534; }
.badge.status-da_huy { background: #fee2e2; color: #991b1b; }
.badge.status-cho_xac_nhan { background: #fef3c7; color: #b45309; }
.badge.status-da_xac_nhan { background: #dcfce7; color: #166534; }
.badge.status-huy { background: #fee2e2; color: #991b1b; }

.top-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  position: relative;
  z-index: 50;
}

.mobile-menu-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 1.1rem;
  line-height: 1;
}

.mobile-sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 95;
  display: none;
}

body.sidebar-mobile-open .mobile-sidebar-overlay {
  display: block;
}

body.purchase-filter-open .mobile-sidebar-overlay {
  display: block;
}

/* Notification dropdown */
.notif-wrap {
  position: relative;
}

.notif-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow);
}

.notif-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.notif-icon {
  font-size: 1.05rem;
  line-height: 1;
}

.notif-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #64748b;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 2px #fff;
}

.notif-btn.has-danger .notif-badge {
  background: #dc2626;
  animation: notif-pulse 2s ease-in-out infinite;
}

@keyframes notif-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.notif-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(380px, calc(100vw - 2rem));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.14);
  overflow: hidden;
  z-index: 200;
}

.notif-dropdown-header {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.notif-dropdown-header h3 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.notif-dropdown-body {
  max-height: min(420px, 60vh);
  overflow-y: auto;
  padding: 0.5rem;
}

.notif-empty {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
}

.notif-loading {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.notif-item {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.notif-item:hover {
  filter: brightness(0.98);
}

.notif-item.notif-danger {
  background: #fef2f2;
  border-color: #fecaca;
}

.notif-item.notif-warning {
  background: #fffbeb;
  border-color: #fde68a;
}

.notif-item.notif-info {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.notif-level-badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  margin-bottom: 0.35rem;
}

.notif-level-danger {
  background: #fee2e2;
  color: #991b1b;
}

.notif-level-warning {
  background: #fef3c7;
  color: #b45309;
}

.notif-level-info {
  background: #dbeafe;
  color: #1d4ed8;
}

.notif-message {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--text);
}

.notif-action {
  align-self: flex-start;
}

.user-pill {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-weight: 500;
}

.recon-ok { border-left: 4px solid var(--success); }
.recon-warn { border-left: 4px solid var(--warning); }
.recon-danger { border-left: 4px solid var(--danger); }
.badge.hoa { background: #ede9fe; color: #6d28d9; }
.badge.kha { background: #cffafe; color: #0e7490; }
.badge.shared { background: #ffedd5; color: #c2410c; }

/* Alerts (inline) */
.alert {
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
}

.alert.warning { background: var(--warning-bg); border: 1px solid #fcd34d; color: #92400e; }
.alert.danger { background: var(--danger-bg); border: 1px solid #fca5a5; color: #991b1b; }
.alert.success { background: var(--success-bg); border: 1px solid #86efac; color: #166534; }
.alert.hidden { display: none; }

/* Import */
.import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.import-result-box {
  margin-top: 1rem;
}

.error-table {
  width: 100%;
  margin-top: 0.5rem;
  font-size: 0.8rem;
}

.error-table th {
  position: static;
}

/* Toast */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 380px;
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  font-size: 0.875rem;
  animation: slideIn 0.25s ease;
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--warning); }
.toast.info { border-left: 4px solid var(--accent); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@media (max-width: 900px) {
  :root {
    --sidebar-width: 64px;
    --sidebar-collapsed-width: 64px;
  }

  .sidebar .logo-title,
  .sidebar .logo small,
  .nav-item span:not(.nav-icon) { display: none; }
  .nav-item { justify-content: center; padding: 0.65rem; }
  .content-wrap { padding: 1rem; }
  .sidebar-footer { padding: 0 8px 14px; }
  .sidebar-info-card { padding: 0.5rem 0.35rem; }
  .sidebar-info-full { display: none; }
  .sidebar-info-mini { display: flex; }
  .sidebar-edit-rates { display: none; }
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filter-bar .filter-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-right: 0.25rem;
}

.dash-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.dash-period-field {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 200px;
  min-width: 0;
}

.dash-period-field .filter-label {
  flex-shrink: 0;
  margin-right: 0;
}

.dash-period-select {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  height: 44px;
  padding: 0 36px 0 12px;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: #0f172a;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  box-sizing: border-box;
}

.dash-period-select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.filter-chip {
  height: 32px;
  padding: 0 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text);
}

.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.filter-custom {
  display: none;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.filter-custom.show {
  display: flex;
}

.danger-zone {
  border-color: #fecaca;
  background: #fffbfb;
}

.danger-zone h2 {
  color: var(--danger);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 8000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-md);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

.modal-wide {
  max-width: min(860px, 96vw);
  width: 100%;
}

.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.modal-header-row h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text);
}

.modal-close-btn {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}

.modal-close-btn:hover {
  background: #f1f5f9;
  color: var(--text);
}

.modal-wide .form-grid {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.modal-actions {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.pur-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.btn-add-purchase {
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow);
}

.btn-add-purchase:hover {
  filter: brightness(1.06);
}

.pur-hide-sold-toggle {
  cursor: pointer;
}

.modal h3 {
  margin-bottom: 0.75rem;
  color: var(--danger);
}

.modal p {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.modal input {
  width: 100%;
  margin-bottom: 0.75rem;
}

input[data-money-input] {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.table-wrap table input.qs-input {
  width: 72px;
  height: 30px;
  padding: 0 0.35rem;
  font-size: 0.8rem;
}

.table-wrap table input.qs-price {
  width: 88px;
}

.table-wrap table input.qs-price.qs-price--saved {
  border-color: #22c55e;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.35);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-xwide {
  width: min(1200px, 96vw);
}

.receipt-modal {
  padding: 32px;
}

.receipt-modal .receipt-modal-dialog {
  width: min(1280px, calc(100vw - 64px));
  max-width: 1280px;
  max-height: calc(100vh - 64px);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.receipt-modal .modal-header-row {
  margin-bottom: 0;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.receipt-modal .receipt-modal-form {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.receipt-modal .receipt-modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.25rem 0.9rem;
}

.receipt-head-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px 16px;
}

.receipt-head-grid input,
.receipt-head-grid select {
  height: 44px;
  min-height: 44px;
  margin-bottom: 0;
}

.receipt-note-field {
  grid-column: span 2;
}

.receipt-items-wrap {
  margin-top: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}

.receipt-table-scroll {
  overflow-x: hidden;
  overflow-y: visible;
}

.receipt-items-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  table-layout: fixed;
}

.receipt-items-table th,
.receipt-items-table td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.receipt-items-table th:nth-child(1) { width: 140px; }
.receipt-items-table th:nth-child(3) { width: 120px; }
.receipt-items-table th:nth-child(4) { width: 100px; }
.receipt-items-table th:nth-child(5) { width: 160px; }
.receipt-items-table th:nth-child(6) { width: 160px; }
.receipt-items-table th:nth-child(8) { width: 56px; }

.receipt-items-table th {
  position: sticky;
  top: 0;
  background: #eef2f7;
  z-index: 1;
  text-transform: uppercase;
  white-space: nowrap;
}

.receipt-items-table input,
.receipt-items-table select {
  width: 100%;
  min-width: 0;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 0.55rem;
  font-size: 0.85rem;
  margin-bottom: 0;
}

.receipt-items-table td.num-cell input {
  text-align: right;
}

.receipt-row-remove {
  min-width: 40px;
  height: 40px;
  padding: 0;
}

.receipt-add-row-btn {
  margin-top: 0.75rem;
}

.receipt-modal .receipt-modal-footer {
  position: sticky;
  bottom: 0;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  padding: 0.85rem 1.25rem 1rem;
}

.receipt-footer-row {
  margin-top: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  font-weight: 600;
}

.receipt-modal .modal-actions {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
}

.receipt-detail-modal {
  padding: 32px;
}

.receipt-detail-modal .receipt-detail-modal-dialog {
  width: min(1400px, calc(100vw - 64px));
  max-width: 1400px;
  height: calc(100vh - 64px);
  max-height: calc(100vh - 64px);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.receipt-detail-modal .modal-header-row {
  margin-bottom: 0;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.receipt-detail-modal .receipt-detail-modal-form {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.receipt-detail-modal .receipt-detail-modal-head {
  padding: 1rem 1.25rem 0.85rem;
}

.receipt-profit-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 0.9rem;
}

.receipt-kpi-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.receipt-kpi-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.receipt-kpi-value {
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #111827;
}

.receipt-kpi-value.profit-pos {
  color: #15803d;
}

.receipt-kpi-value.profit-neg {
  color: #b91c1c;
}

.receipt-profit-warn {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: #b45309;
}

.receipt-profit-warn.hidden {
  display: none;
}

.profit-pos {
  color: #15803d;
  font-weight: 600;
}

.profit-neg {
  color: #b91c1c;
  font-weight: 600;
}

.receipt-detail-modal .receipt-head-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px 16px;
}

.receipt-detail-modal .receipt-note-field {
  grid-column: span 2;
}

.receipt-detail-modal .receipt-head-grid input,
.receipt-detail-modal .receipt-head-grid select {
  height: 44px;
  min-height: 44px;
  margin-bottom: 0;
}

.receipt-detail-modal .receipt-detail-table-zone {
  flex: 1;
  min-height: 0;
  padding: 0 1.25rem 0.8rem;
}

.receipt-detail-modal .receipt-table-scroll {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}

.receipt-detail-modal .receipt-detail-items-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  table-layout: fixed;
}

.receipt-detail-modal .receipt-detail-items-table th,
.receipt-detail-modal .receipt-detail-items-table td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}

.receipt-detail-modal .receipt-detail-items-table th {
  position: sticky;
  top: 0;
  background: #eef2f7;
  z-index: 2;
  text-transform: uppercase;
  white-space: nowrap;
}

.receipt-detail-modal .receipt-detail-items-table input,
.receipt-detail-modal .receipt-detail-items-table select {
  width: 100%;
  min-width: 0;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 0.5rem;
  font-size: 0.82rem;
  margin-bottom: 0;
}

.receipt-detail-modal .receipt-detail-items-table td.num-cell input {
  text-align: right;
}

.receipt-detail-modal .receipt-detail-modal-footer {
  position: sticky;
  bottom: 0;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  padding: 0.85rem 1.25rem 1rem;
}

.receipt-detail-modal .modal-actions {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
}

@media (max-width: 1200px) {
  .receipt-detail-modal {
    padding: 16px;
  }

  .receipt-detail-modal .receipt-detail-modal-dialog {
    width: calc(100vw - 32px);
    height: calc(100vh - 32px);
    max-height: calc(100vh - 32px);
  }
}

@media (max-width: 1024px) {
  .receipt-detail-modal .receipt-head-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .receipt-detail-modal .receipt-note-field {
    grid-column: 1 / -1;
  }

  .receipt-detail-modal .receipt-table-scroll {
    overflow-x: auto;
  }

  .receipt-detail-modal .receipt-detail-items-table {
    min-width: 1480px;
  }

  .receipt-profit-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .receipt-profit-kpis {
    grid-template-columns: 1fr;
  }

  .receipt-detail-modal .receipt-head-grid {
    grid-template-columns: 1fr;
  }

  .receipt-detail-modal .receipt-note-field {
    grid-column: auto;
  }
}

@media (max-width: 1024px) {
  .receipt-modal {
    padding: 16px;
  }

  .receipt-modal .receipt-modal-dialog {
    width: calc(100vw - 32px);
    max-height: calc(100vh - 32px);
  }

  .receipt-head-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .receipt-note-field {
    grid-column: 1 / -1;
  }
}

@media (max-width: 900px) {
  .receipt-table-scroll {
    overflow-x: auto;
  }

  .receipt-items-table {
    min-width: 1196px;
  }
}

@media (max-width: 640px) {
  .receipt-head-grid {
    grid-template-columns: 1fr;
  }

  .receipt-note-field {
    grid-column: auto;
  }
}

.table-wrap tr.pur-row--sold-out,
.table-wrap tr.row-sold-out {
  opacity: 1;
}

.table-wrap tr.pur-row--sold-out input[data-qs-qty],
.table-wrap tr.pur-row--sold-out input[data-qs-soldout],
.table-wrap tr.row-sold-out input[data-qs-qty],
.table-wrap tr.row-sold-out input[data-qs-soldout] {
  pointer-events: none;
  opacity: 0.55;
}

.table-wrap tr.pur-row--sold-out .pur-row-menu-wrap,
.table-wrap tr.pur-row--sold-out .pur-row-menu-btn,
.table-wrap tr.pur-row--sold-out .qs-price,
.table-wrap tr.row-sold-out .pur-row-menu-wrap,
.table-wrap tr.row-sold-out .pur-row-menu-btn,
.table-wrap tr.row-sold-out .qs-price {
  pointer-events: auto;
  opacity: 1;
}

.table-wrap tr.pur-row--sold-out .btn-undo-sale,
.table-wrap tr.row-sold-out .btn-undo-sale {
  color: #b45309;
  border-color: #fcd34d;
}

/* Tables — zebra + sticky header */
.table-wrap {
  max-height: 70vh;
  overflow: auto;
}

.table-wrap table {
  border-collapse: separate;
  border-spacing: 0;
}

.table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--border);
}

.table-wrap tbody tr:nth-child(even) {
  background: #f8fafc;
}

.table-wrap tbody tr:hover {
  background: #eff6ff;
}

/* Purchases — type tabs & summary */
.pur-list-header,
.pur-list-meta {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 0;
}

.pur-type-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
}

.pur-stat-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.pur-stat-chip strong,
.pur-stat-chip .pur-stat-money {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pur-stat-label {
  color: var(--muted);
  font-size: 0.78rem;
}

.pur-stat-chip:not(.capital) .pur-stat-label::after {
  content: ":";
  margin-left: 1px;
}

.pur-stat-value {
  display: inline-flex;
  align-items: baseline;
  gap: 0.2rem;
  flex-wrap: wrap;
}

.pur-stat-chip.total-lots {
  border-color: #e2e8f0;
  background: #f8fafc;
}

.pur-stat-chip.pack { border-color: #86efac; background: #f0fdf4; }
.pur-stat-chip.box { border-color: #fde047; background: #fefce8; }
.pur-stat-chip.other { border-color: #e2e8f0; background: #f8fafc; }
.pur-stat-chip.capital { background: #f8fafc; }
.pur-stat-chip.is-active {
  box-shadow: 0 0 0 2px var(--accent);
  font-weight: 600;
}

.pur-stat-chip.muted {
  color: var(--muted);
  font-size: 0.75rem;
}

.pur-type-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: fit-content;
  max-width: 100%;
}

.pur-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.pur-tab:hover {
  background: #f1f5f9;
  color: var(--text);
}

.pur-tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(30, 58, 95, 0.25);
}

.pur-table-wrap thead th {
  background: #e2e8f0;
  box-shadow: 0 2px 0 var(--border);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.pur-table-wrap tbody tr.pur-row--pack:hover {
  background: #f0fdf4;
}

.pur-table-wrap tbody tr.pur-row--box:hover {
  background: #fefce8;
}

.pur-table-wrap tbody tr.pur-row--other:hover {
  background: #f8fafc;
}

.pur-table-wrap tbody tr.pur-row:nth-child(even) {
  background: #fafbfc;
}

@media (max-width: 720px) {
  .pur-type-tabs {
    width: 100%;
    justify-content: stretch;
  }

  .pur-tab {
    flex: 1 1 auto;
    text-align: center;
    padding: 0.5rem 0.4rem;
    font-size: 0.8rem;
  }

  /* pur-type-summary mobile grid: see mobile-v3.css @768px */
}

/* Dashboard ERP-style */
.dash-hero-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.dash-status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 1rem;
}

.dash-status-strip.hidden {
  display: none !important;
}

.dash-status-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #f1f5f9;
  border: 1px solid #e5e7eb;
  color: #0f172a;
  white-space: nowrap;
}

.dash-status-chip--warn {
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}

.dash-status-chip.qs-muted {
  color: #64748b;
}

.dash-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.dash-qa-btn {
  min-height: 46px;
  padding: 0 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: #0f172a;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.dash-qa-btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.dash-qa-btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.dash-qa-btn--secondary {
  background: #fff;
  border-color: #e5e7eb;
  color: #0f172a;
}

.dash-qa-btn--secondary:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.dash-qa-btn.ghost {
  background: transparent;
  box-shadow: none;
  min-height: 44px;
}

.dash-qa-btn.ghost:hover {
  background: #f8fafc;
}

.dash-qa-btn.secondary {
  background: #f1f5f9;
  min-height: 44px;
}

.chart-box-revenue {
  height: 200px;
}

.chart-box-revenue.chart-box-compact {
  height: 120px;
}

.chart-single-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.65rem;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
}

.chart-single-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.chart-single-value {
  font-size: 1.15rem;
  color: #166534;
}

.chart-single-date {
  font-size: 0.78rem;
  color: var(--muted);
}

.settings-subtitle {
  margin-top: 1.25rem;
}

.settings-rates-grid {
  margin-top: 0.5rem;
}

.qs-submit-btn {
  min-width: 32px;
  padding: 0.25rem 0.4rem !important;
  font-size: 0.85rem;
  line-height: 1;
}

@media (max-width: 1100px) {
  .dash-hero-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .dash-hero-grid { grid-template-columns: 1fr; }
}

.hero-card {
  background: #fff;
  border-radius: 16px;
  padding: 0.9rem 1rem;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
  border: 1px solid rgba(15, 23, 42, 0.06);
  display: flex;
  gap: 0.65rem;
  align-items: center;
  transition: box-shadow 0.15s;
}

.hero-card:hover {
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.07);
}

.hero-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  order: 2;
  margin-left: auto;
  opacity: 0.42;
  background: rgba(15, 23, 42, 0.04) !important;
}

.tone-green .hero-icon,
.tone-amber .hero-icon,
.tone-red .hero-icon,
.tone-purple .hero-icon,
.tone-blue .hero-icon,
.tone-teal .hero-icon {
  background: rgba(15, 23, 42, 0.04) !important;
}

.hero-body {
  min-width: 0;
  flex: 1;
  order: 1;
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  margin-bottom: 0.15rem;
}

.hero-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #64748b;
}

.hero-value {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: #0f172a;
  font-variant-numeric: tabular-nums;
}

.hero-debt .hero-value { color: var(--danger); }

.hero-sub {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.trend-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  white-space: nowrap;
}

.trend-up { background: #dcfce7; color: #15803d; }
.trend-down { background: #fee2e2; color: #b91c1c; }

.dash-section {
  margin-bottom: 1.75rem;
}

.dash-section-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.85rem;
  letter-spacing: -0.02em;
}

.dash-section-sub {
  margin: -0.55rem 0 0.85rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.dash-cash-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.dash-cash-row--4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1100px) {
  .dash-cash-row--4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .dash-cash-row { grid-template-columns: 1fr; }
}

.mini-stat {
  background: #fff;
  border-radius: 16px;
  padding: 1rem 1.15rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.mini-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.mini-value {
  font-size: 1.15rem;
  font-weight: 700;
}

.dash-loading {
  text-align: center;
  padding: 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.dash-charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.chart-card {
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.chart-card h3 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.chart-wide {
  grid-column: span 2;
}

.chart-box {
  height: 200px;
  position: relative;
}

.chart-box-sm {
  height: 180px;
}

@media (max-width: 900px) {
  .dash-charts-grid,
  .chart-wide {
    grid-column: span 1;
  }
  .dash-charts-grid {
    grid-template-columns: 1fr;
  }
}

.dash-analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 900px) {
  .dash-analytics-grid { grid-template-columns: 1fr; }
}

.analytics-panel {
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.analytics-panel h3 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.65rem;
}

.dash-table-wrap {
  max-height: 280px;
}

.dash-table {
  width: 100%;
  font-size: 0.82rem;
}

.empty-cell {
  text-align: center;
  color: var(--muted);
  padding: 1rem !important;
}

.dash-heavy-head {
  display: block;
}

.dash-heavy-head h3 {
  margin-bottom: 0.65rem;
}

@media (min-width: 769px) {
  .dash-heavy-inv-cards,
  .dash-heavy-view-all {
    display: none !important;
  }
}

.dash-header h1 {
  font-size: 1.5rem;
}

/* Empty state */
.empty-state-banner {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: 16px;
  margin-bottom: 1rem;
}

.empty-state-banner p {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.2rem 0 0;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}

.empty-state .empty-icon {
  display: none;
}

.empty-state-cell {
  padding: 0 !important;
  border: none !important;
}

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
  border-radius: 6px;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-card {
  pointer-events: none;
}

.skeleton-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  flex-shrink: 0;
}

.skeleton-body { flex: 1; }

.skeleton-line {
  height: 12px;
  margin-bottom: 0.4rem;
}

.skeleton-line.lg { height: 22px; margin-bottom: 0.5rem; }
.skeleton-line.w60 { width: 60%; }
.skeleton-line.w40 { width: 40%; }
.skeleton-line.w80 { width: 80%; }

.skeleton-row {
  height: 48px;
  width: 100%;
}

.skeleton-chart {
  height: 120px;
  width: 100%;
  max-width: 400px;
  margin: 0 auto 0.75rem;
  border-radius: 12px;
}

.dash-loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
}

/* Hub tabs (Đối soát / Cài đặt) */
.hub-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.65rem;
}

.hub-tab {
  padding: 0.55rem 1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.hub-tab:hover {
  background: #f1f5f9;
  color: var(--text);
}

.hub-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.hub-panel.hidden {
  display: none;
}

/* Reports */
.report-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.report-tab {
  padding: 0.5rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}

.report-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.report-table-wrap {
  max-height: 65vh;
}

tfoot.total-row td {
  background: #f1f5f9;
  font-weight: 600;
  border-top: 2px solid var(--border);
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: min(280px, 84vw);
    z-index: 100;
  }

  .sidebar .logo-title,
  .sidebar .logo small,
  .sidebar .nav-item span:not(.nav-icon) {
    display: initial;
  }

  .sidebar .nav-item {
    justify-content: flex-start;
    padding: 0.72rem 0.85rem;
  }

  .sidebar-info-full {
    display: block;
  }

  .sidebar-info-mini {
    display: none;
  }

  body.sidebar-mobile-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: none;
  }

  .main {
    margin-left: 0 !important;
    width: 100%;
  }

  .content-wrap {
    max-width: 100%;
    padding: 0.8rem 0.9rem 1.2rem;
  }

  .top-bar {
    justify-content: space-between;
    gap: 0.4rem;
  }

  .mobile-menu-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    color: var(--text);
    font-weight: 700;
    font-size: 0;
  }

  .mobile-menu-btn::before {
    content: "☰";
    font-size: 1.15rem;
    line-height: 1;
  }

  .user-pill {
    max-width: 38vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0.3rem 0.55rem;
    font-size: 0.78rem;
  }

  #btn-logout {
    padding: 0 0.6rem;
  }

  .notif-dropdown {
    right: -6px;
    width: min(360px, calc(100vw - 1rem));
  }

  .purchase-filter-card {
    display: none;
  }

  .purchase-filter-card.mobile-open {
    display: block;
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 120;
    max-height: 78vh;
    overflow-y: auto;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.25);
  }

  .pur-mob-toolbar {
    display: grid !important;
  }

  .pur-mob-toolbar .pur-mobile-filter-btn {
    display: inline-flex !important;
  }

  .purchase-filter-grid {
    grid-template-columns: 1fr !important;
  }

  #page-purchases .pur-type-tabs {
    overflow-x: auto;
    white-space: nowrap;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  #page-purchases .pur-tab {
    padding: 0.28rem 0.52rem;
    font-size: 0.76rem;
  }

  .receipt-modal,
  .receipt-detail-modal {
    padding: 12px;
  }

}

.server-error-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.65rem 1rem;
  background: #7f1d1d;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.server-error-banner.hidden {
  display: none !important;
}

.server-error-banner p {
  margin: 0;
  font-weight: 600;
}

.server-error-actions {
  display: flex;
  gap: 0.5rem;
}

.backup-actions {
  flex-wrap: wrap;
}

