* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: #f4f5f7;
  color: #1f2933;
  line-height: 1.6;
}

header {
  background: #1f2933;
  color: #fff;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

h1 {
  margin: 0;
  font-size: 20px;
}

.status {
  font-size: 13px;
  color: #d1d5db;
}

main {
  max-width: 1000px;
  margin: 24px auto;
  padding: 0 16px;
}

.card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 20px;
  margin: 16px 0;
}

.hidden {
  display: none !important;
}

.error {
  color: #c0392b;
  margin: 10px 0 0;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.module-tabs {
  display: flex;
  gap: 10px;
  margin: 0 0 18px;
}

.module-tab {
  border: 1px solid #cbd2d9;
  padding: 10px 20px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  color: #52606d;
  background: #fff;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease, opacity 0.18s ease;
}

.module-tab[data-module="bazi"] {
  color: #0f766e;
  border-color: #0f766e;
}

.module-tab[data-module="liuren"] {
  color: #2563eb;
  border-color: #2563eb;
}

.module-tab[data-module="chat"] {
  color: #d97706;
  border-color: #d97706;
}

.module-tab.active {
  color: #fff;
  opacity: 1;
  box-shadow: 0 8px 18px rgba(31, 41, 51, 0.22);
  transform: translateY(-1px);
}

.module-tab:not(.active) {
  background: #fff;
  opacity: 0.72;
}

.module-tab:not(.active):hover {
  opacity: 1;
  box-shadow: 0 0 0 1px rgba(31, 41, 51, 0.08);
}

.module-tab.active[data-module="bazi"] {
  background: #0f766e;
  border-color: #0f766e;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.28);
}

.module-tab.active[data-module="liuren"] {
  background: #2563eb;
  border-color: #2563eb;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.28);
}

.module-tab.active[data-module="chat"] {
  background: #d97706;
  border-color: #d97706;
  box-shadow: 0 8px 18px rgba(217, 119, 6, 0.28);
}

.module-panel {
  display: none;
}

.module-panel.active {
  display: block;
}

.tab {
  border: 1px solid #b6c2cc;
  background: #f1f5f9;
  color: #334e68;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.tab:hover {
  background: #e3eaf1;
  border-color: #94a3b8;
}

.tab.active {
  background: #1f2933;
  color: #fff;
  border-color: #1f2933;
  box-shadow: 0 2px 5px rgba(31, 41, 51, 0.18);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 12px 0;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  gap: 6px;
}

.field-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-stack label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.field-label {
  font-weight: 600;
}

input,
select,
textarea {
  padding: 9px 10px;
  border: 1px solid #cbd2d9;
  border-radius: 6px;
  font-size: 14px;
  width: 100%;
}

textarea {
  resize: vertical;
  font-family: inherit;
  line-height: 1.5;
}

button {
  border: none;
  background: #334e68;
  color: #fff;
  padding: 9px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

button.primary {
  background: #0f766e;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.result {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 20px;
  font-size: 15px;
  line-height: 1.75;
  min-height: 80px;
}

.result-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  color: #52606d;
  font-size: 15px;
}

.loading-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #0f766e;
  animation: typingBlink 1.2s infinite ease-in-out;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.result .result-segment {
  animation: resultSegmentIn 0.28s ease forwards;
  margin-bottom: 14px;
}

.result .result-segment:last-child {
  margin-bottom: 0;
}

.result p {
  margin: 0 0 12px;
  white-space: pre-wrap;
}

.result p:last-child {
  margin-bottom: 0;
}

.result .md-h1,
.result h1 {
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e2e8f0;
  font-size: 1.35em;
  color: #0f766e;
}

.result .md-h2,
.result h2 {
  margin: 18px 0 10px;
  font-size: 1.18em;
  color: #0f766e;
}

.result .md-h3,
.result h3 {
  margin: 14px 0 8px;
  font-size: 1.05em;
  color: #334e68;
}

.result .result-segment:first-child .md-h1,
.result .result-segment:first-child h1,
.result .result-segment:first-child .md-h2,
.result .result-segment:first-child h2,
.result .result-segment:first-child .md-h3,
.result .result-segment:first-child h3 {
  margin-top: 0;
}

.result strong {
  color: #0f766e;
  font-weight: 700;
}

.result ul,
.result ol {
  margin: 8px 0 14px;
  padding-left: 24px;
}

.result li {
  margin: 4px 0;
  line-height: 1.7;
}

.result blockquote {
  margin: 12px 0;
  padding: 8px 12px;
  border-left: 3px solid #0f766e;
  background: #f0fdfa;
  color: #334e68;
}

.result blockquote p {
  margin: 0;
}

.result code {
  padding: 2px 5px;
  border-radius: 4px;
  background: #eef2f7;
  color: #0f766e;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.result pre {
  margin: 12px 0;
  padding: 12px;
  border-radius: 8px;
  background: #1e293b;
  color: #e2e8f0;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre;
}

.result pre code {
  padding: 0;
  background: none;
  color: inherit;
  font-size: inherit;
}

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

.result-meta {
  font-size: 13px;
  color: #52606d;
  margin: 8px 0;
}

.raw-wrap {
  margin-top: 12px;
  font-size: 13px;
}

.raw-wrap pre {
  white-space: pre-wrap;
  background: #f8fafc;
  padding: 12px;
  border-radius: 6px;
}

@media (max-width: 720px) {
  body {
    font-size: 14px;
    line-height: 1.55;
  }

  main {
    margin: 12px auto;
    padding: 0 10px;
  }

  header {
    padding: 12px 14px;
  }

  h1 {
    font-size: 18px;
  }

  .status {
    font-size: 12px;
  }

  .card {
    padding: 14px 12px;
    margin: 12px 0;
  }

  .module-tabs {
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 14px;
  }

  .module-tab {
    padding: 9px 12px;
    font-size: 13px;
  }

  .tabs {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
  }

  .tab {
    flex: 1 1 auto;
    padding: 10px 12px;
    font-size: 13px;
    text-align: center;
  }

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

  .row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  input,
  select,
  textarea {
    padding: 11px 10px;
    font-size: 16px;
  }

  button {
    padding: 11px 14px;
    min-height: 44px;
    font-size: 15px;
  }

  .result {
    padding: 14px 12px;
    font-size: 14px;
    line-height: 1.7;
  }

  .result pre {
    padding: 10px;
    font-size: 12px;
  }

  .chat-messages {
    padding: 10px;
    max-height: 65vh;
  }

  .chat-input-row {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-body,
  .chat-bubble {
    max-width: 92%;
  }

  .calibration {
    padding: 12px;
  }

  .cal-actions {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 420px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .module-tab {
    flex: 1 1 100%;
  }

  .tab {
    min-width: calc(50% - 4px);
  }
}


.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px;
}

.chat-empty {
  text-align: center;
  color: #9aa5b1;
  font-size: 13px;
  padding: 40px 0;
}

.chat-msg {
  display: flex;
}

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

.chat-assistant {
  justify-content: flex-start;
}

.chat-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

.chat-user .chat-bubble {
  background: #0f766e;
  color: #fff;
}

.chat-assistant .chat-bubble {
  background: #fff;
  border: 1px solid #e2e8f0;
}

/* 长答案折叠：展开/收起按钮（手机友好） */
.chat-collapse-btn {
  display: block;
  margin: 10px auto 0;
  padding: 5px 12px;
  font-size: 12px;
  color: #0f766e;
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: 14px;
  cursor: pointer;
}
.chat-collapse-btn:active {
  opacity: 0.7;
}
.chat-collapse-more {
  margin-top: 8px;
}

/* 语音朗读按钮 */
.chat-speak-btn {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  font-size: 12px;
  color: #0f766e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 12px;
  cursor: pointer;
}
.chat-speak-btn:active {
  opacity: 0.7;
}

.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input-row textarea {
  flex: 1;
}


.calibration {
  margin: 16px 0;
  padding: 16px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #fffbeb;
}
.calibration h3 {
  margin: 0 0 8px;
  font-size: 16px;
  color: #92400e;
}
.cal-hint {
  margin: 0 0 12px;
  font-size: 13px;
  color: #78350f;
}
.cal-target {
  font-size: 13px;
  color: #0f766e;
  font-weight: 600;
  margin-bottom: 8px;
}
.cal-existing {
  font-size: 12px;
  color: #92400e;
  background: #fef3c7;
  padding: 10px;
  border-radius: 6px;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 10px;
}
.calibration textarea {
  width: 100%;
  border: 1px solid #cbd2d9;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.6;
  padding: 10px;
  resize: vertical;
  margin-bottom: 10px;
  box-sizing: border-box;
}
.cal-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.cal-status {
  font-size: 13px;
  color: #0f766e;
}


/* ==== 对话窗口增强 ==== */
.chat-messages {
  gap: 16px;
  padding: 16px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
}
.chat-msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.chat-user {
  flex-direction: row-reverse;
}
.chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex: 0 0 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  user-select: none;
}
.chat-user .chat-avatar {
  background: #0f766e;
}
.chat-assistant .chat-avatar {
  background: #334e68;
}
.chat-body {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}
.chat-meta {
  display: flex;
  gap: 6px;
  align-items: baseline;
  margin-bottom: 4px;
  font-size: 11px;
  color: #9aa5b1;
}
.chat-user .chat-meta {
  justify-content: flex-end;
}
.chat-name {
  font-weight: 600;
  color: #52606d;
}
.chat-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}
.chat-user .chat-bubble {
  background: #0f766e;
  color: #fff;
  border-top-right-radius: 4px;
}
.chat-assistant .chat-bubble {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-top-left-radius: 4px;
}
.chat-bubble code {
  background: rgba(15, 118, 110, 0.1);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
}
.chat-user .chat-bubble code {
  background: rgba(255, 255, 255, 0.2);
}
.chat-bubble pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0;
}
.chat-bubble pre code {
  background: none;
  color: inherit;
  padding: 0;
}
.chat-bubble strong {
  font-weight: 600;
}

