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

:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface-2: #1a1a26;
  --border: rgba(120, 80, 200, 0.2);
  --border-bright: rgba(160, 110, 255, 0.4);
  --text: #e8e4f0;
  --text-muted: #8a86a0;
  --ziping-accent: #a67cff;
  --ziping-glow: rgba(166, 124, 255, 0.15);
  --mangpai-accent: #f0c060;
  --mangpai-glow: rgba(240, 192, 96, 0.12);
  --vedic-accent: #60c8f0;
  --vedic-glow: rgba(96, 200, 240, 0.12);
  --radius: 12px;
  --font-serif: 'Georgia', 'Noto Serif SC', serif;
  --font-sans: 'Inter', 'PingFang SC', 'Helvetica Neue', sans-serif;
}

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
.app-header {
  text-align: center;
  padding: 2rem 1rem 1rem;
  border-bottom: 1px solid var(--border);
}

.app-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--ziping-accent), var(--mangpai-accent), var(--vedic-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.1em;
}

.app-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.4rem;
  letter-spacing: 0.05em;
}

/* ===== Input Section ===== */
.input-section {
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.input-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.input-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field-question { flex: 1; min-width: 260px; }
.field-city { min-width: 120px; }

/* Geo info display */
.geo-info {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 1.2em;
}

.geo-info .geo-success {
  color: #6bcf9a;
}

.geo-info.geo-error {
  color: #f07070;
}

/* Chart block in panels */
.chart-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1rem;
}

.chart-summary {
  cursor: pointer;
  padding: 0.6rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  user-select: none;
}

.chart-summary:hover {
  color: var(--text);
}

.chart-pre {
  padding: 0.8rem 1rem;
  font-size: 0.78rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin: 0;
}

.ai-interpretation {
  /* no extra wrapper styles needed, inherits panel-body */
}

/* ── BaZi visual chart ─────────────────────────────────────────────── */
.bazi-chart { padding: 0.8rem 1rem; }

.bazi-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.bazi-tst {
  font-size: 0.75rem;
  color: #6bcf9a;
  margin-bottom: 0.6rem;
  font-weight: 500;
}

.bazi-table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  margin-bottom: 0.6rem;
}

.bazi-table th {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.3rem;
  letter-spacing: 0.1em;
  border-bottom: 1px solid var(--border);
}

.bazi-table td {
  padding: 0.35rem 0.2rem;
  vertical-align: middle;
}

.bazi-tengod td {
  font-size: 0.65rem;
  color: var(--text-muted);
  padding-bottom: 0;
}

.bazi-stem td, .bazi-branch td {
  font-size: 1.4rem;
  font-family: var(--font-serif, serif);
  font-weight: 700;
}

.bazi-char {
  display: inline-block;
  width: 2.2rem;
  height: 2.2rem;
  line-height: 2.2rem;
  border-radius: 6px;
  text-align: center;
}

.bazi-hidden td {
  font-size: 0.72rem;
  padding-top: 0.15rem;
}

.hidden-stem {
  display: inline-block;
  margin: 0 1px;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.68rem;
}

