/* ============================================
   UNIFIED BUTTON SYSTEM
   Consistent styling for all action buttons
   ============================================ */

/* Base Button Styles */
button,
a.btn,
.btn,
.ph-btn,
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-success,
.btn-save,
.btn-cancel,
.btn-export {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  text-decoration: none;
  vertical-align: middle;
  font-family: inherit;
}

button:disabled,
a.btn:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Icons in buttons inherit text color */
button i,
a.btn i,
.btn i,
.ph-btn i,
.btn-primary i,
.btn-secondary i,
.btn-danger i,
.btn-success i,
.btn-save i,
.btn-cancel i,
.btn-export i,
.ib i,
.pg-btn i,
.tab-btn i {
  color: inherit;
}

/* Primary Button - Blue theme */
.btn-primary,
button.btn-primary,
a.btn-primary,
.ph-btn.primary {
  background: #063970;
  color: #fff;
  border-color: #063970;
}

.btn-primary:hover,
button.btn-primary:hover,
a.btn-primary:hover,
.ph-btn.primary:hover {
  background: #0a4a8a;
  border-color: #0a4a8a;
  box-shadow: 0 2px 8px rgba(6, 57, 112, 0.3);
}

.btn-primary:active,
button.btn-primary:active,
a.btn-primary:active {
  background: #052d52;
  border-color: #052d52;
}

/* Secondary Button - Gray theme */
.btn-secondary,
button.btn-secondary,
a.btn-secondary,
.ph-btn:not(.primary):not(.danger):not(.success) {
  background: #eef2f9;
  color: #1e3a5f;
  border-color: #b0bed4;
}

.btn-secondary:hover,
button.btn-secondary:hover,
a.btn-secondary:hover {
  background: #dce7f7;
  border-color: #063970;
  color: #063970;
}

.btn-secondary:active,
button.btn-secondary:active,
a.btn-secondary:active {
  background: #bfdbfe;
}

/* Danger Button - Red theme */
.btn-danger,
button.btn-danger,
a.btn-danger,
.ph-btn.danger {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fecaca;
}

.btn-danger:hover,
button.btn-danger:hover,
a.btn-danger:hover {
  background: #fecaca;
  border-color: #dc2626;
  color: #dc2626;
}

.btn-danger:active,
button.btn-danger:active,
a.btn-danger:active {
  background: #fca5a5;
  border-color: #b91c1c;
}

/* Success Button - Green theme */
.btn-success,
button.btn-success,
a.btn-success,
.ph-btn.success {
  background: #d1fae5;
  color: #065f46;
  border-color: #a7f3d0;
}

.btn-success:hover,
button.btn-success:hover,
a.btn-success:hover {
  background: #a7f3d0;
  border-color: #16a34a;
  color: #065f46;
}

.btn-success:active,
button.btn-success:active,
a.btn-success:active {
  background: #6ee7b7;
}

/* Save Button - Green variant */
.btn-save,
button.btn-save {
  background: #16a34a;
  color: #fff;
  border-color: #16a34a;
}

.btn-save:hover,
button.btn-save:hover {
  background: #15803d;
  border-color: #15803d;
  box-shadow: 0 2px 8px rgba(22, 163, 74, 0.3);
}

.btn-save:active,
button.btn-save:active {
  background: #127135;
}

/* Cancel Button - Gray variant */
.btn-cancel,
button.btn-cancel,
a.btn-cancel {
  background: #f3f4f6;
  color: #374151;
  border-color: #d1d5db;
}

.btn-cancel:hover,
button.btn-cancel:hover,
a.btn-cancel:hover {
  background: #e5e7eb;
  border-color: #9ca3af;
}

.btn-cancel:active,
button.btn-cancel:active {
  background: #d1d5db;
}

/* Export Button - Teal variant */
.btn-export,
button.btn-export {
  background: #e0f2fe;
  color: #0369a1;
  border-color: #bae6fd;
}

.btn-export:hover,
button.btn-export:hover {
  background: #bae6fd;
  border-color: #0891b2;
  color: #0891b2;
}

.btn-export:active,
button.btn-export:active {
  background: #7dd3fc;
}

/* Header Action Button — sits on blue gradient header background */
.btn-header,
button.btn-header {
  background: rgba(255, 255, 255, 0.95);
  color: #063970;
  border-color: rgba(255, 255, 255, 0.6);
  border-radius: 20px;
}

