:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --line: #dbe1ea;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --danger: #b91c1c;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #d1fae5 0, #f4f7f5 40%, #f4f7f5 100%);
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: var(--text);
  overflow-x: hidden;
  padding-bottom: 56px;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.auth-card {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.auth-card h1 {
  margin: 0;
  font-size: 1.3rem;
}

.auth-card p {
  margin-top: 8px;
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.auth-note {
  margin-top: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

.order-edit-changed {
  color: var(--danger);
  font-weight: 700;
}

.app {
  width: 100%;
  max-width: 1720px;
  margin: 0 auto;
  padding: 0 20px 64px;
}

.app-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  width: 100%;
  text-align: center;
  padding: 12px 16px;
  background: #f1f5f9;
  border-top: 1px solid var(--line);
  color: #334155;
  font-weight: 600;
}

.subscription-expiry-notice {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 48px;
  z-index: 19;
  padding: 8px 14px;
  text-align: center;
  font-size: 0.92rem;
  font-weight: 700;
  border-top: 1px solid transparent;
  border-bottom: 1px solid transparent;
}

.subscription-expiry-notice.warn {
  background: #fff7ed;
  color: #9a3412;
  border-color: #fdba74;
}

.subscription-expiry-notice.danger {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fca5a5;
}

.zalo-support-btn {
  position: fixed;
  right: 18px;
  bottom: 64px;
  z-index: 70;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  border: 1px solid #bfdbfe;
  background: #ffffff;
  color: #1d4ed8;
  text-decoration: none;
  box-shadow: 0 10px 24px rgba(30, 64, 175, 0.22);
}

.zalo-support-btn:hover {
  background: #eff6ff;
}

.zalo-support-icon {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #2563eb;
  color: #fff;
  font-weight: 800;
  font-size: 0.92rem;
  letter-spacing: 0.2px;
}

.zalo-support-text {
  font-size: 0.92rem;
  font-weight: 700;
}

.hero {
  margin: 0 calc(50% - 50vw) 16px;
}

.hero-topbar {
  background: #16a34a;
  border-bottom: 1px solid #14803d;
}

.hero-menubar {
  background: #f1f5f9;
  border-bottom: 1px solid var(--line);
}

.hero-bar-inner {
  width: min(1720px, 100%);
  margin: 0 auto;
  padding: 10px 20px;
}

.hero-userbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
}

.topbar-logo {
  display: block;
  height: 34px;
  width: auto;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-menu {
  position: relative;
}

.top-nav {
  position: relative;
}

.top-menu-groups {
  display: flex;
  align-items: center;
  gap: 20px;
}

.menu-group {
  position: relative;
}

.menu-group-btn {
  width: auto;
  min-width: 0;
  padding: 8px 10px;
  font-weight: 700;
  border-radius: 0;
  border: 0;
  background: transparent;
}

.menu-group-btn.active {
  color: var(--text);
  background: rgba(15, 23, 42, 0.05);
  border-radius: 6px;
}

.menu-group-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 230px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.12);
  padding: 4px;
  z-index: 30;
}

.menu-group-dropdown button {
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  background: transparent;
  white-space: nowrap;
}

.menu-group-dropdown button:hover,
.menu-group-dropdown button.active {
  background: #f1f5f9;
}

.user-chip {
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
}

.hero-userbar .user-chip:hover,
.hero-userbar .user-chip:focus {
  background: transparent;
  color: #fff;
}

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.15);
  padding: 6px;
  z-index: 40;
}

.user-menu-dropdown button {
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
}

.user-menu-dropdown button:hover {
  background: #f1f5f9;
}

.hero-userbar #logoutBtn {
  border: 0;
  background: transparent;
  color: #fff;
  padding: 0;
  font-weight: 700;
}

.hero-userbar #logoutBtn:hover {
  background: transparent;
  opacity: 0.9;
}

.hero-userbar #resetDataBtn {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: #dc2626;
  color: #fff;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
}

.hero-userbar #resetDataBtn:hover {
  background: #b91c1c;
  border-color: rgba(255, 255, 255, 0.55);
}

.user-menu-dropdown #logoutBtn {
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: #b91c1c;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 1.8vw, 2rem);
}

h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.hero p {
  color: var(--muted);
  margin: 8px 0 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.04);
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.stat-card .label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
}

.stat-card .value {
  display: block;
  font-weight: 700;
  font-size: 1.2rem;
  margin-top: 4px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

#orderForm.form-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.form-grid > *,
.toolbar > *,
.filters > * {
  min-width: 0;
}

.user-form {
  align-items: end;
}

.company-logo-preview {
  display: block;
  max-width: 220px;
  max-height: 100px;
  width: auto;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 6px;
  object-fit: contain;
}

.order-meta-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  align-items: start;
}

