/*
 * Starting Point (启点) Design System
 * Based on "Lantern in the Night" metaphor
 * Target: 40-55 year old Chinese users, mobile-first web
 */

:root {
  /* Color Tokens */
  --bg-primary: #0A0A0B;
  --bg-secondary: #1C1C1E;
  --bg-tertiary: #2C2C2E;
  --bg-elevated: #3A3A3C;

  --text-primary: #E7E1DE;
  --text-secondary: #949494;
  --text-tertiary: #8E8E93;

  --gold: #C9A96E;
  --gold-subtle: rgba(201, 169, 110, 0.12);
  --gold-border: rgba(201, 169, 110, 0.25);

  --success: #4CAF50;
  --error: #FF453A;

  --divider: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.10);

  /* Typography */
  --font-main: "PingFang SC", -apple-system, "SF Pro Text", "Helvetica Neue", sans-serif;

  --t-hero: 600 28px/36px var(--font-main);
  --t-title: 600 22px/30px var(--font-main);
  --t-body: 400 17px/28px var(--font-main);
  --t-body-sm: 400 15px/24px var(--font-main);
  --t-caption: 400 13px/18px var(--font-main);
  --t-micro: 500 11px/16px var(--font-main);
  --t-button: 500 17px/24px var(--font-main);

  --tracking-hero: -0.02em;
  --tracking-title: -0.01em;
  --tracking-caption: 0.01em;
  --tracking-micro: 0.02em;

  /* Spacing (4px base) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* Layout */
  --max-width: 480px;
  --page-padding: 20px;
  --header-height: 44px;
  --input-height: 56px;
  --safe-bottom: 34px;

  /* Radius */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-pill: 9999px;

  /* Transitions */
  --transition-fast: 150ms ease-out;
  --transition-normal: 250ms ease-out;
}

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

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font: var(--t-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
  line-height: 1.5;
}

/* Utility */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--page-padding);
}

/* Header */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  padding: 0 var(--page-padding);
  z-index: 100;
}

.app-header__back {
  background: none;
  border: none;
  color: var(--gold);
  font-size: 20px;
  cursor: pointer;
  padding: var(--sp-2);
  margin-left: calc(var(--sp-2) * -1);
}

.app-header__title {
  font: var(--t-body-sm);
  font-weight: 600;
  color: var(--text-primary);
  margin-left: var(--sp-2);
}

.app-header__step {
  font: var(--t-caption);
  color: var(--text-tertiary);
  margin-left: auto;
}

/* Progress Bar */
.progress-bar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  height: 2px;
  background: var(--divider);
  z-index: 100;
}

.progress-bar__fill {
  height: 100%;
  background: var(--gold);
  transition: width 300ms ease-in-out;
}

/* Buttons */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  height: 50px;
  background: var(--gold);
  color: var(--bg-primary);
  font: var(--t-button);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.btn-primary:active {
  opacity: 0.85;
}

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  height: 50px;
  background: transparent;
  color: var(--text-primary);
  font: var(--t-button);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
}

/* Option Buttons */
.options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}

.option-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 var(--sp-5);
  background: transparent;
  color: var(--text-primary);
  font: var(--t-body-sm);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--transition-fast),
              background var(--transition-fast),
              color var(--transition-fast);
}

.option-btn:active {
  transform: scale(0.97);
}

.option-btn--selected {
  background: var(--gold-subtle);
  color: var(--gold);
  border-color: var(--gold);
  font-weight: 500;
}

/* Chat Bubbles */
.bubble-ai {
  max-width: 85%;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font: var(--t-body);
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--r-xl) var(--r-xl) var(--r-xl) 4px;
  margin-bottom: var(--sp-3);
}

.bubble-user-option {
  display: inline-block;
  background: var(--gold);
  color: var(--bg-primary);
  font: var(--t-body-sm);
  font-weight: 500;
  padding: var(--sp-2) var(--sp-5);
  border-radius: var(--r-xl) var(--r-xl) 4px var(--r-xl);
  margin-left: auto;
  margin-bottom: var(--sp-3);
}

