/* =================================
   Global Styles & Variables
==================================== */
:root {
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --color-primary: #0a4d9c;       /* Deep Blue */
  --color-primary-dark: #083a75;
  --color-secondary: #007bff;   /* Bright Blue */
  --color-green: #10b981;
  --color-red: #ef4444;
  --color-gray-light: #f4f7fa; /* Body BG */
  --color-gray-medium: #e2e8f0; /* Borders */
  --color-gray-dark: #6b7280;   /* Light text */
  --color-text: #1f2937;      /* Main text */
  --color-white: #ffffff;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --border-radius: 0.5rem; /* 8px */
}

/* Base */
body {
  font-family: var(--font-primary);
  /* New: Subtle gradient for a cleaner look */
  background: linear-gradient(to bottom, var(--color-white) 0px, var(--color-gray-light) 300px);
  color: var(--color-text);
  margin: 0;
  line-height: 1.6;
  font-size: 16px; /* Explicitly set base */
}

h1, h2, h3, h4, h5, h6 {
  margin-top: 0;
  margin-bottom: 0.75em;
  font-weight: 700;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

/* =================================
   Layout
==================================== */
.app-container {
  max-width: 1024px;
  margin: 0 auto;
}

.app-header {
  position: sticky;
  top: 0;
  background-color: var(--color-white);
  /* New: Padding adjusted for mobile */
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-md);
  z-index: 50;
  border-bottom: 4px solid var(--color-primary);
}

.app-header h1 {
  color: var(--color-primary);
  margin: 0;
  font-size: 1.75rem;
}

.app-main {
  /* New: Padding adjusted for mobile */
  padding: 0.75rem;
}

.view {
  display: none; /* Hidden by default, JS shows the active one */
}
.view.active {
  display: block;
}

.card {
  background-color: var(--color-white);
  /* New: Padding adjusted for mobile */
  padding: 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  /* New: Transition for desktop hover */
  transition: all 0.3s ease;
}

/* New: Subtle hover effect on desktop */
@media (min-width: 769px) {
  .card:hover {
    box-shadow: var(--shadow-xl);
    transform: translateY(-3px);
  }
}

/* =================================
   Forms
==================================== */
.form-label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--color-text);
  font-size: 0.9rem; /* Smaller label */
}

.form-input {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--color-gray-medium);
  border-radius: var(--border-radius);
  box-sizing: border-box; /* Important! */
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(10, 77, 156, 0.2);
}

.form-input:disabled {
  background-color: var(--color-gray-light);
  cursor: not-allowed;
}

.form-group {
  margin-bottom: 1.25rem;
}

/* =================================
   Buttons
==================================== */
.btn {
  display: inline-block;
  font-family: var(--font-primary);
  font-size: 1rem;
  font-weight: 700;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  text-align: center;
  transition: background-color 0.2s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover {
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background-color: var(--color-primary);
  color: var(--color-white);
}
.btn-primary:hover {
  background-color: var(--color-primary-dark);
}

.btn-danger {
  background-color: var(--color-red);
  color: var(--color-white);
}
.btn-danger:hover {
  background-color: #d73737;
}

.btn-green {
  background-color: var(--color-green);
  color: var(--color-white);
}
.btn-green:hover {
  background-color: #0e9f73;
}

.btn-small {
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
}

.btn-full-width {
  display: block;
  width: 100%;
  padding-top: 1rem;
  padding-bottom: 1rem;
  font-size: 1.1rem;
}

/* =================================
   Navigation (Updated for Mobile Scroll)
==================================== */
.nav-bar {
  display: flex;
  /* Mobile: Horizontal scroll, single line */
  flex-wrap: nowrap;
  overflow-x: auto;
  justify-content: flex-start; /* Start align for scrolling */
  -webkit-overflow-scrolling: touch; /* Smooth iOS scroll */
  
  background-color: var(--color-white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  margin-bottom: 1.5rem;
  
  /* Hide Scrollbar */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE */
}
.nav-bar::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.nav-btn {
  font-family: var(--font-primary);
  background: none;
  border: none;
  padding: 0.75rem 1rem; /* Slightly larger target */
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-gray-dark);
  cursor: pointer;
  border-bottom: 4px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  
  /* Prevent wrapping/shrinking on mobile */
  flex-grow: 0;
  flex-shrink: 0;
  white-space: nowrap;
  text-align: center;
}

.nav-btn:hover {
  color: var(--color-primary);
}

.nav-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  font-weight: 700;
}

