/**
 * Al-Muslim Group Garments Factory Maintenance Machine ERP
 * Excel-Like Inventory Grid, Freeze Panes, Sticky Header & Inline Edit Styling
 */

.inventory-page-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 10px;
}

/* Quick Status Filter Pills (1-Click Instant Status Filters) */
.quick-pills-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0;
  align-items: center;
}

.quick-pill {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.quick-pill:hover {
  background: var(--bg-hover);
  color: #fff;
  border-color: var(--primary);
  transform: translateY(-1px);
}

.quick-pill.active {
  background: #0284c7;
  color: #ffffff;
  border-color: #38bdf8;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.4);
}

.quick-pill .pill-cnt {
  background: rgba(0, 0, 0, 0.25);
  padding: 1px 6px;
  border-radius: 9999px;
  font-size: 11px;
}

.active-filter-tag {
  transition: all 0.15s ease;
}

.active-filter-tag:hover {
  border-color: #f87171 !important;
  background: rgba(239, 68, 68, 0.15) !important;
}

/* Cascading Primary Filter Toolbar */
.filter-toolbar-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.filter-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.filter-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.filter-label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.filter-select, .filter-input {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  outline: none;
  transition: all 0.15s ease;
  width: 100%;
}

.filter-select:focus, .filter-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.filter-select option {
  background-color: var(--bg-card);
  color: var(--text-primary);
}

/* Grid Control Actions Bar */
.grid-actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

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

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

/* Bulk Selection Toolbar (Appears when items are checked) */
.bulk-toolbar {
  background: linear-gradient(90deg, #0369a1, #0284c7);
  color: #ffffff;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
}

.bulk-count-badge {
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Machine Inventory Full-Height Screen Fit (Zero Outer Page Scroll, Sticky Pinned Top Control Deck) */
.inventory-page-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  gap: 6px;
  overflow: hidden; /* Prevents outer page vertical scrollbar so toolbar stays fixed */
}

.inventory-sticky-header-panel {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  z-index: 35;
  background: var(--bg-surface, #0f172a);
}

/* Excel-Like Table Container: fills remaining height, scrolls rows inside with sticky headers */
.inventory-page-wrapper .inventory-table-scroll-container,
.excel-table-container,
.inventory-table-scroll-container {
  position: relative;
  width: 100%;
  flex: 1 1 0%;
  min-height: 250px;
  overflow-x: auto !important; /* Real native browser horizontal scrollbar always active */
  overflow-y: auto !important;   /* Vertical scrolling inside table body */
  /* contain: prevent vertical over-scroll from propagating to the parent page */
  overscroll-behavior: contain;
  /* auto: do NOT use smooth scrolling — programmatic restoreAppState must be instant */
  scroll-behavior: auto;
  -webkit-overflow-scrolling: touch;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  scrollbar-width: auto;
  scrollbar-color: #0284c7 #090e1a;
}

/* Thick, High-Contrast 16px Native Horizontal Scrollbar */
.inventory-table-scroll-container::-webkit-scrollbar,
.excel-table-container::-webkit-scrollbar {
  width: 12px;
  height: 16px; /* Thick 16px horizontal scrollbar for easy grabbing */
}

.inventory-table-scroll-container::-webkit-scrollbar-track,
.excel-table-container::-webkit-scrollbar-track {
  background: #090e1a;
  border-top: 1px solid #1e293b;
  border-radius: 4px;
}

.inventory-table-scroll-container::-webkit-scrollbar-thumb,
.excel-table-container::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #38bdf8 0%, #0284c7 100%);
  border-radius: 8px;
  border: 3px solid #090e1a;
  cursor: grab;
}

.inventory-table-scroll-container::-webkit-scrollbar-thumb:hover,
.excel-table-container::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #7dd3fc 0%, #0ea5e9 100%);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.8);
}

.inventory-table-scroll-container::-webkit-scrollbar-thumb:active,
.excel-table-container::-webkit-scrollbar-thumb:active {
  background: #38bdf8;
  cursor: grabbing;
}

.excel-grid-table {
  width: 2150px;     /* Explicit fixed table width guaranteeing horizontal scroll */
  min-width: 2150px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
  color: var(--text-primary);
  table-layout: fixed;
}

/* Screen-Fit 100% variant for Spare Parts Table */
.excel-grid-table.spare-parts-table,
.excel-grid-table.table-screen-fit {
  width: 100% !important;
  min-width: 980px !important;
  table-layout: auto !important;
}

.spare-parts-table-container {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto !important;
  overflow-x: auto !important;
  position: relative;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  scrollbar-width: auto;
  scrollbar-color: #0284c7 #090e1a;
}

.spare-parts-table-container::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.spare-parts-table-container::-webkit-scrollbar-track {
  background: #090e1a;
  border-radius: 4px;
}

.spare-parts-table-container::-webkit-scrollbar-thumb {
  background: #0284c7;
  border-radius: 6px;
}

.spare-parts-table-container::-webkit-scrollbar-thumb:hover {
  background: #38bdf8;
}

/* Screen-Fit variant for Manpower Workforce Table */
.excel-grid-table.manpower-grid-table {
  width: 100% !important;
  min-width: 1100px !important;
  table-layout: auto !important;
}

.manpower-table-scroll-container {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto !important;
  overflow-x: auto !important;
  position: relative;
  scrollbar-width: auto;
  scrollbar-color: #0284c7 #090e1a;
  overscroll-behavior: contain;
}

.manpower-table-scroll-container::-webkit-scrollbar {
  width: 10px;
  height: 12px;
}

.manpower-table-scroll-container::-webkit-scrollbar-track {
  background: #090e1a;
  border-radius: 4px;
}

.manpower-table-scroll-container::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #38bdf8 0%, #0284c7 100%);
  border-radius: 6px;
  border: 2px solid #090e1a;
}

