/* =========================
   Road Service Dispatch
   ========================= */

.dispatch-container {
  max-width: 1600px;
  margin: 0 auto;
}

.dispatch-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-200);
}

.dispatch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.dispatch-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--brand-800) 8%, var(--white));
  border-radius: var(--r-sm);
  flex-wrap: wrap;
}

.dispatch-summary .status-badge {
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.status-badge.status-dispatched {
  background: #dbeafe;
  color: #1e40af;
}

.status-badge.status-in-progress {
  background: #e0e7ff;
  color: #4338ca;
}

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

.dispatch-meta {
  font-size: 12px;
  color: var(--text-600);
}

/* =========================
   Filters
   ========================= */
.dispatch-filters {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 18px;
  padding: 14px;
  background: var(--surface-50);
  border-radius: var(--r-sm);
  border: 1px solid var(--border-200);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
  flex: 1 1 180px;
}

.filter-group label {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-600);
}

.filter-group select {
  padding: 8px 10px;
  border: 1px solid var(--border-300);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-900);
  width: 100%;
}

.filter-group select:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--brand-800) 40%, var(--border-200));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-800) 12%, transparent);
}

.filter-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* =========================
   Table
   ========================= */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.dispatch-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
}

.dispatch-table thead {
  background: var(--surface-50);
}

.dispatch-table th {
  padding: 12px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border-300);
  font-size: 14px;
  vertical-align: middle;
  white-space: nowrap;
}

.dispatch-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border-200);
  font-size: 14px;
  height: 56px;
  vertical-align: middle;
  line-height: 1.25;
}

.dispatch-table tbody tr {
  cursor: pointer;
}

.dispatch-table tbody tr:hover {
  background: var(--surface-50);
}

.dispatch-table .status-cell {
  text-transform: capitalize;
}

.dispatch-table .status-cell.status-new {
  color: #92400e;
  font-weight: 600;
}

.dispatch-table .status-cell.status-dispatched {
  color: #1e40af;
  font-weight: 600;
}

.dispatch-table .status-cell.status-in_progress {
  color: #4338ca;
  font-weight: 600;
}

.dispatch-table .status-cell.status-completed {
  color: #065f46;
  font-weight: 600;
}

.dispatch-table .status-cell.status-cancelled {
  color: #991b1b;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  color: var(--text-600);
  padding: 16px;
}

/* =========================
   Modal
   ========================= */
.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;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--r-lg);
  max-width: 900px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-large {
  max-width: 1100px;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 20px;
  color: var(--text-900);
}

.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--text-500);
  padding: 0;
  line-height: 1;
}

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

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 16px 24px;
  border-top: 1px solid var(--border-200);
  background: var(--surface-50);
}

.modal-footer select {
  padding: 8px 12px;
  border: 1px solid var(--border-300);
  border-radius: var(--r-sm);
  background: var(--surface);
  min-width: 150px;
}

.modal-footer textarea {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-300);
  border-radius: var(--r-sm);
  background: var(--surface);
  resize: vertical;
  min-height: 40px;
  font-family: inherit;
}

.detail-section {
  margin-bottom: 20px;
}

.detail-section h3 {
  font-size: 14px;
  text-transform: uppercase;
  color: var(--text-600);
  margin: 0 0 12px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-200);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-label {
  font-size: 12px;
  color: var(--text-600);
  text-transform: uppercase;
}

.detail-value {
  font-size: 14px;
  color: var(--text-900);
}

/* =========================
   Recipients Modal
   ========================= */
.recipients-description {
  color: var(--text-600);
  margin-bottom: 16px;
  font-size: 14px;
}

.recipients-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.recipient-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface-50);
  border-radius: var(--r-sm);
  border: 1px solid var(--border-200);
}

.recipient-item.inactive {
  opacity: 0.6;
  background: var(--surface);
}

.recipient-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.recipient-email {
  font-weight: 600;
  color: var(--text-900);
}

.recipient-name {
  font-size: 12px;
  color: var(--text-600);
}

.recipient-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.recipient-actions .btn {
  padding: 4px 8px;
  font-size: 12px;
}

.recipient-add-form {
  padding-top: 16px;
  border-top: 1px solid var(--border-200);
}

.recipient-add-form h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--text-900);
}

.form-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.form-row input {
  flex: 1;
  min-width: 180px;
  padding: 8px 12px;
  border: 1px solid var(--border-300);
  border-radius: var(--r-sm);
  background: var(--surface);
}

.form-row input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--brand-800) 40%, var(--border-200));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-800) 12%, transparent);
}

/* =========================
   Mobile
   ========================= */
@media (max-width: 768px) {
  .dispatch-card {
    padding: 16px;
  }

  .dispatch-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-group {
    min-width: 0;
    width: 100%;
  }

  .filter-actions {
    width: 100%;
  }

  .filter-actions .btn {
    flex: 1;
    justify-content: center;
  }

  .dispatch-table thead {
    display: none;
  }

  .dispatch-table tbody tr {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border-200);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    padding: 12px;
    margin-bottom: 12px;
  }

  .dispatch-table tbody td {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 10px;
    padding: 10px 0;
    border: 0;
    height: auto;
    min-width: 0;
    align-items: start;
  }

  .dispatch-table tbody td + td {
    border-top: 1px solid var(--border-200);
  }

  .dispatch-table tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 12px;
    color: var(--text-600);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding-top: 2px;
    min-width: 0;
  }

  .dispatch-table tbody td > * {
    min-width: 0;
  }

  .modal-content {
    width: 95%;
    margin: 10px;
  }

  .modal-footer {
    flex-direction: column;
  }

  .modal-footer select,
  .modal-footer textarea,
  .modal-footer .btn {
    width: 100%;
  }
}