/* =================================
   Login View
==================================== */
.login-view {
  max-width: 450px;
  /* New: Adjust margin for mobile */
  margin: 2rem auto 0 auto;
}
.login-view h2 {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  color: var(--color-primary);
  margin-bottom: 2rem;
}
#login-error {
  color: var(--color-red);
  text-align: center;
  margin-top: 1rem;
  height: 1.2em;
}

/* =================================
   Worker: Sale Form
==================================== */
.page-title {
  font-size: 1.75rem;
  margin-bottom: 1.5rem;
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-gray-medium);
  padding-bottom: 0.5rem;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
  border-top: 1px solid var(--color-gray-medium);
  padding-top: 1.5rem;
}

/* Customer Search */
.customer-search-container {
  position: relative;
}
.customer-search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--color-white);
  border: 1px solid var(--color-gray-medium);
  border-top: none;
  border-radius: 0 0 var(--border-radius) var(--border-radius);
  box-shadow: var(--shadow-md);
  z-index: 10;
  max-height: 200px;
  overflow-y: auto;
}
.customer-search-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
}
.customer-search-item:hover {
  background-color: #f0f6ff;
}
#sale-customer-selected,
#crate-customer-selected-worker {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--color-green);
  margin-top: 0.5rem;
}

/* === NEW: Responsive Line Items === */
.line-items-container {
  display: grid;
  gap: 1.25rem;
  margin-bottom: 1rem;
}

.line-item {
  display: grid;
  /* New: Mobile-first 2-column grid */
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  border: 1px solid var(--color-gray-medium);
  border-radius: var(--border-radius);
  padding: 1rem;
  padding-top: 1.5rem; /* Make space for delete button */
  position: relative; /* For delete button */
}
.line-item .form-group {
  margin: 0;
}
.line-item-total {
  font-weight: 700;
  font-size: 1.1rem;
  text-align: right;
  /* New: Span 2 cols, add border */
  grid-column: span 2;
  border-top: 1px dashed var(--color-gray-medium);
  padding-top: 0.75rem;
  margin-top: 0.5rem;
}
/* New: Position the delete button */
.line-item .remove-line-item-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 2rem;
  height: 2rem;
  padding: 0;
  line-height: 1;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* New: Make "Product" span full width */
.line-item .form-group:nth-child(1) {
  grid-column: span 2;
}
/* (Qty and Unit will sit side-by-side) */
/* (Price and Crates will sit side-by-side) */

/* Sale Totals */
.sale-totals-summary {
  background: #f0f6ff;
  border: 2px solid var(--color-primary);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  margin: 1.5rem 0;
}
.sale-totals-summary h4 {
  margin: 0.5rem 0;
  font-size: 1.25rem;
  color: var(--color-text);
  /* New: Make totals stack cleanly */
  display: flex;
  justify-content: space-between;
}
.sale-totals-summary h4 span {
  font-weight: 700;
  color: var(--color-primary);
  min-width: auto; /* Remove min-width */
}

/* =================================
   Admin: Ledger (Mobile Friendly)
==================================== */

