:root {
  /* Màu và shadow dùng chung để giao diện nhất quán trên desktop/mobile. */
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #64748b;
  --line: #d9e0e8;
  --green: #14835b;
  --green-dark: #0f6849;
  --blue: #2563eb;
  --amber: #b7791f;
  --soft-green: #e7f5ee;
  --soft-blue: #e9f0ff;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  overflow-x: hidden;
}

.file-protocol-warning {
  background: #fff7ed;
  border-bottom: 1px solid #fed7aa;
  color: #9a3412;
  font-size: 14px;
  font-weight: 700;
  padding: 12px 18px;
  text-align: center;
}

button,
input,
select {
  font: inherit;
  min-width: 0;
}

.app-shell {
  /* Desktop: sidebar cố định bên trái, nội dung bên phải. Mobile sẽ đổi thành 1 cột. */
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #10231c;
  color: #f8fafc;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f2c94c;
  color: #10231c;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
}

.brand p {
  margin: 2px 0 0;
  color: #b9c7c1;
}

.account-menu-button {
  display: none;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.role-switch {
  /* Công tắc thử vai trò local. Lên Supabase sẽ thay bằng role thật từ user_profiles. */
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
}

.role-button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #d7e3de;
  cursor: pointer;
  min-height: 36px;
  padding: 0 10px;
}

.role-button.active {
  background: #ffffff;
  color: #10231c;
  font-weight: 700;
}

.role-button:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.data-tools {
  display: grid;
  gap: 8px;
}

.secondary-button {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  cursor: pointer;
  min-height: 38px;
  padding: 0 12px;
  width: 100%;
}

.secondary-button:hover {
  background: rgba(255, 255, 255, 0.14);
}

.nav-tab {
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #d7e3de;
  cursor: pointer;
  padding: 12px;
  text-align: left;
}

.nav-tab.active,
.nav-tab:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.sync-status {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #d7e3de;
  font-size: 14px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f2c94c;
}

.auth-panel {
  display: grid;
  gap: 8px;
  color: #d7e3de;
  font-size: 13px;
}

.auth-panel input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  min-height: 38px;
  padding: 0 10px;
}

.auth-panel input::placeholder {
  color: rgba(255, 255, 255, 0.58);
}

.auth-panel.open {
  display: grid;
}

body.auth-required {
  overflow: hidden;
}

body.auth-required::before {
  background: rgba(15, 23, 42, 0.42);
  content: "";
  inset: 0;
  position: fixed;
  z-index: 80;
}

body.auth-required .auth-panel {
  background: #10231c;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.34);
  display: grid;
  left: 50%;
  max-width: calc(100vw - 32px);
  padding: 18px;
  position: fixed;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 360px;
  z-index: 81;
}

body.auth-required .auth-panel strong {
  color: #ffffff;
  font-size: 18px;
}

body.auth-required .auth-panel input,
body.auth-required .auth-panel button {
  min-height: 44px;
}

body.auth-required .account-menu-button {
  display: none;
}

.auth-panel[hidden],
.account-menu-button[hidden] {
  display: none !important;
}

.main-content {
  padding: 28px;
  min-width: 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

body[data-role="shipper"] .finance-only,
body[data-role="shipper"] .manager-only {
  /* Ẩn dữ liệu nhạy cảm cho shipper ở bản UI local; bảo mật thật nằm ở Supabase RLS. */
  display: none !important;
}

body.supabase-mode[data-role="shipper"] .role-button[data-role="manager"] {
  display: none;
}

body.supabase-mode[data-role="shipper"] .role-switch {
  display: none;
}

body[data-role="manager"] .shipper-only {
  display: none !important;
}

body[data-role="shipper"] #entry-view .summary-grid {
  display: none;
}

