:root {
  color-scheme: dark;
  --bg: #020617;
  --panel: #0f172a;
  --line: #334155;
  --text: #f8fafc;
  --muted: #cbd5e1;
  --faint: #94a3b8;
  --green: #22c55e;
  --green-ink: #052e16;
  --danger: #fca5a5;
  --focus: #22c55e;
  font-family: "Fira Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

button, input { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--line);
}

.eyebrow, .top-note, .picture-note, .meta, .group-label {
  color: var(--faint);
  font-size: 14px;
}

h1, h2, h3, p { margin: 0; }

h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 18px; font-weight: 600; }

.mark {
  font-family: "Fira Code", ui-monospace, monospace;
  font-weight: 500;
}

.load-step {
  background: #020617;
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  border-radius: 12px;
  padding: 16px;
}

.load-head { display: grid; gap: 8px; }

.meter {
  height: 6px;
  background: #1e293b;
  border-radius: 99px;
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  background: var(--green);
}

.load-step-row {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 8px 20px;
  align-items: start;
}

.load-number {
  font-family: "Fira Code", ui-monospace, monospace;
  font-size: 40px;
  line-height: 1;
}

.load-name { font-size: 18px; font-weight: 600; }

.load-place { display: grid; gap: 8px; }

.place-lines {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.place-lines li {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  padding-left: 12px;
  border-left: 3px solid var(--green);
}

.load-step .release { width: 100%; }

.top { flex: none; align-items: center; }

.top-search {
  display: grid;
  gap: 4px;
  flex: 1;
  max-width: 420px;
  min-width: 240px;
}

.top-search input {
  background: var(--bg);
  border: 1px solid var(--green);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
}

.workspace[hidden], .company[hidden], .shipments[hidden], #cargo-edit[hidden] { display: none; }

#cargo-edit:not([open]) > form { display: none; }

.view-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.view-switch button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  cursor: pointer;
}

.view-switch button[aria-pressed="true"] {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
  font-weight: 600;
}

.load-problem { color: var(--danger); }

.company {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 20px 24px 32px;
}

.company-head { display: grid; gap: 6px; margin-bottom: 16px; max-width: 720px; }

.company .order-test { max-width: 520px; margin-bottom: 20px; }

.company-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.order-saved {
  display: grid;
  gap: 8px;
  align-content: start;
}

.order-card {
  display: grid;
  gap: 6px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  min-height: 44px;
  cursor: pointer;
}

.order-card:hover { border-color: var(--muted); }

.order-title { font-weight: 600; }

.status-held, .status-ready { font-weight: 600; font-size: 14px; }

.status-held { color: var(--danger); }

.status-ready { color: var(--green); }

.status-reason { color: var(--muted); font-size: 14px; }

.order-open-name { align-self: center; font-weight: 600; }

.type-pills { display: flex; flex-wrap: wrap; gap: 6px; }

.type-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 420px;
}

.shipments {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex: 0 0 auto;
  min-height: 72px;
  align-items: center;
}

.shipments .tab {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 6px 12px;
  cursor: pointer;
  display: grid;
  text-align: left;
  white-space: nowrap;
}

