/* ============================================
   CRITICAL RESPONSIVE FIXES FOR MACHINES LIST
   ============================================ */

/* Remove the min-width constraint that causes overflow */
.grid.min-w-max {
  min-width: 0 !important;
  width: 100%;
}

/* Ensure parent containers allow proper responsive behavior */
.flex.flex-auto.overflow-auto {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.flex.flex-auto.flex-col {
  min-width: 0;
}

/* ============================================
   INVENTORY GRID - BASE LAYOUT
   ============================================ */

.inventory-grid {
  display: grid;
  align-items: center;
  width: 100%;
  padding: 12px 16px;
  gap: 12px;
}

/* Desktop - All 10 columns visible */
@media (min-width: 1400px) {
  .inventory-grid {
    grid-template-columns: 
      60px      /* 1. ID */
      140px     /* 2. Machine ID */
      180px     /* 3. Model */
      140px     /* 4. Type */
      180px     /* 5. Client */
      180px     /* 6. Branch */
      150px     /* 7. Operation */
      150px     /* 8. Connection */
      150px     /* 9. Password */
      200px;    /* 10. Actions */
  }
}

/* Large Laptop (1024px - 1399px) */
@media (min-width: 1024px) and (max-width: 1399px) {
  .inventory-grid {
    grid-template-columns: 
      50px      /* 1. ID */
      120px     /* 2. Machine ID */
      150px     /* 3. Model */
      110px     /* 4. Type */
      140px     /* 5. Client */
      140px     /* 6. Branch */
      130px     /* 7. Operation */
      130px     /* 8. Connection */
      120px     /* 9. Password */
      170px;    /* 10. Actions */
  }
}

/* Tablet Landscape (768px - 1023px) - Hide Type, Connection, Password */
@media (min-width: 768px) and (max-width: 1023px) {
  .inventory-grid {
    grid-template-columns: 
      50px            /* 1. ID */
      120px           /* 2. Machine ID */
      150px           /* 3. Model */
      minmax(120px, 1fr)  /* 5. Client */
      130px           /* 6. Branch */
      120px           /* 7. Operation */
      160px;          /* 10. Actions */
  }
  
  /* Hide Type (column 4) */
  .inventory-grid > div:nth-child(4),
  .inventory-grid > div:nth-child(8),
  .inventory-grid > div:nth-child(9) {
    display: none !important;
  }
}

/* Tablet Portrait (576px - 767px) - Show ID, Machine ID, Model, Actions */
@media (min-width: 576px) and (max-width: 767px) {
  .inventory-grid {
    grid-template-columns: 
      45px                    /* 1. ID */
      minmax(100px, 1fr)      /* 2. Machine ID */
      140px                   /* 3. Model */
      180px;                  /* 10. Actions */
    padding: 10px 12px;
  }
  
  /* Hide columns 4-9 */
  .inventory-grid > div:nth-child(4),
  .inventory-grid > div:nth-child(5),
  .inventory-grid > div:nth-child(6),
  .inventory-grid > div:nth-child(7),
  .inventory-grid > div:nth-child(8),
  .inventory-grid > div:nth-child(9) {
    display: none !important;
  }
  
  /* Adjust action buttons */
  .inventory-grid .flex.gap-2 {
    flex-direction: row;
    gap: 6px;
  }
  
  .inventory-grid button {
    padding: 4px 8px;
    font-size: 12px;
    min-height: 32px;
  }
}

/* Mobile (< 576px) - Show only ID, Machine ID, Actions */
@media (max-width: 575px) {
  .inventory-grid {
    grid-template-columns: 
      40px                    /* 1. ID */
      minmax(80px, 1fr)       /* 2. Machine ID */
      130px;                  /* 10. Actions */
    padding: 8px 8px;
    gap: 8px;
    font-size: 12px;
  }
  
  /* Hide columns 3-9 */
  .inventory-grid > div:nth-child(3),
  .inventory-grid > div:nth-child(4),
  .inventory-grid > div:nth-child(5),
  .inventory-grid > div:nth-child(6),
  .inventory-grid > div:nth-child(7),
  .inventory-grid > div:nth-child(8),
  .inventory-grid > div:nth-child(9) {
    display: none !important;
  }
  
  /* Stack action buttons vertically */
  .inventory-grid .flex.gap-2 {
    flex-direction: column;
    gap: 6px;
    width: 100%;
  }
  
  .inventory-grid button {
    width: 100%;
    font-size: 11px;
    padding: 6px 4px;
    min-height: 36px;
    min-width: auto !important;
  }
  
  .inventory-grid button mat-icon {
    font-size: 16px;
    width: 16px;
    height: 16px;
  }
}

/* ============================================
   HEADER ROW SPECIFIC STYLING
   ============================================ */

.inventory-grid.text-secondary {
  background: #f9fafb;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 10;
}

.dark .inventory-grid.text-secondary {
  background: rgba(0, 0, 0, 0.05);
  border-bottom-color: rgba(255, 255, 255, 0.1);
}

@media (max-width: 575px) {
  .inventory-grid.text-secondary {
    font-size: 10px;
    padding: 8px 8px;
  }
}

/* ============================================
   DATA ROW STYLING
   ============================================ */

.inventory-grid:not(.text-secondary) {
  transition: background-color 0.2s ease;
  border-bottom: 1px solid #e5e7eb;
}

.inventory-grid:not(.text-secondary):hover {
  background-color: #f3f4f6;
}

.dark .inventory-grid:not(.text-secondary):hover {
  background-color: rgba(255, 255, 255, 0.05);
}

/* Text overflow handling */
.inventory-grid > div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Actions column should wrap on mobile */
.inventory-grid > div:last-child {
  white-space: normal;
}

/* ============================================
   HEADER SECTION (Top bar with search & add button)
   ============================================ */

.relative.flex.flex-0.flex-col.border-b {
  padding: 16px;
}

@media (max-width: 767px) {
  .relative.flex.flex-0.flex-col.border-b {
    padding: 16px 12px;
  }
  
  .text-4xl.font-extrabold.tracking-tight {
    font-size: 1.875rem;
    line-height: 2.25rem;
  }
  
  /* Search and button container */
  .mt-6.flex.shrink-0.items-center {
    flex-direction: column;
    align-items: stretch !important;
    width: 100%;
    margin-top: 16px !important;
    gap: 12px;
  }
  
  /* Search field takes full width */
  mat-form-field.fuse-mat-dense.fuse-mat-rounded.min-w-64 {
    min-width: 0 !important;
    width: 100%;
  }
  
  /* Add button takes full width */
  .mt-6.flex.shrink-0.items-center > button.ml-4 {
    margin-left: 0 !important;
    width: 100%;
    min-height: 48px;
  }
}

@media (max-width: 575px) {
  .relative.flex.flex-0.flex-col.border-b {
    padding: 12px 8px;
  }
  
  .text-4xl.font-extrabold.tracking-tight {
    font-size: 1.5rem;
    line-height: 2rem;
  }
}

/* ============================================
   EXPANDED FORM (Create/Edit Form)
   ============================================ */

/* Form container */
.overflow-hidden.shadow-lg {
  margin: 0;
  border-radius: 0;
}

/* Form fields container */
.flex.flex-col.p-8.sm\:flex-row {
  padding: 24px;
}

@media (max-width: 767px) {
  .flex.flex-col.p-8.sm\:flex-row {
    padding: 16px;
  }
  
  /* Make all form fields full width */
  .mat-form-field.w-full.sm\:w-1\/2 {
    width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-bottom: 12px;
  }
  
  .mat-form-field.w-full.sm\:w-1\/2.pr-2,
  .mat-form-field.w-full.sm\:w-1\/2.pl-2 {
    padding: 0 !important;
  }
}

/* ============================================
   FORM FOOTER BUTTONS (Delete/Create/Update)
   ============================================ */

.flex.w-full.items-center.justify-between.border-t {
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  border-top: 1px solid #e5e7eb;
}

/* Delete button */
.flex.w-full.items-center.justify-between.border-t > button.-ml-4 {
  margin-left: 0 !important;
  min-height: 40px;
}

/* Right side container (flash message + action button) */
.flex.w-full.items-center.justify-between.border-t > .flex.items-center {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

/* Create/Update button */
.flex.w-full.items-center.justify-between.border-t button[color="primary"] {
  min-height: 40px;
  padding: 0 24px;
}

@media (max-width: 767px) {
  .flex.w-full.items-center.justify-between.border-t {
    flex-direction: column;
    align-items: stretch !important;
    padding: 16px;
    gap: 12px;
  }
  
  /* Delete button full width */
  .flex.w-full.items-center.justify-between.border-t > button.-ml-4 {
    width: 100%;
    order: 2;
    min-height: 48px;
  }
  
  /* Empty div placeholder - hide on mobile */
  .flex.w-full.items-center.justify-between.border-t > div:empty {
    display: none;
  }
  
  /* Right side container full width */
  .flex.w-full.items-center.justify-between.border-t > .flex.items-center {
    width: 100%;
    order: 1;
    flex-direction: column;
    gap: 12px;
  }
  
  /* Flash message centered */
  .flex.w-full.items-center.justify-between.border-t .mr-4.flex.items-center {
    margin-right: 0 !important;
    width: 100%;
    justify-content: center;
  }
  
  /* Create/Update button full width */
  .flex.w-full.items-center.justify-between.border-t button[color="primary"] {
    width: 100%;
    min-height: 48px;
    font-size: 15px;
  }
}

@media (max-width: 575px) {
  .flex.w-full.items-center.justify-between.border-t {
    padding: 12px 8px;
  }
  
  .flex.w-full.items-center.justify-between.border-t button {
    min-height: 52px;
    font-size: 14px;
  }
}

/* ============================================
   FLASH MESSAGES
   ============================================ */

.mr-4.flex.items-center {
  transition: opacity 0.3s ease;
}

.mr-4.flex.items-center mat-icon {
  margin-right: 8px;
}

@media (max-width: 575px) {
  .mr-4.flex.items-center {
    font-size: 13px;
  }
}

/* ============================================
   PAGINATOR
   ============================================ */

mat-paginator {
  border-top: 1px solid #e5e7eb;
}

@media (max-width: 767px) {
  mat-paginator {
    font-size: 12px;
  }
  
  .mat-mdc-paginator-container {
    padding: 8px !important;
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .mat-mdc-paginator-page-size {
    margin: 0 !important;
  }
}

/* ============================================
   PASSWORD FIELD WITH TOGGLE
   ============================================ */

.flex.items-center.gap-1 {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 100px;
}

.flex.items-center.gap-1 button {
  padding: 4px;
  min-width: auto;
}

@media (max-width: 767px) {
  .flex.items-center.gap-1 button mat-icon {
    font-size: 18px;
  }
}

/* ============================================
   STATUS BADGES & INDICATORS
   ============================================ */

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
}

.status-badge.active {
  background-color: #dcfce7;
  color: #166534;
}

.status-badge.inactive {
  background-color: #fee2e2;
  color: #991b1b;
}

.status-badge.maintenance {
  background-color: #fef3c7;
  color: #92400e;
}

/* ============================================
   MATERIAL FORM FIELD OVERRIDES
   ============================================ */

.mat-mdc-form-field {
  width: 100%;
}

::ng-deep .mat-mdc-form-field-subscript-wrapper {
  margin-top: 4px;
}

::ng-deep .mat-mdc-form-field-appearance-outline .mat-mdc-form-field-outline {
  border-radius: 8px;
}

/* ============================================
   EMPTY STATE
   ============================================ */

.border-t.p-8.text-center {
  padding: 48px 24px;
}

@media (max-width: 575px) {
  .border-t.p-8.text-center {
    padding: 32px 16px;
    font-size: 1.5rem;
  }
}

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

.dark .flex.border-b {
  border-color: rgba(255, 255, 255, 0.1);
}

.dark .border-b {
  border-color: rgba(255, 255, 255, 0.1);
}

.dark .border-t {
  border-color: rgba(255, 255, 255, 0.1);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

@media (max-width: 767px) {
  .sm\:absolute {
    position: relative !important;
  }
  
  .sm\:inset-0 {
    inset: auto !important;
  }
}

/* Smooth transitions */
button {
  transition: all 0.2s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

/* Focus states for accessibility */
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  .inventory-grid {
    grid-template-columns: auto auto auto auto auto auto auto auto auto auto;
    font-size: 10px;
    padding: 4px;
  }
  
  .inventory-grid button {
    display: none;
  }
  
  mat-paginator {
    display: none;
  }
}