:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --panel: #fffdfa;
  --panel-strong: #f2eee6;
  --ink: #20242a;
  --muted: #626a73;
  --line: #d8d1c5;
  --edge: #b6b0a6;
  --storage: #78909c;
  --navigation: #b0a899;
  --depot: #1f7a5c;
  --charger: #b14545;
  --route: #326bd1;
  --pickup: #a35a00;
  --dropoff: #276b4d;
  --focus: #0f5cb8;
  --idle: #65717d;
  --to-pickup: #2474bf;
  --to-dropoff: #21856d;
  --charging: #be6a15;
  --queued: #a63d48;
  --shadow: 0 16px 42px rgba(30, 26, 18, 0.12);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0)),
    var(--bg);
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

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

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 250, 0.92);
}

.topbar h1 {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 760;
  line-height: 1.2;
  letter-spacing: 0;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.topbar-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 12px;
}

.control-label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.control-label.compact {
  min-width: 82px;
}

select,
input[type="search"] {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

select {
  min-width: 160px;
  padding: 0 32px 0 10px;
}

input[type="search"] {
  width: min(32vw, 320px);
  min-width: 210px;
  padding: 0 10px;
}

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

.map-panel {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(42, 56, 68, 0.06) 1px, transparent 1px),
    linear-gradient(0deg, rgba(42, 56, 68, 0.06) 1px, transparent 1px),
    #fbfaf6;
  background-size: 36px 36px;
}

#warehouseMap {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 9px;
  min-height: 0;
  padding: 12px;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.metric {
  min-width: 0;
  padding: 7px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.metric span,
.section-title {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  min-height: 18px;
  margin-top: 5px;
  overflow-wrap: anywhere;
  font-size: 0.83rem;
  font-weight: 780;
}

.layer-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.layer-controls label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--panel-strong);
  font-size: 0.78rem;
  font-weight: 650;
}

.agv-list {
  display: grid;
  gap: 4px;
  margin-top: 6px;
}

.agv-card {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  min-height: 32px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-left-width: 5px;
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
}

.agv-card:focus-visible,
.agv-card.is-selected {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.agv-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.agv-head strong {
  overflow: hidden;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  justify-self: start;
  flex: 0 0 auto;
  padding: 2px 5px;
  border-radius: 4px;
  color: #fff;
  font-size: 0.58rem;
  font-weight: 800;
  text-transform: uppercase;
}

.agv-meta {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 1px 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.66rem;
}

.agv-meta span:nth-child(even) {
  overflow: hidden;
  color: var(--ink);
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agv-soc {
  display: grid;
  justify-items: end;
  gap: 3px;
  min-width: 50px;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
}

.soc-bar {
  width: 48px;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7e0d5;
}

.soc-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #b94343, #c98a1d 48%, #27805f);
}

.selection-panel {
  min-height: 72px;
  margin-top: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: #fff;
  font-size: 0.78rem;
  line-height: 1.45;
}

.selection-panel strong {
  color: var(--ink);
}

.timeline-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  min-height: 114px;
  max-height: 114px;
  overflow: hidden;
  padding: 12px 18px 14px;
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 250, 0.96);
}

.transport {
  display: flex;
  align-items: end;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

.icon-button:hover {
  border-color: #b8ab98;
  background: var(--panel-strong);
}

.icon-button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.play-icon,
.pause-icon,
.step-back-icon,
.step-forward-icon {
  display: block;
  width: 18px;
  height: 18px;
  position: relative;
}

.play-icon::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 2px;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 10px solid currentColor;
}

.pause-icon::before,
.pause-icon::after {
  content: "";
  position: absolute;
  top: 2px;
  width: 4px;
  height: 14px;
  background: currentColor;
}

.pause-icon::before {
  left: 4px;
}

.pause-icon::after {
  right: 4px;
}

.step-back-icon::before,
.step-forward-icon::before {
  content: "";
  position: absolute;
  top: 3px;
  width: 3px;
  height: 12px;
  background: currentColor;
}

.step-back-icon::before {
  left: 3px;
}

.step-forward-icon::before {
  right: 3px;
}

.step-back-icon::after,
.step-forward-icon::after {
  content: "";
  position: absolute;
  top: 2px;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
}

.step-back-icon::after {
  left: 8px;
  border-right: 9px solid currentColor;
}