.order-meta-grid > label {
  min-width: 0;
}

/* Fallback when server still has old HTML without .order-meta-grid wrapper */
#orderForm:not(:has(.order-meta-grid)):has(#dueDate) label:has(#dueDate),
#orderForm:not(:has(.order-meta-grid)):has(#vatRate) label:has(#vatRate),
#orderForm:not(:has(.order-meta-grid)):has(#depositCash) label:has(#depositCash),
#orderForm:not(:has(.order-meta-grid)):has(#depositTransfer) label:has(#depositTransfer) {
  grid-column: span 1;
}

#orderForm:not(:has(.order-meta-grid)):has(#dueDate).form-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

#orderForm:not(:has(.order-meta-grid)):has(#dueDate) .full {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
}

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

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  width: 100%;
  min-width: 0;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.2);
  border-color: var(--primary);
}

.full {
  grid-column: 1 / -1;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.order-edit-history {
  margin-top: 10px;
}

.order-edit-history h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
}

button:hover {
  background: #f8fafc;
}

button.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

button.primary:hover {
  background: var(--primary-strong);
}

button.danger-ghost {
  color: var(--danger);
  border-color: #fecaca;
  background: #fff5f5;
}

.message {
  color: var(--primary-strong);
  font-size: 0.9rem;
}

.muted-text {
  color: var(--muted);
  font-size: 0.82rem;
}

.voucher-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.voucher-input-row input {
  width: min(260px, 100%);
  flex: 0 1 260px;
}

.order-meta-grid .voucher-input-row {
  display: block;
  width: 100%;
}

.order-meta-grid .voucher-input-row input {
  width: 100%;
  flex: 1 1 auto;
  min-height: 44px;
  box-sizing: border-box;
}

#voucherCode {
  height: auto;
  min-height: 0;
  padding: 10px;
  line-height: normal;
}

.voucher-meta-inline {
  color: #b91c1c;
  font-weight: 700;
  font-size: 0.95rem;
  min-height: 1.4em;
}

#voucherMetaInline:empty {
  display: none;
}

#voucherHint {
  display: block;
  margin-top: 6px;
  line-height: 1.2;
}

.refund-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.refund-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.refund-label-text {
  color: #b91c1c;
  font-weight: 700;
}

.reproduce-label-text {
  color: #15803d;
  font-weight: 700;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.customer-search-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin: 8px 0 6px;
}

#customerSearchInput {
  width: min(520px, 100%);
}

#debtPanel .toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
}

#debtPanel .toolbar h2 {
  margin: 0;
}

.customer-lookup-field {
  position: relative;
  z-index: 6;
}

.customer-lookup-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 90;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.2);
  max-height: 300px;
  overflow-y: auto;
  padding: 6px;
}

.customer-lookup-option {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 8px 10px;
  font-weight: 500;
  color: var(--text);
}

.customer-lookup-option:hover {
  background: #e2e8f0;
}

.customer-lookup-option-grid {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(180px, 2fr) minmax(120px, 1.2fr);
  align-items: center;
  gap: 10px;
}

.customer-lookup-option-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
  border: 1px solid var(--line);
  font-weight: 700;
  cursor: default;
  pointer-events: none;
}

.customer-lookup-col {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.order-customer-advance-total-label {
  color: #b91c1c;
  font-weight: 700;
}

#customerAdvancePanel .table-wrap {
  overflow: visible;
}

.customer-advance-lookup-field .customer-lookup-menu {
  width: min(max(100%, 520px), calc(100vw - 32px));
  right: auto;
}

#debtPanel .filters {
  margin-left: auto;
  display: grid;
  grid-template-columns: minmax(180px, 210px) minmax(170px, 190px) minmax(150px, 170px) minmax(150px, 170px) minmax(260px, 320px) minmax(170px, 210px);
  gap: 8px;
  align-items: center;
}

#debtPanel #debtSearchInput {
  width: 100%;
}

#debtPanel #debtViewType,
#debtPanel #debtReportMode,
#debtPanel #debtReportFrom,
#debtPanel #debtReportTo,
#debtPanel #debtStatusFilter {
  width: 100%;
}

.customer-column-filter {
  position: relative;
}

#customerColumnFilterBtn {
  width: 150px;
  white-space: nowrap;
}

.customer-column-filter-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 320px;
  max-height: 320px;
  overflow: auto;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 8px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.15);
}

