:root {
  --ink: #0d1322;
  --ink-soft: #1e293b;
  --rose: #e11d48;
  --rose-soft: #fff1f2;
  --mint: #059669;
  --mint-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --crimson: #dc2626;
  --crimson-soft: #fee2e2;
  --info: #2563eb;
  --info-soft: #eff6ff;
  --canvas: #f8fafc;
  --card: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --muted: #64748b;
  --radius-card: 14px;
  --radius-btn: 10px;
  --shadow-xs: 0 1px 3px rgba(13, 19, 34, 0.05);
  --shadow-lg: 0 14px 36px rgba(13, 19, 34, 0.16);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: 84px;
}

.hidden { display: none !important; }
.tabular { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 58px;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
  position: relative;
}
.brand-mark::after {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--rose);
  position: absolute;
  top: 5px;
  right: 5px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-sub {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 36px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.pill-btn:hover { border-color: var(--border-strong); }

.icon-btn {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.notif-dot {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--rose);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Layout shell */
.shell {
  display: flex;
  min-height: calc(100vh - 58px);
}

.sidebar {
  display: none;
}

.main-content {
  flex: 1;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 14px;
}

/* Cards & KPIs */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px;
  box-shadow: var(--shadow-xs);
  margin-bottom: 14px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

h1, h2, h3 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}
h2 { font-size: 18px; }
h3 { font-size: 15px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.kpi-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 12px 14px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.kpi-val {
  font-size: 22px;
  font-weight: 800;
  margin-top: 6px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.kpi-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

/* Warehouse Banner */
.wh-card {
  background: var(--mint-soft);
  border: 1px solid #a7f3d0;
  border-radius: var(--radius-card);
  padding: 13px 14px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wh-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #065f46;
}
.wh-addr {
  background: rgba(255, 255, 255, 0.85);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  word-break: break-all;
}

/* Filter chips & search */
.search-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  background: var(--surface-alt);
  color: var(--ink);
  margin-bottom: 10px;
}
.search-input:focus {
  outline: none;
  background: var(--card);
  border-color: var(--ink);
}

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

.chip {
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.chip.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

/* Mission Cards */
.mission-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.mission-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mission-top {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.mission-thumb {
  width: 76px;
  height: 76px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.mission-meta {
  flex: 1;
  min-width: 0;
}

.mission-code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.code-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  background: var(--surface-alt);
  padding: 2px 7px;
  border-radius: 6px;
}

/* 3-step micro progress bar */
.micro-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 2px;
}
.micro-step {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}
.micro-bar {
  height: 4px;
  border-radius: 999px;
  background: var(--border);
}
.micro-step.done { color: var(--mint); font-weight: 600; }
.micro-step.done .micro-bar { background: var(--mint); }
.micro-step.active { color: var(--ink); font-weight: 700; }
.micro-step.active .micro-bar { background: var(--rose); }

.price-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 13px;
}

.price-highlight {
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.mission-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge-ASSIGNED, .badge-IN_PROGRESS { background: var(--info-soft); color: var(--info); }
.badge-PURCHASED, .badge-CN_SHIPPED, .badge-IN_WAREHOUSE { background: var(--mint-soft); color: var(--mint); }
.badge-INTL_SHIPPED, .badge-COMPLETED, .badge-CONFIRMED, .badge-REAL_API { background: var(--mint-soft); color: var(--mint); }
.badge-OUT_OF_STOCK, .badge-ANOMALY, .badge-CANCELLED, .badge-REJECTED { background: var(--crimson-soft); color: var(--crimson); }
.badge-PRICE_CHANGE, .badge-OVERDUE, .badge-PENDING_REFUND, .badge-MANUAL_FALLBACK { background: var(--amber-soft); color: var(--amber); }
.badge-SIMULATED_TEST { background: var(--surface-alt); color: var(--muted); }

/* Forms & Buttons */
label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 5px;
}

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  background: var(--card);
  color: var(--ink);
  margin-bottom: 11px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ink);
}
input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-btn);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.12s ease, transform 0.08s ease;
}
.btn:active { transform: scale(0.99); }
.btn-primary { background: var(--ink); color: #fff; }
.btn-mint { background: var(--mint); color: #fff; }
.btn-rose { background: var(--rose); color: #fff; }
.btn-warning { background: var(--amber); color: #fff; }
.btn-danger { background: var(--crimson); color: #fff; }
.btn-secondary { background: var(--card); color: var(--ink); border-color: var(--border); }
.btn-sm { min-height: 36px; padding: 6px 11px; font-size: 12px; }
.btn-block { width: 100%; }

/* Split Logistics Grid */
.split-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

/* Login & Forced Password Change */
.login-wrap {
  max-width: 420px;
  margin: 48px auto;
  padding: 0 16px;
}

/* Bottom Navigation (Mobile) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 45;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)) 8px;
}

.nav-item {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 6px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.nav-item.active {
  background: var(--ink);
  color: #fff;
}

/* Modal & Drawer */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(13, 19, 34, 0.56);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-sheet {
  background: var(--card);
  width: 100%;
  max-width: 740px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 18px;
  box-shadow: var(--shadow-lg);
}

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); }
th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

.error-box {
  background: var(--crimson-soft);
  color: var(--crimson);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}

.alert-callout {
  background: var(--rose-soft);
  border: 1px solid #fecdd3;
  border-radius: var(--radius-card);
  padding: 14px;
  margin-bottom: 14px;
}

.toast {
  position: fixed;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
}

@media (min-width: 768px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .kpi-grid-5 { grid-template-columns: repeat(5, 1fr); }
  .mission-grid { grid-template-columns: repeat(2, 1fr); }
  .split-grid { grid-template-columns: repeat(2, 1fr); }
  .modal-backdrop { align-items: center; }
  .modal-sheet { border-radius: 18px; }
}

@media (min-width: 1024px) {
  body { padding-bottom: 24px; }
  .bottom-nav { display: none; }
  .sidebar {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 236px;
    flex-shrink: 0;
    background: var(--card);
    border-right: 1px solid var(--border);
    padding: 16px 12px;
  }
  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .sidebar-item {
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .sidebar-item:hover { background: var(--surface-alt); color: var(--ink); }
  .sidebar-item.active { background: var(--ink); color: #fff; }
}
