/* Inventory Management Styles */

/* Summary Cards */
.inventory-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.inventory-summary-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,.04);
}

.inventory-summary-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
  border-color: var(--primary);
}

.inventory-summary-card .card-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  margin: 0;
}

.inventory-summary-card .card-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.inventory-summary-card.primary .card-value {
  color: var(--primary);
}

.inventory-summary-card.danger .card-value {
  color: var(--danger);
}

.inventory-summary-card.warning .card-value {
  color: #d97706;
}

/* Toolbar Improvements */
.toolbar .filter-select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.875rem;
  min-width: 140px;
}

.toolbar .filter-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  color: var(--muted);
  margin: 0;
  white-space: nowrap;
}

.toolbar .filter-checkbox input[type="checkbox"] {
  margin: 0;
  width: auto;
}

/* Inventory Table */
.inventory-table .row {
  display: grid;
  grid-template-columns: 
    minmax(100px, 0.8fr)  /* Item Code */
    minmax(200px, 1.8fr)  /* Name */
    minmax(120px, 1fr)    /* Category */
    minmax(80px, 0.7fr)   /* On Hand */
    minmax(80px, 0.7fr)   /* Available */
    minmax(100px, 0.8fr)  /* Unit Cost */
    minmax(120px, 1fr)    /* Total Value */
    minmax(80px, 0.7fr)   /* Status */
    minmax(180px, 1.2fr); /* Actions */
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.inventory-table .row:last-child {
  border-bottom: none;
}

.inventory-table .row.header {
  background: rgba(127,127,127,.08);
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.inventory-table .row:not(.header):hover {
  background: rgba(47,111,237,.04);
  cursor: pointer;
}

/* Item Details */
.inventory-item-code {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary);
}

.inventory-item-name {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.inventory-item-description {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

.inventory-category {
  display: inline-flex;
  padding: 4px 8px;
  background: rgba(127,127,127,.12);
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

/* Stock Status */
.stock-level {
  font-weight: 600;
  font-size: 0.9rem;
}

.stock-level.low {
  color: var(--danger);
}

.stock-level.normal {
  color: var(--text);
}

.stock-level.good {
  color: #059669;
}

/* Currency and Numbers */
.currency {
  font-family: 'SF Mono', Monaco, monospace;
  font-weight: 600;
  font-size: 0.9rem;
}

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  gap: 4px;
}

.status-badge.in-stock {
  background: #dcfce7;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.status-badge.low-stock {
  background: #fef3c7;
  color: #d97706;
  border: 1px solid #fde68a;
}

.status-badge.out-of-stock {
  background: #fee2e2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.status-badge.reorder {
  background: #dbeafe;
  color: #2563eb;
  border: 1px solid #bfdbfe;
}

.status-badge.discontinued {
  background: #e5e7eb;
  color: #374151;
  border: 1px solid #d1d5db;
}

/* Action Buttons */
.inventory-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.inventory-actions .btn {
  padding: 6px 10px;
  font-size: 0.75rem;
  border-radius: 6px;
  font-weight: 500;
  position: relative;
  z-index: 2;
  touch-action: manipulation;
}

.inventory-actions .btn.btn-sm {
  padding: 4px 8px;
  font-size: 0.7rem;
}

/* Empty State */
.inventory-table .empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

.inventory-table .empty-state h3 {
  margin: 0 0 8px 0;
  color: var(--text);
  font-weight: 600;
}

/* Responsive Design */
@media (max-width: 1200px) {
  .inventory-table .row {
    grid-template-columns: 
      minmax(80px, 0.7fr)   /* Item Code */
      minmax(180px, 1.5fr)  /* Name */
      minmax(100px, 0.8fr)  /* Category */
      minmax(70px, 0.6fr)   /* On Hand */
      minmax(70px, 0.6fr)   /* Available */
      minmax(90px, 0.7fr)   /* Unit Cost */
      minmax(100px, 0.8fr)  /* Total Value */
      minmax(70px, 0.6fr)   /* Status */
      minmax(160px, 1fr);   /* Actions */
  }
}

@media (max-width: 900px) {
  .inventory-table .row {
    grid-template-columns:
      minmax(120px, 1fr)
      minmax(80px, 0.8fr)
      minmax(100px, 0.9fr)
      minmax(80px, 0.8fr)
      minmax(140px, 1fr);
  }
  
  /* Hide some columns on mobile */
  .inventory-table .row > div:nth-child(3), /* Category */
  .inventory-table .row > div:nth-child(5), /* Available */
  .inventory-table .row > div:nth-child(6)  /* Unit Cost */ {
    display: none;
  }
}

@media (max-width: 640px) {
  .inventory-summary-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  #inventoryTab .toolbar {
    align-items: stretch;
  }

  #inventoryTab .toolbar > * {
    min-width: 0;
  }

  #inventoryTab .toolbar .btn,
  #inventoryTab .toolbar .filter-select,
  #inventoryTab .toolbar input[type="text"] {
    width: 100%;
  }

  .inventory-table {
    border: none;
    background: transparent;
    box-shadow: none;
  }

  .inventory-table .row.header {
    display: none;
  }

  .inventory-table .row {
    grid-template-columns: 1fr;
    gap: 10px;
    align-items: stretch;
    margin-bottom: 12px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--card);
    box-shadow: 0 4px 12px rgba(0,0,0,.05);
  }

  .inventory-table .row > div {
    display: block !important;
    min-width: 0;
  }

  .inventory-table .row > div:nth-child(3),
  .inventory-table .row > div:nth-child(5),
  .inventory-table .row > div:nth-child(6) {
    display: block !important;
  }

  .inventory-item-code,
  .inventory-item-name,
  .currency,
  .stock-level,
  .status-badge {
    display: inline-flex;
  }

  .inventory-actions {
    justify-content: stretch;
    flex-wrap: wrap;
    gap: 8px;
  }

  .inventory-actions .btn {
    flex: 1 1 calc(33.333% - 8px);
    min-height: 40px;
    text-align: center;
    justify-content: center;
  }

  #inventoryItemModal .grid2,
  #stockMovementModal .grid2,
  #inventoryReorderModal .grid2 {
    grid-template-columns: 1fr;
  }

  #inventoryItemModal .grid2 > div,
  #stockMovementModal .grid2 > div,
  #inventoryReorderModal .grid2 > div {
    grid-column: auto !important;
  }

  #inventoryReorderModal .modal-content,
  #inventoryPurchaseOrdersModal .modal-content {
    width: min(96vw, 96vw);
    max-height: calc(100vh - 20px);
    overflow-y: auto;
    padding: 16px;
  }

  #inventoryReorderList .row,
  #inventoryPurchaseOrdersList .row,
  #inventoryPurchaseOrderDetail .row {
    grid-template-columns: 1fr !important;
    align-items: stretch;
  }

  #inventoryReorderList .row > div,
  #inventoryPurchaseOrdersList .row > div,
  #inventoryPurchaseOrderDetail .row > div {
    width: 100%;
  }

  .inventory-reorder-qty {
    min-height: 42px;
  }

  #inventoryReorderModal .row.end.gap,
  #inventoryPurchaseOrderDetail .row.end.gap {
    flex-direction: column;
    align-items: stretch;
  }

  #inventoryReorderModal .row.end.gap .btn,
  #inventoryPurchaseOrderDetail .row.end.gap .btn {
    width: 100%;
  }
}

/* Loading State */
.inventory-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--muted);
  font-size: 0.9rem;
}

.inventory-loading::before {
  content: "";
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top: 2px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 12px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
