:root {
  --bg: #f4f5f7; --card: #ffffff; --ink: #1c2330; --muted: #6b7280;
  --line: #e5e7eb; --brand: #2563eb; --green: #16a34a; --amber: #d97706;
  --red: #dc2626; --radius: 12px; --shadow: 0 1px 3px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--card); padding: 28px; border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card input { padding: 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 16px; }
.muted { color: var(--muted); font-size: 13px; margin: 0; }
/* Honeypot: kept out of sight and tab order; real users never fill it. */
.hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.alert { background: #fee2e2; color: var(--red); padding: 10px; border-radius: 8px; font-size: 14px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; justify-content: center; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 10px 14px; border-radius: 8px;
  font-size: 14px; text-decoration: none; font-weight: 600; }
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-ship { background: var(--green); color: #fff; border-color: var(--green); flex: 1; }
.btn-unship { background: #fff; color: var(--amber); border-color: var(--amber); flex: 1; }
.btn-upload { background: #eef2ff; color: var(--brand); border-color: #c7d2fe; position: relative; overflow: hidden; }
.btn-upload input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* Top bar */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 900px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { font-weight: 700; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.inline { display: inline; margin: 0; }
.role-chip { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: #eef2ff; color: var(--brand);
  padding: 3px 8px; border-radius: 999px; font-weight: 700; }

/* Sync progress (admin) */
.sync-progress { border-top: 1px solid var(--line); background: #eef2ff; }
.sync-progress-inner { max-width: 900px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; gap: 12px; }
.sync-progress-label { font-size: 13px; font-weight: 600; color: var(--brand); white-space: nowrap; }
.sync-progress-track { flex: 1; height: 8px; background: #c7d2fe; border-radius: 999px; overflow: hidden; }
.sync-progress-fill { height: 100%; width: 0; background: var(--brand); border-radius: 999px; transition: width .3s ease; }
.sync-progress-fill.indeterminate { width: 30%; animation: sync-slide 1.1s ease-in-out infinite; }
@keyframes sync-slide { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }
.sync-progress.is-error { background: #fee2e2; }
.sync-progress.is-error .sync-progress-label { color: var(--red); }
.sync-progress.is-error .sync-progress-track { background: #fecaca; }
.sync-progress.is-error .sync-progress-fill { background: var(--red); }

.container { max-width: 900px; margin: 0 auto; padding: 16px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat-num { display: block; font-size: 22px; font-weight: 700; }
.stat-lbl { font-size: 12px; color: var(--muted); }
.stat.shipped .stat-num { color: var(--green); }
.stat.pending .stat-num { color: var(--amber); }

/* Controls */
.controls { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; margin-bottom: 14px; }
.tabs { display: flex; gap: 6px; background: var(--card); padding: 4px; border-radius: 10px; border: 1px solid var(--line); }
.tab { padding: 7px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; }
.tab.active { background: var(--brand); color: #fff; }
.search { display: flex; gap: 6px; }
.search input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; min-width: 180px; }
.empty { text-align: center; color: var(--muted); padding: 40px; }

/* Order card */
.order { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 14px; overflow: hidden; scroll-margin-top: 70px; }
.order.is-shipped { border-color: #bbf7d0; }
.order-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line); background: #fafafa; }
.order.is-shipped .order-head { background: #f0fdf4; }
.order-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.order-meta .date { font-weight: 700; }
.order-meta .seller { color: var(--ink); font-size: 14px; }
.order-meta .ordno { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.badges { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; flex-shrink: 0; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.badge.status { background: #eff6ff; color: var(--brand); }
.badge.ship-yes { background: #dcfce7; color: var(--green); }
.badge.ship-no { background: #fef3c7; color: var(--amber); }

.order-body { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 14px; }
.items { display: flex; flex-direction: column; gap: 8px; }
.item { border-left: 3px solid var(--line); padding-left: 10px; }
.item-name { font-size: 14px; line-height: 1.35; }
.item-orig { font-size: 11px; color: #9aa1ad; line-height: 1.3; margin-top: 1px; }
.item-sub { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.item-sub .qty { font-weight: 700; color: var(--ink); }
.order-foot { margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--line); display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.order-foot .total strong { color: var(--ink); }

/* Tracking table */
.track-table { border-collapse: collapse; margin-top: 10px; width: 100%; max-width: 340px;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font-size: 13px; }
.track-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 10px;
  white-space: nowrap; width: 96px; background: #f9fafb; border-bottom: 1px solid var(--line); }
.track-table tr:last-child th { border-bottom: none; }
.track-table td { padding: 6px 10px; border-bottom: 1px solid var(--line); word-break: break-all; }
.track-table tr:last-child td { border-bottom: none; }
.track-table .track-no { font-variant-numeric: tabular-nums; font-weight: 600; letter-spacing: .01em; }
.no-track { margin-top: 10px; font-size: 12px; color: var(--muted); font-style: italic; }

/* Agent panel */
.agent-panel { display: flex; flex-direction: column; gap: 10px; }
.photos { display: flex; flex-wrap: wrap; gap: 8px; min-height: 40px; }
.photo { position: relative; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-del { position: absolute; top: 2px; right: 2px; margin: 0; }
.photo-del button { background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 999px; width: 22px; height: 22px;
  cursor: pointer; font-size: 15px; line-height: 1; }
.no-photo { color: var(--muted); font-size: 13px; display: grid; place-items: center; width: 100%; border: 1px dashed var(--line); border-radius: 8px; padding: 14px; }
.agent-actions { display: flex; gap: 8px; }
.agent-actions form { margin: 0; display: flex; flex: 1; }
.notes-form { display: flex; gap: 8px; align-items: flex-start; }
.notes-form textarea { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: inherit; font-size: 13px; resize: vertical; }

@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .order-body { grid-template-columns: 1fr; }
  .controls { flex-direction: column; }
  .search input { flex: 1; min-width: 0; }
}
