.table-wrap {
  /* allow horizontal scrolling but permit vertical overflow so tooltips can extend
     above/below the table rows without being clipped by the wrapper */
  overflow-x: auto;
  overflow-y: visible;
}

.table-card {
  padding: 0;
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

.table-wrap table {
  width: 100%;
  min-width: 1200px;
  border-collapse: collapse;
  font-size: 12px;
}

/* Compact tables without min-width constraint */
.table-wrap.compact table {
  min-width: unset;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.table-toolbar h3 {
  margin: 0;
}

.search-input {
  max-width: 280px;
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid #d5deea;
  background: #fff;
}

.bulk-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.bulk-actions .actions-wrap {
  justify-content: flex-end;
  margin-right: -8px;
}

.bulk-search-input {
  width: 280px;
  min-width: 240px;
  height: 34px;
}

.bulk-action-btn {
  min-width: 132px;
  height: 34px;
  border-radius: 10px;
  font-weight: 400;
  font-size: 14px;
}

.bulk-action-add {
  background: #0ea5a4;
  color: #ffffff;
}

.bulk-action-export {
  background: #e5eef9;
  color: #1e3a8a;
}

.bulk-action-delete {
  background: #ef4444;
  color: #ffffff;
}

.bulk-action-add:disabled {
  background: #cfeeed;
  color: #0f766e;
  opacity: 1;
}

.bulk-action-export:disabled {
  background: #edf2fb;
  color: #475569;
  opacity: 1;
}

.bulk-action-delete:disabled {
  background: #fee2e2;
  color: #b91c1c;
  opacity: 1;
}

.bulk-action-clear {
  background: #f3f4f6;
  color: #334155;
}

.bulk-action-clear:disabled {
  background: #f8fafc;
  color: #9ca3af;
  opacity: 1;
}

.bulk-selection-summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.bulk-selection-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}

.bulk-selection-count {
  font-size: 14px;
  color: #0f172a;
  font-weight: 800;
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 10px;
  border-top: 1px solid var(--line);
  background: #fbfdff;
  font-size: 12px;
  color: var(--muted);
  /* keep pagination controls on a single row */
  flex-wrap: nowrap;
  /* allow the pagination container to shrink if its parent is constrained */
  min-width: 0;
}

.pagination-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  width: auto;
  white-space: nowrap;
}

.pagination-size {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #6b7280;
}

.pagination-size span {
  font-weight: 500;
  white-space: nowrap;
}

.pagination-size select {
  width: auto;
  min-width: 60px;
  padding: 5px 6px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #0f172a;
  font-size: 12px;
  cursor: pointer;
}

.pagination-info {
  font-weight: 600;
  color: #0f172a;
  white-space: nowrap;
}

.pagination-center {
  display: flex;
  align-items: center;
  gap: 6px;
  /* allow center area to grow and shrink to remaining space */
  flex: 1 1 auto;
  min-width: 0;
  justify-content: flex-end;
  width: auto;
  white-space: nowrap;
}

