/* ============================================================
   LK 拼团 — 全局样式（移动端优先）
   ============================================================ */

/* --- Reset & Variables --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --c-bg: #f0f2f5;
  --c-white: #ffffff;
  --c-text: #1a1a2e;
  --c-text-secondary: #6b7280;
  --c-border: #e5e7eb;
  --c-primary: #4f46e5;
  --c-primary-hover: #4338ca;
  --c-danger: #ef4444;
  --c-danger-hover: #dc2626;
  --c-success: #10b981;
  --c-warning: #f59e0b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

/* --- Header --- */
.header {
  text-align: center;
  padding: 32px 0 16px;
}
.header h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.subtitle {
  color: var(--c-text-secondary);
  font-size: 0.95rem;
  margin-top: 4px;
}
.back-link {
  display: inline-block;
  color: var(--c-primary);
  text-decoration: none;
  font-weight: 500;
  margin-bottom: 8px;
  font-size: 0.9rem;
}
.back-link:hover { text-decoration: underline; }
.badge {
  display: inline-block;
  background: var(--c-primary);
  color: #fff;
  font-size: 0.8rem;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
  font-weight: 600;
}

/* --- Cards --- */
.main-card {
  background: var(--c-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
}
.section { margin-bottom: 8px; }
.section h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 12px;
}
.hint {
  color: var(--c-text-secondary);
  font-size: 0.85rem;
  margin-bottom: 12px;
}

/* --- Products Editor --- */
.products-editor { margin-bottom: 8px; }
.product-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.product-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--c-primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.product-name-input { flex: 1; }

/* --- Batch Size --- */
.batch-size-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.batch-size-input { width: 90px; }
.batch-size-unit {
  color: var(--c-text-secondary);
  font-size: 0.9rem;
}

/* --- Join --- */
.join-row {
  display: flex;
  gap: 8px;
}
.join-input {
  flex: 1;
  font-family: monospace;
  font-size: 1.1rem;
  letter-spacing: 2px;
  text-align: center;
}

/* --- Inputs --- */
.input {
  padding: 10px 14px;
  border: 1.5px solid var(--c-border);
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color .15s;
  width: 100%;
  font-family: inherit;
}
.input:focus { border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }
.input-sm { padding: 6px 10px; font-size: 0.85rem; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--c-primary-hover); }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--c-border);
  color: var(--c-text);
}
.btn-outline:hover:not(:disabled) { background: var(--c-bg); }
.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--c-danger-hover); }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 14px 24px; font-size: 1.1rem; }
.btn-full { width: 100%; }

/* --- Form --- */
.order-form { margin-top: 8px; }
.form-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.label {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}
.qty-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.qty-label {
  font-size: 0.85rem;
  color: var(--c-text-secondary);
}
.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.order-tip {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--c-text-secondary);
}

