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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3350;
  --accent: #4f8ef7;
  --accent-hover: #6ba3ff;
  --success: #34c57a;
  --warning: #f5a623;
  --danger: #e05252;
  --text: #e8eaf0;
  --text-muted: #7a80a0;
  --radius: 10px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* HEADER */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

#date-display {
  color: var(--text-muted);
  font-size: 13px;
  margin-left: 0; /* overridden below in date-nav context */
}

#stats {
  color: var(--text-muted);
  font-size: 13px;
}

/* MAIN LAYOUT */
main {
  display: block;
  padding: 24px 28px;
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
}

/* SVG CONNECTOR OVERLAY */
#connectors-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  overflow: visible;
}

/* COLUMN HEADERS */
.col-headers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin-bottom: 8px;
  position: relative;
  z-index: 10;
}

.col-header-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.col-header-cell h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* BOARD ROWS — each row aligns one route with one driver */
#board-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  z-index: 10;
}

.board-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  align-items: stretch;
  /* Smooth shift during drag */
  transition: transform 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

.board-cell {
  display: flex;
  flex-direction: column;
}

.board-cell .card {
  flex: 1;
}

.card-placeholder {
  flex: 1;
  min-height: 62px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  opacity: 0.25;
}

/* ANIMATIONS */
@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes drawLine {
  to { stroke-dashoffset: 0; }
}

@keyframes flashAssign {
  0%   { box-shadow: 0 0 0 0 rgba(79,142,247,0.5); }
  50%  { box-shadow: 0 0 0 6px rgba(79,142,247,0.15); }
  100% { box-shadow: 0 0 0 0 rgba(79,142,247,0); }
}

@keyframes flashComplete {
  0%   { box-shadow: 0 0 0 0 rgba(52,197,122,0.5); }
  50%  { box-shadow: 0 0 0 6px rgba(52,197,122,0.15); }
  100% { box-shadow: 0 0 0 0 rgba(52,197,122,0); }
}

/* VIEW TRANSITIONS — cards slide to new positions */
::view-transition-group(*) {
  animation-duration: 0.38s;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* New cards fade+lift in */
::view-transition-new(*) {
  animation: cardIn 0.28s ease-out both;
}

/* Old cards (removed) fade out */
::view-transition-old(*) {
  animation: fadeOut 0.18s ease-in both;
}

@keyframes fadeOut {
  to { opacity: 0; transform: scale(0.97); }
}

/* CARDS — uniform height */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px 8px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 62px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.card.flash-assign   { animation: flashAssign   0.5s ease-out; }
.card.flash-complete { animation: flashComplete 0.5s ease-out; }

/* LEFT COLOR STRIP via ::before */
.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: var(--radius) 0 0 var(--radius);
  background: var(--border);
  transition: background 0.25s;
}

.route-card.unassigned::before { background: var(--warning); }
.route-card.assigned::before   { background: var(--accent); }
.route-card.completed::before  { background: var(--success); }

.card:hover {
  border-color: #3a4070;
}

.card.completed {
  opacity: 0.45;
  border-style: dashed;
}

.card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.card-id {
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
}

.route-legs {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 5px;
}

.pickup-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.arrow { color: var(--border); }

.card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}

/* ASSIGNMENT BADGE */
.assigned-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(79,142,247,0.1);
  border: 1px solid rgba(79,142,247,0.25);
  border-radius: 20px;
  padding: 2px 6px 2px 8px;
  font-size: 11px;
  color: var(--accent);
  align-self: flex-start;
}

.assigned-badge .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.btn-unassign {
  background: transparent;
  border: none;
  color: rgba(79,142,247,0.45);
  font-size: 10px;
  cursor: pointer;
  padding: 0;
  margin-left: 1px;
  transition: color 0.15s;
  line-height: 1;
}

.btn-unassign:hover { color: var(--danger); }

/* UNASSIGNED PLACEHOLDER */
.unassigned-hint {
  font-size: 11px;
  color: var(--warning);
  opacity: 0.6;
}

/* DRIVER LOAD */
.driver-load {
  font-size: 11px;
  color: var(--text-muted);
}

.driver-free .driver-load span { color: var(--success); }
.driver-busy .driver-load span { color: var(--warning); }

/* DRAG-OVER STATE — assigning a driver to a route */
.route-card.drag-over {
  border-color: var(--accent) !important;
  background: rgba(79,142,247,0.05);
  box-shadow: 0 0 0 2px rgba(79,142,247,0.2);
}

/* DRAG-TARGET STATE — reordering (route→route or driver→driver) */
.card.drag-target {
  border-color: var(--accent) !important;
  border-style: dashed !important;
  background: rgba(79,142,247,0.04);
}