.pagination-pages {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pagination-page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.pagination-page-btn:hover {
  border-color: #9ca3af;
  background: #f3f4f6;
  color: #111827;
}

.pagination-page-btn.active {
  border-color: #008fa3;
  background: linear-gradient(135deg, #008fa3 0%, #006b7f 100%);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(0, 143, 163, 0.18);
}

.pagination-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: #9ca3af;
  font-size: 12px;
  font-weight: 500;
}

/* Strong pagination layout fixes (apply Fix 1 from analysis)
   - Keep pagination on one line on desktop
   - Prevent child blocks from shrinking too far
   - Ensure page buttons don't force wrapping
 */
.pagination {
  flex-wrap: nowrap !important;
  min-width: 100% !important;
  box-sizing: border-box;
}

.pagination-left,
.pagination-center {
  flex-shrink: 0 !important;
}

.pagination-center {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  justify-content: flex-end !important;
}

.pagination-pages,
.pagination-page-btn,
.pagination-btn {
  flex-shrink: 0;
}

.pagination-btn {
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pagination-btn:hover:not(:disabled) {
  border-color: #9ca3af;
  background: #f3f4f6;
  color: #111827;
}

.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Make booking table responsive: allow wrapping and avoid forced horizontal scroll */
.booking-table table {
  /* allow the booking table to shrink to parent's width instead of forcing 1200px */
  min-width: 0;
  table-layout: auto;
}

.booking-table th,
.booking-table td {
  white-space: normal;
}

.table-wrap th,
.table-wrap td {
  padding: 10px 9px;
  border-bottom: 1px solid #edf2f7;
  text-align: left;
  vertical-align: top;
}

.table-wrap thead th {
  position: sticky;
  top: 0;
  background: var(--panel-soft);
  z-index: 1;
  font-size: 11px;
  text-transform: uppercase;
  color: #111827;
  letter-spacing: 0.01em;
  white-space: normal;
  line-height: 1.2;
  padding: 10px 9px;
}


.table-wrap tbody tr:hover {
  background: #fafcff;
}

/* Indicate rows that are clickable to view details */
.clickable-row {
  cursor: pointer;
}

thead th {
  background: #f9fbfd;
  font-size: 12px;
  text-transform: uppercase;
  color: #111827;
  letter-spacing: 0.03em;
}

tbody tr:hover {
  background: #fafcff;
}

/* Table cell types for booking table */
.name-cell {
  min-width: 130px;
}

.owner-cell {
  min-width: 80px;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Product name column: cap its max width to the configured base width
   scaled by the base factor (previously 0.66) then reduced by an
   additional 1/5 (×0.8). Resulting scale ≈ 0.528 of `--product-col-max`.
   Consumers may override `--product-col-max` on a parent to change the base. */
.booking-table .product-cell {
  max-width: calc(var(--product-col-max, 330px) * 0.528);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

/* Make campaign name column match product column max-width */
.booking-table .name-cell {
  max-width: calc(var(--product-col-max, 330px) * 0.528);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

/* Inline custom tooltip for truncated table cells (campaign name, product) */
.cell-with-tooltip {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.cell-with-tooltip .cell-label {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.cell-with-tooltip .cell-tooltip {
  display: none;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100% + 8px);
  background: rgba(17, 24, 39, 0.95);
  color: #fff;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.2;
  white-space: normal;
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.4);
  z-index: 1200;
  max-width: 240px;
  /* SHORTER MAX WIDTH as requested */
  word-break: break-word;
}

.cell-with-tooltip .cell-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px;
  border-style: solid;
  border-color: rgba(17, 24, 39, 0.95) transparent transparent transparent;
}

.cell-with-tooltip:hover .cell-tooltip,
.cell-with-tooltip:focus-within .cell-tooltip {
  display: block;
}

/* Portal tooltip (appended to body) to avoid clipping by overflowed ancestors */
.portal-tooltip {
  position: absolute;
  display: block;
  pointer-events: none;
  background: rgba(17, 24, 39, 0.95);
  color: #fff;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.2;
  white-space: normal;
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.4);
  z-index: 2147483647;
  /* very high to be above sticky headers */
  max-width: 240px;
  word-break: break-word;
  opacity: 0;
  transform-origin: bottom center;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.portal-tooltip.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.portal-tooltip.hide {
  opacity: 0;
  transform: translateY(6px) scale(0.98);
}

/* Ensure the inline cell tooltip is never shown to avoid duplicate tooltips
   (we use the portal tooltip appended to body instead). */
.cell-with-tooltip .cell-tooltip {
  display: none !important;
  visibility: hidden !important;
}

.link-cell {
  min-width: 70px;
  max-width: 70px;
  /* cap link column width to 100px as requested */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.links-wrap {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.link-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 30px;
  border-radius: 8px;
  background: #f0f7ff;
  color: #0b4f9f;
  text-decoration: none;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid rgba(11, 79, 159, 0.15);
  transition: all 0.2s ease;
}

.link-icon:hover {
  background: #0369a1;
  color: #fff;
}

.contact-cell {
  min-width: 63px;
  max-width: 120px;
  /* tăng chiều rộng tối thiểu để text "Liên hệ" không bị đẩy xuống hàng */
  overflow-wrap: anywhere;
  /* cho phép xuống hàng khi quá dài */
}

/* Contact button in table: opens a small popover with full contact details */
.contact-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 36px;
  height: 28px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  background: #fff;
  color: #0f172a;
  cursor: pointer;
  font-size: 14px;
}

/* Small interactive popover mounted on body */
.contact-popover {
  position: absolute;
  pointer-events: auto;
  background: #111827;
  color: #fff;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.2;
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.45);
  z-index: 2147483646;
  min-width: 160px;
  max-width: 320px;
  opacity: 0;
  transform-origin: left center;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.contact-popover.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.contact-popover.hide {
  opacity: 0;
  transform: translateY(6px) scale(0.98);
}

.contact-popover .contact-line {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
}

.contact-popover .contact-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.contact-popover .contact-icon img {
  width: 20px;
  height: 20px;
}

/* Slightly larger email icon for better visibility */
.contact-icon.email-icon img {
  width: 24px;
  height: 24px;
}

.contact-popover .contact-value {
  color: #fff;
  text-decoration: none;
  word-break: break-word;
}

.contact-popover .contact-empty {
  color: #9ca3af;
}

/* Allow users to select (copy) contact text inside popover */
.contact-popover .contact-value {
  user-select: text;
  cursor: text;
}

/* Arrow triangle pointing to the contact button */
.contact-popover::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  background: #111827;
  transform: translateY(-50%) rotate(45deg);
  top: var(--arrow-top, 50%);
  pointer-events: none;
  box-shadow: 0 6px 16px rgba(2, 6, 23, 0.2);
}

.contact-popover.arrow-left::after {
  left: -6px;
}

.contact-popover.arrow-right::after {
  right: -6px;
}

.contact-badges {
  display: flex;
  gap: 6px;
}

.contact-lines {
  display: flex;
  align-items: center;
  gap: 8px;
  gap: 4px;
}

/* Keep label and value inline; allow value to wrap when necessary */
.contact-line {
  display: block;
  /* normal block so inline/inline-block elements flow naturally */
}

.contact-label {
  display: inline;
  white-space: nowrap;
  /* keep label on single line */
  font-weight: 700;
  margin-right: 0;
  /* label and value sit adjacent */
}

/* Icon used in contact column (phone, zalo, email, address) */
.contact-icon {
  display: inline-block;
  margin-right: 6px;
  color: #0f172a;
  font-size: 15px;
  /* unified icon size for emoji and images */
  line-height: 1;
}

/* Make contact values wrap and read clearly instead of truncating */
.contact-cell .contact-value {
  display: block;
  max-width: 320px;
  overflow-wrap: anywhere;
  white-space: normal;
  color: #0f172a;
  font-size: 13px;
}

/* Size adjustments for inline SVG/icon images */
.contact-icon img {
  width: 20px;
  height: 20px;
  display: inline-block;
  vertical-align: middle;
  transform: translateY(1px);
}

/* Make Zalo noticeably larger */
.contact-icon.zalo-icon img {
  width: 20px;
  height: 20px;
  transform: translateY(0);
}

.contact-value {
  display: inline;
  /* inline so it flows after label; wrap happens naturally at column boundary */
  overflow-wrap: break-word;
  word-break: break-all;
  /* allow breaking inside long tokens */
}

.contact-line {
  font-size: 12px;
  color: #334155;
}

.contact-label {
  font-weight: 700;
  color: #1f2937;
}

.number-cell,
.number-cell * {
  text-align: right;
}

.number-cell {
  min-width: 70px;
  font-variant-numeric: tabular-nums;
}

.currency-cell,
.currency-cell * {
  text-align: right;
}

.currency-cell {
  min-width: 80px;
  font-variant-numeric: tabular-nums;
}

/* Stronger rule scoped to KOC table to ensure numeric cells are right-aligned */
#kocs-table td.number-cell,
#kocs-table td.number-cell *,
#kocs-table td.currency-cell,
#kocs-table td.currency-cell * {
  text-align: right !important;
}

/* Align headers for numeric/currency columns to match cell alignment */
#kocs-table thead th:nth-child(5),
#kocs-table thead th:nth-child(6),
#kocs-table thead th:nth-child(7),
#kocs-table thead th:nth-child(9),
#kocs-table thead th:nth-child(10),
#kocs-table thead th:nth-child(13) {
  text-align: right;
}

/* Limit max width for "Số chiến dịch" column; allow normal flexible width up to the max */
#kocs-table th:nth-child(13),
#kocs-table td:nth-child(13) {
  max-width: 87px;
  /* reduced maximum */
  width: 87px;
  /* allow the cell to flex within table layout */
  white-space: nowrap;
  /* keep count on single line */
  overflow: hidden;
  /* hide overflow beyond max-width */
  text-overflow: ellipsis;
  text-align: center;
  /* center small numeric count */
}