.customer-main {
  /* Dòng shipper tinh gọn: tên khách + nút mở chi tiết. */
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.customer-title {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.delivery-quick-summary {
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  min-height: 16px;
}

.delivery-quick-summary.is-paid {
  color: var(--green);
}

.delivery-quick-summary.is-due {
  color: #b42318;
}

.delivery-quick-summary.is-warning {
  color: var(--amber);
}

.detail-toggle {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--text);
  cursor: pointer;
  min-height: 34px;
  padding: 0 10px;
  white-space: nowrap;
}

.entry-toggle {
  display: none;
}

.detail-toggle::after {
  content: "⌄";
  display: inline-block;
  font-size: 16px;
  line-height: 1;
  margin-left: 6px;
  transform: translateY(-1px);
}

.detail-toggle[aria-expanded="true"]::after {
  transform: rotate(180deg) translateY(1px);
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.page-head h2 {
  margin: 0;
  font-size: 28px;
}

.page-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.secondary-light-button {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  min-height: 44px;
  padding: 0 16px;
}

.secondary-light-button:hover {
  border-color: #9fb0c3;
}

.date-control,
.search-box {
  display: grid;
  gap: 6px;
  min-width: 180px;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  padding: 10px 11px;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  padding: 10px 11px;
}

input:focus,
select:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(37, 99, 235, 0.16);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

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

.entry-filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}

.entry-filter-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  min-height: 36px;
  padding: 0 12px;
}

.entry-filter-button.active {
  border-color: var(--green);
  background: var(--soft-green);
  color: var(--green-dark);
}

.mobile-save-bar {
  display: none;
}

.primary-button {
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #ffffff;
  cursor: pointer;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 700;
  max-width: 100%;
}

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

.danger-button {
  border: 1px solid #efb3b3;
  border-radius: 8px;
  background: #fff1f1;
  color: #b42318;
  cursor: pointer;
  min-height: 34px;
  padding: 0 10px;
}

.danger-button:hover {
  background: #ffe4e4;
}

.warning-row {
  background: #fff8e6;
}

.price-warning-panel {
  background: #fff8e6;
  border: 1px solid #f0c36d;
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  padding: 14px;
}

.price-warning-panel .section-head {
  margin-bottom: 8px;
}

.price-warning-panel h3 {
  color: #8a5a00;
}

.price-warning-item,
.price-warning-empty {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(240, 195, 109, 0.7);
  border-radius: 8px;
  padding: 10px 12px;
}

.price-warning-item {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) minmax(210px, 280px);
}

.price-warning-item + .price-warning-item {
  margin-top: 8px;
}

.price-warning-item strong {
  display: block;
}

.price-warning-item span,
.price-warning-empty {
  color: #8a5a00;
  font-size: 13px;
  font-weight: 700;
}

.quick-price-form {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.quick-price-button,
.delete-missing-price-customer {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  min-height: 42px;
  padding: 0 12px;
  white-space: nowrap;
}

.quick-price-button {
  background: var(--green);
  color: #ffffff;
}

.delete-missing-price-customer {
  background: #fff1f2;
  color: #be123c;
}

.debt-badge {
  background: #fef3c7;
  border: 1px solid #f0c36d;
  border-radius: 999px;
  color: #8a5a00;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  margin-left: 8px;
  padding: 3px 8px;
  white-space: nowrap;
}

.debt-detail-button {
  background: var(--soft-blue);
  border: 1px solid #bfd0ff;
  border-radius: 8px;
  color: var(--blue);
  cursor: pointer;
  font-weight: 800;
  min-height: 34px;
  padding: 0 12px;
}

.debt-detail-row {
  display: none;
}

.debt-detail-row.open {
  display: table-row;
}

.debt-detail-row td {
  background: #f8fafc;
  padding: 12px;
}

.debt-detail-list {
  display: grid;
  gap: 8px;
}

.debt-allocation-note,
.debt-extra-paid {
  background: var(--soft-blue);
  border: 1px solid #bfd0ff;
  border-radius: 8px;
  color: #1e3a8a;
  font-size: 13px;
  font-weight: 800;
  padding: 10px;
}

.debt-extra-paid {
  background: var(--soft-green);
  border-color: #b7dfc8;
  color: var(--green-dark);
}

.collect-debt-button {
  background: var(--green);
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  cursor: pointer;
  font-weight: 800;
  min-height: 42px;
  padding: 0 14px;
  text-align: center;
  width: 100%;
}

.copy-debt-message-button {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  min-height: 42px;
  padding: 0 14px;
  width: 100%;
}

.debt-detail-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(150px, 1.4fr) repeat(3, minmax(110px, 1fr));
  padding: 10px;
}

