/* ========== 基础 ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* 兜底：防止组件的 display 样式覆盖 hidden 属性（如 .overlay 的 display:flex） */
[hidden] { display: none !important; }

:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --border: #e3e8f0;
  --text: #1f2733;
  --text-sub: #6b7686;
  --primary: #4f6ef7;
  --primary-hover: #3d5bf5;
  --danger: #e5484d;
  --success: #30a46c;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(31, 39, 51, .06), 0 4px 16px rgba(31, 39, 51, .05);
}

html, body { height: 100%; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}

/* ========== 顶栏 ========== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 22px; }
.topbar h1 { font-size: 17px; font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.model-badge {
  background: #eef1fe;
  color: var(--primary);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}

.status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot-ok { background: var(--success); }
.status-dot-missing { background: #d0d5dd; }

/* ========== 布局 ========== */
.layout {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 20px;
  padding: 20px 24px;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  flex: 1;
  align-items: start;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
}

/* ========== 面板 ========== */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.panel-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

/* ========== 表单 ========== */
.field { margin-bottom: 14px; }

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

/* input/select 有固有最小宽度，会撑破窄屏网格布局 */
.field-row .field { min-width: 0; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.required { color: var(--danger); font-style: normal; }

.field input[type="text"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fbfcfe;
  transition: border-color .15s, box-shadow .15s;
}

.field textarea { resize: vertical; }

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, .12);
  background: #fff;
}

.field-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
}

.field-hint {
  color: var(--text-sub);
  font-size: 12px;
  margin-top: 4px;
}

.form-hint {
  color: var(--text-sub);
  font-size: 12px;
  margin-top: 12px;
  text-align: center;
}

/* ========== 按钮 ========== */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { background: #f0f3f9; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-lg {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  margin-top: 6px;
}

.btn-sm { padding: 5px 10px; font-size: 13px; }

/* ========== 结果区 ========== */
.result-panel { display: flex; flex-direction: column; min-height: 480px; }

.result-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.result-toolbar .panel-title { margin-bottom: 0; }

.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.result-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  gap: 4px;
  padding: 60px 0;
}

.result-empty-icon { font-size: 40px; margin-bottom: 8px; }
.result-empty-sub { font-size: 12px; }

.result-error {
  background: #fdf0f0;
  border: 1px solid #f5c6c8;
  color: #a3272b;
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 13px;
  white-space: pre-wrap;
}

.result-content {
  flex: 1;
  overflow-y: auto;
  max-height: calc(100vh - 200px);
  animation: fadeIn .2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* 生成中的光标 */
.generating .result-content::after {
  content: "▋";
  color: var(--primary);
  animation: blink 1s step-start infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* ========== Markdown 渲染 ========== */
.markdown-body { font-size: 14px; }

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 18px 0 10px;
  line-height: 1.4;
}
.markdown-body h1 { font-size: 19px; }
.markdown-body h2 { font-size: 16px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.markdown-body h3 { font-size: 14.5px; }

.markdown-body p { margin: 8px 0; }
.markdown-body ul, .markdown-body ol { margin: 8px 0; padding-left: 22px; }
.markdown-body li { margin: 4px 0; }

.markdown-body strong { color: var(--text); }

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 13px;
  display: block;
  overflow-x: auto;
}

.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: #f0f3f9;
  font-weight: 600;
  white-space: nowrap;
}

.markdown-body tr:nth-child(even) td { background: #fafbfd; }

.markdown-body code {
  background: #eef1f6;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
}

.markdown-body blockquote {
  border-left: 3px solid var(--primary);
  background: #f6f8fe;
  padding: 8px 14px;
  margin: 10px 0;
  color: var(--text-sub);
  border-radius: 0 6px 6px 0;
}

.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ========== 弹窗 ========== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 39, 51, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(31, 39, 51, .2);
  width: 100%;
  max-width: 520px;
  padding: 20px 24px;
  animation: modalIn .18s ease;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h3 { font-size: 16px; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.test-status { margin-right: auto; font-size: 12px; }
.test-status.ok { color: var(--success); }
.test-status.fail { color: var(--danger); }

.key-input-group { display: flex; gap: 8px; }
.key-input-group input { flex: 1; }

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2733;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 4px 20px rgba(31, 39, 51, .3);
  z-index: 200;
  animation: toastIn .2s ease;
}

.toast.toast-error { background: var(--danger); }

@keyframes toastIn { from { transform: translate(-50%, 8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
