* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #0052CC;
  --primary-dark: #003A99;
  --primary-light: #E3F2FD;
  --secondary: #6C757D;
  --success: #28A745;
  --danger: #DC3545;
  --warning: #FFC107;
  --white: #FFFFFF;
  --light: #F8F9FA;
  --border: #DEE2E6;
  --text: #212529;
  --text-light: #6C757D;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--white);
  color: var(--text);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.screen {
  display: none;
  flex: 1;
  overflow: auto;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* Login */
.login-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: linear-gradient(135deg, #0052CC 0%, #003A99 100%);
  color: white;
}

.login-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.login-container h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  text-align: center;
}

.login-container p {
  font-size: 1rem;
  margin-bottom: 2rem;
  opacity: 0.9;
}

#login-form {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  color: var(--text);
}

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

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-row.full {
  grid-template-columns: 1fr;
}

.hint {
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-light);
  margin-top: 1rem;
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

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

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

.btn-secondary {
  background: var(--secondary);
  color: white;
}

.btn-secondary:hover {
  background: #5A6268;
}

.btn-logout {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.9rem;
}

.btn-logout:hover {
  background: var(--light);
}

#login-form .btn {
  width: 100%;
  margin-top: 1rem;
}

/* Navbar */
.navbar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
}

.logo {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--primary);
  white-space: nowrap;
}

.nav-left {
  flex: 0 0 auto;
}

.nav-center {
  flex: 1;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.nav-right {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

#user-display {
  font-size: 0.9rem;
  color: var(--text-light);
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-btn:hover,
.nav-btn.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}

/* Container */
.container {
  flex: 1;
  overflow: auto;
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* Views */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.controls {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.controls input[type="text"] {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 250px;
}

h2 {
  color: var(--primary);
  margin-bottom: 1.5rem;
  font-size: 2rem;
}

h3 {
  color: var(--text);
  margin-bottom: 1rem;
  font-size: 1.25rem;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--border);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 0.75rem 1.5rem;
  border-bottom: 3px solid transparent;
  font-weight: 500;
  transition: all 0.2s;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Tables */
.customers-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  table-layout: fixed;
}

/* Column widths */
.customers-table th:nth-child(1) { width: 16%; }  /* Name */
.customers-table th:nth-child(2) { width: 9%; }   /* Mode */
.customers-table th:nth-child(3) { width: 13%; white-space: nowrap; }  /* Phone */
.customers-table th:nth-child(4) { width: 14%; }  /* Truck Type */
.customers-table th:nth-child(5) { width: 11%; }  /* Schedule */
.customers-table th:nth-child(6) { width: 17%; }  /* Next Load */
.customers-table th:nth-child(7) { width: 20%; }  /* Actions */

.customers-table td:nth-child(3) { white-space: nowrap; }  /* Phone never wraps */

.customers-table thead {
  background: var(--light);
}

.customers-table th {
  padding: 0.75rem 0.6rem;
  text-align: left;
  font-weight: 600;
  color: var(--text);
  border-bottom: 2px solid var(--border);
}

.customers-table td {
  padding: 0.75rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

.customers-table tr:hover {
  background: var(--primary-light);
}

.action-btns {
  display: flex;
  gap: 0.5rem;
}

.action-btns button {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: white;
  border-radius: 4px;
  transition: all 0.2s;
}

.action-btns button:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Dashboard Stats */
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
}

.stat-number {
  font-size: 2.5rem;
  font-weight: bold;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.stat-label {
  color: var(--text-light);
  font-size: 0.9rem;
}

/* Lookup */
.lookup-container {
  max-width: 600px;
  margin: 0 auto;
}

#lookup-search {
  width: 100%;
  padding: 1rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 4px;
  margin-bottom: 2rem;
}

.lookup-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.lookup-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.lookup-info {
  display: grid;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
}

.lookup-info-row {
  display: flex;
  justify-content: space-between;
}

/* Week View */
#week-container {
  display: grid;
  gap: 2rem;
}

.day-section {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}

.day-header {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--primary-light);
  padding-bottom: 0.5rem;
}