.bubble-user-text {
  max-width: 85%;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font: var(--t-body);
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--r-xl) var(--r-xl) 4px var(--r-xl);
  margin-left: auto;
  margin-bottom: var(--sp-3);
}

/* Confidence Boost */
.confidence-boost {
  background: var(--gold-subtle);
  border-left: 3px solid var(--gold);
  padding: var(--sp-4) var(--sp-5);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  margin-bottom: var(--sp-3);
  font: var(--t-body-sm);
  color: var(--gold);
}

/* Input Bar */
.input-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-primary);
  border-top: 1px solid var(--divider);
  padding: var(--sp-3) var(--page-padding) calc(var(--sp-3) + var(--safe-bottom));
  z-index: 100;
}

.input-bar__inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  background: var(--bg-tertiary);
  border-radius: var(--r-pill);
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-5);
}

.input-bar__field {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font: var(--t-body);
  font-size: 17px; /* Prevent iOS zoom */
}

.input-bar__field::placeholder {
  color: var(--text-tertiary);
}

.input-bar__send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--text-tertiary);
  color: var(--bg-primary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
  flex-shrink: 0;
}

.input-bar__send--active {
  background: var(--gold);
}

/* Deliverable Card */
.result-card {
  background: var(--bg-secondary);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  margin: var(--sp-6) 0;
}

.result-card__title {
  font: var(--t-title);
  color: var(--text-primary);
  margin-bottom: var(--sp-6);
}

.result-item {
  padding: var(--sp-5) 0;
  border-bottom: 1px solid var(--divider);
}

.result-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.result-item__name {
  font: var(--t-body);
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: var(--sp-1);
}

.result-item__evidence {
  font: var(--t-body-sm);
  font-style: italic;
  color: var(--text-secondary);
}

.result-item__value {
  display: inline-block;
  background: var(--gold-subtle);
  color: var(--gold);
  font: var(--t-caption);
  font-weight: 500;
  padding: var(--sp-1) var(--sp-4);
  border-radius: var(--r-pill);
  margin-top: var(--sp-3);
}

.result-item__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}

.result-item__tag {
  background: var(--bg-primary);
  color: var(--text-secondary);
  font: var(--t-micro);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-sm);
}

/* Loading */
.loading-dots {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
}

.loading-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: loading-pulse 1.2s infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 200ms; }
.loading-dots span:nth-child(3) { animation-delay: 400ms; }

@keyframes loading-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* Animations */
.fade-in {
  animation: fadeIn var(--transition-normal) ease-out;
}

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

/* Focus Styles */
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.btn-primary:hover,
.btn-secondary:hover {
  opacity: 0.9;
}

.btn-primary:disabled,
.btn-secondary:disabled,
.option-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.option-btn:hover {
  border-color: var(--gold-border);
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Responsive */
@media (min-width: 640px) {
  .container {
    border-left: 1px solid var(--divider);
    border-right: 1px solid var(--divider);
  }
}

/* === V2 Components === */

/* Progress Chip */
.progress-chip {
  position: fixed;
  top: calc(var(--header-height) + 2px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font: var(--t-caption);
  padding: var(--sp-1) var(--sp-4);
  border-radius: var(--r-pill);
  border: 1px solid var(--divider);
  z-index: 100;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.progress-chip:hover {
  border-color: var(--gold-border);
}

/* Progress Grid (expanded) */
.progress-grid {
  position: fixed;
  top: calc(var(--header-height) + 2px + 32px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-3);
  z-index: 101;
  min-width: 240px;
  max-width: calc(100vw - 40px);
}

.progress-grid__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-3);
  border-radius: var(--r-md);
  cursor: default;
  border: none;
  background: none;
  font-family: var(--font-main);
}

.progress-grid__item--completed {
  color: var(--gold);
  cursor: pointer;
}

.progress-grid__item--completed:hover {
  background: var(--gold-subtle);
}

.progress-grid__item--current {
  background: var(--gold-subtle);
  color: var(--gold);
}

.progress-grid__item--future {
  color: var(--text-tertiary);
}

.progress-grid__icon {
  font-size: 20px;
  line-height: 1;
}

.progress-grid__name {
  font: var(--t-micro);
  text-align: center;
}

/* Output Card (shared base) */
.output-card {
  background: var(--bg-secondary);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  margin: var(--sp-4) 0;
  border-left: 3px solid var(--gold);
}

.output-card__title {
  font: var(--t-title);
  color: var(--gold);
  margin-bottom: var(--sp-4);
}

.output-card__subtitle {
  font: var(--t-caption);
  color: var(--text-tertiary);
  margin-bottom: var(--sp-4);
}

.output-card__field {
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--divider);
}

