/* =========================================================
   呈尚策划 · 外卖店铺四件套 · Design System
   Light workspace, precise spacing, clean cards
   ========================================================= */

/* ── Design Tokens ────────────────────────────────────────── */
:root {
  /* Core colors */
  --background: #f6f7fb;
  --surface: #ffffff;
  --surface-raised: #f8fafc;
  --surface-overlay: #f1f5f9;
  --border: #d9e0ea;
  --border-subtle: #e8edf4;
  --border-strong: #b8c3d2;

  /* Text */
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-tertiary: #8a94a6;
  --text-inverse: #ffffff;

  /* Accent — amber for brand warmth within a light system */
  --accent: #b45309;
  --accent-foreground: #ffffff;
  --accent-subtle: rgba(180, 83, 9, 0.09);
  --accent-border: rgba(180, 83, 9, 0.28);

  /* Semantic colors */
  --success: #059669;
  --success-subtle: rgba(5, 150, 105, 0.1);
  --error: #dc2626;
  --error-subtle: rgba(220, 38, 38, 0.08);
  --error-border: rgba(220, 38, 38, 0.24);

  /* Per-module accent colors */
  --module-brand: #b45309;
  --module-market: #2563eb;
  --module-activity: #c2410c;
  --module-stats: #6d28d9;

  /* Radius */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 8px 32px rgba(15, 23, 42, 0.12);

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Typography */
  --font-sans: "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;

  /* Transitions */
  --transition: 0.15s ease;
  --transition-slow: 0.25s ease;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--background);
  min-height: 100vh;
}

/* ── Layout ───────────────────────────────────────────────── */
.page {
  max-width: 860px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-5) 80px;
}

/* ── Header ───────────────────────────────────────────────── */
.site-header {
  padding: var(--space-8) var(--space-8) var(--space-8);
  border-radius: var(--radius-xl);
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: var(--space-5);
  position: relative;
  overflow: hidden;
}

.site-header::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(180, 83, 9, 0.35), transparent);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  background: var(--accent-subtle);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: var(--space-5);
}

.brand-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.header-title {
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: var(--space-2);
}

.header-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 480px;
}

/* ── Line Switch ──────────────────────────────────────────── */
.line-switch {
  display: flex;
  align-items: stretch;
  gap: var(--space-3);
  margin-top: var(--space-6);
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.72), rgba(248, 250, 252, 0.9)),
    var(--surface-raised);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}

.line-switch-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 52px;
  padding: 0 var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  white-space: nowrap;
}

.line-switch-label::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-subtle);
}

.line-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  min-width: 320px;
}

.line-option {
  --route-color: var(--accent);
  --route-subtle: var(--accent-subtle);
  --route-border: var(--accent-border);
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 52px;
  padding: 9px 42px 9px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition:
    color var(--transition),
    background var(--transition),
    border-color var(--transition),
    box-shadow var(--transition),
    transform var(--transition);
  user-select: none;
}

.line-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.line-option-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.2;
  min-width: 0;
}

.line-option-copy > span:first-child {
  color: var(--text-primary);
  font-weight: 700;
  font-size: var(--text-sm);
}

.line-option-name {
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.line-option-emblem {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  border: 1px solid var(--route-border);
  background: var(--route-subtle);
  color: var(--route-color);
  font-size: var(--text-sm);
  font-weight: 800;
  flex-shrink: 0;
}

.line-option-check {
  position: absolute;
  top: 50%;
  right: 12px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
  transform: translateY(-50%);
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.line-option-check::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 3px;
  width: 5px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  opacity: 0;
  transform: rotate(45deg) scale(0.8);
  transition: opacity var(--transition), transform var(--transition);
}

.line-option:hover {
  color: var(--text-primary);
  border-color: var(--route-border);
  background: color-mix(in srgb, var(--route-color) 4%, var(--surface));
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
  transform: translateY(-1px);
}

.line-option:has(input:checked) {
  border-color: var(--route-color);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--route-color) 12%, transparent), transparent 70%),
    var(--surface);
  color: var(--text-primary);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--route-color) 18%, transparent);
}

.line-option:has(input:checked) .line-option-emblem {
  background: var(--route-color);
  border-color: var(--route-color);
  color: #fff;
}

.line-option:has(input:checked) .line-option-name {
  color: color-mix(in srgb, var(--route-color) 70%, var(--text-secondary));
}

.line-option:has(input:checked) .line-option-check {
  background: var(--route-color);
  border-color: var(--route-color);
  box-shadow: 0 0 0 4px var(--route-subtle);
}

.line-option:has(input:checked) .line-option-check::after {
  opacity: 1;
  transform: rotate(45deg) scale(1);
}

.line-option-line1 {
  --route-color: var(--accent);
  --route-subtle: var(--accent-subtle);
  --route-border: var(--accent-border);
}

.line-option-line2 {
  --route-color: #2563eb;
  --route-subtle: rgba(37, 99, 235, 0.08);
  --route-border: rgba(37, 99, 235, 0.24);
}

/* ── Module Card ──────────────────────────────────────────── */
.module-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  margin-bottom: var(--space-5);
  position: relative;
  transition: border-color var(--transition-slow);
}

