:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --panel-alt: #f8faff;
  --text: #1a2133;
  --muted: #5d687c;
  --primary: #2d6df6;
  --primary-strong: #1c4fd6;
  --success: #1a9b5d;
  --danger: #d94a4a;
  --border: #d7e0ee;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  --button-text: #ffffff;
  --chip: #edf4ff;
  --warning: #fff1c8;
}

body.dark {
  --bg: #0b1220;
  --panel: #111b2b;
  --panel-alt: #15233b;
  --text: #eaf2ff;
  --muted: #a5b4cf;
  --primary: #7aa9ff;
  --primary-strong: #a4c0ff;
  --success: #4ad59d;
  --danger: #ff7f7f;
  --border: #273550;
  --shadow: 0 12px 30px rgba(2, 6, 23, 0.35);
  --button-text: #0b1220;
  --chip: #1b2a42;
  --warning: #332d1a;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 1100px);
  padding: 1rem;
  margin: 0 auto;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 5vw, 2.4rem);
}

h2 {
  margin-bottom: 0;
  font-size: 1.2rem;
}

.layout {
  display: grid;
  gap: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 1rem;
}

/* Details-based collapsible panels */
details.panel {
  padding: 0; /* panel body holds padding */
}

details.panel summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: pointer;
  padding: 1rem;
  border-radius: 20px 20px 0 0;
  margin: 0;
  background: transparent;
}

details.panel summary::-webkit-details-marker {
  display: none;
}

details.panel summary .section-heading {
  margin-bottom: 0;
}

.panel-body {
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: transparent;
  overflow: hidden;
  max-height: 2000px;
  transition: max-height 0.22s ease, opacity 0.18s ease;
}

details.panel:not([open]) .panel-body {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-top: none;
}

/* simple caret using pseudo-element */
details.panel summary::after {
  content: '';
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--muted);
  border-top: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.18s ease, border-color 0.18s ease;
  margin-left: 0.5rem;
}

details.panel[open] summary::after {
  transform: rotate(-135deg);
  border-color: var(--primary-strong);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--chip);
  color: var(--text);
  border-radius: 999px;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.address-form,
#paymentForm {
  display: grid;
  gap: 0.8rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.95rem;
  color: var(--muted);
}

input,
textarea,
select {
  width: 100%;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 0.9rem;
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 90px;
}

.split-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.3rem;
}