.chat-bubble p {
  margin: 0 0 8px;
}

.chat-bubble p:last-child {
  margin-bottom: 0;
}

.chat-bubble .md-h1,
.chat-bubble .md-h2,
.chat-bubble .md-h3,
.chat-bubble h1,
.chat-bubble h2,
.chat-bubble h3 {
  margin: 8px 0 6px;
  font-size: 1em;
  color: #0f766e;
}

.chat-user .chat-bubble .md-h1,
.chat-user .chat-bubble .md-h2,
.chat-user .chat-bubble .md-h3,
.chat-user .chat-bubble h1,
.chat-user .chat-bubble h2,
.chat-user .chat-bubble h3 {
  color: #fff;
}

.chat-bubble ul,
.chat-bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}

.chat-bubble li {
  margin: 2px 0;
}

.chat-bubble blockquote {
  margin: 8px 0;
  padding: 6px 10px;
  border-left: 3px solid #0f766e;
  background: rgba(15, 118, 110, 0.08);
  color: #334e68;
}

.chat-user .chat-bubble blockquote {
  border-left-color: #fff;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.chat-bubble blockquote p {
  margin: 0;
}

.chat-tool {
  color: #6b4f00;
  background: #fffbeb;
  border-color: #f1d48f;
  font-size: 13px;
}