.manpower-table-scroll-container::-webkit-scrollbar-thumb:hover {
  background: #38bdf8;
}

/* Manpower Workforce Table Enhancements */
.manpower-grid-table tbody tr.manpower-row-selected {
  background: rgba(2, 132, 199, 0.16) !important;
  box-shadow: inset 3px 0 0 #38bdf8;
}

.manpower-grid-table tbody tr {
  transition: background-color 0.15s ease;
}

.manpower-grid-table tbody tr:hover {
  background-color: rgba(56, 189, 248, 0.08) !important;
}

.manpower-bulk-bar {
  background: linear-gradient(90deg, #0b1329 0%, #111e38 100%);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: var(--radius-md, 8px);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 4px 16px rgba(2, 132, 199, 0.22);
  animation: fadeInSlideDown 0.2s ease-out;
}

@keyframes fadeInSlideDown {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}


/* Sticky Header (Frozen Top) */
.excel-grid-table thead th {
  position: sticky;
  top: 0;
  background-color: #0b1329 !important;
  color: #cbd5e1;
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid #38bdf8;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  padding: 8px 8px;
  text-align: left;
  z-index: 15;
  white-space: nowrap;
  user-select: none;
  overflow: hidden;
  text-overflow: ellipsis;
}

.excel-grid-table thead th:hover {
  background-color: #132247 !important;
}

/* Frozen Columns (Left Pinned: SL, Checkbox, Machine Name) */
.col-freeze-sl {
  position: sticky !important;
  left: 0;
  z-index: 10;
  width: 50px !important;
  min-width: 50px !important;
  max-width: 50px !important;
  text-align: center;
  background-color: #0f172a !important;
  border-right: 1px solid var(--border-color) !important;
}

.col-freeze-check {
  position: sticky !important;
  left: 50px;
  z-index: 10;
  width: 44px !important;
  min-width: 44px !important;
  max-width: 44px !important;
  text-align: center;
  background-color: #0f172a !important;
  border-right: 1px solid var(--border-color) !important;
}

.col-freeze-name {
  position: sticky !important;
  left: 94px;
  z-index: 10;
  width: 180px !important;
  min-width: 180px !important;
  max-width: 180px !important;
  background-color: #0f172a !important;
  border-right: 2px solid #38bdf8 !important;
  box-shadow: 4px 0 10px rgba(0, 0, 0, 0.55);
}

/* Frozen Headers have highest z-index (Intersection of Sticky Top + Sticky Left) */
thead th.col-freeze-sl,
thead th.col-freeze-check,
thead th.col-freeze-name {
  z-index: 30 !important;
  background-color: #070d1e !important;
}

tbody tr td.col-freeze-sl,
tbody tr td.col-freeze-check,
tbody tr td.col-freeze-name {
  background-color: var(--bg-surface) !important;
}

tbody tr:hover td.col-freeze-sl,
tbody tr:hover td.col-freeze-check,
tbody tr:hover td.col-freeze-name {
  background-color: #172554 !important;
}

tbody tr.selected td.col-freeze-sl,
tbody tr.selected td.col-freeze-check,
tbody tr.selected td.col-freeze-name {
  background-color: #1e3a8a !important;
}

/* Dynamic Admin-Configurable Frozen Table Columns */
.col-frozen-cell {
  position: sticky !important;
  background-color: #0f172a !important;
}

thead th.col-frozen-cell {
  z-index: 30 !important;
  background-color: #070d1e !important;
}

tbody tr td.col-frozen-cell {
  background-color: var(--bg-surface) !important;
}

tbody tr:hover td.col-frozen-cell {
  background-color: #172554 !important;
}

tbody tr.selected td.col-frozen-cell {
  background-color: #1e3a8a !important;
}

.col-frozen-boundary {
  border-right: 2.5px solid #38bdf8 !important;
  box-shadow: 4px 0 14px rgba(0, 0, 0, 0.65) !important;
}

/* Table Cells */
.excel-grid-table tbody td {
  border-bottom: 1px solid var(--border-light);
  border-right: 1px solid var(--border-light);
  padding: 6px 8px;
  white-space: nowrap;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
}

.excel-grid-table tbody td.col-actions-cell,
.excel-grid-table thead th.col-actions-header,
td.col-actions-cell {
  overflow: visible !important;
  text-overflow: clip !important;
  padding: 4px 6px !important;
  text-align: center !important;
}

.excel-grid-table tbody td.col-wrap-text,
.excel-grid-table thead th.col-wrap-text {
  white-space: normal !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  text-overflow: clip !important;
  overflow: visible !important;
  line-height: 1.35 !important;
}

.excel-grid-table tbody tr {
  transition: background-color 0.1s ease;
}

.excel-grid-table tbody tr:hover {
  background-color: rgba(2, 132, 199, 0.08) !important;
}

.excel-grid-table tbody tr:hover td.col-freeze-1,
.excel-grid-table tbody tr:hover td.col-freeze-2,
.excel-grid-table tbody tr:hover td.col-freeze-3,
.excel-grid-table tbody tr:hover td.col-freeze-4 {
  background-color: #172554 !important;
}

.excel-grid-table tbody tr.selected {
  background-color: rgba(2, 132, 199, 0.18) !important;
}

.excel-grid-table tbody tr.selected td.col-freeze-1,
.excel-grid-table tbody tr.selected td.col-freeze-2,
.excel-grid-table tbody tr.selected td.col-freeze-3,
.excel-grid-table tbody tr.selected td.col-freeze-4 {
  background-color: #1e3a8a !important;
}

/* Serial Number Cell Highlighting */
.serial-number-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  color: #38bdf8;
  letter-spacing: 0.5px;
  cursor: pointer;
}