.customer-column-filter-menu label {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  column-gap: 10px;
  padding: 7px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.customer-column-filter-menu label:hover {
  background: #f8fafc;
}

.customer-column-filter-menu label input[type="checkbox"] {
  margin: 0;
}

.expense-report-toolbar {
  align-items: center;
}

.expense-report-toolbar h2 {
  margin: 0;
  white-space: nowrap;
}

.expense-report-toolbar .filters {
  flex-wrap: nowrap;
  justify-content: flex-end;
}

#expensePanel .expense-report-toolbar .filters {
  margin-left: auto;
}

#expenseReportMode {
  width: 220px;
  flex: 0 0 auto;
}

#expenseReportFrom,
#expenseReportTo {
  width: 220px;
  flex: 0 0 auto;
}

#runExpenseReportBtn {
  white-space: nowrap;
  width: auto;
  min-width: max-content;
  flex: 0 0 auto;
}

.reproduce-report-toolbar {
  display: block;
}

.reproduce-report-toolbar h2 {
  margin: 0 0 10px;
}

.reproduce-report-toolbar .filters {
  display: grid;
  grid-template-columns: minmax(180px, 340px) minmax(170px, 260px) minmax(170px, 260px) auto;
  justify-content: end;
  align-items: center;
  gap: 10px;
}

#runReproduceReportBtn {
  white-space: nowrap;
  width: auto;
  min-width: max-content;
}

#reportTypeBtn,
#quickPeriodBtn,
#runReportBtn {
  white-space: nowrap;
  width: auto;
  min-width: max-content;
  flex-shrink: 0;
}

.filters .quick-period {
  min-width: max-content;
  flex-shrink: 0;
}

#reportPanel .filters > input[type="date"] {
  width: 170px;
  flex: 0 0 auto;
}

#orderListPanel .filters {
  flex-wrap: nowrap;
  justify-content: flex-end;
}

#orderListPanel .order-list-toolbar {
  display: block;
}

#orderListPanel .order-list-toolbar h2 {
  margin: 0 0 10px;
}

#orderListPanel .order-list-date-filters {
  margin-bottom: 8px;
}

#orderListPanel #statusFilter {
  width: 240px;
  flex: 0 0 auto;
}

#orderListPanel #orderSalesFilter {
  width: 240px;
  flex: 0 0 auto;
}

#orderListPanel #orderListMode {
  width: 220px;
  flex: 0 0 auto;
}

#orderListPanel #orderListFrom,
#orderListPanel #orderListTo {
  width: 170px;
  flex: 0 0 auto;
}

#orderListPanel #searchInput {
  width: 360px;
  flex: 0 0 auto;
}

.quick-period {
  position: relative;
}

.quick-period-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
  padding: 6px;
  z-index: 20;
}

.quick-period-menu button {
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  background: transparent;
}

.quick-period-menu button:hover {
  background: #f1f5f9;
}

.line-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.item-input {
  width: 100%;
}

.item-note {
  min-height: 78px;
  resize: vertical;
}

.item-note-row td {
  border-top: 0;
  padding-top: 0;
}

.item-note-wrap {
  display: grid;
  gap: 6px;
}

.item-note-wrap label {
  width: fit-content;
  font-weight: 700;
  color: #0f172a;
}

.item-total {
  font-weight: 600;
  white-space: nowrap;
}

.item-remove {
  padding: 6px 8px;
  font-size: 0.82rem;
}

.order-total {
  margin-top: 8px;
  font-weight: 700;
  color: var(--primary-strong);
}

.order-total-row {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.order-total-row .order-total {
  margin-top: 0;
}

.order-customer-voucher-notice {
  font-size: 1.02rem;
  font-weight: 700;
  color: #111827;
  text-align: right;
}

.order-customer-voucher-notice .highlight {
  color: #dc2626;
}

.transfer-reconcile-box {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}

.transfer-reconcile-toolbar {
  align-items: center;
}

.transfer-reconcile-toolbar h2 {
  margin: 0;
  white-space: nowrap;
}

.transfer-reconcile-toolbar .filters {
  margin-left: auto;
  display: grid;
  grid-template-columns: minmax(170px, 220px) minmax(140px, 170px) minmax(140px, 170px) auto auto;
  gap: 8px;
  align-items: center;
}

.permission-box {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.permission-box.no-top-border {
  margin-top: 0;
  border-top: 0;
  padding-top: 0;
}

.permission-box h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.permission-toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.quick-role-create {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.quick-role-create input {
  flex: 1;
}

.permission-role-manager {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  max-height: 220px;
  overflow: auto;
}

.permission-role-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.permission-role-row:last-child {
  border-bottom: 0;
}

.permission-role-row.active {
  background: #eef6ff;
}

.permission-role-label-btn {
  border: 0;
  background: transparent;
  text-align: left;
  font-weight: 600;
  color: var(--text);
  padding: 0;
  cursor: pointer;
  flex: 1;
}

.permission-role-actions {
  display: flex;
  gap: 6px;
}

.permission-list {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.permission-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
}

.permission-list input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.permission-edit-days-row {
  display: block;
  margin-top: 10px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

#customerPanel .table-wrap {
  overflow-x: auto;
}

#customerPanel .table-wrap table {
  min-width: 1400px;
}

#customerPanel .table-wrap th,
#customerPanel .table-wrap td {
  white-space: nowrap;
}

th,
td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}

