/* ===== 全局重置与基础 ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0f1419;
  --bg-secondary: #1a2332;
  --bg-card: #ffffff;
  --bg-input: #f5f7fa;
  --text-primary: #1a2332;
  --text-secondary: #5a6a7e;
  --text-light: #8b9bb4;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #dbeafe;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.15);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "Courier New", "Consolas", monospace;
}

html, body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===== 顶部导航栏 ===== */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  background: var(--bg-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-title {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.nav-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  object-fit: cover;
  background: #fff;
}

.nav-author-name {
  color: #e2e8f0;
  font-size: 14px;
  font-weight: 500;
}

.follow-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.follow-btn:hover {
  background: var(--accent-hover);
}

.help-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  background: transparent;
  color: #e2e8f0;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  line-height: 1;
}

.help-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(37,99,235,0.1);
}

.tools-link {
  color: #e2e8f0;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.3);
  transition: all 0.2s;
  white-space: nowrap;
}

.tools-link:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(37,99,235,0.1);
}

/* ===== 主体布局 ===== */
.main-container {
  display: flex;
  gap: 24px;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: flex-start;
}

/* ===== 左侧表单 ===== */
.form-panel {
  flex: 0 0 420px;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-section {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--accent-light);
}

.form-row {
  margin-bottom: 14px;
}

.form-row:last-child {
  margin-bottom: 0;
}

.field-hint {
  font-size: 12px;
  color: var(--danger);
  margin-top: 5px;
  font-weight: 500;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.required {
  color: var(--danger);
  margin-left: 2px;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-sans);
  background: var(--bg-input);
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.form-row input:focus,
.form-row select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
  background: #fff;
}

.date-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
}

.date-inputs input {
  flex: 1;
  text-align: center;
}

.date-sep {
  color: var(--text-light);
  font-weight: 600;
}

/* datalist 下拉箭头包裹 */
.datalist-wrap {
  position: relative;
}

.datalist-wrap input {
  padding-right: 32px !important;
  cursor: pointer;
}

.datalist-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--text-light);
  pointer-events: none;
  transition: border-top-color 0.2s;
}

.datalist-wrap:hover .datalist-arrow {
  border-top-color: var(--accent);
}

/* 自定义下拉菜单 */
.custom-dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  list-style: none;
  padding: 4px 0;
  z-index: 50;
  display: none;
  max-height: 200px;
  overflow-y: auto;
}

.dropdown-menu.active {
  display: block;
  animation: dropdownIn 0.15s ease;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.dropdown-menu li {
  padding: 9px 14px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s;
}

.dropdown-menu li:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.dropdown-menu li.selected {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

/* 日期 select 适配 */
.date-inputs select {
  flex: 1;
  text-align: center;
  padding: 10px 8px;
  appearance: auto;
}

/* 股票表头 */
.stock-header {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 8px;
  padding: 0 10px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--accent-light);
}

.section-header .section-title {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.clear-stock-btn {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.clear-stock-btn:hover {
  background: var(--danger);
  color: #fff;
}

.stock-header span {
  text-align: center;
}

.stock-header span:first-child {
  text-align: left;
}

.stock-header-action {
  width: 28px;
  text-align: center !important;
}

/* 股票列表 */
.stock-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.stock-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.stock-row input {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
  outline: none;
}

.stock-row input:focus {
  border-color: var(--accent);
}

.stock-row .stock-name-input {
  min-width: 0;
}

.remove-stock-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
  line-height: 1;
}

.remove-stock-btn:hover {
  background: rgba(239,68,68,0.1);
}

.add-stock-btn {
  width: 100%;
  padding: 10px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.add-stock-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* 操作区 */
.action-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.privacy-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.privacy-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.generate-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 14px rgba(37,99,235,0.35);
}

.generate-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(37,99,235,0.45);
}

.generate-btn:active {
  transform: translateY(0);
}

/* ===== 右侧预览区 ===== */
.preview-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
  position: sticky;
  top: 84px;
}

.preview-wrapper {
  width: 100%;
  max-width: 420px;
}

/* 长图卡片 */
.preview-card {
  background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  padding: 28px 24px 40px;
  position: relative;
  min-height: 600px;
}

/* 卡片头部 */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 8px;
}

.card-market-tag {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
}

