:root {
  --cream: #f6f1e8;
  --paper: #fbf7ef;
  --paper-deep: #efe7d7;
  --ink: #2a1e2e;
  --muted: #6d6171;
  --faint: #9c8fa2;
  --line: #e1d6c5;
  --line-soft: #ede3d4;
  --violet: #5a3d7a;
  --mauve: #8b6fa0;
  --rose: #c9919b;
  --gold: #b89968;
  --sage: #a8b89a;
  --teal: #3e7c92;
  --danger: #aa504f;
  --shadow: 0 12px 34px rgba(42, 30, 46, 0.1);
  --font-serif: "Fraunces", Georgia, serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  background: var(--cream);
  font-family: var(--font-sans);
  font-size: 14px;
  overflow: hidden;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(230px, 1fr) auto auto;
  gap: 24px;
  align-items: center;
  min-height: 78px;
  padding: 12px 22px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  min-width: 0;
}

.brand-logo {
  display: block;
  width: clamp(165px, 15vw, 235px);
  height: auto;
  max-height: 44px;
  object-fit: contain;
}

.brand-meta {
  display: flex;
  gap: 5px;
  align-items: baseline;
  padding-left: 14px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.brand-meta span::after {
  content: "·";
  margin-left: 5px;
}

.brand-meta strong {
  color: var(--mauve);
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 500;
}

.topbar-stats {
  display: flex;
  gap: 26px;
}

.stat {
  min-width: 50px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: center;
}

.stat strong {
  display: block;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
}

.stat span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  justify-content: end;
  gap: 7px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(350px, 405px) minmax(0, 1fr);
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--paper);
  border-right: 1px solid var(--line);
}

.controls {
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--line);
}

.search-field {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.64);
}

.search-field svg {
  width: 15px;
  color: var(--faint);
}

.search-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.filter-block {
  margin-top: 15px;
}

.filter-label,
.eyebrow {
  display: block;
  margin-bottom: 8px;
  color: var(--mauve);
  font-family: var(--font-serif);
  font-size: 13px;
  font-style: italic;
  font-weight: 500;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0;
  border: 0;
  background: transparent;
}

.segmented button,
.pill,
.ghost-btn,
.primary-btn,
.danger-btn,
.icon-btn,
.square-btn {
  border: 0;
  cursor: pointer;
  color: var(--ink);
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.segmented button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  min-height: 31px;
  padding: 0 12px;
  border: 1px solid color-mix(in srgb, var(--filter-color) 20%, var(--line));
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.38);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.segmented button i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--filter-color);
  opacity: 0.55;
}

.segmented button span {
  display: inline;
  margin-top: 0;
  font-weight: 500;
  opacity: 0.68;
}

.segmented button.active {
  background: color-mix(in srgb, var(--violet) 92%, white);
  border-color: color-mix(in srgb, var(--violet) 80%, var(--line));
  color: var(--paper);
}

.segmented button.active i {
  background: var(--paper);
  opacity: 0.9;
}

.zone-filter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 8px;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.pill {
  min-height: 31px;
  padding: 0 12px;
  border: 1px solid color-mix(in srgb, var(--pill-color, var(--line)) 34%, var(--line));
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.38);
  color: color-mix(in srgb, var(--pill-color, var(--muted)) 75%, var(--muted));
  font-size: 12px;
  font-weight: 600;
}

.pill span {
  margin-left: 5px;
  opacity: 0.65;
  font-weight: 500;
}

.pill.active {
  background: color-mix(in srgb, var(--violet) 92%, white);
  border-color: color-mix(in srgb, var(--violet) 80%, var(--line));
  color: var(--paper);
}

.order-list {
  min-height: 0;
  overflow: auto;
  padding: 4px 0;
}

.order-card {
  position: relative;
  padding: 17px 22px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}

.order-card:hover,
.order-card.selected {
  background: rgba(239, 231, 215, 0.62);
}

.order-card.selected::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 3px;
  background: color-mix(in srgb, var(--violet) 86%, white);
  content: "";
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 600;
}

