/* ===== AI自助建站平台 前端样式 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #4f6ef7;
  --primary-dark: #3a56d4;
  --success: #10b981;
  --danger: #ef4444;
  --bg: #f5f7fb;
  --card: #ffffff;
  --border: #e5e8f0;
  --text: #1f2937;
  --text-light: #6b7280;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(79, 110, 247, 0.08);
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border: none; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 500; transition: all .2s; white-space: nowrap;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #0ea371; }
.btn-ghost { background: transparent; color: var(--text-light); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f0f2f8; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* 登录视图 */
.auth-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4f6ef7 0%, #7c3aed 50%, #a855f7 100%);
}
.auth-card {
  background: #fff; border-radius: 16px; padding: 40px 36px; width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.auth-logo { font-size: 48px; text-align: center; }
.auth-card h1 { text-align: center; font-size: 22px; margin: 8px 0 4px; }
.auth-sub { text-align: center; color: var(--text-light); font-size: 13px; margin-bottom: 20px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; background: #f0f2f8; padding: 4px; border-radius: 8px; }
.tab-btn { flex: 1; padding: 8px; border: none; background: transparent; border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--text-light); }
.tab-btn.active { background: #fff; color: var(--primary); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.auth-form .form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--text); font-weight: 500; }
.form-group input, .form-group select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none;
  transition: border .2s;
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); }
.auth-msg { color: var(--danger); font-size: 13px; margin-top: 12px; text-align: center; min-height: 18px; }
.field-tip { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.checkbox-group label { display: flex; align-items: center; gap: 8px; font-weight: normal; cursor: pointer; }
.checkbox-group input { width: auto; }

/* 主应用布局 */
.app-view { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: 56px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.04); z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 28px; }
.logo { font-size: 18px; font-weight: 700; color: var(--primary); }
.main-nav { display: flex; gap: 4px; }
.nav-btn {
  padding: 8px 14px; border: none; background: transparent; border-radius: 8px; cursor: pointer;
  font-size: 14px; color: var(--text-light); transition: all .2s;
}
.nav-btn:hover { background: #f0f2f8; }
.nav-btn.active { background: var(--primary); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.quota-badge { background: #f0f2f8; padding: 4px 10px; border-radius: 20px; font-size: 12px; color: var(--text-light); }
.user-info { font-size: 14px; font-weight: 500; }

.view { display: none; }
.view-active { display: block; }

/* 智能建站三栏布局 */
.builder-layout { display: flex; height: calc(100vh - 56px); overflow: hidden; }
#view-builder { max-width: none; width: 100%; margin: 0; }
.conv-sidebar { width: 240px; background: #fff; border-right: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.conv-list { flex: 1; overflow-y: auto; min-height: 0; }
.conv-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 4px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  border: 1px solid transparent; transition: all .2s;
}
.conv-item:hover { background: #f5f7fb; }
.conv-item.active { background: #eef1fe; border-color: var(--primary); }
.conv-item .conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.conv-item .conv-del { color: #ccc; cursor: pointer; font-size: 14px; }
.conv-item .conv-del:hover { color: var(--danger); }

.chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.chat-messages { flex: 1; overflow-y: auto; min-height: 0; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 82%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  background: #eef1fe;
}
.msg.user .msg-avatar { background: var(--primary); color: #fff; }
.msg-bubble {
  padding: 12px 16px; border-radius: 12px; line-height: 1.7; font-size: 14px;
  background: #fff; border: 1px solid var(--border); box-shadow: 0 1px 4px rgba(0,0,0,.04);
  white-space: pre-wrap; word-break: break-word;
}
.msg.user .msg-bubble { background: var(--primary); color: #fff; border: none; }
.msg-bubble code { background: #f0f2f8; padding: 2px 5px; border-radius: 4px; font-size: 13px; }
.msg.user .msg-bubble code { background: rgba(255,255,255,.2); }
.msg-bubble pre { background: #1e293b; color: #e2e8f0; padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 12px; margin: 8px 0; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { margin: 8px 0 4px; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; }
.msg-bubble p { margin: 4px 0; }

.chat-input-wrap { padding: 12px 20px 14px; background: #fff; border-top: 1px solid var(--border); }
.chat-input-row { display: flex; gap: 10px; align-items: flex-end; }
.chat-input-row textarea {
  flex: 1; border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  font-size: 14px; resize: none; outline: none; max-height: 140px; line-height: 1.6;
}
.chat-input-row textarea:focus { border-color: var(--primary); }
.chat-tips { color: #b0b5c0; font-size: 12px; margin-top: 8px; text-align: center; }
.site-preview-status { font-size: 12px; color: var(--success); margin-bottom: 6px; min-height: 16px; }

/* 预览面板 */
.preview-panel { width: 42%; min-width: 380px; background: #fff; border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.preview-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.preview-actions { display: flex; gap: 6px; }
.preview-frame { flex: 1; border: none; background: #fff; min-height: 0; }
.preview-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #b0b5c0; text-align: center; line-height: 2; background: #fafbfe; min-height: 0;
}
.empty-icon { font-size: 56px; margin-bottom: 10px; }

/* 通用页面 */
.page-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px 12px; }
.page-header h2 { font-size: 20px; }
.view { max-width: 1200px; margin: 0 auto; }
.card-list { padding: 8px 24px 24px; display: grid; gap: 12px; }
.provider-tips { margin: 0 24px 16px; background: #eef5ff; border: 1px solid #d0e2ff; padding: 12px 16px; border-radius: 8px; color: #3a56d4; font-size: 13px; line-height: 1.8; }
.card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; justify-content: space-between; align-items: center; box-shadow: var(--shadow);
}
.card .card-main { flex: 1; min-width: 0; }
.card .card-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.card .card-desc { color: var(--text-light); font-size: 13px; }
.card .card-actions { display: flex; gap: 8px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.tag-deepseek { background: #eef5ff; color: #3a56d4; }
.tag-openai { background: #ecfdf5; color: #0ea371; }
.tag-default { background: #fef3c7; color: #b45309; }
.tag-disabled { background: #f3f4f6; color: #9ca3af; }
.tag-status { background: #ecfdf5; color: #0ea371; }
.tag-status.failed { background: #fee2e2; color: #b91c1c; }
.tag-status.draft { background: #f3f4f6; color: #6b7280; }

/* 用量统计 */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 8px 24px 16px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat-card .stat-num { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 13px; color: var(--text-light); margin-top: 4px; }
.chart-box { margin: 8px 24px 24px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; min-height: 180px; display: flex; align-items: flex-end; gap: 4px; }
.chart-col { flex: 1; background: linear-gradient(180deg, var(--primary), #93b0ff); border-radius: 4px 4px 0 0; position: relative; min-height: 4px; transition: height .3s; }
.chart-col .chart-val { position: absolute; top: -22px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--text-light); white-space: nowrap; }
.chart-col .chart-day { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: 10px; color: #b0b5c0; }
.chart-box { padding-bottom: 30px; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.modal { background: #fff; border-radius: 14px; width: 460px; max-width: 92vw; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-close { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--text-light); }
.modal-body { padding: 20px; }
.modal-body .form-group { margin-bottom: 14px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* Toast */
.toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: 10px 20px; border-radius: 8px; font-size: 14px; z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* 响应式 */
@media (max-width: 1100px) {
  .preview-panel { width: 36%; min-width: 300px; }
}
@media (max-width: 900px) {
  .builder-layout { flex-direction: column; height: auto; overflow: visible; }
  #view-builder { max-width: none; }
  .conv-sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; min-height: auto; max-height: 30vh; overflow-y: auto; }
  .chat-area { min-height: 55vh; }
  .preview-panel { width: 100%; min-width: 0; height: 50vh; min-height: 0; }
  .msg { max-width: 92%; }
}
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .topbar-left { gap: 12px; flex-wrap: wrap; }
  .main-nav { flex-wrap: wrap; }
  .builder-layout { min-height: calc(100vh - 120px); }
  .chat-area { min-height: 60vh; }
  .preview-panel { height: 45vh; }
  .msg { max-width: 96%; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