.output-card__field:last-child {
  border-bottom: none;
}

.output-card__label {
  font: var(--t-caption);
  color: var(--text-tertiary);
  margin-bottom: var(--sp-1);
}

.output-card__value {
  font: var(--t-body-sm);
  color: var(--text-primary);
}

/* Content Plan Accordion */
.content-week {
  background: var(--bg-secondary);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-3);
  border: 1px solid var(--divider);
}

.content-week summary {
  padding: var(--sp-4);
  font: var(--t-body-sm);
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.content-week summary::-webkit-details-marker {
  display: none;
}

.content-week summary::after {
  content: '▶';
  font-size: 12px;
  color: var(--text-tertiary);
  transition: transform var(--transition-fast);
}

.content-week[open] summary::after {
  transform: rotate(90deg);
}

.content-week__body {
  padding: 0 var(--sp-4) var(--sp-4);
}

/* Content Piece */
.content-piece {
  background: var(--bg-primary);
  border-radius: var(--r-sm);
  margin-bottom: var(--sp-2);
}

.content-piece summary {
  padding: var(--sp-3) var(--sp-4);
  font: var(--t-caption);
  color: var(--text-secondary);
  cursor: pointer;
  list-style: none;
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}

.content-piece summary::-webkit-details-marker {
  display: none;
}

.content-piece summary::after {
  content: '▼';
  font-size: 10px;
  color: var(--text-tertiary);
  margin-left: auto;
}

.content-piece[open] summary::after {
  content: '▲';
}

.content-piece__script {
  padding: var(--sp-3) var(--sp-4);
  font: var(--t-body-sm);
  color: var(--text-primary);
  border-top: 1px solid var(--divider);
  white-space: pre-wrap;
}

.content-piece__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  padding: 0 var(--sp-4) var(--sp-3);
}

.content-piece__tag {
  background: var(--gold-subtle);
  color: var(--gold);
  font: var(--t-micro);
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
}

/* Emotional Support */
.emotional-support {
  background: var(--gold-subtle);
  border-left: 3px solid var(--gold);
  padding: var(--sp-3) var(--sp-4);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  margin: var(--sp-3) 0;
  font: var(--t-body-sm);
  color: var(--gold);
}

/* Paywall / Pricing Cards */
.paywall {
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
}

.paywall__title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: var(--sp-2);
}

.paywall__subtitle {
  color: var(--text-secondary);
  margin-bottom: var(--sp-6);
}

.pricing-grid {
  display: grid;
  gap: var(--sp-4);
  max-width: 600px;
  margin: 0 auto;
}

.pricing-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.pricing-card:hover {
  border-color: var(--gold);
}

.pricing-card__name {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-primary);
  margin-bottom: var(--sp-1);
}

.pricing-card__price {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: var(--sp-2);
}

.pricing-card__price span {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text-secondary);
}

.pricing-card__desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.pricing-card--popular {
  border-color: var(--gold);
  position: relative;
}

.pricing-card--popular::after {
  content: '推荐';
  position: absolute;
  top: -10px;
  right: 16px;
  background: var(--gold);
  color: var(--bg-primary);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: var(--r-pill);
}

/* === Chat Layout (shared) === */

.chat-area {
  padding-top: calc(var(--header-height) + 2px + 32px + var(--sp-4));
  padding-bottom: calc(var(--input-height) + var(--sp-3) + var(--safe-bottom) + var(--sp-3));
  padding-left: var(--page-padding);
  padding-right: var(--page-padding);
  max-width: var(--max-width);
  margin: 0 auto;
}

