/* ==========================================================================
   Mr. Rubbish - Paperless Refuse Collection & Dispatch System
   Modern High-Contrast Logistics & Field Operations Stylesheet
   ========================================================================== */

:root {
  --bg-app: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-muted: #f8fafc;
  --bg-nav: #0f172a;
  --bg-nav-hover: #1e293b;

  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;

  --primary: #0f766e;       /* Deep Emerald Teal */
  --primary-hover: #115e59;
  --primary-soft: #ccfbf1;

  --fuso: #2563eb;          /* Fuso Blue */
  --fuso-soft: #dbeafe;
  --fuso-border: #93c5fd;

  --hino: #059669;          /* Hino Emerald */
  --hino-soft: #d1fae5;
  --hino-border: #6ee7b7;

  --unassigned: #d97706;    /* Amber */
  --unassigned-soft: #fef3c7;
  --unassigned-border: #fcd34d;

  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #16a34a;
  --success-soft: #dcfce7;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.14);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  text-decoration: underline;
}

/* ---------- Top Navigation ---------- */
.topbar {
  background: var(--bg-nav);
  color: var(--text-inverse);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 1.25rem;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: #ffffff;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
  opacity: 0.95;
}

.brand-badge {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, #10b981, #0f766e);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.9rem;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.35);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.nav-link {
  color: #cbd5e1;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.9rem;
  transition: background 0.15s ease, color 0.15s ease;
  text-decoration: none;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.nav-link:hover {
  background: var(--bg-nav-hover);
  color: #ffffff;
  text-decoration: none;
}

.nav-link.active {
  background: var(--primary);
  color: #ffffff;
}

.user-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.82rem;
  color: #f8fafc;
}

.user-role-pill {
  background: rgba(16, 185, 129, 0.25);
  color: #6ee7b7;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
}

/* ---------- Main Container ---------- */
.app-container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.25rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.page-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.page-subtitle {
  margin: 0.2rem 0 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ---------- Cards & Panels ---------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
}

.card-header {
  padding: 0.9rem 1.15rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.card-body {
  padding: 1.15rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.52rem 0.95rem;
  min-height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  text-decoration: none;
}

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

.btn-sm {
  padding: 0.35rem 0.65rem;
  min-height: 32px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 0.7rem 1.25rem;
  min-height: 46px;
  font-size: 0.95rem;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #ffffff;
  color: var(--text-main);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-muted);
}

.btn-outline-light {
  background: transparent;
  color: #e2e8f0;
  border-color: rgba(255, 255, 255, 0.25);
}
.btn-outline-light:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}
.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
}

.btn-fuso {
  background: var(--fuso);
  color: #ffffff;
}
.btn-hino {
  background: var(--hino);
  color: #ffffff;
}
.btn-amber {
  background: var(--unassigned);
  color: #ffffff;
}

/* ---------- Forms & Inputs ---------- */
.form-group {
  margin-bottom: 0.9rem;
}

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.form-control,
.form-select {
  width: 100%;
  padding: 0.5rem 0.7rem;
  min-height: 38px;
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--text-main);
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus,
.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
}

/* ---------- Badges & Pills ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.25;
}

.badge-mono {
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

.badge-fuso {
  background: var(--fuso-soft);
  color: #1d4ed8;
  border: 1px solid var(--fuso-border);
}

.badge-hino {
  background: var(--hino-soft);
  color: #047857;
  border: 1px solid var(--hino-border);
}

.badge-unassigned,
.badge-pending {
  background: var(--unassigned-soft);
  color: #b45309;
  border: 1px solid var(--unassigned-border);
}

.badge-scheduled {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
}

.badge-completed {
  background: var(--success-soft);
  color: #15803d;
  border: 1px solid #86efac;
}

.badge-exported {
  background: #f3e8ff;
  color: #7e22ce;
  border: 1px solid #d8b4fe;
}

.badge-neutral {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}

/* ---------- KPI Grid ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.15rem;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.9rem 1.05rem;
  box-shadow: var(--shadow-xs);
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 1.55rem;
  font-weight: 700;
  margin-top: 0.2rem;
  color: var(--text-main);
}

.kpi-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

/* ---------- Filters & Tabs ---------- */
.filters-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  box-shadow: var(--shadow-xs);
}

.filter-item {
  min-width: 150px;
  flex: 1 1 160px;
}

.filter-item.filter-search {
  flex: 2 1 220px;
}

.tabs-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.tab-btn.active {
  background: var(--bg-nav);
  color: #ffffff;
  border-color: var(--bg-nav);
}

/* ---------- Dispatch Drag-and-Drop Board ---------- */
.dispatch-board {
  display: grid;
  grid-template-columns: 270px repeat(5, minmax(220px, 1fr));
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  align-items: start;
}

