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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-card: #1e2a4a;
  --bg-input: #1c2541;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0b8;
  --text-muted: #6c6c80;
  --accent: #6c63ff;
  --accent-glow: rgba(108, 99, 255, 0.3);
  --user-bubble: #2d5aa0;
  --ai-bubble: #2a2a40;
  --border: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.12);
  --success: #4caf50;
  --warning: #ff9800;
  --danger: #f44336;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-icon { font-size: 24px; }
.app-header h1 { font-size: 18px; font-weight: 600; background: linear-gradient(135deg, #a78bfa, #6c63ff); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.header-right { display: flex; gap: 8px; }
.header-btn {
  padding: 6px 14px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}
.header-btn:hover { background: rgba(255,255,255,0.12); color: var(--text-primary); }

/* ===== Main Layout ===== */
.app-main {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 53px);
  overflow: hidden;
}

/* ===== Birth Form ===== */
.birth-form-section {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}
.form-container {
  width: 100%;
  max-width: 520px;
  background: linear-gradient(145deg, var(--bg-secondary), var(--bg-card));
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.5s ease;
}
.form-title { text-align: center; font-size: 20px; margin-bottom: 6px; }
.form-subtitle { text-align: center; color: var(--text-secondary); font-size: 13px; margin-bottom: 28px; }
.form-row { display: flex; gap: 16px; margin-bottom: 18px; }
.form-group { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.form-group input[type="date"],
.form-group input[type="time"],
.form-group input[type="text"] {
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}
.form-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

/* Gender */
.gender-select { display: flex; gap: 10px; }
.gender-option input { display: none; }
.gender-btn {
  display: inline-block;
  padding: 9px 20px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}
.gender-option input:checked + .gender-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 12px var(--accent-glow);
}
.gender-btn:hover { border-color: var(--accent); }

/* City dropdown */
.city-input-wrapper { position: relative; }
.city-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
  z-index: 50;
  display: none;
  box-shadow: var(--shadow);
}
.city-dropdown.show { display: block; }
.city-option {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: var(--transition);
}
.city-option:hover { background: rgba(108, 99, 255, 0.15); color: var(--text-primary); }

/* Calculate button */
.btn-calculate {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #6c63ff, #a78bfa);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  margin-top: 8px;
}
.btn-calculate:hover { transform: translateY(-1px); box-shadow: 0 6px 24px var(--accent-glow); }
.btn-calculate:active { transform: translateY(0); }
.btn-calculate:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

