* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f2f6fb;
  color: #1f2937;
  line-height: 1.5;
}

header {
  background: #0f4c81;
  color: white;
  padding: 20px 16px;
  text-align: center;
}

header h1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

header nav {
  margin-top: 10px;
}

.nav-link {
  color: white;
  text-decoration: none;
  font-weight: 500;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  transition: background-color 0.2s;
}

.role-indicator {
  display: inline-block;
  margin-right: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Role and PIN Modals */
#role-modal,
#pin-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.role-modal-content,
.pin-modal-content {
  background: white;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  max-width: 400px;
  width: 90%;
  text-align: center;
}

.role-modal-content h2,
.pin-modal-content h2 {
  margin-top: 0;
  color: #0f4c81;
  font-size: 1.5rem;
}

.role-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
}

.role-btn {
  padding: 12px 16px;
  border: 2px solid #0f4c81;
  background: white;
  color: #0f4c81;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  font-size: 1rem;
}

.role-btn:hover {
  background: #0f4c81;
  color: white;
}

.pin-modal-content p {
  margin: 12px 0;
  font-size: 0.95rem;
}

#pin-role-label {
  font-weight: 600;
  color: #0f4c81;
  margin-bottom: 16px;
}

#pin-input {
  width: 100%;
  padding: 12px;
  font-size: 1.5rem;
  text-align: center;
  letter-spacing: 8px;
  border: 2px solid #e2e8f0;
  border-radius: 6px;
  margin: 16px 0;
  font-family: monospace;
}

#pin-input:focus {
  outline: none;
  border-color: #0f4c81;
}

#pin-submit-btn,
#pin-cancel-btn {
  padding: 10px 20px;
  margin: 8px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

#pin-submit-btn {
  background: #047857;
  color: white;
}

#pin-submit-btn:hover {
  background: #065f46;
}

#pin-cancel-btn {
  background: #e5e7eb;
  color: #1f2937;
}

#pin-cancel-btn:hover {
  background: #d1d5db;
}

@media (max-width: 600px) {
  .role-buttons {
    grid-template-columns: 1fr;
  }
}



.panel {
  background: white;
  margin: 16px auto;
  padding: 20px;
  border-radius: 12px;
  max-width: 800px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.panel h2 {
  margin-top: 0;
  font-size: 1.25rem;
  color: #0f4c81;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 600px) {
  .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.95rem;
  font-weight: 500;
}

input,
select {
  margin-top: 6px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s;
}

input:focus,
select:focus {
  outline: none;
  border-color: #0f4c81;
}

.actions {
  margin-top: 24px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

button {
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 500;
  transition: background-color 0.2s;
  flex: 1;
  min-width: 120px;
}

@media (min-width: 600px) {
  .actions {
    justify-content: flex-start;
  }

  button {
    flex: none;
  }
}

button#save-button {
  background: #0f4c81;
  color: white;
}

button#save-button:hover {
  background: #0a3d6a;
}

button#clear-button {
  background: #e2e8f0;
  color: #374151;
}

button#clear-button:hover {
  background: #cbd5e1;
}

.table-container {
  overflow-x: auto;
}

.mobile-only {
  display: none;
}

.desktop-only {
  display: block;
}

.mobile-trip-list {
  display: none;
}

.mobile-trip-card {
  border: 1px solid #dbe4f0;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.mobile-trip-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.mobile-trip-truck {
  font-size: 1rem;
  font-weight: 700;
}

.mobile-trip-grid {
  display: grid;
  gap: 6px;
  font-size: 0.86rem;
  color: #334155;
}

.mobile-trip-actions {
  margin-top: 10px;
}