.shipments .tab[aria-pressed="true"] {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.shipments .tab[aria-pressed="true"] .meta { color: #334155; }

.vehicle-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  margin: 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: #0f172a;
  border: 1px solid var(--line);
  font-weight: 600;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow: auto;
  min-height: 0;
}

.detail { border-right: 0; border-left: 1px solid var(--line); }

.search { display: grid; gap: 6px; margin-bottom: 16px; }

.order-test {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.order-test summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.order-test textarea {
  width: 100%;
  min-height: 132px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-family: "Fira Code", ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.4;
}

.order-test button {
  width: 100%;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 8px 12px;
  cursor: pointer;
}

#load-hard, #run-order {
  background: var(--green);
  color: var(--green-ink);
  border-color: var(--green);
  font-weight: 600;
}

input[type="search"] {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 44px;
}

.group { display: grid; gap: 6px; margin-bottom: 16px; }

.part {
  display: grid;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 44px;
  cursor: pointer;
}

.part:hover { background: #1e293b; }

.part[aria-current="true"] {
  background: #1e293b;
  border-color: var(--line);
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 8px;
}

.stage {
  display: grid;
  grid-template-rows: auto auto auto auto auto minmax(0, 1fr) auto auto;
  min-width: 0;
  min-height: 0;
  padding: 12px 16px 16px;
  gap: 8px;
}

.stage-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}

.departures { display: flex; flex-wrap: wrap; gap: 8px; min-height: 44px; }

.legs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.legs[hidden] { display: none; }
.vehicle-pick {
  width: 168px;
  min-height: 108px;
  border-radius: 8px;
  border: 1px solid #134e4a;
  background: #020617;
  color: #5eead4;
  padding: 6px 8px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.vehicle-pick img { width: 152px; height: 68px; object-fit: contain; display: block; pointer-events: none; }
.vehicle-pick span { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; }
.vehicle-pick[aria-pressed="true"] {
  border-color: #5eead4;
  box-shadow: inset 0 0 0 1px #5eead4;
  background: #042f2e;
  color: #ccfbf1;
}

.play-row, .view-row, .cargo-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.view-row button, .cargo-actions button, .cargo-form select {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 8px 12px;
  cursor: pointer;
}

.legend { display: flex; flex-wrap: wrap; gap: 10px; }

.legend-item { color: var(--muted); font-size: 14px; }

.cargo-form, .cargo-grid, .add-form { display: grid; gap: 8px; margin-bottom: 16px; }

.add-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

.add-form input, .add-form select, .add-grid label { width: 100%; }

.add-form label, .add-grid label { display: grid; gap: 4px; color: var(--faint); font-size: 13px; }

.add-form input, .add-form select {
  min-height: 44px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

#add-error:empty { display: none; }

.cargo-form[hidden] { display: none; }

.cargo-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.cargo-form input, .cargo-form select, .order-test input[type="file"] {
  width: 100%;
  min-height: 44px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.cargo-grid label { display: grid; gap: 4px; color: var(--faint); font-size: 13px; }

.check { display: flex; gap: 8px; align-items: center; min-height: 44px; }

#cargo-add {
  background: var(--green);
  color: var(--green-ink);
  border-color: var(--green);
  font-weight: 600;
}

#cargo-error:empty { display: none; }

.plan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.plan-table th, .plan-table td {
  text-align: left;
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.dim-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

.dim-grid label { display: grid; gap: 4px; color: var(--faint); font-size: 13px; }

.dim-grid input {
  width: 100%;
  min-height: 44px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

#play-load {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--green);
  background: var(--green);
  color: var(--green-ink);
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
  flex: none;
}

#play-load[data-mode="stop"] {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

#play-status { margin: 0; color: var(--muted); }

.departures button, .release {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 8px 12px;
  cursor: pointer;
}

.departures button {
  display: block;
  text-align: left;
  min-width: 0;
  white-space: nowrap;
}

.departures button[aria-pressed="true"] {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.departures button[aria-pressed="true"] .meta { color: #334155; }

.view {
  position: relative;
  min-height: 0;
  height: 100%;
  background: #020617;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

#truck { width: 100%; height: 100%; display: block; cursor: grab; }

.view-hint {
  position: absolute;
  left: 12px;
  bottom: 12px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}

.stack { display: grid; gap: 14px; }

.facts, .missing { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }

.facts li, .missing li, .check-list li {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.missing li { color: var(--danger); }

.check-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; }

.release {
  background: var(--green);
  color: var(--green-ink);
  border-color: var(--green);
  font-weight: 600;
}

.release:disabled {
  background: #1e293b;
  color: var(--faint);
  border-color: var(--line);
  cursor: not-allowed;
}

.tag {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
  font-size: 13px;
}

.quality-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.quality-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-height: 64px;
}

.quality-grid span {
  display: block;
  color: var(--faint);
  font-size: 13px;
}

.quality-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.check-list p { margin: 4px 0 0; }

.plan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.plan-actions .part { min-height: 44px; }

#print-sheet { display: none; }

@media print {
  body {
    height: auto;
    overflow: visible;
    background: #fff;
    color: #111;
  }

  body > *:not(#print-sheet) { display: none !important; }

  #print-sheet {
    display: block;
    padding: 16px;
    color: #111;
  }

  #print-sheet .quality-grid div,
  #print-sheet table,
  #print-sheet th,
  #print-sheet td {
    border-color: #111;
    color: #111;
  }

  #print-sheet .quality-grid span,
  #print-sheet .meta { color: #333; }
}

@media (max-width: 1024px) {
  body { height: auto; overflow: auto; }
  .top { flex-direction: column; align-items: start; }
  .workspace { grid-template-columns: 1fr; min-height: auto; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .detail { border-left: 0; }
  .view { height: 70vw; min-height: 320px; }
}