.chat-area--no-chip {
  padding-top: calc(var(--header-height) + 2px + var(--sp-4));
}

.chat-area__messages {
  display: flex;
  flex-direction: column;
}

.chat-row {
  margin-bottom: var(--sp-3);
}

.chat-row--ai {
  display: flex;
  justify-content: flex-start;
}

.chat-row--user {
  display: flex;
  justify-content: flex-end;
}

.chat-row--confidence {
  display: flex;
  justify-content: flex-start;
}

.chat-row--loading {
  display: flex;
  justify-content: flex-start;
}

.chat-row--options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  padding-top: var(--sp-1);
}

/* Task Cards */
.task-card {
  background: var(--surface-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  margin: var(--sp-3) 0;
  transition: opacity 0.3s ease;
}
.task-card--done {
  opacity: 0.6;
}
.task-card--done .task-card__task {
  text-decoration: line-through;
}
.task-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-2);
}
.task-card__checkbox {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
}
.task-card__day {
  font-weight: 700;
  color: var(--text-primary);
}
.task-card__time {
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}
.task-card__task {
  font-size: var(--text-base);
  color: var(--text-primary);
  margin-bottom: var(--sp-2);
  line-height: 1.5;
}
.task-card__meta {
  margin-bottom: var(--sp-2);
}
.task-card__platform {
  display: inline-block;
  background: var(--surface-secondary);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}
.task-card__why {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
}
.task-card__signal {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* Market Radar */
.radar-section {
  margin-top: var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border-default);
}
.radar__title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--sp-3);
}
.radar__summary {
  font-size: var(--text-base);
  color: var(--text-secondary);
  margin-bottom: var(--sp-3);
  line-height: 1.5;
}
.radar__demand-row,
.radar__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-2) 0;
}
.radar__label {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}
.radar__value {
  font-size: var(--text-sm);
  color: var(--text-primary);
}
.radar__value--highlight {
  color: var(--color-primary, #4F46E5);
  font-weight: 600;
}
.radar__badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
}
.radar__badge--high {
  background: #DEF7EC;
  color: #03543F;
}
.radar__badge--medium {
  background: #FDF6B2;
  color: #723B13;
}
.radar__badge--low {
  background: #FDE8E8;
  color: #9B1C1C;
}
.radar__block {
  margin-top: var(--sp-2);
}
.radar__seller {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  padding: var(--sp-1) 0;
  padding-left: var(--sp-3);
  position: relative;
}
.radar__seller::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--text-tertiary);
}
.radar__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  margin-top: var(--sp-1);
}
.radar__tag {
  display: inline-block;
  background: var(--surface-secondary);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* --- Checkin Card --- */
.checkin-card {
  background: var(--surface-primary);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin: 8px 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.checkin-card__progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.checkin-card__progress-bar {
  flex: 1;
  height: 6px;
  background: var(--surface-secondary);
  border-radius: 3px;
  overflow: hidden;
}
.checkin-card__progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff6b35, #ff9a56);
  border-radius: 3px;
  transition: width 0.4s ease;
}
.checkin-card__progress-text {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
}
.checkin-card__task-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.checkin-card__meta {
  display: flex;
  gap: 12px;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.checkin-card__why {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.checkin-card__signal {
  font-size: var(--text-xs);
  color: #ff6b35;
}

/* --- Rescue Card --- */
.rescue-card {
  background: #fff8f0;
  border: 1px solid #ffe0c0;
  border-radius: var(--radius-lg);
  padding: 18px;
  margin: 8px 0;
}
.rescue-card__title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: #ff6b35;
  margin-bottom: 10px;
}
.rescue-card__advice {
  font-size: var(--text-sm);
  color: var(--text-primary);
  line-height: 1.6;
  white-space: pre-line;
}

/* --- Other Input --- */
.other-input-wrapper input:focus {
  border-color: #ff6b35;
  box-shadow: 0 0 0 2px rgba(255,107,53,0.15);
}