.serial-number-badge:hover {
  text-decoration: underline;
}

/* Inline Editable Cell */
.editable-cell {
  position: relative;
  cursor: cell;
}

.editable-cell:hover::after {
  content: '✎';
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-muted);
}

.inline-edit-input {
  width: 100%;
  background: #0f172a;
  color: #fff;
  border: 2px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  font-size: 12px;
  outline: none;
}

/* Pagination Bar */
.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  font-size: 12.5px;
  color: var(--text-secondary);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
}

.page-btn:hover:not(:disabled) {
  background: var(--primary);
  border-color: var(--primary);
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  font-weight: bold;
}

/* Machine History & Movement Passport Styles */
.history-page-wrapper {
  animation: fadeIn 0.2s ease-in-out;
}

.history-tab-btn {
  padding: 8px 16px;
  border-radius: 6px 6px 0 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}

.history-tab-btn:hover {
  color: #fff;
  background: rgba(56, 189, 248, 0.08);
}

.history-tab-btn.active {
  color: #38bdf8;
  border-bottom: 2.5px solid #38bdf8;
  font-weight: 800;
  background: rgba(56, 189, 248, 0.12);
}

.btn-quick-serial.active {
  background: #0284c7 !important;
  color: #fff !important;
  border-color: #38bdf8 !important;
}

@media print {
  .passport-printable-area, .passport-printable-area * {
    visibility: visible !important;
  }
  .passport-printable-area {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }
}

/* ==========================================================================
   GRID & INVENTORY RESPONSIVE SYSTEM
   ========================================================================== */