th {
  background: #f8fafc;
}

#expensePanel .table-wrap table:has(#expenseFlowBody) th:nth-child(4),
#expensePanel .table-wrap table:has(#expenseFlowBody) td:nth-child(4) {
  background: #f1f5f9;
}

.badge {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  border: 1px solid transparent;
}

.badge.status-moi { background: #e0f2fe; color: #0c4a6e; }
.badge.status-thiet-ke { background: #fef3c7; color: #92400e; }
.badge.status-in { background: #ede9fe; color: #5b21b6; }
.badge.status-hoan-tat { background: #dcfce7; color: #166534; }
.badge.status-da-giao { background: #d1fae5; color: #065f46; }
.badge.status-huy { background: #fee2e2; color: #991b1b; }

.badge.priority-thuong { background: #f1f5f9; color: #334155; border-color: #cbd5e1; }
.badge.priority-cao { background: #ffedd5; color: #9a3412; border-color: #fed7aa; }
.badge.priority-gap { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

.badge.role-admin { background: #ede9fe; color: #5b21b6; }
.badge.role-sales { background: #e0f2fe; color: #075985; }
.badge.role-production { background: #dcfce7; color: #166534; }
.badge.role-accounting { background: #fef3c7; color: #92400e; }
.badge.role-chiefAccounting { background: #dbeafe; color: #1d4ed8; }
.badge.role-delivery { background: #fef9c3; color: #854d0e; }

.badge.state-active { background: #dcfce7; color: #166534; }
.badge.state-inactive { background: #fee2e2; color: #991b1b; }

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.row-actions button {
  padding: 6px 8px;
  font-size: 0.82rem;
}

.debt-collected-total {
  font-weight: 700;
}

.debt-history-line {
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.debt-history-line button {
  padding: 2px 8px;
  font-size: 0.75rem;
}

.debt-history-list {
  margin-top: 4px;
}

.tenant-expiry-note {
  margin-top: 2px;
  font-size: 0.82rem;
  font-weight: 600;
}

.tenant-expiry-note.warn {
  color: #b45309;
}

.tenant-expiry-note.danger {
  color: #b91c1c;
}

.tenant-inline-status {
  margin-top: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
}

.tenant-inline-status.ok {
  color: #0f766e;
}

.tenant-inline-status.error {
  color: #b91c1c;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 18px;
}

.muted {
  color: var(--muted);
}

.expense-receipt-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  display: block;
}

.expense-receipt-preview-btn {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
}

.receipt-preview-dialog {
  max-width: min(92vw, 1100px);
}

.receipt-preview-content {
  text-align: center;
  overflow: auto;
  max-height: 78vh;
}

.receipt-preview-tools {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.receipt-preview-tools button {
  min-width: 38px;
}

.receipt-preview-tools button.active {
  background: #0f766e;
  color: #fff;
  border-color: #0f766e;
}

.receipt-preview-content.pan-enabled {
  cursor: grab;
}

.receipt-preview-content.pan-enabled.panning {
  cursor: grabbing;
  user-select: none;
}

.receipt-preview-image {
  width: 100%;
  max-width: 100%;
  max-height: 78vh;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  transition: width 0.15s ease;
}

.expense-title {
  color: #b91c1c;
}

.report-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 8px 0 12px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-dialog {
  position: relative;
  width: min(900px, 100%);
  max-height: min(88vh, 920px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.2);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: #fff;
}

.modal-head h2 {
  margin: 0;
}

.modal-content {
  padding: 14px;
}

#debtCollectForm .actions {
  align-items: end;
  display: flex;
}

#debtCollectForm .actions:not(.full) {
  justify-content: center;
}

#debtCollectPayFullBtn {
  width: 100%;
  align-self: end;
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}

#debtCollectPayFullBtn:hover {
  background: #15803d;
  border-color: #15803d;
}

#debtCollectPayFullBtn:disabled {
  background: #94a3b8;
  border-color: #94a3b8;
  color: #fff;
  cursor: not-allowed;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.detail-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.detail-item .label {
  color: var(--muted);
  font-size: 0.82rem;
}

.detail-item .value {
  margin-top: 4px;
  font-weight: 600;
}

.detail-note {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  white-space: pre-wrap;
}

.menu-section-hidden {
  display: none !important;
}

.hidden {
  display: none !important;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.pagination button {
  min-width: 34px;
  padding: 6px 10px;
}

.pagination button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.pagination-info {
  margin-left: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 1000px) {
  .zalo-support-btn {
    right: 12px;
    bottom: 62px;
    padding-right: 10px;
  }

  .zalo-support-icon {
    width: 36px;
    height: 36px;
    font-size: 0.86rem;
  }

  .zalo-support-text {
    font-size: 0.85rem;
  }

  .stats,
  .report-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #orderForm.form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .permission-list {
    grid-template-columns: 1fr;
  }

  .permission-toolbar {
    grid-template-columns: 1fr;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .expense-report-toolbar {
    flex-direction: row;
    align-items: center;
  }

  .transfer-reconcile-toolbar {
    flex-direction: row;
    align-items: center;
  }

  .expense-report-toolbar .filters {
    flex-direction: row;
    margin-left: auto;
  }

  .transfer-reconcile-toolbar .filters {
    margin-left: auto;
    grid-template-columns: minmax(150px, 190px) minmax(130px, 150px) minmax(130px, 150px) auto auto;
  }

  .reproduce-report-toolbar .filters {
    grid-template-columns: minmax(150px, 1fr) minmax(140px, 1fr) minmax(140px, 1fr) auto;
  }

  .order-meta-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  #debtPanel .toolbar {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  #debtPanel .filters {
    grid-template-columns: 1fr;
    margin-left: 0;
  }

  .zalo-support-btn {
    bottom: 56px;
  }

  html,
  body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .app {
    padding: 10px;
  }

  .reproduce-report-toolbar .filters {
    grid-template-columns: 1fr;
  }

  .transfer-reconcile-toolbar .filters {
    grid-template-columns: minmax(120px, 160px) minmax(110px, 130px) minmax(110px, 130px) auto auto;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .hero {
    margin: 0 -10px 12px;
  }

  .hero-bar-inner {
    padding: 8px 10px;
  }

  .panel {
    padding: 10px;
    width: 100%;
    max-width: 100%;
  }

  .hero-userbar {
    flex-wrap: wrap;
  }

  .topbar-logo {
    height: 28px;
  }

  .user-menu-dropdown {
    right: auto;
    left: 0;
  }

  .top-menu-groups {
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }

  .menu-group {
    width: auto;
  }

  .menu-group-btn {
    width: auto;
    min-width: 0;
    text-align: center;
  }

  .menu-group-dropdown {
    position: static;
    min-width: 0;
    margin-top: 6px;
  }

  .form-grid,
  .stats,
  .report-summary {
    grid-template-columns: 1fr;
  }


  #orderForm {
    display: block;
    width: 100%;
  }

  #orderForm label,
  #orderForm .full,
  #orderForm .actions {
    width: 100%;
    display: block;
    margin-bottom: 10px;
  }

  #orderForm .order-meta-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  #orderForm .order-meta-grid > label {
    width: 100%;
    min-width: 0;
    margin-bottom: 0;
    display: grid;
  }

  /* Mobile override for old HTML fallback */
  #orderForm:not(:has(.order-meta-grid)):has(#dueDate).form-grid {
    grid-template-columns: 1fr;
  }

  #orderForm .actions button {
    width: 100%;
    margin-bottom: 8px;
  }

  .filters {
    flex-direction: column;
  }

  .customer-search-row {
    justify-content: stretch;
    flex-direction: column;
    gap: 8px;
  }

  #customerSearchInput {
    width: 100%;
  }

  .customer-column-filter {
    width: 100%;
  }

  #customerColumnFilterBtn {
    width: 100%;
  }

  .customer-column-filter-menu {
    left: 0;
    right: auto;
    width: 100%;
    min-width: 0;
  }

  .expense-report-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .expense-report-toolbar .filters {
    flex-direction: column;
    margin-left: 0;
  }

  #expenseReportMode,
  #expenseReportFrom,
  #expenseReportTo,
  #runExpenseReportBtn {
    width: 100%;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .line-head {
    flex-direction: column;
    align-items: stretch;
  }

  #orderForm .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
  }

  #orderForm .table-wrap table {
    min-width: 560px;
  }

  #orderForm input,
  #orderForm select,
  #orderForm textarea {
    width: 100%;
    max-width: 100%;
  }

  th,
  td {
    padding: 8px;
  }
}
