/* ============ 基础重置 ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6366f1;
  --primary-h: #4f52e0;
  --primary-light: rgba(99,102,241,.1);
  --bg: #f1f5f9;
  --white: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #22c55e;
  --error: #ef4444;
  --warn: #f59e0b;
  --sidebar-w: 220px;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

.hidden { display: none !important; }

/* ============ 登录 / 注册 ============ */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-box {
  background: var(--white);
  border-radius: 20px;
  padding: 44px 40px;
  width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

.logo-area { text-align: center; margin-bottom: 32px; }
.logo-icon {
  width: 64px; height: 64px; border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 28px; color: white; margin-bottom: 12px;
}
.logo-area h1 { font-size: 26px; font-weight: 700; }
.logo-area p  { color: var(--muted); font-size: 13px; margin-top: 4px; }

.form-pane h2 { font-size: 20px; margin-bottom: 20px; }

.field {
  position: relative; margin-bottom: 16px;
}
.field i {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 15px;
}
.field input {
  width: 100%; padding: 13px 14px 13px 42px;
  border: 2px solid var(--border); border-radius: 10px;
  font-size: 14px; transition: border .25s;
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

.btn-submit {
  width: 100%; padding: 14px; background: var(--primary); color: white;
  border: none; border-radius: 10px; font-size: 16px; font-weight: 600;
  cursor: pointer; letter-spacing: 2px; transition: all .25s;
}
.btn-submit:hover { background: var(--primary-h); transform: translateY(-2px); box-shadow: 0 8px 20px rgba(99,102,241,.35); }
.btn-submit:disabled { opacity: .6; cursor: not-allowed; transform: none; box-shadow: none; }

.toggle-link { text-align: center; margin-top: 16px; color: var(--muted); font-size: 13px; }
.toggle-link a { color: var(--primary); font-weight: 600; text-decoration: none; }
.toggle-link a:hover { text-decoration: underline; }

/* ============ 主布局 ============ */
#app-container { display: flex; min-height: 100vh; }

#sidebar {
  width: var(--sidebar-w); background: var(--white);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; height: 100vh;
  z-index: 200;
}

.sidebar-logo {
  padding: 20px 18px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.logo-icon-sm {
  width: 36px; height: 36px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 16px; flex-shrink: 0;
}
.logo-text { font-size: 17px; font-weight: 700; }

nav { flex: 1; padding: 12px 0; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 13px 18px; color: var(--muted);
  text-decoration: none; cursor: pointer; transition: all .2s;
  border-right: 3px solid transparent;
}
.nav-item i { font-size: 16px; width: 20px; text-align: center; }
.nav-item span { font-size: 14px; }
.nav-item:hover { background: var(--bg); color: var(--primary); }
.nav-item.active { background: var(--primary-light); color: var(--primary); border-right-color: var(--primary); font-weight: 600; }

.sidebar-bottom {
  padding: 16px 18px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.user-row { display: flex; align-items: center; gap: 8px; }
.user-row i { font-size: 26px; color: var(--muted); }
.uname { font-weight: 600; font-size: 14px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 18px; padding: 6px; border-radius: 8px; transition: all .2s;
}
.logout-btn:hover { background: #fee2e2; color: var(--error); }

#main {
  flex: 1; margin-left: var(--sidebar-w); padding: 28px 32px;
  min-height: 100vh;
}

.page { display: none; animation: fadeUp .25s ease; }
.page.active { display: block; }

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

.page-title { margin-bottom: 24px; }
.page-title h2 { font-size: 24px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.page-title h2 i { color: var(--primary); }
.page-title p  { color: var(--muted); margin-top: 4px; font-size: 13px; }

/* ============ 双栏布局 ============ */
.two-col {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
  height: calc(100vh - 140px);
}

.ctrl-card {
  background: var(--white); border-radius: var(--radius);
  padding: 22px; overflow-y: auto; box-shadow: var(--shadow);
}
.result-card {
  background: var(--white); border-radius: var(--radius);
  padding: 22px; overflow-y: auto; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}

/* ============ 模式 Tabs ============ */
.mode-tabs {
  display: flex; gap: 8px; margin-bottom: 18px;
}
.mode-tab {
  flex: 1; padding: 10px 8px;
  border: 2px solid var(--border); background: white;
  border-radius: 9px; cursor: pointer; font-size: 13px;
  transition: all .2s; display: flex; align-items: center; justify-content: center; gap: 6px;
  color: var(--muted);
}
.mode-tab:hover { border-color: var(--primary); color: var(--primary); }
.mode-tab.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); font-weight: 600; }

/* ============ 表单元素 ============ */
.field-label { display: block; font-weight: 600; margin-bottom: 8px; }
.req { color: var(--error); }

textarea {
  width: 100%; padding: 12px;
  border: 2px solid var(--border); border-radius: 10px;
  font-size: 14px; font-family: inherit; resize: vertical;
  transition: border .25s; line-height: 1.6;
}
textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

.char-hint { text-align: right; font-size: 11px; color: var(--muted); margin: 4px 0 14px; }

.params-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0 18px; }
.param-item label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.param-item.full { grid-column: 1/-1; }

select {
  width: 100%; padding: 9px 10px;
  border: 2px solid var(--border); border-radius: 8px;
  font-size: 13px; background: white; cursor: pointer; transition: border .25s;
}
select:focus { outline: none; border-color: var(--primary); }

input[type=range] { width: 100%; accent-color: var(--primary); margin-top: 6px; }
input[type=range] + b { color: var(--primary); font-size: 15px; }

/* ============ 上传区 ============ */
.upload-zone { margin-bottom: 16px; }
.upload-inner {
  border: 2px dashed var(--border); border-radius: 10px;
  padding: 30px; text-align: center; cursor: pointer; transition: all .2s;
}
.upload-inner:hover { border-color: var(--primary); background: var(--primary-light); }
.upload-inner i { font-size: 36px; color: var(--muted); margin-bottom: 8px; }
.upload-inner p { color: var(--muted); font-size: 13px; }

.img-preview-wrap { position: relative; margin-top: 12px; }
.img-preview-wrap img { width: 100%; border-radius: 10px; max-height: 260px; object-fit: contain; background: var(--bg); }
.rm-img {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,.5); color: white; border: none;
  border-radius: 50%; width: 28px; height: 28px;
  cursor: pointer; font-size: 14px; transition: background .2s;
  display: flex; align-items: center; justify-content: center;
}
.rm-img:hover { background: var(--error); }