.card-meta em {
  color: var(--mauve);
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 500;
}

.zone-chip {
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--zone-color) 13%, white);
  color: var(--zone-color);
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 500;
}

.order-card h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 3px;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
}

.order-card h3 b {
  display: inline-grid;
  place-items: center;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--violet);
  color: var(--paper);
  font-family: var(--font-serif);
  font-size: 12px;
}

.order-card p {
  margin: 0 0 11px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.card-foot em {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--font-serif);
  font-size: 12px;
  font-style: italic;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill,
.detail-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--status-color) 17%, white);
  color: color-mix(in srgb, var(--status-color) 72%, var(--ink));
  font-size: 12px;
  font-weight: 600;
}

.status-pill span,
.detail-status span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-color);
}

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--paper-deep);
}

.map {
  width: 100%;
  height: 100%;
}

.map-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 24px;
  text-align: center;
  background: var(--paper-deep);
}

.map-fallback[hidden] {
  display: none;
}

.map-fallback h2 {
  margin: 0 0 6px;
  font-family: var(--font-serif);
}

.route-drawer,
.order-detail,
.map-legend {
  position: absolute;
  z-index: 500;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 247, 239, 0.94);
  box-shadow: var(--shadow);
}

.route-drawer {
  top: 16px;
  left: 16px;
  display: none;
  width: min(380px, calc(100% - 36px));
  max-height: calc(100% - 36px);
  overflow: hidden;
}

.route-drawer.open {
  display: flex;
  flex-direction: column;
}

.drawer-head,
.detail-head,
.modal-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.drawer-head {
  padding: 16px 16px 11px;
  border-bottom: 1px solid var(--line-soft);
}

.drawer-head h2,
.detail-head h2,
.modal-head h2 {
  margin: 0;
  color: var(--violet);
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 600;
}