/* Make Address (11) and Notes (12) columns use similar max-width/wrapping as Contact */
#kocs-table th:nth-child(11),
#kocs-table td:nth-child(11),
#kocs-table th:nth-child(12),
#kocs-table td:nth-child(12) {
  max-width: 140px;
  width: auto;
  overflow-wrap: anywhere;
  /* allow breaking long tokens similar to contact */
  white-space: normal;
  /* allow wrapping */
}

.text-cell {
  min-width: 70px;
  word-break: break-word;
}

.note-cell {
  min-width: 80px;
}

.note-truncate {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #6b7280;
}

.action-cell {
  text-align: left;
  min-width: 56px;
  display: flex;
  gap: 0;
  /* no gap between action icons per request */
  justify-content: flex-start;
  align-items: center;
}

/* Prevent action buttons from wrapping to multiple lines */
.action-cell {
  flex-wrap: nowrap;
}

.action-cell .btn-icon {
  white-space: nowrap;
}

.btn-icon {
  background: none;
  border: none;
  padding: 2px 4px;
  /* tighter padding */
  cursor: pointer;
  font-size: 13px;
  /* slightly smaller to fit */
  border-radius: 4px;
  transition: background 0.12s ease;
}

.btn-icon:hover {
  background: #f0f9ff;
}