/* Sticky Header - Offset below App Header */
.ledger-sticky-header {
  position: sticky;
  /* Adjust this based on your app header height */
  top: 70px; 
  background-color: var(--color-white);
  z-index: 45; /* Below app-header(50), above content */
  padding: 10px 0;
  /* Negative margins to pull it to the edge of the padding box */
  margin: -0.75rem -0.75rem 1rem -0.75rem;
  padding-left: 0.75rem; 
  padding-right: 0.75rem;
  border-bottom: 1px solid var(--color-gray-medium);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.ledger-controls {
  display: flex;
  flex-direction: column; /* Stack on mobile */
  gap: 1rem;
  margin-bottom: 1rem;
}
.ledger-controls .form-input {
  flex-grow: 1;
}

/* Tablet+ override for controls */
@media (min-width: 768px) {
  .ledger-controls {
    flex-direction: row; 
  }
}

/* Re-introducing the Customer Card Style (From "Before") */
.customer-card {
  background: var(--color-white);
  border: 1px solid var(--color-gray-medium);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
}

.customer-card h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--color-text);
}

.customer-card .stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  background: var(--color-gray-light);
  padding: 0.75rem;
  border-radius: 6px;
  margin: 0.75rem 0;
}

.customer-card .stats-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--color-gray-dark);
  margin-bottom: 2px;
}

.customer-card .stats-value {
  font-size: 1.25rem;
  font-weight: 700;
}

/* Actions Row */
.customer-card .actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
}

/* =================================
   Admin: Dashboard & Reports
==================================== */
.dashboard-cards {
  display: grid;
  /* New: Changed to 1-col on mobile, 2-col on tablet+ */
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 2rem;
}
/* New: Container for the two charts */
.dashboard-charts-container {
  display: grid;
  grid-template-columns: 1fr; /* 1-col on mobile */
  gap: 1.5rem;
}

.summary-card {
  background: var(--color-white);
  padding: 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  border-left: 5px solid var(--color-primary);
}
.summary-card-title {
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-gray-dark);
  margin-bottom: 0.5rem;
}
.summary-card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-primary);
}
.chart-container {
  position: relative;
  height: 320px;
  width: 100%;
}
.report-list {
  /* New: Remove default list styling */
  list-style: none;
  padding: 0;
  margin: 0;
}
.report-list li {
  background: #f9fafb;
  padding: 0.75rem 1rem;
  border-radius: var(--border-radius);
  margin-bottom: 0.5rem;
}
.report-list li a {
  font-weight: 500;
}

/* =================================
   Modal
==================================== */
.modal-container {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 40, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-container.show {
  display: flex;
}
.modal-content {
  background: var(--color-white);
  /* New: Padding adjusted for mobile */
  padding: 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
.modal-close-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--color-gray-dark);
  cursor: pointer;
}
.modal-close-btn:hover {
  color: var(--color-red);
}

/* Modal: History */
.history-modal-title {
  font-size: 1.5rem; /* New: Adjusted size */
  color: var(--color-primary);
  margin-bottom: 1rem;
}
.history-entry {
  border: 1px solid var(--color-gray-medium);
  border-radius: var(--border-radius);
  margin-bottom: 1rem;
}
.history-entry-header {
  display: flex;
  /* New: Stack on mobile */
  flex-direction: column;
  align-items: flex-start;
  background: #f9fafb;
  padding: 1rem;
  border-bottom: 1px solid var(--color-gray-medium);
  gap: 0.25rem; /* New: Add gap */
}
.history-entry-header h4 {
  margin: 0;
  font-size: 1.25rem;
}
.history-entry-header span {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-gray-dark);
}
.history-entry-body {
  padding: 1rem;
}
.history-entry-body p {
  margin: 0.5rem 0;
  font-size: 1rem; /* New: Adjusted size */
}
.history-entry-body p strong {
  display: inline-block;
  min-width: 100px; /* New: Adjusted min-width */
}
.history-entry-items {
  list-style: none;
  /* New: Adjusted padding */
  padding-left: 0.5rem;
  margin-top: 1rem;
  border-top: 1px dashed var(--color-gray-medium);
  padding-top: 1rem;
}
.history-entry-items li {
  color: var(--color-gray-dark);
}