.drawer-body {
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.route-card {
  padding: 9px;
  border-bottom: 1px solid var(--line-soft);
}

.route-card:last-child {
  border-bottom: 0;
}

.route-card.active {
  background: #f2edf6;
  border-radius: 8px;
}

.route-main {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.route-swatch {
  width: 12px;
  height: 12px;
  margin-top: 5px;
  border-radius: 50%;
}

.route-main strong {
  font-family: var(--font-serif);
  font-size: 15px;
}

.route-main em {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.route-card ol {
  display: grid;
  gap: 4px;
  margin: 12px 0;
  padding: 0;
  list-style: none;
}

.route-card li {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.route-card li span {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--violet);
  color: var(--paper);
  font-size: 11px;
}

.route-card li strong,
.route-card li em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-card li em {
  grid-column: 2;
  color: var(--faint);
  font-style: normal;
}

.route-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.order-detail {
  top: 16px;
  right: 16px;
  width: min(320px, calc(100% - 32px));
  padding: 16px;
}

.map-legend {
  right: 16px;
  bottom: 16px;
  z-index: 420;
  width: 185px;
  padding: 15px 17px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 25px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
}

.legend-item span {
  width: 11px;
  height: 11px;
  border: 3px solid var(--paper);
  border-radius: 50%;
  background: var(--legend-color);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--legend-color) 45%, var(--line));
}

.detail-status {
  margin: 12px 0;
}

.order-detail dl {
  display: grid;
  gap: 9px;
  margin: 0;
}

.order-detail dl div {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 10px;
}

.order-detail dt {
  color: var(--faint);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.order-detail dd {
  margin: 0;
  color: var(--muted);
}

.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.detail-empty,
.empty-state {
  display: grid;
  gap: 7px;
  place-items: center;
  padding: 34px 18px;
  color: var(--muted);
  text-align: center;
}

.empty-state svg {
  width: 26px;
  height: 26px;
  color: var(--mauve);
}

.empty-state strong {
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 18px;
}

.icon-btn,
.primary-btn,
.ghost-btn,
.danger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.icon-btn,
.ghost-btn {
  border: 1px solid color-mix(in srgb, var(--line) 82%, white);
  background: transparent;
}

.icon-btn:hover,
.icon-btn.active,
.ghost-btn:hover {
  background: rgba(238, 228, 245, 0.72);
  border-color: color-mix(in srgb, #d5c3df 70%, var(--line));
  color: var(--violet);
}

.primary-btn {
  background: color-mix(in srgb, var(--violet) 92%, white);
  color: var(--paper);
}

.primary-btn:hover {
  background: #6b4f80;
}

.danger-btn {
  border: 1px solid rgba(170, 80, 79, 0.32);
  background: rgba(170, 80, 79, 0.08);
  color: var(--danger);
}

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

.square-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid color-mix(in srgb, var(--line) 82%, white);
  border-radius: 999px;
  background: transparent;
}

.square-btn:hover {
  background: #eee4f5;
  color: var(--violet);
}

svg {
  width: 15px;
  height: 15px;
  stroke-width: 2;
}

.modal {
  width: min(740px, calc(100vw - 28px));
  max-height: min(820px, calc(100vh - 28px));
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
}

.modal::backdrop {
  background: rgba(42, 30, 46, 0.42);
  backdrop-filter: blur(5px);
}

.modal-panel {
  max-height: min(820px, calc(100vh - 28px));
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

label.wide {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf7ef;
  color: var(--ink);
  outline: 0;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  padding: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--mauve);
  box-shadow: 0 0 0 3px rgba(139, 111, 160, 0.13);
}

.helper {
  margin: 10px 0 14px;
  color: var(--muted);
}

.paste-box {
  min-height: 210px;
  line-height: 1.6;
}

.check-row {
  display: flex;
  align-items: center;
  grid-template-columns: auto 1fr;
  gap: 9px;
  margin-top: 12px;
}

.check-row input {
  width: 16px;
  height: 16px;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}

.modal-actions-right {
  display: flex;
  gap: 8px;
}

.zones-editor {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.zone-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(150px, 1.4fr) 74px 90px 90px 38px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fbf7ef;
}

.zone-row input[type="color"] {
  padding: 4px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 3000;
  padding: 12px 15px;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

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

.shop-marker {
  border: 3px solid var(--paper);
  border-radius: 50%;
  background: var(--violet);
  box-shadow: 0 0 0 3px rgba(90, 61, 122, 0.24), 0 8px 18px rgba(42, 30, 46, 0.24);
}

.order-marker {
  display: grid;
  place-items: center;
}

.order-marker span {
  display: block;
  width: 16px;
  height: 16px;
  border: 3px solid var(--paper);
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(42, 30, 46, 0.25);
}

.order-marker.active span {
  width: 22px;
  height: 22px;
}

.route-marker {
  display: grid;
  place-items: center;
}

.route-line {
  filter: drop-shadow(0 2px 4px rgba(42, 30, 46, 0.16));
}

.route-marker span {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 3px solid var(--paper);
  border-radius: 50%;
  background: var(--violet);
  color: var(--paper);
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(42, 30, 46, 0.24);
}

.leaflet-popup-content-wrapper {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.popup {
  display: grid;
  gap: 4px;
  min-width: 180px;
}

.popup strong {
  font-family: var(--font-serif);
  font-size: 16px;
}

.popup span {
  color: var(--muted);
  font-size: 12px;
}

.popup em {
  font-family: var(--font-serif);
  font-size: 12px;
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .topbar-stats,
  .topbar-actions {
    justify-content: start;
  }

  .workspace {
    grid-template-columns: 380px minmax(0, 1fr);
  }

  .order-detail {
    width: min(340px, calc(100% - 36px));
  }
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
  }

  .topbar-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: 560px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .map-stage {
    height: 620px;
  }

  .segmented {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .order-detail {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
  }

  .route-drawer {
    top: 12px;
    left: 12px;
    width: calc(100% - 24px);
  }

  .form-grid,
  .modal-actions,
  .modal-actions-right {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .zone-row {
    grid-template-columns: 1fr;
  }
}