/* --- Stats --- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--c-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
}
.stat-num {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--c-primary);
}
.stat-label {
  font-size: 0.8rem;
  color: var(--c-text-secondary);
  margin-top: 2px;
}

/* Product color stat cards */
.stat-a .stat-num { color: #3b82f6; }
.stat-b .stat-num { color: #10b981; }
.stat-c .stat-num { color: #8b5cf6; }
.stat-d .stat-num { color: #f59e0b; }
.stat-e .stat-num { color: #ec4899; }
.stat-f .stat-num { color: #06b6d4; }

/* --- Person Summary --- */
.person-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.person-card {
  background: var(--c-bg);
  border-radius: 8px;
  padding: 10px 14px;
  min-width: 140px;
}
.person-name {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 4px;
}
.person-qty { display: flex; gap: 6px; flex-wrap: wrap; }
.person-qty-item {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 6px;
  color: #fff;
  font-weight: 600;
}
.badge-a { background: #3b82f6; }
.badge-b { background: #10b981; }
.badge-c { background: #8b5cf6; }
.badge-d { background: #f59e0b; }
.badge-e { background: #ec4899; }
.badge-f { background: #06b6d4; }

/* --- Admin --- */
.admin-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.admin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}
.share-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.share-row .input {
  flex: 1;
  min-width: 200px;
  font-family: monospace;
  font-size: 0.85rem;
}
.toast {
  color: var(--c-success);
  font-size: 0.85rem;
  font-weight: 600;
}

/* --- Batches --- */
.batches-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}
.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 4px;
}
.legend-a .legend-dot { background: #3b82f6; }
.legend-b .legend-dot { background: #10b981; }
.legend-c .legend-dot { background: #8b5cf6; }
.legend-d .legend-dot { background: #f59e0b; }
.legend-e .legend-dot { background: #ec4899; }
.legend-f .legend-dot { background: #06b6d4; }
.legend-violation .legend-dot { background: #ef4444; }

.batch-card {
  background: var(--c-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.batch-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 10px;
}
.batch-count {
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--c-text-secondary);
}

/* Batch grid — items flow left-to-right, wrapping */
.batch-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.batch-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 10px;
  border-radius: 8px;
  min-width: 70px;
  color: #fff;
  font-weight: 600;
  font-size: 0.8rem;
  transition: transform .1s;
}
.batch-item:hover { transform: scale(1.05); }

/* Product colors */
.item-a { background: #3b82f6; }
.item-b { background: #10b981; }
.item-c { background: #8b5cf6; }
.item-d { background: #f59e0b; }
.item-e { background: #ec4899; }
.item-f { background: #06b6d4; }
.item-g { background: #6366f1; }
.item-h { background: #14b8a6; }

/* Violation highlight */
.item-violation {
  outline: 3px dashed #ef4444;
  outline-offset: 2px;
  animation: pulse-violation .8s infinite;
}
@keyframes pulse-violation {
  0%, 100% { outline-color: #ef4444; }
  50% { outline-color: #fca5a5; }
}

.item-person {
  font-size: 0.85rem;
  line-height: 1.2;
}
.item-product {
  font-size: 0.7rem;
  opacity: .85;
  line-height: 1.2;
}

/* --- History --- */
.history-section {
  margin-top: 24px;
}
.history-section h2 {
  font-size: 1rem;
  margin-bottom: 8px;
  color: var(--c-text-secondary);
}
.history-list { display: flex; flex-direction: column; gap: 6px; }
.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--c-white);
  border-radius: 8px;
  text-decoration: none;
  color: var(--c-text);
  box-shadow: var(--shadow);
  transition: box-shadow .15s;
}
.history-item:hover { box-shadow: var(--shadow-md); }
.history-code {
  font-weight: 700;
  font-family: monospace;
  font-size: 1rem;
  color: var(--c-primary);
}
.history-meta {
  flex: 1;
  font-size: 0.85rem;
  color: var(--c-text-secondary);
}
.history-badge {
  font-size: 0.75rem;
  background: var(--c-primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
}

/* --- States --- */
.loading, .error-msg, .empty-state, .closed-notice {
  text-align: center;
  padding: 32px;
  font-size: 1rem;
  color: var(--c-text-secondary);
}
.error-msg {
  color: var(--c-danger);
  background: #fef2f2;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

/* --- Entry Bar --- */
.entry-bar {
  text-align: center;
  padding: 20px 0 40px;
}
.entry-link {
  background: none;
  border: none;
  color: var(--c-text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  font-family: inherit;
}
.entry-link:hover {
  color: var(--c-primary);
}

/* --- Responsive --- */
@media (max-width: 600px) {
  .header h1 { font-size: 1.5rem; }
  .header { padding: 20px 0 8px; }
  .main-card { padding: 16px; }
  .stats-row { grid-template-columns: repeat(3, 1fr); }
  .batch-item { min-width: 55px; padding: 4px 6px; font-size: 0.7rem; }
  .batch-grid { gap: 4px; }
  .form-row { flex-direction: column; align-items: flex-start; }
  .admin-row { flex-direction: column; align-items: flex-start; }
  .share-row { flex-direction: column; align-items: stretch; }
}