@media (max-width: 768px) {
  .table-container {
    font-size: 0.75rem;
  }

  th,
  td {
    padding: 6px 4px;
    white-space: nowrap;
  }

  .weight-inputs {
    flex-direction: column;
    gap: 2px;
  }

  .weight-input,
  .weight-operator-select,
  .weight-operator-other {
    font-size: 0.75rem;
    padding: 3px 4px;
  }

  .save-weight-btn {
    padding: 3px 6px;
    font-size: 0.7rem;
  }

  .action-buttons {
    flex-direction: column;
  }

  .action-btn {
    width: 100%;
    margin-bottom: 1px;
    font-size: 0.7rem;
    padding: 3px 4px;
  }
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: 0.9rem;
}

thead {
  background: #0f4c81;
  color: white;
}

th,
td {
  padding: 12px 8px;
  border: 1px solid #e2e8f0;
  text-align: left;
}

th {
  font-weight: 600;
}

tr:nth-child(even) {
  background: #f8fafc;
}

.status-badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
}

.status-cell {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  max-width: 220px;
}

.cancel-reason-text {
  font-size: 0.75rem;
  color: #991b1b;
  background: #fef2f2;
  border-radius: 4px;
  padding: 2px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.status-in_gate {
  background: #e5e7eb;
  color: #374151;
}

.status-in-gate {
  background: #e5e7eb;
  color: #374151;
}

.status-at-dispatch,
.status-at_dispatch {
  background: #dbeafe;
  color: #1e40af;
}

.status-waiting {
  background: #ede9fe;
  color: #5b21b6;
}

.status-sent-for-tare-weight {
  background: #e0f2fe;
  color: #075985;
}

.status-tare-weight-done,
.status-tare_weight_done {
  background: #fef3c7;
  color: #92400e;
}

.status-ready-for-loading {
  background: #cffafe;
  color: #155e75;
}

.status-loading-in-progress,
.status-loading_in_progress {
  background: #fed7aa;
  color: #9a3412;
}

.status-loading-completed {
  background: #fde68a;
  color: #92400e;
}

.status-loaded {
  background: #fde68a;
  color: #92400e;
}

.status-gross-weight-pending {
  background: #ede9fe;
  color: #6d28d9;
}

.status-gross-weight-done,
.status-gross_weight_done {
  background: #d1fae5;
  color: #065f46;
}

.status-billing-pending {
  background: #f3e8ff;
  color: #7e22ce;
}

.status-billing-completed {
  background: #e9d5ff;
  color: #6b21a8;
}

.status-completed {
  background: #d1fae5;
  color: #065f46;
}

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

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

/* Delayed truck highlighting */
.truck-delayed-warning {
  background-color: #fefce8; /* Light yellow */
}

.truck-delayed-critical {
  background-color: #fef2f2; /* Light red */
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

@media (max-width: 768px) {
  .action-buttons {
    flex-direction: column;
  }

  .action-btn {
    width: 100%;
    margin-bottom: 2px;
  }
}

.action-btn {
  padding: 4px 8px;
  border: none;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  background: #e5e7eb;
  color: #374151;
  transition: background-color 0.2s;
}

.action-btn:hover {
  background: #d1d5db;
}

.status-action-select {
  min-width: 150px;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.82rem;
  background: #ffffff;
}

.status-action-select:disabled {
  background: #f3f4f6;
  color: #6b7280;
  cursor: not-allowed;
}

.weight-inputs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: stretch;
}

.weight-readonly {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mini-muted {
  font-size: 0.76rem;
  color: #6b7280;
}

.workflow-details {
  margin-bottom: 6px;
  font-size: 0.78rem;
  color: #334155;
  display: grid;
  gap: 2px;
}

.workflow-container {
  min-width: 220px;
  display: grid;
  gap: 6px;
}

.workflow-group {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.workflow-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.workflow-btn {
  flex: 0 0 auto;
  min-width: 120px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1f2937;
  font-size: 0.78rem;
}

.workflow-btn.primary {
  background: #0f4c81;
  color: white;
  border-color: #0f4c81;
}

.workflow-btn.danger {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fecaca;
}

.workflow-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.dispatch-editor {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}

.dispatch-editor label {
  font-size: 0.8rem;
  font-weight: 600;
  gap: 4px;
}

.dispatch-input,
.dispatch-other-input {
  margin-top: 4px;
  padding: 6px 8px;
  font-size: 0.8rem;
  border-radius: 6px;
}

.reason-chip {
  font-size: 0.72rem;
  background: #f8fafc;
  border: 1px solid #dbeafe;
  border-radius: 6px;
  padding: 3px 6px;
  color: #334155;
}

.reason-chip-error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.weight-input {
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.85rem;
  width: 100%;
  box-sizing: border-box;
}

.weight-input.net-weight {
  background: #f8fafc;
  color: #374151;
}

.weight-operator-select,
.weight-operator-other {
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.85rem;
  width: 100%;
  box-sizing: border-box;
}

.save-weight-btn {
  padding: 6px 12px;
  background: #059669;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  margin-top: 4px;
  transition: background-color 0.2s;
}

.save-weight-btn:hover {
  background: #047857;
}

@media (max-width: 768px) {
  .weight-inputs {
    flex-direction: column;
  }

  .weight-input,
  .weight-operator-select,
  .weight-operator-other {
    font-size: 0.8rem;
    padding: 4px 6px;
  }

  .save-weight-btn {
    padding: 4px 8px;
    font-size: 0.75rem;
  }
}

.filters {
  margin-bottom: 16px;
  padding: 16px;
  background: #f8fafc;
  border-radius: 8px;
}

.filter-group {
  display: flex;
  gap: 16px;
  align-items: end;
  flex-wrap: wrap;
}

.filter-group label {
  display: flex;
  flex-direction: column;
  font-size: 0.9rem;
  font-weight: 500;
  min-width: 150px;
}

.filter-group input,
.filter-group select {
  margin-top: 4px;
  padding: 8px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.9rem;
}

@media (max-width: 768px) {
  .filter-group {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-group label {
    min-width: auto;
  }
}

.summary-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  border-left: 4px solid;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.card-blue {
  border-left-color: #0f4c81;
}

.card-light-blue {
  border-left-color: #38bdf8;
}

.card-gray {
  border-left-color: #6b7280;
}

.card-orange {
  border-left-color: #f59e0b;
}

.card-green {
  border-left-color: #10b981;
}

.card-red {
  border-left-color: #ef4444;
}

.card-purple {
  border-left-color: #8b5cf6;
}

.card-yellow {
  border-left-color: #facc15;
}

.card-number {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.card-title {
  font-size: 0.9rem;
  color: #6b7280;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-trucks {
  margin-top: 8px;
  font-size: 0.74rem;
  color: #475569;
  line-height: 1.35;
  word-break: break-word;
}

@media (max-width: 768px) {
  .summary-cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .summary-card {
    padding: 16px;
  }

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

  .card-title {
    font-size: 0.8rem;
  }

  .card-trucks {
    font-size: 0.68rem;
  }
}

/* Mobile field mode */
@media (max-width: 768px) {
  header {
    padding: 14px 12px;
  }

  header h1 {
    font-size: 1.2rem;
    margin-bottom: 4px;
  }

  header p {
    margin: 0;
    font-size: 0.88rem;
  }

  header nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
  }

  .nav-link {
    display: block;
    text-align: center;
    width: 100%;
  }

  .panel {
    margin: 10px;
    padding: 14px;
    border-radius: 10px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  label {
    width: 100%;
  }

  input,
  select,
  .filter-group input,
  .filter-group select {
    width: 100%;
    font-size: 1rem;
    padding: 12px;
  }

  .filters {
    padding: 12px;
    margin-bottom: 12px;
  }

  .filter-group {
    gap: 10px;
  }

  .actions {
    gap: 10px;
  }

  .actions button {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
  }

  .desktop-only {
    display: none !important;
  }

  .mobile-only,
  .mobile-trip-list {
    display: block !important;
  }

  .summary-cards {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .summary-card {
    padding: 14px;
  }

  .card-number {
    font-size: 1.6rem;
    margin-bottom: 4px;
  }
}