/* DRAGGABLE cards */
.route-card:not(.completed) {
  cursor: grab;
  user-select: none;
}

.driver-card {
  cursor: grab;
  user-select: none;
}

.route-card:not(.completed):active,
.driver-card:active { cursor: grabbing; }

.card.dragging {
  opacity: 0.35;
  transform: scale(0.97);
}

.drag-handle {
  font-size: 13px;
  color: var(--text-muted);
  cursor: grab;
  padding: 0 2px;
  opacity: 0.4;
  flex-shrink: 0;
}

.driver-busy::before { background: var(--accent); }

/* SAVED BADGE + COLUMN HINT */
.saved-badge {
  background: rgba(52,197,122,0.15);
  color: var(--success);
  border: 1px solid rgba(52,197,122,0.3);
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  vertical-align: middle;
  margin-left: 8px;
}

.column-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: -4px;
}

/* EMPTY STATE */
.empty-state {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 32px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* BUTTONS */
.btn-add {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-add:hover { background: var(--accent-hover); }

.btn-complete {
  background: var(--success);
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.btn-complete:hover { opacity: 0.85; }

.btn-remove {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--danger);
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-remove:hover {
  background: rgba(224,82,82,0.1);
  border-color: var(--danger);
}

/* MODAL */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

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

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: 380px;
  max-width: 90vw;
}

.modal h3 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 20px;
}

.modal label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}

.modal input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.modal input:focus { border-color: var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

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

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 9px 20px;
  font-size: 14px;
  cursor: pointer;
}

.btn-secondary:hover { background: var(--surface2); }

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--success);
  color: var(--success);
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.25s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.completed-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

.completed-time {
  font-size: 11px;
  color: var(--success);
}

.completed-driver {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── PAGE BODY (main board + sidebar) ─────────────────────────────────────── */

.page-body {
  display: flex;
  align-items: flex-start;
}

/* Override the old standalone main rules */
main {
  flex: 1;
  min-width: 0;
  max-width: none;
}

/* ── DATE NAVIGATION ──────────────────────────────────────────────────────── */

.header-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-day-nav {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}

.btn-day-nav:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-today {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.4px;
  transition: background 0.15s;
  display: none;
}

.btn-today:hover { background: rgba(79,142,247,0.1); }

#date-display {
  /* override the old header rule */
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  margin-left: 0;
  min-width: 160px;
  text-align: center;
}

body.not-today #date-display { color: var(--text-muted); }

/* ── UPCOMING SIDEBAR ─────────────────────────────────────────────────────── */

#sidebar {
  width: 230px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--surface);
  padding: 20px 14px;
  min-height: calc(100vh - 57px);
}

.sidebar-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 14px;
}

.upcoming-empty {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 20px 0;
  opacity: 0.6;
}

.upcoming-item {
  border-radius: 8px;
  padding: 10px 10px 8px;
  margin-bottom: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.upcoming-item:hover {
  background: var(--surface2);
  border-color: var(--border);
}

.upcoming-item.active {
  background: rgba(79,142,247,0.07);
  border-color: rgba(79,142,247,0.3);
}

.upcoming-item-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
}

.upcoming-day-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.upcoming-day-sub {
  font-size: 10px;
  color: var(--text-muted);
}

.upcoming-count {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Progress bar */
.upcoming-bar {
  display: flex;
  height: 3px;
  border-radius: 2px;
  overflow: hidden;
  background: var(--surface2);
  margin-bottom: 6px;
}

.bar-seg { height: 100%; }

.bar-completed  { background: var(--success); }
.bar-assigned   { background: var(--accent);  }
.bar-unassigned { background: var(--warning); }

/* Detail chips */
.upcoming-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.detail-chip {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 10px;
  font-weight: 500;
}

.detail-warn { background: rgba(245,166,35,0.12); color: var(--warning); }
.detail-ok   { background: rgba(79,142,247,0.10); color: var(--accent);  }
.detail-done { background: rgba(52,197,122,0.10); color: var(--success); }

/* ── CARRY-OVER ROUTES (created on a previous day, still pending) ─────────── */

.route-card.carryover::before { background: #9b6ff5; }  /* purple strip — distinct from amber/blue */

.carryover-badge {
  font-size: 10px;
  color: #9b6ff5;
  background: rgba(155,111,245,0.1);
  border: 1px solid rgba(155,111,245,0.25);
  border-radius: 10px;
  padding: 1px 6px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── RATE / NOTES META LINE ──────────────────────────────────────────────────── */

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.route-rate {
  font-size: 11px;
  font-weight: 700;
  color: var(--success);
  background: rgba(52, 197, 122, 0.12);
  border: 1px solid rgba(52, 197, 122, 0.25);
  border-radius: 10px;
  padding: 1px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.route-notes-meta {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 260px;
}