.debt-detail-item span,
.debt-detail-empty {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
}

.debt-detail-item strong {
  display: block;
  margin-top: 3px;
}

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: auto;
}

.month-strip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin-bottom: 18px;
  overflow: hidden;
}

.month-strip div {
  padding: 14px 16px;
}

.month-strip span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-weight: 700;
}

.month-strip strong {
  display: block;
  font-size: 20px;
  margin-top: 6px;
}

.report-section {
  margin-top: 22px;
}

.delivery-log {
  display: grid;
  gap: 10px;
}

.delivery-log-summary {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 10px;
}

.delivery-log-summary div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.delivery-log-summary span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
}

.delivery-log-summary strong {
  display: block;
  font-size: 19px;
  margin-top: 5px;
}

.delivery-log-card,
.empty-log {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.delivery-log-card {
  display: grid;
  gap: 12px;
  padding: 14px;
}

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

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

.log-customer strong {
  font-size: 17px;
}

.log-customer span {
  background: var(--soft-green);
  border-radius: 999px;
  color: var(--green-dark);
  font-weight: 800;
  padding: 5px 10px;
  white-space: nowrap;
}

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

.log-money-grid div {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.log-money-grid span,
.log-note span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
}

.log-money-grid strong {
  display: block;
  font-size: 18px;
  margin-top: 5px;
}

.log-balance-due strong {
  color: #b42318;
}

.log-balance-paid strong {
  color: var(--green);
}

.log-note {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.log-note p {
  margin: 5px 0 0;
}

.chart-section {
  /* Khối biểu đồ tháng chỉ dành cho manager trong tab Báo cáo. */
  margin-bottom: 18px;
}

.section-head {
  margin-bottom: 10px;
}

.section-head h3 {
  font-size: 19px;
  margin: 0;
}

.report-log-head {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.report-copy-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, max-content);
  justify-content: end;
}

.report-copy-button {
  background: var(--soft-green);
  border: 1px solid #b7dfc8;
  border-radius: 8px;
  color: var(--green-dark);
  cursor: pointer;
  font-weight: 800;
  min-height: 38px;
  padding: 0 12px;
  white-space: nowrap;
}

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

.chart-toggle {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 4px;
  padding: 4px;
}

.chart-button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  min-height: 34px;
  padding: 0 12px;
}

.chart-button.active {
  background: var(--green);
  color: #ffffff;
  font-weight: 700;
}

.chart-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.payment-panel {
  /* Form ghi nhận thanh toán trong tab Công nợ. */
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  padding: 16px;
}

.highlight-panel {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(20, 131, 91, 0.18), var(--shadow);
}

.period-panel {
  /* Bộ lọc kỳ công nợ: ngày kết thúc, 1-3 tuần hoặc 1 tháng, và ngưỡng cảnh báo. */
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  grid-template-columns: 150px 120px 150px 110px minmax(140px, 1fr) 150px minmax(0, 1fr);
  margin-bottom: 18px;
  padding: 16px;
}

.period-panel > div {
  display: grid;
  gap: 6px;
}

.period-label span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-weight: 700;
}

.period-label strong {
  display: block;
  font-size: 18px;
}

.debt-filter-summary {
  display: flex !important;
  flex-wrap: wrap;
  gap: 8px;
  grid-column: 1 / -1;
}

