:root {
  --bg: #f3f4f8;
  --card-bg: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e2e5ec;
  --accent: #4f46e5;
  --accent-soft: #eef0fd;
  --good: #16a34a;
  --good-soft: #ecfdf3;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --neutral: #475569;
  --neutral-soft: #f1f5f9;
  --customer: #4f46e5;
  --stock: #d97706;
  --company: #0f766e;
  --company-soft: #f0fdfa;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  padding: 20px clamp(16px, 4vw, 32px) 48px;
}

h1, h2 {
  margin: 0 0 4px;
}

h2 {
  font-size: 16px;
}

.page-header {
  margin-bottom: 16px;
}

.subtitle {
  color: var(--muted);
  margin: 0;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.control-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.control-bar label {
  font-weight: 600;
}

.control-bar input[type="date"] {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

.date-stepper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.control-bar .stepper-button {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
}

.control-bar .stepper-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.control-bar button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.control-bar button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.control-hint {
  flex-basis: 100%;
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.status-area {
  margin-bottom: 16px;
}

.status-banner {
  border-radius: var(--radius);
  padding: 14px 18px;
  font-weight: 500;
}

.status-banner.loading {
  background: var(--accent-soft);
  color: var(--accent);
}

.status-banner.error {
  background: var(--bad-soft);
  color: var(--bad);
}

.section-hint {
  color: var(--muted);
  margin: 0 0 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: #fafbff;
}

.metric-card .label {
  color: var(--muted);
  font-size: 12.5px;
  margin-bottom: 4px;
}

.metric-card .value {
  font-size: 22px;
  font-weight: 700;
}

.metric-card .value .of-total {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.metric-card-hint {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
}

.chip.good {
  background: var(--good-soft);
  color: var(--good);
}

.chip.bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.empty-state {
  color: var(--muted);
  padding: 12px 0;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  font-size: 13px;
}

.pagination button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.driver-tabs-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.driver-tab-list-wrap {
  flex: 0 0 220px;
}

.driver-select-mobile {
  display: none;
  width: 100%;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.driver-tab-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 480px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.driver-tab-list li {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
}

.driver-tab-list li:last-child {
  border-bottom: none;
}

.driver-tab-list li.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.driver-tab-list li .tab-sub {
  display: block;
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
}

.driver-detail {
  flex: 1 1 auto;
  min-width: 0;
}

/* Compact driver header: name/shift on the left, stop counts, points,
   distance, and status badges on the right. */
.route-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.route-header-main h3 {
  margin: 0 0 2px;
  font-size: 15px;
}

.route-header-sub {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.route-header-summary {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  text-align: right;
  font-size: 13px;
}

.summary-figure {
  color: var(--muted);
  font-weight: 600;
}

.summary-badges {
  display: flex;
  gap: 6px;
}

/* Compact colored badges, reused for "Jenis" and "Status" cells. */
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-order {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-moving {
  background: var(--warn-soft);
  color: var(--stock);
}

.badge-company {
  background: var(--company-soft);
  color: var(--company);
}

.status-success {
  background: var(--good-soft);
  color: var(--good);
}

.status-danger {
  background: var(--bad-soft);
  color: var(--bad);
}

.status-warning {
  background: var(--warn-soft);
  color: var(--warn);
}

.status-neutral {
  background: var(--neutral-soft);
  color: var(--neutral);
}

.route-table .task-cell-primary {
  font-weight: 600;
}

.route-table .task-cell-sub {
  color: var(--muted);
  font-size: 12px;
  white-space: normal;
  max-width: 260px;
}

/* The actual route (unchanged from before "Permintaan" existed) stays
   the one prominent line. A small "Permintaan" tag + the one differing
   origin is added below only when a stop's requested and actual origin
   diverge (see dashboard.js#renderRouteCell) - deliberately not a
   second full "X -> Y" line, since the destination never differs. */
.route-table .route-primary {
  white-space: nowrap;
}

.route-table .route-requested {
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.route-table .route-requested-tag {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--neutral-soft);
  color: var(--neutral);
}

/* One card per trip - each trip has its own table and its own
   Total Points Trip footer, since the 600-point cap is per trip. */
.trip-group {
  margin-bottom: 18px;
}

.trip-group:last-child {
  margin-bottom: 0;
}

.trip-group-title {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.trip-total-row td {
  font-weight: 700;
  background: #fafbff;
  white-space: normal;
}

.detail-button {
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.detail-button:hover {
  background: var(--accent-soft);
}

/* -------------------------------------------------------------
   Detail modal (Order / Moving row inspection)
------------------------------------------------------------- */

.detail-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(15, 18, 26, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* `display: flex` above is an author-stylesheet rule, which always beats
   the browser's own default `[hidden] { display: none }` UA rule
   regardless of specificity - without this override the backdrop stays
   visible (and un-closable) even while the `hidden` attribute is set. */
.detail-modal-backdrop[hidden] {
  display: none;
}

.detail-modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  width: min(560px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.detail-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.detail-modal-header h3 {
  margin: 0;
  font-size: 15px;
}

.detail-modal-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 2px 6px;
}

.detail-modal-close:hover {
  color: var(--text);
}

.detail-modal-body {
  padding: 16px 18px;
  overflow-y: auto;
}

.detail-field {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.detail-field-label {
  color: var(--muted);
  font-weight: 600;
}

.detail-field-value {
  white-space: normal;
  word-break: break-word;
}

.detail-section-title {
  margin: 16px 0 8px;
  font-size: 13px;
  color: var(--muted);
}

.detail-record {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.detail-record:last-child {
  margin-bottom: 0;
}

.detail-items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 4px;
}

.detail-items-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}

.detail-items-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.detail-items-table tr:last-child td {
  border-bottom: none;
}

.detail-items-table th:last-child,
.detail-items-table td:last-child {
  text-align: right;
}

.detail-empty {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0;
}

.legend {
  display: flex;
  gap: 16px;
  margin-bottom: 10px;
  font-size: 13px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.swatch-customer {
  background: var(--customer);
}

.swatch-stock {
  background: var(--stock);
}

/* -------------------------------------------------------------
   Peta Rute Driver (Leaflet map)
------------------------------------------------------------- */

.map-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 10px;
  font-size: 13px;
}

.map-controls label {
  font-weight: 600;
  color: var(--muted);
}

.map-controls select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
}

.map-trip-figure {
  color: var(--muted);
  font-weight: 600;
  margin-left: auto;
}

.swatch-branch {
  background: var(--neutral);
}

.swatch-order {
  background: var(--customer);
}

.swatch-moving {
  background: var(--stock);
}

.line-swatch {
  width: 22px;
  height: 0;
  border-top-width: 3px;
  border-top-style: solid;
  border-top-color: #4f46e5;
  display: inline-block;
}

.line-swatch-outbound {
  opacity: 0.9;
}

.line-swatch-return {
  opacity: 0.55;
  border-top-style: dashed;
}

.route-map {
  height: 460px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--neutral-soft);
}

.map-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid #fff;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.map-marker-branch {
  background: var(--neutral);
}

.map-marker-order {
  background: var(--customer);
}

.map-marker-moving {
  background: var(--stock);
}

.map-popup {
  font-size: 12.5px;
  line-height: 1.5;
}

.map-popup-muted {
  color: var(--muted);
}

@media (max-width: 640px) {
  .route-map {
    height: 320px;
  }

  .map-trip-figure {
    margin-left: 0;
  }
}

.timetable-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.timetable-grid {
  display: grid;
  min-width: 900px;
}

.tt-row {
  display: grid;
  grid-template-columns: 180px 1fr;
  border-bottom: 1px solid var(--border);
}

.tt-row:last-child {
  border-bottom: none;
}

.tt-driver-cell {
  padding: 10px 12px;
  font-size: 13px;
  border-right: 1px solid var(--border);
  background: #fafbff;
}

.tt-driver-cell .tab-sub {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
}

.tt-track {
  position: relative;
  min-height: 44px;
}

.tt-idle {
  color: var(--muted);
  font-size: 12.5px;
  padding: 12px;
}

.tt-block {
  position: absolute;
  top: 8px;
  bottom: 8px;
  border-radius: 6px;
  color: #fff;
  font-size: 11px;
  padding: 4px 6px;
  overflow: hidden;
  cursor: pointer;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tt-block.customer {
  background: var(--customer);
}

.tt-block.stock {
  background: var(--stock);
}

.tt-header {
  display: grid;
  grid-template-columns: 180px 1fr;
  border-bottom: 1px solid var(--border);
  background: #fafbff;
}

.tt-header-hours {
  position: relative;
  height: 28px;
  font-size: 11px;
  color: var(--muted);
}

.tt-hour-mark {
  position: absolute;
  top: 6px;
}

.notes-toggle {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  display: flex;
  justify-content: space-between;
}

.notes-body {
  margin-top: 14px;
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.notes-group h3 {
  font-size: 13px;
  margin: 0 0 6px;
}

.notes-group ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
}

.task-popover {
  position: fixed;
  z-index: 20;
  background: #1f2430;
  color: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  max-width: 260px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.task-popover dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
}

.task-popover dt {
  color: #c7cbe0;
}

.task-popover dd {
  margin: 0;
}

@media (max-width: 640px) {
  .driver-tabs-layout {
    flex-direction: column;
  }

  .driver-tab-list-wrap {
    flex-basis: auto;
    width: 100%;
  }

  .driver-tab-list {
    display: none;
  }

  .driver-select-mobile {
    display: block;
  }
}