.chat-citations {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  font-size: 12px;
  color: #52606d;
  max-width: 78%;
}

.chat-citations-title {
  font-weight: 600;
  color: #0f766e;
  margin-bottom: 4px;
}

.chat-citations-toggle {
  border: none;
  background: transparent;
  color: #0f766e;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  font-weight: 600;
}

.chat-citations-list {
  margin-top: 4px;
}

.chat-citation-item {
  margin: 2px 0;
  line-height: 1.5;
  word-break: break-word;
}

.chat-bubble.typing {
  display: flex;
  gap: 4px;
  align-items: center;
  min-width: 46px;
  justify-content: center;
}
.chat-bubble.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #cbd5e1;
  animation: typingBlink 1.2s infinite ease-in-out;
}
.chat-bubble.typing span:nth-child(2) {
  animation-delay: 0.15s;
}
.chat-bubble.typing span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes typingBlink {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ==== 对话式起课/断课工具栏与图片预览 ==== */
.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #52606d;
}

.toolbar-select {
  width: auto;
  min-width: 168px;
  padding: 8px 10px;
  border: 1px solid #cbd2d9;
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
}

button.ghost {
  background: #fff;
  color: #334e68;
  border: 1px solid #cbd2d9;
}

button.ghost:hover {
  background: #f1f5f9;
}