.btn-header:hover,
button.btn-header:hover {
  background: #ffffff;
  color: #0a4a8a;
  border-color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.btn-header i {
  color: #063970 !important;
}

.btn-header:hover i {
  color: #0a4a8a !important;
}

/* Size Variants */
.btn-sm,
button.btn-sm,
a.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-lg,
button.btn-lg,
a.btn-lg {
  padding: 12px 24px;
  font-size: 14px;
}

/* Outline Button Variant */
.btn-outline,
button.btn-outline,
a.btn-outline {
  background: transparent;
  color: #063970;
  border-color: #063970;
}

.btn-outline:hover,
button.btn-outline:hover,
a.btn-outline:hover {
  background: #eff6ff;
  border-color: #0a4a8a;
}

/* Icon-only Button */
.btn-icon,
button.btn-icon {
  padding: 8px;
  width: 36px;
  height: 36px;
  justify-content: center;
}

/* Full-width Button */
.btn-block,
button.btn-block {
  width: 100%;
  display: flex;
}

/* Inline Button (small action buttons) */
.ib {
  font-size: 11px;
  font-weight: 700;
  padding: 0 7px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid #b0bed4;
  background: #eef2f9;
  color: #1e3a5f;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 2px;
  transition: background 0.15s;
  white-space: nowrap;
}

.ib:hover {
  background: #dce7f7;
  border-color: #063970;
}

/* Inline Button Variants */
.ib-view {
  border-color: #0891b2;
  background: #e0f2fe;
  color: #0369a1;
}

.ib-view:hover {
  background: #bae6fd;
}

.ib-edit {
  border-color: #d97706;
  background: #fef3c7;
  color: #92400e;
}

.ib-edit:hover {
  background: #fde68a;
}

.ib-delete,
.ib-del {
  border-color: #dc2626;
  background: #fee2e2;
  color: #991b1b;
}

.ib-delete:hover,
.ib-del:hover {
  background: #fecaca;
}

.ib-add {
  border-color: #16a34a;
  background: #d1fae5;
  color: #065f46;
}

.ib-add:hover {
  background: #a7f3d0;
}

.ib-download {
  border-color: #0891b2;
  background: #e0f2fe;
  color: #0369a1;
}

.ib-download:hover {
  background: #bae6fd;
}

/* Restore/Undo Buttons */
.ib-restore,
.ib-restore-pmt {
  border-color: #7c3aed;
  background: #ede9fe;
  color: #4c1d95;
}

.ib-restore:hover,
.ib-restore-pmt:hover {
  background: #ddd6fe;
  border-color: #6d28d9;
}

/* Reset Button */
button[type="reset"],
.btn-reset,
button.btn-reset {
  background: #f3f4f6;
  color: #374151;
  border-color: #d1d5db;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
}

button[type="reset"]:hover,
.btn-reset:hover,
button.btn-reset:hover {
  background: #e5e7eb;
  border-color: #9ca3af;
  color: #111827;
}

button[type="reset"]:active,
.btn-reset:active,
button.btn-reset:active {
  background: #d1d5db;
}

/* Tab Buttons */
.tab-btn,
button.tab-btn {
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: #666;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border-radius: 0;
}

.tab-btn:hover,
button.tab-btn:hover {
  color: #063970;
  background: rgba(6, 57, 112, 0.05);
}

.tab-btn.active,
button.tab-btn.active {
  color: #063970;
  border-bottom-color: #063970;
  background: #eff6ff;
  font-weight: 600;
}

/* ============================================
   TABLE ACTION COLUMNS FIX
   Ensure action buttons are fully visible
   ============================================ */

/* Allow action columns to expand */
td.col-actions,
td[data-label="Actions"],
th:contains("Actions") {
  width: auto !important;
  min-width: 200px;
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: unset !important;
}

/* Ensure action buttons don't wrap awkwardly */
td.col-actions .ib,
td[data-label="Actions"] .ib {
  margin-bottom: 4px;
  display: inline-flex;
}

/* Table action button rows */
.action-buttons,
.actions-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  width: 100%;
}

/* Pagination Buttons */
.pg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid #dde3ee;
  background: #fff;
  color: #374151;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.pg-btn:hover {
  background: #eef2f9;
  border-color: #063970;
  color: #063970;
}

.pg-btn.active {
  background: #063970;
  color: #fff;
  border-color: #063970;
  font-weight: 700;
}

.pg-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
  button,
  a.btn,
  .btn,
  .ph-btn,
  .btn-primary,
  .btn-secondary,
  .btn-danger {
    padding: 10px 14px;
    font-size: 12px;
  }

  .btn-block,
  button.btn-block {
    width: 100%;
  }

  .ib {
    padding: 0 6px;
    font-size: 10px;
    height: 22px;
  }
}

/* ============================================
   DARK MODE SUPPORT
   ============================================ */

@media (prefers-color-scheme: dark) {
  .btn-secondary,
  button.btn-secondary,
  a.btn-secondary {
    background: #1f2937;
    color: #e5e7eb;
    border-color: #4b5563;
  }

  .btn-secondary:hover,
  button.btn-secondary:hover {
    background: #374151;
    border-color: #3b82f6;
  }

  .btn-cancel,
  button.btn-cancel {
    background: #374151;
    color: #e5e7eb;
    border-color: #4b5563;
  }

  .btn-cancel:hover,
  button.btn-cancel:hover {
    background: #4b5563;
  }

  .tab-btn,
  button.tab-btn {
    color: #9ca3af;
  }

  .tab-btn:hover,
  button.tab-btn:hover {
    color: #3b82f6;
  }

  .pg-btn {
    background: #1f2937;
    border-color: #4b5563;
    color: #e5e7eb;
  }

  .pg-btn:hover {
    background: #374151;
  }
}

/* ============================================
   OPERATIONAL ACTION BUTTONS
   Receiving / Sorting / EAN Packing tables
   Order: History → Restore → Action → Danger
   ============================================ */

.btn-op {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: #fff;
  transition: background 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-op:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* History — grey */
.btn-op-history { background: #6b7280; }
.btn-op-history:hover:not(:disabled) { background: #4b5563; }

/* Restore — amber */
.btn-op-restore { background: #f59e0b; }
.btn-op-restore:hover:not(:disabled) { background: #d97706; }

/* Primary action (Receive / Sort / Pack) — green */
.btn-op-action { background: #16a34a; }
.btn-op-action:hover:not(:disabled) { background: #15803d; }

/* Claim — blue-grey */
.btn-op-claim { background: #0284c7; }
.btn-op-claim:hover:not(:disabled) { background: #0369a1; }

/* Danger (Wastage / Write-off) — red */
.btn-op-danger { background: #dc2626; }
.btn-op-danger:hover:not(:disabled) { background: #b91c1c; }