.debt-filter-summary span {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  padding: 7px 10px;
}

.reset-filter-button {
  align-self: end;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  min-height: 42px;
  padding: 0 12px;
}

.copy-debt-list-button {
  align-self: end;
  background: var(--soft-green);
  border: 1px solid #b7dfc8;
  border-radius: 8px;
  color: var(--green-dark);
  cursor: pointer;
  font-weight: 800;
  min-height: 42px;
  padding: 0 12px;
}

.payment-form {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: 150px minmax(180px, 1fr) 160px minmax(180px, 1fr) auto;
}

.payment-form > div {
  display: grid;
  gap: 6px;
}

.chart-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.chart-summary span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-weight: 700;
}

.chart-summary strong {
  display: block;
  font-size: 20px;
  margin-top: 5px;
}

.bar-chart {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-auto-flow: column;
  grid-auto-columns: minmax(34px, 1fr);
  min-height: 240px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.bar-item {
  align-items: center;
  display: grid;
  gap: 6px;
  grid-template-rows: auto 1fr auto;
  height: 230px;
  min-width: 34px;
}

.bar-value {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  white-space: nowrap;
}

.bar-track {
  align-items: end;
  background: #eef3f0;
  border-radius: 8px;
  display: flex;
  height: 100%;
  overflow: hidden;
  width: 100%;
}

.bar-fill {
  background: linear-gradient(180deg, #2b9c72, #0f6849);
  border-radius: 8px 8px 0 0;
  width: 100%;
}

.bar-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.empty-chart {
  align-self: center;
  color: var(--muted);
  grid-column: 1 / -1;
  justify-self: center;
  padding: 70px 0;
}

.compact-table {
  min-width: 560px;
}

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

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

th {
  background: #f8fafc;
  color: #475569;
  font-size: 13px;
  position: sticky;
  top: 0;
  z-index: 1;
}

td input[type="number"] {
  max-width: 130px;
}

td input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.quantity-wrap {
  align-items: center;
  display: grid;
  grid-template-columns: minmax(80px, 1fr) auto;
  gap: 6px;
  max-width: 160px;
}

.quantity-label {
  display: none;
}

.quantity-wrap span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.cash-wrap {
  align-items: center;
  display: grid;
  grid-template-columns: minmax(118px, 1fr) auto;
  gap: 6px;
  max-width: 230px;
}

.cash-label,
.cash-wrap span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.cash-label {
  display: none;
  grid-column: 1 / -1;
}

.fill-cash-button {
  background: var(--soft-green);
  border: 1px solid #b7dfc8;
  border-radius: 8px;
  color: var(--green-dark);
  cursor: pointer;
  display: block;
  font-size: 13px;
  font-weight: 800;
  grid-column: 1 / -1;
  min-height: 38px;
}

.fill-cash-button:disabled {
  background: #f1f5f9;
  border-color: var(--line);
  color: var(--muted);
  cursor: not-allowed;
}

.cash-help {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  grid-column: 1 / -1;
}

.money,
.number {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.phone-link {
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

.phone-link:hover,
.map-link:hover {
  text-decoration: underline;
}

.map-link {
  color: var(--green);
  display: inline-block;
  font-weight: 700;
  margin-left: 8px;
  text-decoration: none;
  white-space: nowrap;
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

.entry-empty-row {
  padding: 18px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #10231c;
  color: #ffffff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  padding: 12px 14px;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 860px) {
  /* Tablet/mobile: sidebar chuyển lên trên để người giao hàng dùng điện thoại dễ hơn. */
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    min-height: auto;
    min-width: 0;
    padding: 16px 70px 16px 16px;
  }

  .account-menu-button {
    align-items: center;
    background: #ffffff;
    border: 1px solid rgba(15, 35, 28, 0.18);
    border-radius: 999px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
    color: #10231c;
    cursor: pointer;
    display: flex;
    font-size: 13px;
    font-weight: 800;
    height: 44px;
    justify-content: center;
    padding: 0;
    position: fixed;
    right: 14px;
    top: 14px;
    width: 44px;
    z-index: 60;
  }

  .account-menu-button[aria-expanded="true"] {
    background: #f2c94c;
  }

  .auth-panel {
    background: #10231c;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    box-shadow: 0 16px 34px rgba(15, 23, 42, 0.24);
    display: none;
    max-width: calc(100vw - 28px);
    padding: 12px;
    position: fixed;
    right: 14px;
    top: 66px;
    width: 300px;
    z-index: 59;
  }

  .auth-panel.open {
    display: grid;
  }

  body.auth-required .auth-panel {
    left: 50%;
    max-width: calc(100vw - 32px);
    padding: 18px;
    right: auto;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 360px;
    z-index: 81;
  }

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

  .nav-tab {
    text-align: center;
  }

  .sync-status {
    display: none;
  }

  .main-content {
    padding: 18px;
  }

  .page-head,
  .toolbar {
    display: grid;
  }

  .entry-filter-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .month-strip {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  /* Mobile nhỏ: bảng biến thành card để không phải kéo ngang như Google Sheet. */
  .sidebar {
    gap: 14px;
    padding-right: 64px;
  }

  .brand > div {
    align-items: baseline;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .brand h1 {
    font-size: 18px;
  }

  .brand p {
    display: none;
  }

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

  .role-switch {
    max-width: none;
    width: 100%;
  }

  .nav-tab {
    min-height: 44px;
    padding: 10px 12px;
    white-space: normal;
  }

  .price-warning-item,
  .quick-price-form {
    grid-template-columns: 1fr;
  }

  .debt-detail-row.open {
    display: block;
  }

  .debt-detail-row.open td {
    display: block;
  }

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

  .data-tools {
    width: 100%;
  }

  .main-content {
    padding: 14px;
  }

  .page-head h2 {
    font-size: 23px;
  }

  .metric {
    padding: 13px;
  }

  .metric strong {
    font-size: 22px;
  }

  .table-wrap {
    background: transparent;
    border: 0;
    box-shadow: none;
    overflow: visible;
  }

  .report-section {
    margin-top: 18px;
  }

  .chart-head {
    align-items: stretch;
    display: grid;
  }

  .report-log-head {
    align-items: stretch;
    display: grid;
  }

  .report-copy-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .report-copy-button {
    width: 100%;
  }

  .chart-summary {
    grid-template-columns: 1fr;
  }

  .log-money-grid {
    grid-template-columns: 1fr;
  }

  .delivery-log-summary {
    grid-template-columns: 1fr;
  }

  .payment-form {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .period-panel {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .bar-chart {
    grid-auto-columns: minmax(42px, 1fr);
    min-height: 220px;
  }

  .compact-table {
    min-width: 0;
  }

  .mobile-save-bar {
    align-items: center;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--line);
    border-radius: 8px 8px 0 0;
    bottom: 0;
    box-shadow: 0 -10px 26px rgba(15, 23, 42, 0.12);
    display: flex;
    gap: 12px;
    justify-content: space-between;
    left: 0;
    padding: 10px 14px;
    position: sticky;
    right: 0;
    z-index: 3;
  }

  .mobile-save-bar span {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-weight: 700;
  }

  .mobile-save-bar strong {
    display: block;
    font-size: 18px;
    margin-top: 2px;
  }

  .mobile-save-bar .primary-button {
    min-width: 96px;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tr {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    padding: 6px 0;
  }

  td {
    border-bottom: 0;
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 10px;
    padding: 8px 12px;
  }

  td::before {
    color: var(--muted);
    content: attr(data-label);
    font-size: 13px;
    font-weight: 700;
    padding-top: 10px;
  }

  td:first-child {
    border-bottom: 1px solid var(--line);
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 2px;
    padding-bottom: 10px;
  }

  td:first-child::before {
    padding-top: 0;
  }

  td input[type="number"],
  td input[type="text"],
  td input[type="search"] {
    max-width: none;
    min-height: 44px;
  }

  td input[type="checkbox"] {
    align-self: center;
  }

  .empty-row {
    display: block;
    text-align: center;
  }

  .empty-row::before {
    content: "";
  }

  #entry-view .entry-empty-row {
    background: var(--panel);
    border: 1px dashed var(--line);
    border-radius: 8px;
    box-shadow: none;
    padding: 18px 14px;
  }

  #entry-view thead {
    /* Màn nhập giao hàng trên điện thoại dùng list xổ xuống cho cả shipper và quản lý. */
    display: none;
  }

  #entry-view tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 0;
  }

  #entry-view td {
    display: block;
    padding: 0;
  }

  #entry-view td::before {
    content: "";
    display: none;
  }

  #entry-view .customer-cell {
    border-bottom: 0;
    grid-column: 1 / -1;
    margin: 0;
    padding: 14px 14px;
  }

  #entry-view .quantity-cell,
  #entry-view .cash-cell,
  #entry-view .shipper-detail,
  #entry-view .finance-detail {
    display: none;
    grid-column: 1 / -1;
    padding: 0 14px 10px;
  }

  #entry-view tr.details-open .quantity-cell,
  #entry-view tr.details-open .cash-cell {
    display: block;
  }

  #entry-view tr.details-open .shipper-detail,
  #entry-view tr.details-open .finance-detail {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 10px;
  }

  #entry-view tr.details-open .shipper-detail::before,
  #entry-view tr.details-open .finance-detail::before {
    color: var(--muted);
    content: attr(data-label);
    display: block;
    font-size: 13px;
    font-weight: 700;
    padding-top: 10px;
  }

  #entry-view tr.details-open .shipper-detail:first-of-type::before,
  #entry-view tr.details-open .finance-detail:first-of-type::before {
    padding-top: 0;
  }

  #entry-view .quantity-input {
    font-size: 18px;
    font-weight: 700;
    min-height: 48px;
    text-align: center;
  }

  #entry-view .quantity-wrap {
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 8px;
    grid-template-columns: 1fr auto;
    max-width: none;
    min-height: 74px;
    padding: 10px 12px;
  }

  #entry-view .quantity-label {
    color: var(--text);
    display: block;
    font-size: 14px;
    grid-column: 1 / -1;
  }

  #entry-view .cash-wrap {
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 8px;
    grid-template-columns: 1fr auto;
    max-width: none;
    min-height: 74px;
    padding: 10px 12px;
  }

  #entry-view .cash-label {
    color: var(--text);
    display: block;
    font-size: 14px;
  }

  #entry-view .cash-input {
    font-size: 16px;
    font-weight: 700;
    min-height: 44px;
  }

  #entry-view .fill-cash-button {
    min-height: 42px;
  }

  #entry-view .customer-main {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
  }

  #entry-view .customer-main span {
    font-size: 18px;
    line-height: 1.25;
  }

  #entry-view .detail-toggle {
    align-items: center;
    display: inline-flex;
    flex: 0 0 auto;
    justify-content: center;
    min-height: 38px;
    min-width: 84px;
  }

  body[data-role="shipper"] #entry-view .mobile-save-bar {
    justify-content: center;
  }

  body[data-role="shipper"] #entry-view .mobile-save-bar > div {
    display: none;
  }

  body[data-role="shipper"] #entry-view .mobile-save-bar .primary-button {
    width: 100%;
  }

  body[data-role="shipper"] #customers-view tr {
    padding: 10px 12px;
  }

  body[data-role="shipper"] #customers-view td {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  body[data-role="shipper"] #customers-view td:first-child {
    border-bottom: 0;
    font-size: inherit;
    font-weight: inherit;
    margin-bottom: 0;
    padding-bottom: 8px;
  }
}