/* ============ 生成按钮 ============ */
.btn-gen {
  width: 100%; padding: 16px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: white; border: none; border-radius: 11px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all .25s;
}
.btn-gen:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(99,102,241,.4); }
.btn-gen:disabled { opacity: .55; cursor: not-allowed; }

/* ============ 空状态 ============ */
.empty-hint {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--muted); gap: 12px; padding: 60px 20px;
}
.empty-hint i { font-size: 56px; opacity: .2; }
.empty-hint p { font-size: 15px; }

/* ============ 图片网格 ============ */
.img-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 14px; }
.img-card {
  position: relative; border-radius: 10px; overflow: hidden;
  cursor: pointer; transition: transform .2s, box-shadow .2s;
}
.img-card:hover { transform: scale(1.03); box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.img-card img { width: 100%; display: block; aspect-ratio: 1; object-fit: cover; }
.img-card-ov {
  position: absolute; inset: 0;
  background: linear-gradient(transparent 50%, rgba(0,0,0,.7));
  opacity: 0; transition: opacity .2s;
  display: flex; align-items: flex-end; padding: 10px;
}
.img-card:hover .img-card-ov { opacity: 1; }
.img-card-ov p { color: white; font-size: 12px; }

/* ============ 视频结果 ============ */
.video-result-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
.video-result-wrap video { width: 100%; border-radius: 10px; max-height: 480px; background: #000; }
.video-actions { display: flex; gap: 10px; }

/* ============ 视频加载蒙层 ============ */
.video-loading {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
.vl-card {
  background: white; border-radius: 16px; padding: 40px;
  text-align: center; width: 320px; box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.vl-spinner {
  width: 52px; height: 52px; border: 5px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 1s linear infinite; margin: 0 auto 18px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.vl-card p { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.vl-hint { font-size: 12px !important; font-weight: 400 !important; color: var(--muted); }
.vl-progress {
  height: 6px; background: var(--border); border-radius: 99px;
  margin-top: 18px; overflow: hidden;
}
#vl-bar {
  height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #a78bfa);
  border-radius: 99px; transition: width .5s ease;
  animation: progress-anim 120s linear forwards;
}
@keyframes progress-anim { from { width:0% } to { width:95% } }

/* ============ 对话页 ============ */
.chat-layout {
  display: grid; grid-template-columns: 220px 1fr;
  gap: 20px; height: calc(100vh - 60px);
}

.chat-sidebar {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  overflow: hidden;
}

.btn-new-chat {
  margin: 14px; padding: 12px;
  background: var(--primary); color: white;
  border: none; border-radius: 9px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all .2s; flex-shrink: 0;
}
.btn-new-chat:hover { background: var(--primary-h); }

.chat-sessions { flex: 1; overflow-y: auto; padding: 0 8px 8px; }

.session-item {
  padding: 12px 10px; border-radius: 8px; cursor: pointer;
  transition: background .2s; position: relative;
  border-bottom: 1px solid var(--border);
}
.session-item:hover { background: var(--bg); }
.session-item.active { background: var(--primary-light); }
.session-item p { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item span { font-size: 11px; color: var(--muted); }
.session-del {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 13px; opacity: 0; transition: opacity .2s;
}
.session-item:hover .session-del { opacity: 1; }
.session-del:hover { color: var(--error); }

.chat-main {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.chat-header h3 { font-size: 15px; font-weight: 600; }
.model-tag {
  display: inline-block; padding: 3px 10px;
  background: var(--primary-light); color: var(--primary);
  border-radius: 99px; font-size: 11px; font-weight: 600; margin-top: 3px;
}
.chat-header select { padding: 7px 10px; border: 2px solid var(--border); border-radius: 8px; font-size: 13px; }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
}

.chat-welcome {
  margin: auto; text-align: center; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 40px;
}
.welcome-icon {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--primary-light); display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: var(--primary);
}
.chat-welcome h3 { font-size: 18px; color: var(--text); }
.chat-welcome p { font-size: 14px; }

.msg { display: flex; gap: 10px; max-width: 85%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.assistant { align-self: flex-start; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}
.msg.user .msg-avatar { background: var(--primary); color: white; }
.msg.assistant .msg-avatar { background: var(--primary-light); color: var(--primary); }

.msg-bubble {
  padding: 12px 16px; border-radius: 12px;
  font-size: 14px; line-height: 1.7; white-space: pre-wrap; word-break: break-word;
}
.msg.user .msg-bubble { background: var(--primary); color: white; border-bottom-right-radius: 4px; }
.msg.assistant .msg-bubble { background: var(--bg); color: var(--text); border-bottom-left-radius: 4px; }

.typing-cursor::after { content: '▋'; animation: blink .6s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

.chat-input-wrap {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; align-items: flex-end; flex-shrink: 0;
}
.chat-input-wrap textarea {
  flex: 1; min-height: 44px; max-height: 160px;
  resize: none; border-radius: 10px; padding: 11px 14px; font-size: 14px;
}
.btn-send {
  width: 44px; height: 44px; background: var(--primary); color: white;
  border: none; border-radius: 10px; cursor: pointer; font-size: 16px;
  flex-shrink: 0; transition: all .2s; display: flex; align-items: center; justify-content: center;
}
.btn-send:hover:not(:disabled) { background: var(--primary-h); transform: scale(1.05); }
.btn-send:disabled { opacity: .5; cursor: not-allowed; }

/* ============ 历史页 ============ */
.history-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.filter-tabs { display: flex; gap: 8px; }
.filter-tab {
  padding: 8px 18px; border: 2px solid var(--border); background: white;
  border-radius: 99px; cursor: pointer; font-size: 13px; font-weight: 500;
  transition: all .2s;
}
.filter-tab:hover { border-color: var(--primary); color: var(--primary); }
.filter-tab.active { background: var(--primary); color: white; border-color: var(--primary); }

.btn-danger {
  padding: 9px 18px; background: white; color: var(--error);
  border: 2px solid var(--error); border-radius: 9px; font-size: 13px;
  cursor: pointer; transition: all .2s; display: flex; align-items: center; gap: 6px; font-weight: 500;
}
.btn-danger:hover { background: var(--error); color: white; }

.history-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px,1fr));
  gap: 20px;
}

.hist-card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; transition: transform .2s, box-shadow .2s;
}
.hist-card:hover { transform: translateY(-4px); box-shadow: 0 10px 24px rgba(0,0,0,.12); }

.hist-thumb {
  width: 100%; height: 180px; object-fit: cover; cursor: pointer;
  display: block;
}
.hist-video-thumb {
  width: 100%; height: 180px; object-fit: cover; cursor: pointer;
  display: block; background: #000;
}
.hist-body { padding: 14px; }
.hist-type { display: inline-block; padding: 3px 10px; background: var(--primary-light); color: var(--primary); border-radius: 99px; font-size: 11px; font-weight: 600; }
.hist-prompt { font-size: 13px; color: var(--muted); margin: 8px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-date { font-size: 11px; color: var(--muted); }
.hist-actions {
  padding: 10px 14px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}
.hist-btn {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 15px; padding: 6px; border-radius: 6px; transition: all .2s;
}
.hist-btn:hover { background: var(--bg); color: var(--primary); }
.hist-btn.del:hover { color: var(--error); }

/* ============ 分页 ============ */
.pagination {
  display: flex; justify-content: center; gap: 8px; margin-top: 28px;
}
.pagination button {
  padding: 8px 14px; background: white; border: 2px solid var(--border);
  border-radius: 8px; cursor: pointer; font-size: 13px; transition: all .2s;
}
.pagination button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }

/* ============ Toast ============ */
#toast-box { position: fixed; top: 20px; right: 20px; z-index: 99999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: white; border-radius: 10px; padding: 13px 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
  display: flex; align-items: center; gap: 10px;
  animation: slideIn .3s ease; min-width: 260px;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error   { border-left: 4px solid var(--error); }
.toast.warn    { border-left: 4px solid var(--warn); }
.toast i { font-size: 18px; }
.toast.success i { color: var(--success); }
.toast.error i   { color: var(--error); }
.toast.warn i    { color: var(--warn); }
.toast p { font-size: 14px; }
@keyframes slideIn { from { transform:translateX(360px); opacity:0; } to { transform:translateX(0); opacity:1; } }
@keyframes slideOut { from { transform:translateX(0); opacity:1; } to { transform:translateX(360px); opacity:0; } }

/* ============ 图片模态框 ============ */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.88);
  display: flex; align-items: center; justify-content: center;
  z-index: 10000; animation: fadeIn .25s ease;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
.modal-body { position: relative; max-width: 90vw; max-height: 92vh; }
.modal-close {
  position: absolute; top: -38px; right: 0;
  background: none; border: none; color: white;
  font-size: 24px; cursor: pointer; transition: color .2s;
}
.modal-close:hover { color: var(--error); }
.modal-body img { max-width: 100%; max-height: 82vh; border-radius: 10px; display: block; }
.modal-footer { display: flex; justify-content: center; margin-top: 14px; }
.btn-dl {
  padding: 10px 24px; background: var(--primary); color: white;
  border: none; border-radius: 9px; font-size: 14px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; gap: 8px; transition: all .2s;
}
.btn-dl:hover { background: var(--primary-h); }

/* ============ 响应式 ============ */
@media (max-width: 1024px) {
  .two-col { grid-template-columns: 1fr; height: auto; }
  .result-card { min-height: 400px; }
  .chat-layout { grid-template-columns: 1fr; }
  .chat-sidebar { display: none; }
}
@media (max-width: 768px) {
  #sidebar { width: 60px; }
  .sidebar-logo .logo-text, .nav-item span, .uname { display: none; }
  #main { margin-left: 60px; padding: 16px; }
}
