@media (max-width: 1199px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }
}

/* Mobile Tabs (Hidden on Desktop) */
.mobile-tabs {
  display: none;
}
.mobile-tab-content {
  display: block; /* Always show content on desktop */
}

@media (max-width: 767px) {
  /* Global Sizing */
  :root {
    --text-main: 14px;
    --text-small: 12px;
  }
  
  body {
    font-size: var(--text-main);
  }

  .app-header,
  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .user-chip {
    align-items: flex-start;
  }

  .app-main,
  .app-header,
  .app-nav {
    padding-left: 12px;
    padding-right: 12px;
  }

  .form-grid,
  .chart-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  /* Smaller buttons and inputs on mobile */
  .btn {
    padding: 6px 12px;
    font-size: 13px;
  }
  
  .form-field input,
  .form-field select,
  .form-field textarea {
    padding: 6px 10px;
    font-size: 14px;
  }

  /* Compact Line Item Grid */
  .line-item-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fdfdfd;
  }
  
  /* Material and Supplier take full width */
  .line-item-row > .form-field:nth-child(1),
  .line-item-row > .form-field:nth-child(2) {
    grid-column: 1 / -1;
  }
  /* Remove line item actions to bottom full width */
  .line-item-row > .form-field:last-child {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
  }

  /* CSS-based Table Cards */
  .datagrid table, 
  .datagrid thead, 
  .datagrid tbody, 
  .datagrid th, 
  .datagrid td, 
  .datagrid tr { 
    display: block; 
  }
  
  .datagrid thead tr { 
    position: absolute;
    top: -9999px;
    left: -9999px;
  }
  
  .datagrid tr { 
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 8px;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
  }
  
  .datagrid td { 
    border: none;
    border-bottom: 1px solid #f0f0f0; 
    position: relative;
    padding-left: 50% !important; 
    text-align: right !important;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }
  
  .datagrid td:before { 
    position: absolute;
    top: 50%;
    left: 8px;
    transform: translateY(-50%);
    width: 45%; 
    padding-right: 10px; 
    white-space: nowrap;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    content: attr(data-label);
  }

  .datagrid td:last-child {
    border-bottom: 0;
  }

  /* Responsive Tabs UI */
  .mobile-tabs {
    display: flex;
    overflow-x: auto;
    border-bottom: 2px solid var(--line);
    margin-bottom: 16px;
    scrollbar-width: none;
  }
  .mobile-tabs::-webkit-scrollbar {
    display: none;
  }
  .mobile-tab-btn {
    background: none;
    border: none;
    padding: 10px 16px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
  }
  .mobile-tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
  }
  .mobile-tab-content {
    display: none;
  }
  .mobile-tab-content.active {
    display: block;
  }
}