.module-card:hover {
  border-color: var(--border-strong);
}

/* Colored left accent bar */
.module-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: var(--space-4);
  bottom: var(--space-4);
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--module-color, var(--accent));
  opacity: 0.8;
}

/* ── Module Head ──────────────────────────────────────────── */
.module-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-4);
}

.module-head-left {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.module-title {
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.module-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
}

.module-tag {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-inverse);
  background: var(--module-color, var(--accent));
  white-space: nowrap;
}

/* ── Field Grid ───────────────────────────────────────────── */
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4) var(--space-5);
}

.field-grid + .field-grid,
.field-section {
  margin-top: var(--space-4);
}

.field-full {
  grid-column: 1 / -1;
}

/* ── Form Labels ──────────────────────────────────────────── */
.field-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
  margin-bottom: var(--space-2);
}

.field-label-required::after {
  content: " *";
  color: var(--error);
}

/* ── Inputs ───────────────────────────────────────────────── */
.field-input,
.field-select,
.field-textarea {
  width: 100%;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.field-input::placeholder,
.field-textarea::placeholder {
  color: var(--text-tertiary);
}

.field-input:hover,
.field-select:hover,
.field-textarea:hover {
  border-color: var(--border-strong);
  background: var(--surface-overlay);
}

.field-input:focus,
.field-select:focus,
.field-textarea:focus {
  border-color: var(--module-color, var(--accent));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--module-color, var(--accent)) 15%, transparent);
  background: var(--surface-overlay);
}

.field-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238a94a6' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}

.field-select option {
  background: var(--surface-raised);
  color: var(--text-primary);
}

.field-textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.6;
}

.field-hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: var(--space-1);
  line-height: 1.5;
}

/* Input readonly */
.field-input[readonly] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Error state */
.field-input.is-error,
.field-select.is-error,
.field-textarea.is-error {
  border-color: var(--error) !important;
  box-shadow: 0 0 0 3px var(--error-subtle) !important;
}

/* ── Checkbox Group ───────────────────────────────────────── */
.checkbox-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 7px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
  user-select: none;
}

.checkbox-label:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.checkbox-label input[type="checkbox"] {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  accent-color: var(--module-color, var(--accent));
  cursor: pointer;
}

.checkbox-label:has(input:checked) {
  border-color: color-mix(in srgb, var(--module-color, var(--accent)) 40%, transparent);
  background: color-mix(in srgb, var(--module-color, var(--accent)) 8%, transparent);
  color: var(--text-primary);
}

/* ── Range Input ──────────────────────────────────────────── */
.range-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

input[type="range"] {
  width: 100%;
  height: 4px;
  appearance: none;
  -webkit-appearance: none;
  background: var(--border);
  border-radius: var(--radius-full);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--module-color, var(--accent));
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--module-color, var(--accent));
  border: 2px solid var(--surface);
  cursor: pointer;
}

/* ── Upload Section ───────────────────────────────────────── */
.upload-section {
  margin-top: var(--space-4);
}

.upload-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.upload-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border-strong);
  background: var(--surface-raised);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.upload-card:hover {
  border-color: var(--module-color, var(--accent));
  background: color-mix(in srgb, var(--module-color, var(--accent)) 5%, var(--surface-raised));
}

.upload-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--surface-overlay);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.upload-icon svg {
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
}

.upload-body {
  flex: 1;
  min-width: 0;
}

.upload-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.upload-desc {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.upload-filename {
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--module-color, var(--accent));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-tools {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-3);
  flex-wrap: wrap;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--text-primary);
  color: var(--text-inverse);
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.88;
  transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
  opacity: 1;
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 7px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: var(--font-sans);
  text-decoration: none;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
  white-space: nowrap;
}

.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
  background: var(--surface-raised);
}

/* ── Actions Row ──────────────────────────────────────────── */
.actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

/* ── Status & Error Messages ──────────────────────────────── */
.status-msg {
  font-size: var(--text-xs);
  color: var(--success);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.error-msg {
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--error-subtle);
  border: 1px solid var(--error-border);
  font-size: var(--text-xs);
  color: var(--error);
  line-height: 1.5;
  display: none;
}

.error-msg:not(:empty) {
  display: block;
}

/* ── Section Label ────────────────────────────────────────── */
.section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: var(--space-3);
}

/* ── Stats Grid (data-statistics module) ─────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
}

.stats-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

/* ── Toggle Grid (yes/no selects) ────────────────────────── */
.toggle-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--space-3);
}

/* ── Loading Spinner ──────────────────────────────────────── */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--text-inverse);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 760px) {
  .page {
    padding: var(--space-5) var(--space-4) 60px;
  }

  .site-header {
    padding: var(--space-6);
  }

  .header-title {
    font-size: var(--text-2xl);
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .toggle-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .checkbox-group {
    grid-template-columns: repeat(2, 1fr);
  }

  .module-head {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .line-options {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 480px) {
  .btn-primary {
    width: 100%;
    justify-content: center;
  }

  .line-switch {
    padding: var(--space-2);
  }

  .line-switch-label {
    width: 100%;
    justify-content: flex-start;
  }

  .line-options {
    grid-template-columns: 1fr;
  }

  .toggle-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .checkbox-group {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }
}