.step-forward-icon::after {
  right: 8px;
  border-left: 9px solid currentColor;
}

.timeline {
  min-width: 0;
  min-height: 0;
}

.timeline-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--focus);
}

#queueChart {
  display: block;
  width: 100%;
  height: 44px;
  max-height: 44px;
  margin-top: 3px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px 8px;
  margin-top: 6px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-size: 0.68rem;
  font-weight: 650;
}

.legend-grid span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.legend-dot,
.legend-square,
.legend-diamond {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1px solid #fffdfa;
  box-shadow: 0 0 0 1px var(--line);
  flex: 0 0 auto;
}

.legend-dot {
  border-radius: 50%;
}

.legend-square {
  border-radius: 2px;
}

.legend-diamond {
  transform: rotate(45deg);
}

.legend-line {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 999px;
  background: var(--route);
  flex: 0 0 auto;
}

.legend-depot {
  background: var(--depot);
}

.legend-charger {
  background: var(--charger);
}

.legend-storage {
  background: var(--storage);
}

.legend-pickup {
  background: var(--pickup);
}

.legend-dropoff {
  background: var(--dropoff);
}

.hover-card {
  position: fixed;
  z-index: 12;
  max-width: min(320px, calc(100vw - 24px));
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  box-shadow: var(--shadow);
  pointer-events: none;
  font-size: 0.82rem;
  line-height: 1.35;
}

.load-error {
  position: absolute;
  z-index: 10;
  inset: 18px;
  max-width: 720px;
  padding: 14px 16px;
  border: 1px solid #c76969;
  border-radius: var(--radius);
  color: #6f1f1f;
  background: #fff4f2;
  box-shadow: var(--shadow);
}

.map-edge {
  stroke: var(--edge);
  stroke-width: 0.035;
  stroke-linecap: round;
  opacity: 0.72;
  vector-effect: non-scaling-stroke;
}

.map-node {
  stroke: #fffdfa;
  stroke-width: 0.018;
  vector-effect: non-scaling-stroke;
}

.node-navigation {
  fill: var(--navigation);
}

.node-storage {
  fill: var(--storage);
  opacity: 0.72;
}

.node-depot {
  fill: var(--depot);
}

.node-dropoff {
  fill: var(--dropoff);
}

.node-charger {
  fill: var(--charger);
}

.label-text {
  fill: #333942;
  paint-order: stroke;
  stroke: #fffdfa;
  stroke-width: 0.035;
  stroke-linejoin: round;
  font-size: 0.085px;
  font-weight: 700;
  pointer-events: none;
}

.route-line {
  fill: none;
  stroke: var(--route);
  stroke-width: 0.16;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.88;
  vector-effect: non-scaling-stroke;
}

.task-marker {
  stroke: #fffdfa;
  stroke-width: 0.035;
  vector-effect: non-scaling-stroke;
}

.task-pickup {
  fill: var(--pickup);
}

.task-dropoff {
  fill: var(--dropoff);
}

.agv-marker {
  cursor: pointer;
}

.agv-dot {
  stroke: #fffdfa;
  stroke-width: 0.052;
  vector-effect: non-scaling-stroke;
}

.agv-label {
  fill: #16191d;
  paint-order: stroke;
  stroke: #fffdfa;
  stroke-width: 0.045;
  stroke-linejoin: round;
  font-size: 0.075px;
  font-weight: 800;
  text-anchor: middle;
  pointer-events: none;
}

.focus-ring {
  fill: none;
  stroke: var(--focus);
  stroke-width: 0.045;
  opacity: 0.95;
  vector-effect: non-scaling-stroke;
}

.is-hidden {
  display: none;
}

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

  .app-shell {
    height: auto;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-controls {
    justify-content: start;
  }

  input[type="search"] {
    width: min(100%, 520px);
  }

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

  .map-panel {
    min-height: 58vh;
  }

  .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .timeline-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar,
  .side-panel,
  .timeline-panel {
    padding-inline: 12px;
  }

  .topbar-controls,
  .transport {
    align-items: stretch;
    flex-direction: column;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .metric-grid,
  .layer-controls {
    grid-template-columns: 1fr;
  }

  select,
  input[type="search"] {
    width: 100%;
    min-width: 0;
  }
}