.btn-icon-danger {
  color: #dc2626;
}

.btn-icon-danger:hover {
  background: #fee2e2;
}

/* ============================================================================
   SORTABLE TABLE HEADERS
   Reusable component for any sortable column
   ============================================================================ */

.sortable-header {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  /* tightened gap to bring icon very close to label */
  cursor: pointer;
  user-select: none;
  padding: 2px 4px;
  margin: -2px -4px;
  border-radius: 3px;
  transition: background-color 0.12s ease;
  /* allow inner label to wrap when needed */
  white-space: normal;
}

.sortable-header:hover {
  background-color: rgba(15, 23, 42, 0.08);
}

.sort-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 12px;
  height: 12px;
  font-size: 11px;
  color: #cbd5e1;
  transition: color 0.12s ease, transform 0.12s ease;
  margin-left: 0;
  /* icon sits immediately after label */
}

/* Inner label for sortable headers: allow wrapping and constrain width */
.sortable-header .label {
  display: inline-block;
  white-space: normal;
  max-width: 60px;
  /* further tightened width so indicator stays very near label */
  line-height: 1.05;
  font-weight: 600;
  vertical-align: top;
}

/* Slight transform to make current sort direction clearer */
.sortable-header.sort-asc .sort-indicator {
  transform: translateY(-1px);
}

.sortable-header.sort-desc .sort-indicator {
  transform: translateY(1px);
}

.sortable-header.sort-asc .sort-indicator {
  color: #0f766e;
}

.sortable-header.sort-desc .sort-indicator {
  color: #0f766e;
}

.sortable-header.sort-asc .sort-indicator::before {
  content: '▲';
}

.sortable-header.sort-desc .sort-indicator::before {
  content: '▼';
}