.delivery-item {
  padding: 1rem;
  border-left: 4px solid var(--primary);
  background: var(--primary-light);
  margin-bottom: 0.75rem;
  border-radius: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.delivery-item.Done {
  border-left-color: var(--success);
  background: #D4EDDA;
}

.delivery-item.Canceled {
  border-left-color: var(--danger);
  background: #F8D7DA;
}

.delivery-info {
  flex: 1;
}

.delivery-customer {
  font-weight: 600;
  color: var(--text);
}

.delivery-details {
  font-size: 0.85rem;
  color: var(--text-light);
}

.delivery-status {
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
}

.delivery-status.Scheduled {
  background: var(--primary-light);
  color: var(--primary);
}

.delivery-status.Done {
  background: #D4EDDA;
  color: var(--success);
}

.delivery-status.Moved {
  background: #FFF3CD;
  color: #856404;
}

.delivery-status.Canceled {
  background: #F8D7DA;
  color: var(--danger);
}

/* Daily View */
.daily-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  gap: 1rem;
}

#daily-date-picker {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
}

/* Calendar */
.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
  background: white;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.calendar-day-header {
  text-align: center;
  font-weight: 600;
  color: var(--primary);
  padding: 0.5rem;
  border-bottom: 2px solid var(--primary-light);
}

.calendar-cell {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  padding: 0.75rem;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s;
}

.calendar-cell:hover {
  background: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.calendar-day-number {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.calendar-day-count {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 500;
}

.calendar-cell.other-month {
  background: var(--light);
  color: var(--text-light);
}

/* Settings */
.settings-section {
  margin-bottom: 3rem;
}

#holidays-list {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.holiday-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.holiday-item:last-child {
  border-bottom: none;
}

.holiday-date {
  font-weight: 600;
  color: var(--primary);
}

.stub-card {
  background: white;
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 2rem;
  text-align: center;
  margin-bottom: 1.5rem;
}

.stub-icon {
  font-size: 2rem;
  margin-bottom: 0.75rem;
}

.stub-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.stub-card p {
  color: var(--text-light);
  font-size: 0.9rem;
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: 8px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  color: var(--text);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-light);
}

.modal-close:hover {
  color: var(--text);
}

#customer-form,
#delivery-form,
#holiday-form {
  padding: 1.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  padding: 1.5rem;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

/* Print styles */
@media print {
  body {
    background: white;
  }

  .navbar,
  .view-header,
  #add-manual-delivery-btn,
  .action-btns,
  .controls {
    display: none !important;
  }

  .calendar-grid {
    page-break-inside: avoid;
    border: 1px solid black;
  }

  .modal {
    display: none !important;
  }

  @page {
    size: landscape;
    margin: 0;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .navbar {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem;
  }

  .nav-center {
    justify-content: flex-start;
    overflow-x: auto;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .dashboard-stats {
    grid-template-columns: 1fr;
  }

  .controls {
    flex-direction: column;
  }

  .controls input[type="text"] {
    width: 100%;
  }

  .customers-table {
    font-size: 0.9rem;
  }

  .customers-table th,
  .customers-table td {
    padding: 0.75rem;
  }

  .calendar-grid {
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
    padding: 0.5rem;
  }

  .calendar-cell {
    padding: 0.5rem;
    font-size: 0.8rem;
  }

  .delivery-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .delivery-status {
    margin-top: 0.5rem;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 1rem;
  }

  .login-container {
    padding: 1rem;
  }

  #login-form {
    padding: 1rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  .stat-card {
    padding: 1rem;
  }

  .stat-number {
    font-size: 2rem;
  }

  .lookup-search {
    padding: 0.75rem;
  }
}

/* ===== CALENDAR OVERRIDES ===== */
.calendar-nav {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: space-between !important;
  margin-bottom: 20px !important;
  padding: 0 4px !important;
}
.calendar-month-heading {
  font-size: 26px !important;
  font-weight: 700 !important;
  color: #1a56a0 !important;
  margin: 0 !important;
  text-align: center !important;
  flex: 1 !important;
}
.calendar-nav-btn {
  background: #1a56a0 !important;
  color: #fff !important;
  border: none !important;
  border-radius: 8px !important;
  padding: 10px 22px !important;
  font-size: 20px !important;
  cursor: pointer !important;
  flex-shrink: 0 !important;
  line-height: 1 !important;
}
.calendar-nav-btn:hover {
  background: #0f3a72 !important;
}
.calendar-cell {
  min-height: 200px !important;
  height: auto !important;
  overflow: visible !important;
  vertical-align: top !important;
}
.calendar-day-list {
  display: flex !important;
  flex-direction: column !important;
  gap: 2px !important;
  overflow: visible !important;
}
.calendar-entry {
  font-size: 11px !important;
  line-height: 1.4 !important;
  color: #1a56a0 !important;
  padding: 2px 4px !important;
  border-radius: 3px !important;
  background: #e8f0fe !important;
  word-break: break-word !important;
  white-space: normal !important;
  overflow: visible !important;
}
@media print {
  .calendar-nav-btn { display: none !important; }
  .calendar-month-heading { font-size: 18px !important; color: #000 !important; }
  .calendar-cell { min-height: 100px !important; }
  .calendar-entry { font-size: 8px !important; background: none !important; color: #000 !important; }
}

/* ===== CALENDAR FINAL FIX ===== */
#calendar-view {
  overflow-x: auto !important;
}
#calendar-container {
  min-width: 1100px !important;
  width: 100% !important;
}
.calendar-nav {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: space-between !important;
  margin-bottom: 16px !important;
  padding: 0 !important;
}
.calendar-month-heading {
  font-size: 24px !important;
  font-weight: 700 !important;
  color: #1a56a0 !important;
  margin: 0 !important;
  text-align: center !important;
  flex: 1 !important;
}
.calendar-nav-btn {
  background: #1a56a0 !important;
  color: #fff !important;
  border: none !important;
  border-radius: 8px !important;
  padding: 8px 20px !important;
  font-size: 22px !important;
  cursor: pointer !important;
  flex-shrink: 0 !important;
}
.calendar-grid {
  display: grid !important;
  grid-template-columns: repeat(7, minmax(140px, 1fr)) !important;
  gap: 4px !important;
}
.calendar-cell {
  min-height: 180px !important;
  height: auto !important;
  overflow: visible !important;
}
.calendar-entry {
  white-space: normal !important;
  word-break: break-word !important;
  overflow: visible !important;
  font-size: 11px !important;
  background: #e8f0fe !important;
  color: #1a56a0 !important;
  padding: 2px 4px !important;
  border-radius: 3px !important;
  margin-bottom: 2px !important;
  display: block !important;
}

/* ===== CALENDAR SATURDAY FIX + CELL HEIGHT ===== */
#calendar-view {
  overflow-x: scroll !important;
  -webkit-overflow-scrolling: touch !important;
}
#calendar-container {
  width: max-content !important;
  min-width: 100% !important;
}
.calendar-grid {
  grid-template-columns: repeat(7, 160px) !important;
  gap: 4px !important;
  width: max-content !important;
}
.calendar-cell {
  width: 160px !important;
  height: auto !important;
  min-height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}