/* =================================
   Toast / Message
==================================== */
.toast-message {
  position: fixed;
  /* New: Full width on mobile */
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  padding: 1rem 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  font-size: 1.1rem;
  font-weight: 500;
  z-index: 200;
  color: var(--color-white);
  transform: translateY(200%);
  opacity: 0;
  transition: transform 0.4s ease, opacity 0.4s ease;
}
.toast-message.show {
  transform: translateY(0);
  opacity: 1;
}
.toast-message.success {
  background-color: var(--color-green);
}
.toast-message.error {
  background-color: var(--color-red);
}

/* =================================
   Action Badges (From your file)
==================================== */
.action-badge {
  padding: 0.25rem 0.6rem;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--color-white);
  /* New: Make it non-breaking */
  white-space: nowrap;
}
.action-badge.SALE { background-color: #c81e1e; }
.action-badge.DEPOSIT { background-color: #0e9f73; }
.action-badge.RETURN { background-color: #d97706; }
.action-badge.CRATE_DEPOSIT { background-color: #0a4d9c; }
.action-badge.CREATE_CUSTOMER { background-color: #5850ec; }


/* =================================
   Desktop & Tablet Media Queries
==================================== */
@media (min-width: 768px) {
  /* Restore desktop padding */
  .app-main {
    padding: 1.5rem;
  }
  .card {
    padding: 2rem;
  }
  .modal-content {
    padding: 2.5rem;
  }

  /* Header */
  .app-header h1 {
    font-size: 1.75rem;
  }

  /* Navigation: Restore Centered Layout on Desktop */
  .nav-bar {
    flex-wrap: wrap; /* Back to wrapping */
    overflow-x: visible;
    justify-content: center;
  }

  .nav-btn {
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
    flex-grow: 0; /* Let buttons be their natural width */
  }

  /* Login */
  .login-view {
    margin-top: 5rem;
  }
  
  /* Sale Form: Go back to 7-col grid */
  .line-item {
    grid-template-columns: 3fr 1fr 1fr 1fr 1fr 1.5fr auto;
    align-items: end;
    padding: 1rem;
    position: static;
  }
  .line-item .form-group:nth-child(1) {
    grid-column: auto;
  }
  .line-item .remove-line-item-btn {
    position: static;
    width: auto;
    height: auto;
    padding: 0.4rem 0.8rem; /* btn-small */
  }
  .line-item-total {
    grid-column: auto;
    border-top: none;
    padding-top: 0;
    padding-bottom: 0.75rem; /* Align with inputs */
    margin-top: 0;
    font-size: 1.1rem;
  }
  
  /* Sale Totals */
  .sale-totals-summary h4 {
    display: block; /* Stack again */
    text-align: right;
  }
  .sale-totals-summary h4 span {
    display: inline-block;
    min-width: 120px;
  }
  
  /* Ledger Controls */
  .ledger-controls {
    flex-direction: row; /* Side-by-side */
  }

  /* Dashboard */
  .dashboard-cards {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); /* Use your good responsive grid */
  }
  .dashboard-charts-container {
    grid-template-columns: 1fr 1fr; /* 2-col on desktop */
  }

  /* History Modal */
  .history-modal-title {
    font-size: 1.75rem;
  }
  .history-entry-header {
    flex-direction: row; /* Side-by-side */
    align-items: center;
    justify-content: space-between;
  }
  .history-entry-body p {
    font-size: 1.1rem;
  }
  .history-entry-body p strong {
    min-width: 120px;
  }
  .history-entry-items {
    padding-left: 1.5rem;
  }

  /* Toast: Move to corner */
  .toast-message {
    bottom: 1.5rem;
    right: 1.5rem;
    left: auto;
    width: auto; /* Let content define width */
    max-width: 400px;
  }
}
/* Toggle Switch */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--color-primary); }
input:checked + .slider:before { transform: translateX(20px); }