/* Five-element colors */
.wx-木 { color: #4ade80; background: rgba(74, 222, 128, 0.12); }
.wx-火 { color: #f87171; background: rgba(248, 113, 113, 0.12); }
.wx-土 { color: #fbbf24; background: rgba(251, 191, 36, 0.12); }
.wx-金 { color: #e2e8f0; background: rgba(226, 232, 240, 0.12); }
.wx-水 { color: #60a5fa; background: rgba(96, 165, 250, 0.12); }

/* Relations tags */
.bazi-relations {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.6rem;
}

.rel-tag {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* Dayun timeline */
.bazi-dayun {
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

.dayun-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.3rem;
  letter-spacing: 0.1em;
}

.dayun-list {
  display: flex;
  gap: 0.15rem;
  overflow-x: auto;
  padding-bottom: 0.3rem;
}

.dayun-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 3.2rem;
  padding: 0.3rem 0.2rem;
  border-radius: 6px;
  background: var(--surface-2);
}

.dayun-gz {
  font-size: 0.9rem;
  font-weight: 700;
  font-family: var(--font-serif, serif);
}

.dayun-age {
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.dayun-shishen {
  font-size: 0.58rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.liuri-today {
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 6px rgba(166, 124, 255, 0.3);
}

.dayun-current {
  border: 1.5px solid var(--ziping-accent);
  box-shadow: 0 0 8px rgba(166, 124, 255, 0.3);
  background: rgba(166, 124, 255, 0.1);
}

.liunian-current {
  border: 1.5px solid var(--ziping-accent);
  box-shadow: 0 0 6px rgba(166, 124, 255, 0.3);
}

.liuyue-current {
  border: 1.5px solid var(--mangpai-accent);
  box-shadow: 0 0 6px rgba(240, 192, 96, 0.3);
}

/* ── Vedic South Indian Chart ──────────────────────────────────────── */
.vedic-chart-wrapper { padding: 0.8rem 1rem; }

.vedic-chart-south {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 2px;
  aspect-ratio: 1;
  max-width: 360px;
  margin: 0 auto;
  border: 2px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.vedic-cell {
  border: 1px solid var(--border);
  padding: 4px;
  min-height: 55px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: var(--surface-2);
  position: relative;
}

.vedic-center {
  grid-area: 2 / 2 / 4 / 4;
  background: var(--surface);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  letter-spacing: 0.1em;
}

/* Lagna (Ascendant) cell styling */
.vedic-cell-lagna {
  background: rgba(96, 200, 240, 0.08);
  border-color: var(--vedic-accent);
  border-width: 1.5px;
}

/* Diagonal line in Lagna cell (traditional South Indian marker) */
.vedic-cell-lagna::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 16px;
  height: 16px;
  border-bottom: 1.5px solid var(--vedic-accent);
  transform: rotate(-45deg);
  transform-origin: top right;
  pointer-events: none;
}

.vedic-asc-marker {
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 0.5rem;
  font-weight: 700;
  color: var(--vedic-accent);
  letter-spacing: 0.02em;
  line-height: 1;
}

/* Cell header: sign label + house number on same row */
.vedic-cell-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 2px;
}

.vedic-house-num {
  font-size: 0.5rem;
  color: var(--text-muted);
  opacity: 0.7;
  letter-spacing: 0.02em;
}

.vedic-lagna-info {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  padding-left: 2px;
}

.vedic-lagna-info strong {
  color: var(--vedic-accent);
}

.vedic-sign-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.vedic-planets {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-content: center;
}

.vedic-planet {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text);
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(255,255,255,0.06);
  cursor: default;
}

.dignity-exalted { color: #4ade80; background: rgba(74, 222, 128, 0.15); }
.dignity-debilitated { color: #f87171; background: rgba(248, 113, 113, 0.15); }
.dignity-own { color: #fbbf24; background: rgba(251, 191, 36, 0.15); }
.dignity-moolatrikona { color: #fb923c; background: rgba(251, 146, 60, 0.15); }
.dignity-friend { color: #a3e635; background: rgba(163, 230, 53, 0.10); }
.dignity-enemy { color: #e879f9; background: rgba(232, 121, 249, 0.10); }

.vedic-status-mark {
  font-size: 0.5rem;
  font-weight: 400;
  opacity: 0.8;
  margin-left: 1px;
}

.vedic-text-details {
  margin-top: 0.6rem;
}

label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

input[type="date"],
input[type="time"],
input[type="number"],
input[type="text"],
select,
textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  outline: none;
  transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--border-bright);
}

textarea { resize: vertical; }

.radio-group {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}

/* City presets */
.city-presets {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.preset-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.preset-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  transition: all 0.2s;
}

.preset-btn:hover {
  border-color: var(--border-bright);
  color: var(--text);
}

/* Start button */
.start-btn {
  background: linear-gradient(135deg, #6a3de8, #a050d0);
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 0.7rem 2rem;
  transition: opacity 0.2s, transform 0.1s;
  white-space: nowrap;
  align-self: flex-end;
}

.start-btn:hover { opacity: 0.9; }
.start-btn:active { transform: scale(0.97); }
.start-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Panels ===== */
.panels-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  padding: 1rem 1.5rem 2rem;
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 600px;
  overflow: hidden;
}

.panel-header {
  padding: 1rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.ziping-header  { background: var(--ziping-glow); }
.mangpai-header { background: var(--mangpai-glow); }
.vedic-header   { background: var(--vedic-glow); }

.panel-icon { font-size: 1.1rem; opacity: 0.7; }

.panel-header h2 {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 600;
}

.ziping-header  h2 { color: var(--ziping-accent); }
.mangpai-header h2 { color: var(--mangpai-accent); }
.vedic-header   h2 { color: var(--vedic-accent); }

.panel-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.panel-status {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.panel-status.loading::after {
  content: '解盘中…';
  animation: pulse 1.5s infinite;
}

.panel-status.done::after {
  content: '✓ 完成';
  color: #6bcf9a;
}

.panel-status.error::after {
  content: '✗ 错误';
  color: #f07070;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.panel-body {
  padding: 1.2rem;
  overflow-y: auto;
  flex: 1;
  font-size: 0.9rem;
  line-height: 1.75;
}

.idle-hint {
  color: var(--text-muted);
  text-align: center;
  margin-top: 3rem;
  font-size: 0.85rem;
}

/* Markdown content styles */
.panel-body h1, .panel-body h2, .panel-body h3 {
  font-family: var(--font-serif);
  margin: 1.2rem 0 0.5rem;
  line-height: 1.4;
}

.panel-body h1 { font-size: 1.2rem; }
.panel-body h2 { font-size: 1.05rem; }
.panel-body h3 { font-size: 0.95rem; color: var(--text-muted); }

.panel-body p { margin: 0.5rem 0; }
.panel-body ul, .panel-body ol { margin: 0.5rem 0 0.5rem 1.5rem; }
.panel-body li { margin: 0.25rem 0; }
.panel-body strong { color: #fff; font-weight: 600; }

.panel-body code {
  background: var(--surface-2);
  border-radius: 4px;
  font-size: 0.85em;
  padding: 0.1em 0.4em;
}

.panel-body blockquote {
  border-left: 3px solid var(--border-bright);
  color: var(--text-muted);
  margin: 0.5rem 0;
  padding-left: 1rem;
}

/* ── Vedic Tab Switcher ───────────────────────────────────────────── */
.vedic-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 0.5rem;
  overflow-x: auto;
}

.vedic-tab {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.72rem;
  padding: 0.35rem 0.6rem;
  white-space: nowrap;
  transition: all 0.2s;
}

.vedic-tab:hover { color: var(--text); border-color: var(--border-bright); }
.vedic-tab.active {
  background: var(--surface);
  color: var(--vedic-accent);
  border-color: var(--vedic-accent);
  border-bottom-color: var(--surface);
}

/* ===== Archive Toggle Button (header) ===== */
.archive-toggle-btn {
  position: absolute;
  right: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.82rem;
  padding: 0.45rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
}

.archive-toggle-btn:hover {
  border-color: var(--border-bright);
  color: var(--text);
}

.archive-icon { font-size: 1rem; }

.archive-count {
  background: linear-gradient(135deg, #6a3de8, #a050d0);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  min-width: 1.2rem;
  height: 1.2rem;
  line-height: 1.2rem;
  text-align: center;
  border-radius: 10px;
  padding: 0 0.3rem;
}

.archive-count:empty { display: none; }

.app-header { position: relative; }

/* ===== Save Button ===== */
.save-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.7rem 1.5rem;
  white-space: nowrap;
  align-self: flex-end;
  transition: all 0.2s;
}

.save-btn:hover {
  border-color: var(--border-bright);
  color: var(--text);
  background: rgba(106, 61, 232, 0.15);
}

/* ===== Archive Sidebar ===== */
.archive-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 900;
}

.archive-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.archive-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  max-width: 90vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.archive-panel.open {
  transform: translateX(0);
}

.archive-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.2rem 1rem;
  border-bottom: 1px solid var(--border);
}

.archive-panel-header h3 {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.archive-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.2rem;
  transition: color 0.2s;
}

.archive-close-btn:hover { color: var(--text); }

.archive-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.archive-empty {
  color: var(--text-muted);
  text-align: center;
  margin-top: 3rem;
  font-size: 0.85rem;
}

.archive-item {
  display: flex;
  align-items: stretch;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.archive-item:hover {
  border-color: var(--border-bright);
}

.archive-item-main {
  flex: 1;
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  min-width: 0;
}

.archive-item-date {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.archive-item-info {
  font-size: 0.8rem;
  color: var(--text);
  font-weight: 500;
}

.archive-item-question {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.archive-delete-btn {
  background: none;
  border: none;
  border-left: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0 0.7rem;
  transition: all 0.2s;
  display: flex;
  align-items: center;
}

.archive-delete-btn:hover {
  color: #f07070;
  background: rgba(240, 112, 112, 0.1);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: linear-gradient(135deg, #6a3de8, #a050d0);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.6rem 1.5rem;
  border-radius: 8px;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 2000;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