.calendar-entry {
  font-size: 12px !important;
  white-space: normal !important;
  word-break: break-word !important;
  overflow: visible !important;
  background: #dbeafe !important;
  color: #1e40af !important;
  padding: 3px 5px !important;
  margin-bottom: 3px !important;
  border-radius: 3px !important;
  display: block !important;
  line-height: 1.5 !important;
}

/* ===== PRINT LAYOUT - ONE PAGE LANDSCAPE ===== */
@page {
  size: A4 landscape;
  margin: 8mm;
}
@media print {
  /* Hide everything except the calendar */
  .navbar, .view:not(#calendar-view), #calendar-view .calendar-header,
  .calendar-nav-btn, button, nav, header, footer,
  #calendar-view h1, #calendar-view .btn {
    display: none !important;
  }
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
  }
  #app {
    padding: 0 !important;
    margin: 0 !important;
  }
  #calendar-view {
    display: block !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
  }
  #calendar-container {
    width: 100% !important;
    min-width: unset !important;
  }
  .calendar-nav {
    display: flex !important;
    justify-content: center !important;
    margin-bottom: 6px !important;
  }
  .calendar-month-heading {
    font-size: 16pt !important;
    font-weight: bold !important;
    color: black !important;
    text-align: center !important;
  }
  .calendar-grid {
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    width: 100% !important;
    gap: 2px !important;
  }
  .calendar-day-header {
    font-size: 9pt !important;
    font-weight: bold !important;
    text-align: center !important;
    background: #ddd !important;
    padding: 3px !important;
    border: 0.5px solid #999 !important;
  }
  .calendar-cell {
    border: 0.5px solid #999 !important;
    padding: 3px !important;
    width: auto !important;
    min-height: 60px !important;
    height: auto !important;
    overflow: visible !important;
    page-break-inside: avoid !important;
    background: white !important;
  }
  .calendar-cell.other-month {
    background: #f5f5f5 !important;
  }
  .calendar-day-number {
    font-size: 9pt !important;
    font-weight: bold !important;
    color: black !important;
    margin-bottom: 2px !important;
  }
  .calendar-entry {
    font-size: 7pt !important;
    line-height: 1.3 !important;
    background: none !important;
    color: black !important;
    padding: 0 !important;
    margin-bottom: 1px !important;
    border-radius: 0 !important;
    display: block !important;
    white-space: normal !important;
    word-break: break-word !important;
  }
}