button.link {
  background: none;
  color: #0f766e;
  border: none;
  padding: 0;
  font-size: 12px;
  cursor: pointer;
}

button.icon-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  border-radius: 8px;
  background: #fff;
  color: #334e68;
  border: 1px solid #cbd2d9;
}

button.icon-btn:hover {
  background: #f1f5f9;
}

.image-preview {
  margin: 0 0 12px;
  padding: 10px;
  border: 1px dashed #cbd2d9;
  border-radius: 10px;
  background: #fff;
}

.image-preview img {
  display: block;
  max-width: 100%;
  max-height: 220px;
  margin: 0 auto 8px;
  border-radius: 8px;
  object-fit: contain;
}

.image-preview-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: #52606d;
}

.module-panel .chat-messages {
  min-height: 280px;
}

.chat-input-row textarea {
  min-height: 44px;
}


/* ==== 紫微斗数 ==== */
.module-tab[data-module="ziwei"] {
  color: #7c3aed;
  border-color: #7c3aed;
}

.module-tab.active[data-module="ziwei"] {
  color: #fff;
  background: #7c3aed;
  border-color: #7c3aed;
  box-shadow: 0 8px 18px rgba(124, 58, 237, 0.28);
}

.ziwei-form-card {
  margin: 0 0 16px;
}

.ziwei-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  margin-bottom: 14px;
}

.ziwei-form-row label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  flex: 1 1 160px;
  min-width: 150px;
}

.ziwei-form-row input[type="date"],
.ziwei-form-row select {
  width: 100%;
}

.ziwei-leap {
  flex: 0 0 auto !important;
  flex-direction: row !important;
  align-items: center;
  gap: 6px !important;
}

.ziwei-check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #52606d;
  white-space: nowrap;
}

.ziwei-check-label input[type="checkbox"] {
  width: auto;
}

.ziwei-chart-box {
  margin: 16px 0;
  padding: 16px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow-x: auto;
}

.ziwei-chart {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, auto);
  gap: 6px;
  max-width: 560px;
  margin: 0 auto;
}

.ziwei-cell {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 6px;
  background: #fafbfc;
  min-height: 74px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ziwei-cell.is-ming {
  background: #f5f3ff;
  border-color: #7c3aed;
  box-shadow: 0 0 0 1px rgba(124, 58, 237, 0.25);
}

.ziwei-cell.is-body {
  box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.35) inset;
}

.ziwei-cell-name {
  font-size: 13px;
  font-weight: 700;
  color: #334e68;
}

.ziwei-cell.is-ming .ziwei-cell-name {
  color: #7c3aed;
}

.ziwei-cell-ganzhi {
  font-size: 12px;
  color: #9aa5b1;
}

.ziwei-cell-stars {
  font-size: 12px;
  color: #1f2933;
  line-height: 1.5;
  word-break: break-all;
}

.ziwei-cell.is-ming .ziwei-cell-stars {
  color: #6d28d9;
  font-weight: 600;
}

.ziwei-center {
  background: #f5f3ff;
  border: 1px solid #ddd6fe;
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  text-align: center;
}

.ziwei-center-title {
  font-size: 14px;
  font-weight: 700;
  color: #6d28d9;
  margin-bottom: 4px;
}

.ziwei-center-item {
  font-size: 12px;
  color: #4c1d95;
  line-height: 1.5;
}

@media (max-width: 720px) {
  .ziwei-chart {
    gap: 4px;
    max-width: 100%;
  }
  .ziwei-cell {
    padding: 6px 4px;
    min-height: 60px;
  }
  .ziwei-cell-name {
    font-size: 12px;
  }
  .ziwei-cell-stars {
    font-size: 11px;
  }
  .ziwei-center {
    padding: 8px 6px;
  }
  .ziwei-center-title {
    font-size: 12px;
  }
  .ziwei-center-item {
    font-size: 11px;
  }
  .ziwei-form-row label {
    flex: 1 1 100%;
    min-width: 100%;
  }
}

/* 备案 footer */
.site-footer {
  text-align: center;
  padding: 16px 12px 24px;
  font-size: 12px;
  color: #94a3b8;
}
.site-footer a {
  color: #94a3b8;
  text-decoration: none;
}
.site-footer a:hover {
  color: #64748b;
}
