:root {
  --bg-0: #060c18;
  --bg-1: #0d1a2e;
  --bg-2: #122034;
  --card: #0c1828;
  --card-border: #1c3058;
  --text: #e8f0ff;
  --muted: #7a9dc4;
  --accent: #4f8aff;
  --accent-2: #2cc482;
  --warn: #f4bc6a;
  --bad: #f06464;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(79, 138, 255, 0.45); }
  50%       { box-shadow: 0 0 0 7px rgba(79, 138, 255, 0); }
}

@keyframes progress-shine {
  0%   { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", "Trebuchet MS", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse at 10% 5%,  rgba(79, 138, 255, 0.14) 0%, transparent 38%),
    radial-gradient(ellipse at 92% 15%, rgba(44, 196, 130, 0.09) 0%, transparent 32%),
    radial-gradient(ellipse at 50% 95%, rgba(79, 138, 255, 0.06) 0%, transparent 40%),
    linear-gradient(165deg, var(--bg-0) 0%, var(--bg-1) 50%, var(--bg-2) 100%);
  background-attachment: fixed;
}

.app-shell {
  max-width: 1520px;
  margin: 0 auto;
  padding: 20px 22px;
  animation: fadeIn 0.4s ease;
}

/* ── TOPBAR ──────────────────────────────────────────────── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  padding: 14px 20px;
  background: rgba(8, 16, 30, 0.85);
  border: 1px solid rgba(79, 138, 255, 0.18);
  border-radius: 16px;
  backdrop-filter: blur(14px);
  box-shadow: 0 4px 28px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255,255,255,0.04);
}

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

.brand-icon {
  width: 46px;
  height: 46px;
  background: linear-gradient(135deg, #1a3c72, #264e96);
  border-radius: 12px;
  border: 1px solid rgba(79, 138, 255, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35), 0 0 20px rgba(79,138,255,0.15);
}

.brand h1 {
  margin: 0;
  font-size: 1.58rem;
  font-weight: 800;
  background: linear-gradient(90deg, #d4eaff 0%, #9ac6ff 50%, #6fa8ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.87rem;
  letter-spacing: 0.01em;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.score-chip {
  background: linear-gradient(135deg, rgba(14, 28, 54, 0.95), rgba(18, 36, 68, 0.95));
  border: 1px solid rgba(79, 138, 255, 0.38);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  box-shadow: 0 0 20px rgba(79, 138, 255, 0.1);
}

.score-chip span {
  margin-left: 8px;
  font-size: 1.08rem;
  color: #7ae3ff;
  font-weight: 800;
}

/* ── PHASE TRACK ─────────────────────────────────────────── */
.phase-track {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 16px;
  background: rgba(8, 16, 30, 0.75);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 10px 18px;
  backdrop-filter: blur(8px);
}

.phase-step {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 10px;
  transition: all 0.3s ease;
}

.phase-step-num {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(22, 38, 68, 0.9);
  border: 2px solid #243d66;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--muted);
  flex-shrink: 0;
  transition: all 0.3s ease;
}

.phase-step-text {
  font-size: 0.88rem;
  font-weight: 600;
  color: #4a6a96;
  transition: all 0.3s ease;
  letter-spacing: 0.01em;
}

.phase-connector {
  flex: 0 0 40px;
  height: 2px;
  background: #162538;
  margin: 0 4px;
  border-radius: 2px;
  transition: background 0.3s ease;
}

.phase-step.active {
  background: rgba(26, 52, 96, 0.55);
}

.phase-step.active .phase-step-num {
  background: linear-gradient(135deg, #2356aa, #3070d4);
  border-color: #4a8aec;
  color: #fff;
  animation: pulse-glow 2.2s ease infinite;
}

.phase-step.active .phase-step-text {
  color: #c8deff;
}

.phase-step.completed .phase-step-num {
  background: linear-gradient(135deg, #1a6044, #24864e);
  border-color: #34b062;
  color: #fff;
}

.phase-step.completed .phase-step-text {
  color: #5ebf90;
}

/* ── WORKSPACE ───────────────────────────────────────────── */
.workspace {
  display: grid;
  grid-template-columns: 440px 1fr;
  gap: 16px;
  align-items: start;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── CARDS ───────────────────────────────────────────────── */
.card {
  background: linear-gradient(160deg, rgba(10, 20, 36, 0.97), rgba(8, 16, 30, 0.97));
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 36px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255,255,255,0.025);
  animation: slideUp 0.3s ease;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #b8d4f8;
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
}

.card h2 .icon { font-size: 1rem; }

/* ── STATUS CARD ─────────────────────────────────────────── */
.status-card {
  border-color: rgba(79, 138, 255, 0.22);
  background: linear-gradient(160deg, rgba(10, 22, 42, 0.97), rgba(8, 16, 30, 0.97));
}

#notice {
  margin: 0 0 14px;
  color: #d0e4ff;
  min-height: 40px;
  font-size: 0.88rem;
  line-height: 1.55;
  padding: 9px 12px;
  background: rgba(12, 24, 46, 0.85);
  border: 1px solid rgba(79, 138, 255, 0.14);
  border-radius: 10px;
  transition: color 0.3s ease;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric-item {
  background: linear-gradient(160deg, rgba(18, 36, 62, 0.9), rgba(14, 28, 52, 0.9));
  border: 1px solid #1e3a60;
  border-radius: 12px;
  padding: 10px 8px 9px;
  text-align: center;
  transition: border-color 0.25s ease, transform 0.2s ease;
}

.metric-item:hover {
  border-color: #2e5484;
  transform: translateY(-1px);
}

.metric-item .k {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.metric-item strong {
  font-size: 1.1rem;
  font-weight: 800;
  color: #7ae3ff;
}

/* ── PANELS ──────────────────────────────────────────────── */
.panel { display: none; }
.panel.visible { display: block; }

.panel-tip {
  color: var(--muted);
  margin: 0 0 12px;
  font-size: 0.86rem;
  line-height: 1.55;
  padding: 9px 12px;
  background: rgba(8, 18, 36, 0.7);
  border-left: 3px solid rgba(79, 138, 255, 0.5);
  border-radius: 0 8px 8px 0;
}

.summary {
  margin-bottom: 12px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(14, 28, 52, 0.9);
  border: 1px solid #1e3a60;
  font-size: 0.85rem;
  color: #9abcd8;
  line-height: 1.5;
}

/* ── CLASSIFICATION TABLE ────────────────────────────────── */
.table-wrap {
  max-height: 380px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: #1e3a60 transparent;
}

.table-wrap::-webkit-scrollbar { width: 5px; }
.table-wrap::-webkit-scrollbar-thumb { background: #1e3a60; border-radius: 4px; }

.sku-row {
  background: rgba(12, 24, 44, 0.95);
  border: 1px solid #1a3460;
  border-radius: 10px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  transition: border-color 0.22s ease, background 0.22s ease;
}

.sku-row:hover {
  border-color: #2a4e82;
  background: rgba(16, 30, 54, 0.95);
}

.sku-row.good {
  border-color: rgba(44, 196, 122, 0.65);
  background: rgba(8, 34, 22, 0.7);
}

.sku-row.bad {
  border-color: rgba(240, 100, 100, 0.58);
  background: rgba(36, 10, 10, 0.65);
}

.sku-row .label { font-size: 0.84rem; }

.sku-row .label strong {
  display: block;
  color: #deeaff;
  font-size: 0.88rem;
  margin-bottom: 2px;
}

.sku-row .label .rot-text {
  color: var(--muted);
  font-size: 0.78rem;
}

.sales-bar {
  height: 3px;
  background: rgba(79, 138, 255, 0.18);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 5px;
}

.sales-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #4f8aff, #2cc482);
  transition: width 0.5s ease;
}

.class-buttons { display: flex; gap: 4px; }

.class-btn {
  min-width: 30px;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 800;
  font-size: 0.84rem;
  color: #fff;
  cursor: pointer;
  transition: all 0.16s ease;
  letter-spacing: 0.04em;
}

.class-btn:hover { transform: translateY(-1px); filter: brightness(1.18); }

.class-btn.a { background: linear-gradient(135deg, #1e6a45, #28924e); border-color: #2db86a; }
.class-btn.b { background: linear-gradient(135deg, #1c4c9c, #2460c4); border-color: #3a7ee4; }
.class-btn.c { background: linear-gradient(135deg, #882020, #ac3434); border-color: #d05858; }

.class-btn.active {
  outline: 2px solid rgba(255,255,255,0.85);
  outline-offset: 1px;
  filter: brightness(1.12);
}

/* ── PENDING CARDS ───────────────────────────────────────── */
.pending-cards {
  display: grid;
  gap: 6px;
  max-height: 250px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: #1e3a60 transparent;
}

.pending-cards::-webkit-scrollbar { width: 5px; }
.pending-cards::-webkit-scrollbar-thumb { background: #1e3a60; border-radius: 4px; }

.sku-card {
  border-radius: 10px;
  padding: 9px 12px;
  border: 1px solid transparent;
  cursor: grab;
  font-size: 0.86rem;
  user-select: none;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.sku-card::after {
  content: '⠿';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.05rem;
  opacity: 0.3;
}

.sku-card:hover {
  transform: translateX(4px);
  filter: brightness(1.1);
  cursor: grabbing;
}

.sku-card.a {
  background: linear-gradient(135deg, rgba(22, 84, 56, 0.92), rgba(16, 66, 44, 0.88));
  border-color: rgba(44, 196, 122, 0.42);
}

.sku-card.b {
  background: linear-gradient(135deg, rgba(22, 68, 136, 0.92), rgba(16, 54, 114, 0.88));
  border-color: rgba(79, 138, 255, 0.42);
}

.sku-card.c {
  background: linear-gradient(135deg, rgba(116, 32, 32, 0.92), rgba(92, 24, 24, 0.88));
  border-color: rgba(240, 100, 100, 0.42);
}

.sku-card-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  margin-left: 7px;
  vertical-align: middle;
  letter-spacing: 0.06em;
}

.sku-card.a .sku-card-badge { background: rgba(44,196,122,0.25); color: #60d898; border: 1px solid rgba(44,196,122,0.38); }
.sku-card.b .sku-card-badge { background: rgba(79,138,255,0.25); color: #80a8ff; border: 1px solid rgba(79,138,255,0.38); }
.sku-card.c .sku-card-badge { background: rgba(240,100,100,0.25); color: #f88888; border: 1px solid rgba(240,100,100,0.38); }

/* ── BUTTONS ─────────────────────────────────────────────── */
.slotting-actions {
  display: grid;
  gap: 8px;
  margin-bottom: 4px;
}

.sim-actions {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.btn {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.02em;
}

.btn:disabled {
  opacity: 0.36;
  cursor: not-allowed;
  filter: grayscale(0.25);
}

.btn-primary {
  background: linear-gradient(135deg, #2258cc, #3470e8);
  color: #eef4ff;
  border-color: #4484f8;
  box-shadow: 0 4px 16px rgba(50, 112, 232, 0.3);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #2a64d8, #3e7ef4);
  box-shadow: 0 6px 22px rgba(50, 112, 232, 0.45);
  transform: translateY(-2px);
}

.btn-secondary {
  background: linear-gradient(135deg, #145e80, #1a7ca6);
  color: #e4f6ff;
  border-color: #1e94c0;
  box-shadow: 0 4px 14px rgba(26, 124, 166, 0.22);
}

.btn-secondary:hover:not(:disabled) {
  background: linear-gradient(135deg, #1a6e94, #2090be);
  transform: translateY(-2px);
}

.btn-outline {
  background: rgba(10, 22, 42, 0.7);
  border-color: #223a62;
  color: #b4cef0;
}

.btn-outline:hover:not(:disabled) {
  background: rgba(18, 34, 62, 0.9);
  border-color: #34527e;
  transform: translateY(-2px);
}

/* ── SIMULATION METRICS ──────────────────────────────────── */
.sim-metrics {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.sim-metric-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.87rem;
  background: linear-gradient(135deg, rgba(12, 26, 50, 0.9), rgba(8, 20, 42, 0.9));
  border: 1px solid #1a3460;
  border-radius: 10px;
  padding: 8px 12px;
  transition: border-color 0.25s ease;
}

.sim-metric-item:hover { border-color: #2a4878; }

.sim-metric-item .metric-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.sim-metric-item .metric-icon { opacity: 0.85; }

.sim-metric-item strong {
  font-weight: 700;
  color: #a8caff;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

/* ── PROGRESS BAR ────────────────────────────────────────── */
.progress-wrap {
  height: 9px;
  background: rgba(16, 30, 56, 0.85);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid #1a3460;
  margin-top: 4px;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #1ea86a, #2ddc88, #1ea86a);
  background-size: 200% 100%;
  animation: progress-shine 1.8s linear infinite;
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* ── RESULTS BLOCK ───────────────────────────────────────── */
.results-block {
  background: rgba(10, 20, 38, 0.92);
  border: 1px solid #1a3460;
  border-radius: 14px;
  margin-bottom: 12px;
  overflow: hidden;
}

.results-header {
  padding: 16px 18px;
  background: linear-gradient(135deg, rgba(18, 36, 66, 0.9), rgba(12, 28, 52, 0.9));
  border-bottom: 1px solid #1a3460;
  display: flex;
  align-items: center;
  gap: 16px;
}

.results-score-circle {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 3px solid;
  flex-shrink: 0;
  box-shadow: 0 0 20px currentColor;
}

.results-score-circle .score-num {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
}

.results-score-circle .score-of {
  font-size: 0.62rem;
  opacity: 0.65;
  margin-top: 1px;
}

.results-grade {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  margin-top: 5px;
  letter-spacing: 0.04em;
}

.grade-low  { background: rgba(240,100,100,0.18); color: #f08080; border: 1px solid rgba(240,100,100,0.3); }
.grade-mid  { background: rgba(244,188,106,0.18); color: #f4bc6a; border: 1px solid rgba(244,188,106,0.3); }
.grade-high { background: rgba(44,196,130,0.18);  color: #4de0a8; border: 1px solid rgba(44,196,130,0.3); }

.results-body { padding: 14px 18px; }

.results-scores {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.results-score-item {
  text-align: center;
  background: rgba(14, 28, 52, 0.85);
  border: 1px solid #1a3460;
  border-radius: 10px;
  padding: 10px 6px;
}

.results-score-item .rs-label {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 5px;
}

.results-score-item .rs-val {
  font-size: 1.12rem;
  font-weight: 800;
  color: #8ec8ff;
}

.results-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, #1a3460, transparent);
  margin: 10px 0;
}

.results-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-size: 0.83rem;
}

.results-metric {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 9px;
  background: rgba(10, 20, 40, 0.75);
  border-radius: 8px;
  border: 1px solid #162840;
}

.results-metric .rm-label { color: var(--muted); font-size: 0.79rem; }
.results-metric .rm-val { font-weight: 700; color: #b0caee; font-variant-numeric: tabular-nums; }

/* ── STAGE / CANVAS ──────────────────────────────────────── */
.stage {
  background: rgba(8, 16, 28, 0.98);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.44);
}

.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}

.stage-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#warehouseCanvas {
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid #162840;
  display: block;
}

/* ── LEGEND ──────────────────────────────────────────────── */
.legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 8px 12px;
  background: rgba(8, 16, 30, 0.8);
  border: 1px solid #162840;
  border-radius: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot.a       { background: #2dbc7c; box-shadow: 0 0 7px rgba(45,188,124,0.7); }
.dot.b       { background: #4f8aff; box-shadow: 0 0 7px rgba(79,138,255,0.7); }
.dot.c       { background: #f06464; box-shadow: 0 0 7px rgba(240,100,100,0.7); }
.dot.pick    { background: #6bc9ea; }
.dot.storage { background: #b6c7de; }
.dot.recv    { background: #89b6d8; }
.dot.dock    { background: #64c4ff; }

/* ── SCROLLBARS ──────────────────────────────────────────── */
::-webkit-scrollbar        { width: 5px; height: 5px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: #1e3a60; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #2a4e7e; }

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 1200px) {
  .workspace { grid-template-columns: 1fr; }
}