.primary-button,
.secondary-button,
.small-button,
.link-button,
.route-button,
.delivered-button {
  border: none;
  border-radius: 14px;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.primary-button,
.secondary-button,
.route-button,
.delivered-button {
  min-height: 48px;
  padding: 0.85rem 1rem;
  font-weight: 700;
}

.primary-button {
  background: var(--primary);
  color: var(--button-text);
}

.secondary-button,
.small-button {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.small-button {
  min-height: 40px;
  padding: 0.6rem 0.9rem;
}

.danger {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.address-list,
.route-list,
.history-list {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.address-card,
.route-card,
.history-card {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.9rem;
}

.address-card-header,
.route-card-header,
.history-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.address-card h3,
.route-card h3,
.history-card h3 {
  margin: 0;
  font-size: 1.02rem;
}

.card-meta,
.card-subtext,
.route-meta,
.history-summary {
  color: var(--muted);
  font-size: 0.85rem;
}

.address-card-actions,
.route-card-actions,
.history-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.8rem;
}

.link-button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  min-height: 40px;
}

.route-card.active {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.route-card .route-summary {
  margin-top: 0.75rem;
}

.route-card .route-summary strong {
  color: var(--text);
}

.delivered-button {
  background: var(--success);
  color: var(--button-text);
}

.summary-box {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.earnings-block {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.earnings-textarea {
  flex: 1 1 auto;
  min-height: 88px;
  padding: 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  resize: vertical;
}

/* Slide-to-confirm */
.slide-confirm {
  width: 100%;
}

.slide-track {
  position: relative;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  height: 48px;
  display: flex;
  align-items: center;
  padding: 6px;
  overflow: hidden;
}

.slide-label {
  position: absolute;
  left: 16px;
  right: 16px;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  pointer-events: none;
}

.slide-knob {
  width: 44px;
  height: 44px;
  background: var(--primary);
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(15,23,42,0.12);
  transform: translateX(0);
  transition: transform 0.12s linear;
  z-index: 2;
}

.slide-confirm.success .slide-track {
  background: linear-gradient(90deg, rgba(26,155,93,0.12), rgba(45,109,246,0.04));
}

.slide-confirm.success .slide-label {
  color: var(--success);
}

.slide-confirm.small .slide-track { height: 40px; }


.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.summary-item {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
}

.summary-item strong {
  display: block;
  font-size: 1.15rem;
  margin-top: 0.15rem;
}

.current-stop {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(140deg, var(--panel-alt), rgba(45, 109, 246, 0.08));
  padding: 1rem;
}

.current-stop h3 {
  margin: 0 0 0.4rem;
  font-size: 1.25rem;
}

.current-stop strong {
  display: inline-block;
  margin-top: 0.5rem;
}

.current-stop .map-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.current-stop .map-actions a {
  text-decoration: none;
  flex: 1 1 140px;
  text-align: center;
}

.next-stop {
  margin-top: 0.9rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.next-stop strong {
  display: block;
  margin-top: 0.2rem;
  color: var(--text);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 120px;
  color: var(--muted);
  text-align: center;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 2147483647;
}

.modal-card {
  width: min(100%, 420px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 1rem;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.modal-stop-title {
  margin: 0 0 1rem;
  font-size: 1.08rem;
  font-weight: 700;
}

.history-card {
  display: grid;
  gap: 0.3rem;
}

.history-item-detail {
  margin-top: 0.4rem;
  display: grid;
  gap: 0.45rem;
}

.history-item-detail .row {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.history-item-detail .row strong,
.row-value {
  color: var(--text);
}

.delivery-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 16, 28, 0.78);
  display: grid;
  place-items: end center;
  padding: 0;
  animation: slideUpIn 0.2s ease-out;
}

.delivery-panel {
  width: 100%;
  max-width: 100%;
  height: min(92vh, 820px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 28px 28px 0 0;
  padding: 1rem;
  display: grid;
  grid-template-rows: auto 1fr;
  box-shadow: var(--shadow);
}

@keyframes slideUpIn {
  from {
    opacity: 0;
    transform: translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.delivery-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.delivery-header-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.delivery-body {
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: 1rem;
  padding-top: 1rem;
}

.delivery-stop-card {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 1rem;
}

.delivery-kicker {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.delivery-stop-card h3 {
  margin: 0;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
}

.delivery-stop-card p {
  margin: 0.3rem 0 0;
}

.delivery-info-box {
  background: rgba(45, 109, 246, 0.06);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.8rem;
  margin-top: 0.9rem;
}

.delivery-info-box strong {
  display: block;
  margin-bottom: 0.3rem;
}

.delivery-next-stop {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem;
  color: var(--muted);
}

.delivery-actions {
  display: grid;
  gap: 0.75rem;
}

.delivery-actions a,
.delivery-actions button {
  width: 100%;
  min-height: 58px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  border-radius: 16px;
}

.delivery-done-button {
  background: var(--success);
  border: none;
  color: var(--button-text);
  font-weight: 700;
  padding: 1rem;
}

.delivery-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.25rem;
}

.delivery-progress {
  font-weight: 700;
  color: var(--text);
}

.delivery-mini-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.75rem 0.9rem;
  margin-top: 0.8rem;
}

.delivery-panel.minimized .delivery-body {
  display: none;
}

.delivery-overlay.minimized .delivery-panel {
  height: auto;
}

@media (min-width: 760px) {
  .layout {
    grid-template-columns: 1.05fr 1.2fr 0.8fr;
    align-items: start;
  }

  .top-bar {
    padding-inline: 0.25rem;
  }
}

@media print {
  body {
    background: white;
  }

  .no-print {
    display: none !important;
  }

  .print-report {
    display: block !important;
    padding: 1.5rem;
    color: #111;
    font-family: Arial, Helvetica, sans-serif;
  }

  .print-report h2,
  .print-report h3,
  .print-report p,
  .print-report li {
    color: #111;
  }

  .report-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 1rem 0;
  }

  .report-card {
    border: 1px solid #d9d9d9;
    border-radius: 12px;
    padding: 0.75rem;
  }
}