/* ===== Cards Section ===== */
.cards-section {
  flex-shrink: 0;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  animation: fadeInUp 0.4s ease;
}
.cards-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.cards-header h3 { font-size: 15px; color: var(--text-secondary); }
.cards-actions { display: flex; gap: 8px; }
.btn-send-selected, .btn-send-all {
  padding: 6px 14px;
  background: rgba(108, 99, 255, 0.15);
  border: 1px solid rgba(108, 99, 255, 0.3);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition);
}
.btn-send-selected:hover, .btn-send-all:hover {
  background: rgba(108, 99, 255, 0.25);
}
.cards-container {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.chart-card {
  flex-shrink: 0;
  width: 180px;
  background: linear-gradient(145deg, var(--bg-card), var(--bg-secondary));
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: var(--transition);
  scroll-snap-align: start;
  position: relative;
}
.chart-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
  border-color: rgba(108, 99, 255, 0.3);
}
.chart-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow);
}
.chart-card .card-checkbox {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-light);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: var(--transition);
}
.chart-card.selected .card-checkbox {
  background: var(--accent);
  border-color: var(--accent);
}
.card-icon { font-size: 32px; margin-bottom: 10px; }
.card-name { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.card-summary { font-size: 12px; color: var(--text-secondary); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card-send-btn {
  margin-top: 10px;
  width: 100%;
  padding: 6px;
  background: rgba(108, 99, 255, 0.12);
  border: 1px solid rgba(108, 99, 255, 0.2);
  border-radius: 6px;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  transition: var(--transition);
}
.card-send-btn:hover { background: rgba(108, 99, 255, 0.25); }

/* ===== Card Modal ===== */
.card-modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
.modal-content {
  position: relative;
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.3s ease;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 22px;
  cursor: pointer;
  border-radius: 6px;
  transition: var(--transition);
}
.modal-close:hover { background: rgba(255,255,255,0.1); }
.modal-body { flex: 1; overflow-y: auto; padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }
.btn-modal-send {
  padding: 8px 20px;
  background: linear-gradient(135deg, #6c63ff, #a78bfa);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
}
.btn-modal-send:hover { box-shadow: 0 4px 16px var(--accent-glow); }

/* ===== Chat Section ===== */
.chat-section {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  scroll-behavior: smooth;
}
.welcome-message {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  animation: fadeIn 0.6s ease;
}
.welcome-icon { font-size: 48px; margin-bottom: 16px; }
.welcome-message h3 { font-size: 20px; color: var(--text-primary); margin-bottom: 8px; }
.welcome-message p { font-size: 14px; }

/* Chat messages */
.chat-msg {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  animation: msgIn 0.3s ease;
  max-width: 85%;
}
.chat-msg.user { flex-direction: row-reverse; margin-left: auto; }
.chat-msg .msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.chat-msg.ai .msg-avatar { background: linear-gradient(135deg, #6c63ff, #a78bfa); }
.chat-msg.user .msg-avatar { background: var(--user-bubble); }
.chat-msg .msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}
.chat-msg.ai .msg-bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
}
.chat-msg.user .msg-bubble {
  background: linear-gradient(135deg, #2d5aa0, #1e3a6e);
  border-top-right-radius: 4px;
}

/* Typing cursor */
.typing-cursor::after {
  content: '▊';
  animation: blink 0.8s step-end infinite;
  color: var(--accent);
  margin-left: 2px;
}

/* Chart info box in chat */
.chart-info-box {
  background: rgba(108, 99, 255, 0.08);
  border: 1px solid rgba(108, 99, 255, 0.2);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  overflow: hidden;
}
.chart-info-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--accent);
  transition: var(--transition);
}
.chart-info-header:hover { background: rgba(108, 99, 255, 0.05); }
.chart-info-header .arrow { transition: transform 0.2s; font-size: 10px; }
.chart-info-header .arrow.open { transform: rotate(90deg); }
.chart-info-body {
  padding: 0 14px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  line-height: 1.6;
  display: none;
  max-height: 300px;
  overflow-y: auto;
}
.chart-info-body.show { display: block; }

/* ===== Markdown in chat ===== */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3, .msg-bubble h4 {
  margin: 12px 0 6px;
  font-size: 15px;
  color: var(--text-primary);
}
.msg-bubble h1 { font-size: 18px; }
.msg-bubble h2 { font-size: 16px; }
.msg-bubble p { margin: 4px 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin: 6px 0; }
.msg-bubble li { margin: 2px 0; }
.msg-bubble strong { color: #c8c8e0; }
.msg-bubble code {
  background: rgba(255,255,255,0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'Fira Code', 'Consolas', monospace;
}
.msg-bubble pre {
  background: rgba(0,0,0,0.3);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 8px 0;
  overflow-x: auto;
}
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 13px;
}
.msg-bubble th, .msg-bubble td {
  border: 1px solid var(--border-light);
  padding: 6px 10px;
  text-align: left;
}
.msg-bubble th { background: rgba(255,255,255,0.05); }
.msg-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
}

/* ===== Input Section ===== */
.input-section {
  flex-shrink: 0;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
}
.input-container {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 800px;
  margin: 0 auto;
}
.chat-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 150px;
  transition: var(--transition);
}
.chat-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.chat-input:disabled { opacity: 0.5; }
.chat-input::placeholder { color: var(--text-muted); }
.btn-send {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #6c63ff, #a78bfa);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}
.btn-send:hover { box-shadow: 0 4px 16px var(--accent-glow); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Animations ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes blink {
  50% { opacity: 0; }
}

/* ===== Bazi Chart Component ===== */
.bazi-table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  font-size: 14px;
}
.bazi-table th {
  padding: 8px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.bazi-table td { padding: 10px 8px; }
.bazi-stem {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}
.bazi-branch {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}
.bazi-nayin { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.bazi-shishen { font-size: 11px; color: var(--warning); }
.bazi-dayun-timeline {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0;
  margin-top: 12px;
}
.dayun-item {
  flex-shrink: 0;
  text-align: center;
  padding: 8px 12px;
  background: rgba(255,255,255,0.04);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 12px;
  min-width: 60px;
}
.dayun-item.current { border-color: var(--accent); background: rgba(108, 99, 255, 0.1); }
.dayun-age { color: var(--text-muted); font-size: 10px; }
.dayun-gz { font-size: 16px; font-weight: 600; margin: 4px 0; }

/* Wuxing bar */
.wuxing-bars { margin-top: 12px; }
.wuxing-bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 12px; }
.wuxing-label { width: 24px; text-align: center; }
.wuxing-bar { flex: 1; height: 16px; background: rgba(255,255,255,0.05); border-radius: 8px; overflow: hidden; }
.wuxing-fill { height: 100%; border-radius: 8px; transition: width 0.6s ease; }
.wuxing-val { width: 30px; text-align: right; color: var(--text-muted); }

/* ===== Astro Chart Component ===== */
.astro-chart-svg { display: block; margin: 0 auto; }
.astro-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.astro-info-item {
  padding: 8px 10px;
  background: rgba(255,255,255,0.04);
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.astro-info-item .planet-name { color: var(--text-muted); font-size: 11px; }
.astro-info-item .planet-sign { font-weight: 600; }

/* ===== Mayan Glyph Component ===== */
.mayan-display { text-align: center; padding: 16px; }
.mayan-kin { font-size: 48px; font-weight: 700; color: var(--accent); }
.mayan-tone { font-size: 14px; color: var(--text-secondary); margin: 8px 0; }
.mayan-glyph-visual {
  width: 100px;
  height: 100px;
  margin: 16px auto;
  border: 3px solid var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  background: radial-gradient(circle, rgba(108,99,255,0.15), transparent);
}
.mayan-info { font-size: 13px; color: var(--text-secondary); line-height: 1.8; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .app-header { padding: 10px 14px; }
  .app-header h1 { font-size: 15px; }
  .header-btn { padding: 5px 10px; font-size: 12px; }
  .birth-form-section { padding: 14px; }
  .form-container { padding: 20px; }
  .form-row { flex-direction: column; gap: 12px; }
  .form-title { font-size: 17px; }
  .cards-section { padding: 12px 14px; }
  .cards-header { flex-direction: column; align-items: flex-start; }
  .chart-card { width: 160px; padding: 14px; }
  .chat-section { padding: 12px 14px; }
  .input-section { padding: 10px 14px 14px; }
  .chat-input { padding: 10px 12px; }
  .chat-msg { max-width: 92%; }
  .modal-content { width: 95%; max-height: 85vh; }
}

/* ===== Error toast ===== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  padding: 12px 24px;
  background: var(--danger);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 14px;
  z-index: 999;
  transition: transform 0.3s ease;
  box-shadow: var(--shadow);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