@media (max-width: 768px) {
  .inventory-table-scroll-container,
  .excel-table-container,
  .spare-parts-table-container,
  .manpower-table-scroll-container {
    max-height: calc(100dvh - 210px);
    min-height: 280px;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  /* Release wide data columns on mobile so they don't consume the screen width (584px) */
  .excel-grid-table tbody td.col-frozen-cell {
    position: static !important;
    left: auto !important;
    box-shadow: none !important;
    border-right: 1px solid var(--border-color) !important;
  }

  .excel-grid-table thead th.col-frozen-cell {
    position: sticky !important;
    top: 0 !important;
    left: auto !important;
    box-shadow: none !important;
    border-right: 1px solid var(--border-color) !important;
    z-index: 20 !important;
  }

  /* Keep SL (38px) and Checkbox (38px) sticky so user always maintains row context */
  .col-freeze-sl {
    position: sticky !important;
    left: 0 !important;
    width: 38px !important;
    min-width: 38px !important;
    max-width: 38px !important;
    z-index: 25 !important;
    box-sizing: border-box !important;
    padding: 6px 2px !important;
    text-align: center !important;
    font-size: 11px !important;
  }

  .col-freeze-check {
    position: sticky !important;
    left: 38px !important;
    width: 38px !important;
    min-width: 38px !important;
    max-width: 38px !important;
    z-index: 25 !important;
    box-sizing: border-box !important;
    padding: 6px 2px !important;
    text-align: center !important;
    border-right: 2px solid #38bdf8 !important;
  }

  thead th.col-freeze-sl,
  thead th.col-freeze-check {
    top: 0 !important;
    z-index: 35 !important;
  }

  .quick-pills-bar {
    padding: 6px 0;
    gap: 5px;
    scrollbar-width: thin;
  }

  .quick-pill {
    padding: 4px 10px;
    font-size: 11px;
  }

  .filter-toolbar-card {
    padding: 10px 12px;
  }

  .filter-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
}

@media (max-width: 480px) {
  .filter-grid {
    grid-template-columns: 1fr;
  }
}




/* ==========================================================================
   EXCEL GRID & TABLE LIGHT THEME FULL COMPATIBILITY
   ========================================================================== */
body.theme-light .excel-grid-table thead th {
  background-color: #f1f5f9 !important;
  color: #0f172a !important;
  border-bottom: 2px solid #0284c7 !important;
  border-right: 1px solid #cbd5e1 !important;
}

body.theme-light .excel-grid-table thead th:hover {
  background-color: #e2e8f0 !important;
}

body.theme-light .col-freeze-sl,
body.theme-light .col-freeze-check,
body.theme-light .col-freeze-name,
body.theme-light .col-frozen-cell {
  background-color: #f8fafc !important;
  border-right-color: #cbd5e1 !important;
  color: #0f172a !important;
}

body.theme-light thead th.col-freeze-sl,
body.theme-light thead th.col-freeze-check,
body.theme-light thead th.col-freeze-name,
body.theme-light thead th.col-frozen-cell {
  background-color: #e2e8f0 !important;
  color: #0f172a !important;
}

body.theme-light tbody tr td.col-freeze-sl,
body.theme-light tbody tr td.col-freeze-check,
body.theme-light tbody tr td.col-freeze-name,
body.theme-light tbody tr td.col-frozen-cell {
  background-color: #ffffff !important;
  color: #0f172a !important;
}

body.theme-light tbody tr:hover td.col-freeze-sl,
body.theme-light tbody tr:hover td.col-freeze-check,
body.theme-light tbody tr:hover td.col-freeze-name,
body.theme-light tbody tr:hover td.col-frozen-cell {
  background-color: #f1f5f9 !important;
}

body.theme-light tbody tr.selected td.col-freeze-sl,
body.theme-light tbody tr.selected td.col-freeze-check,
body.theme-light tbody tr.selected td.col-freeze-name,
body.theme-light tbody tr.selected td.col-frozen-cell {
  background-color: #e0f2fe !important;
}

body.theme-light .col-frozen-boundary {
  border-right: 2.5px solid #0284c7 !important;
  box-shadow: 3px 0 8px rgba(0, 0, 0, 0.1) !important;
}

body.theme-light .excel-grid-table tbody td {
  border-bottom: 1px solid #e2e8f0 !important;
  border-right: 1px solid #e2e8f0 !important;
  color: #0f172a !important;
  background-color: #ffffff;
}

body.theme-light .excel-grid-table tbody tr:hover {
  background-color: rgba(2, 132, 199, 0.06) !important;
}

body.theme-light .excel-grid-table tbody tr.selected {
  background-color: rgba(2, 132, 199, 0.12) !important;
}

body.theme-light .quick-pill {
  background: #ffffff !important;
  border-color: #cbd5e1 !important;
  color: #1e293b !important;
}

body.theme-light .quick-pill:hover {
  background: #f1f5f9 !important;
  color: #0284c7 !important;
}

body.theme-light .quick-pill.active {
  background: #0284c7 !important;
  color: #ffffff !important;
}