.board-col {
  background: #e2e8f0;
  border-radius: var(--radius-md);
  border: 1px solid #cbd5e1;
  min-height: 460px;
  display: flex;
  flex-direction: column;
}

.board-col-unassigned {
  background: #fef3c7;
  border-color: #fcd34d;
}

.board-col-header {
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.board-col-title {
  font-weight: 700;
  font-size: 0.9rem;
}

.board-col-date {
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.driver-lanes {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem;
  flex: 1;
}

.driver-dropzone {
  background: rgba(255, 255, 255, 0.65);
  border: 2px dashed transparent;
  border-radius: var(--radius-sm);
  padding: 0.45rem;
  min-height: 155px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.driver-dropzone.lane-fuso {
  border-top: 3px solid var(--fuso);
}

.driver-dropzone.lane-hino {
  border-top: 3px solid var(--hino);
}

.driver-dropzone.lane-unassigned {
  border-top: 3px solid var(--unassigned);
  min-height: 400px;
}

.driver-dropzone.drag-over {
  background: #ffffff;
  border-color: var(--primary);
  box-shadow: inset 0 0 0 2px rgba(15, 118, 110, 0.2);
}

.lane-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.lane-label-fuso { color: #1d4ed8; }
.lane-label-hino { color: #047857; }
.lane-label-unassigned { color: #b45309; }

.booking-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--unassigned);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.65rem;
  margin-bottom: 0.5rem;
  box-shadow: var(--shadow-xs);
  cursor: grab;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
  user-select: none;
}

.booking-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.booking-card:active {
  cursor: grabbing;
}

.booking-card.dragging {
  opacity: 0.45;
  transform: scale(0.98);
  box-shadow: var(--shadow-lg);
}

.booking-card.truck-fuso { border-left-color: var(--fuso); }
.booking-card.truck-hino { border-left-color: var(--hino); }
.booking-card.status-completed { opacity: 0.85; background: #f8fafc; }

.booking-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  margin-bottom: 0.3rem;
}

.booking-inst {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--text-main);
  background: #f1f5f9;
  padding: 0.1rem 0.38rem;
  border-radius: 4px;
}

.booking-customer {
  font-weight: 600;
  font-size: 0.84rem;
  color: var(--text-main);
  margin-bottom: 0.2rem;
}

.booking-meta {
  font-size: 0.76rem;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.booking-notes {
  margin-top: 0.35rem;
  font-size: 0.74rem;
  color: var(--text-muted);
  background: var(--bg-muted);
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
}

.booking-actions {
  margin-top: 0.45rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.3rem;
}

/* ---------- Map View ---------- */
.map-wrapper {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.map-legend {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--bg-muted);
}

.legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.82rem;
  font-weight: 600;
}

.legend-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  margin-right: 0.35rem;
}

#dispatchMap {
  width: 100%;
  height: 580px;
  z-index: 1;
}

/* ---------- Tables ---------- */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.data-table th,
.data-table td {
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: var(--bg-muted);
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 2000;
}

.modal-backdrop.open {
  display: flex;
}

.modal-dialog {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 580px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
}

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

.modal-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem 0.4rem;
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  background: var(--bg-muted);
}

/* ---------- Toast Notifications ---------- */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 380px;
}

.toast {
  background: var(--bg-nav);
  color: #ffffff;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.86rem;
  font-weight: 500;
  border-left: 4px solid var(--primary);
  animation: toastSlideIn 0.2s ease-out;
}

.toast.toast-success { border-left-color: #22c55e; }
.toast.toast-error { border-left-color: #ef4444; background: #7f1d1d; }
.toast.toast-warning { border-left-color: #f59e0b; }

@keyframes toastSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Login Page ---------- */
.login-shell {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
}

.login-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.75rem;
}

.demo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .app-container {
    padding: 0.85rem;
  }
  .topbar-inner {
    padding: 0.5rem 0.85rem;
  }
  .demo-grid {
    grid-template-columns: 1fr;
  }
  #dispatchMap {
    height: 420px;
  }
}

/* ---------- Print Stylesheet (Trip Sheets & Reports) ---------- */
@media print {
  body {
    background: #ffffff;
    color: #000000;
    font-size: 11pt;
  }
  .topbar,
  .no-print,
  .filters-bar,
  .tabs-bar,
  .toast-container,
  .btn {
    display: none !important;
  }
  .app-container {
    max-width: 100%;
    padding: 0;
    margin: 0;
  }
  .card {
    border: none;
    box-shadow: none;
  }
  .card-header {
    border-bottom: 2px solid #000000;
    padding-left: 0;
    padding-right: 0;
  }
  .card-body {
    padding: 0.5rem 0;
  }
  .data-table th,
  .data-table td {
    border: 1px solid #333333;
    padding: 6px 8px;
  }
  .print-only {
    display: block !important;
  }
}

.print-only {
  display: none;
}