.card-date {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.card-mood {
  width: 100%;
  font-size: 13px;
  color: var(--warning);
  font-weight: 600;
  margin-top: 4px;
}

/* 资产总览 */
.card-total-section {
  text-align: center;
  margin-bottom: 24px;
}

.card-total-label {
  font-size: 12px;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.card-total-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.card-total-value.masked {
  letter-spacing: 4px;
}

/* 环形图区域 */
.chart-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
}

.doughnut-container {
  position: relative;
  width: 200px;
  height: 200px;
  margin-bottom: 16px;
}

.doughnut-container canvas {
  width: 200px;
  height: 200px;
}

.doughnut-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.doughnut-center-label {
  font-size: 11px;
  color: var(--text-light);
}

.doughnut-center-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

/* 图例 */
.legend-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-name {
  flex: 1;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.legend-value {
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.legend-percent {
  width: 48px;
  text-align: right;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

/* 分区标题 */
.card-part-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-left: 10px;
  border-left: 3px solid var(--accent);
}

/* 目标持仓 */
.target-section {
  margin-bottom: 24px;
}

.target-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.target-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.target-bar-wrap {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  min-width: 0;
}

.target-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

.target-name {
  width: 80px;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
  font-weight: 500;
}

.target-percent {
  width: 44px;
  text-align: right;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

/* 达成率 */
.achievement-section {
  margin-bottom: 20px;
}

.achievement-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.achievement-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.achievement-name {
  width: 90px;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
  font-weight: 500;
}

.achievement-bar-wrap {
  flex: 1;
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
  min-width: 0;
}

.achievement-bar {
  height: 100%;
  border-radius: 5px;
  transition: width 0.3s;
}

.achievement-bar.over {
  background: linear-gradient(90deg, var(--warning), var(--danger)) !important;
}

.achievement-percent {
  width: 52px;
  text-align: right;
  font-weight: 700;
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.achievement-percent.over {
  color: var(--danger);
}

/* 时间戳 */
.card-timestamp {
  position: absolute;
  bottom: 12px;
  right: 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-light);
  letter-spacing: 1px;
}

/* 图注说明 */
.card-caption {
  font-size: 11px;
  color: var(--text-light);
  text-align: center;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  line-height: 1.6;
}

/* 空状态提示 */
.empty-hint {
  text-align: center;
  color: var(--text-light);
  font-size: 13px;
  padding: 20px;
}

/* ===== 模态框 ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 32px 28px 28px;
  max-width: 360px;
  width: 90%;
  position: relative;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.25s ease;
}

.modal-small {
  max-width: 400px;
}

.modal-ad {
  max-width: 380px;
  text-align: center;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-light);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-content {
  text-align: center;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.modal-qr {
  width: 180px;
  height: 180px;
  border-radius: var(--radius-md);
  margin: 0 auto 12px;
  display: block;
  border: 1px solid var(--border);
}

.modal-wechat-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.copy-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.copy-btn:hover {
  background: var(--accent-hover);
}

/* 确认弹窗 */
.confirm-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
  text-align: left;
}

.confirm-btns {
  display: flex;
  gap: 12px;
}

.confirm-btn {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.2s;
}

.confirm-btn.primary {
  background: var(--accent);
  color: #fff;
}

.confirm-btn.secondary {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.confirm-btn:hover {
  opacity: 0.85;
}

/* 广告弹窗 */
.cat-emoji {
  font-size: 48px;
  margin-bottom: 12px;
}

.ad-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 16px;
  text-align: left;
}

.ad-close-btn {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: #94a3b8;
  color: #fff;
  transition: background 0.2s;
  margin-top: 8px;
}

.ad-close-btn:not(:disabled) {
  background: var(--accent);
  cursor: pointer;
}

.ad-close-btn:not(:disabled):hover {
  background: var(--accent-hover);
}

.ad-close-btn:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

/* 声明弹窗 */
.modal-disclaimer {
  max-width: 420px;
}

.disclaimer-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.disclaimer-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 20px;
  text-align: left;
  padding: 0 8px;
}

.disclaimer-check {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  margin-bottom: 16px;
  user-select: none;
}

.disclaimer-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.disclaimer-btn {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  background: #94a3b8;
  color: #fff;
  transition: background 0.2s;
}

.disclaimer-btn:not(:disabled) {
  background: var(--accent);
  cursor: pointer;
}

.disclaimer-btn:not(:disabled):hover {
  background: var(--accent-hover);
}

.disclaimer-btn:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

/* 帮助内容 */
.help-content {
  text-align: left;
  max-height: 400px;
  overflow-y: auto;
}

.help-content p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 10px;
}

.help-content strong {
  color: var(--text-primary);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--text-primary);
  color: #fff;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  box-shadow: var(--shadow-lg);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== 响应式：手机端 ===== */
@media (max-width: 900px) {
  .main-container {
    flex-direction: column;
    padding: 16px;
    gap: 16px;
  }

  .form-panel {
    flex: none;
    max-width: 100%;
    width: 100%;
  }

  .preview-panel {
    position: static;
    width: 100%;
  }

  .preview-wrapper {
    max-width: 100%;
  }

  .top-nav {
    padding: 0 16px;
  }

  .site-title {
    font-size: 15px;
  }

  .nav-author-name {
    display: none;
  }
}

@media (max-width: 480px) {
  .stock-row {
    grid-template-columns: 1fr 1fr;
  }

  .stock-row .stock-name-input {
    grid-column: 1 / -1;
  }

  .remove-stock-btn {
    grid-column: 2;
    justify-self: end;
  }
}
