:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #1c232c;
  --border: #30363d;
  --primary: #6366f1;
  --primary-2: #818cf8;
  --accent: #ec4899;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --gradient: linear-gradient(135deg, #6366f1 0%, #ec4899 100%);
  --gradient-soft: linear-gradient(135deg, rgba(99,102,241,.15) 0%, rgba(236,72,153,.15) 100%);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

a { color: var(--primary-2); text-decoration: none; }
a:hover { color: var(--accent); }

button { font-family: inherit; cursor: pointer; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ---------- 布局 ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 17px; font-weight: 700;
  padding: 0 12px 18px; border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.sidebar .logo-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .2s;
  margin-bottom: 4px;
  font-size: 14px;
}
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active {
  background: var(--gradient-soft);
  color: var(--text);
  border-left: 3px solid var(--primary);
  padding-left: 9px;
}
.nav-item .ico { width: 18px; height: 18px; opacity: .9; }

.sidebar-section {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted); margin: 14px 12px 8px;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 60px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
}
.topbar h1 { font-size: 17px; font-weight: 600; }
.topbar .top-actions { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.balance-pill {
  background: var(--gradient-soft);
  border: 1px solid var(--border);
  padding: 6px 14px; border-radius: 20px;
  display: flex; align-items: center; gap: 6px;
}
.balance-pill b { color: var(--primary-2); font-size: 14px; }

.content { flex: 1; padding: 24px; overflow-y: auto; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.card-hd {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  font-size: 15px; font-weight: 600;
}
.card-bd { padding: 20px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  font-size: 13px;
  transition: all .2s;
}
.btn:hover { border-color: var(--primary); color: var(--primary-2); }
.btn-primary { background: var(--gradient); border: 0; color: #fff; font-weight: 500; }
.btn-primary:hover { color: #fff; opacity: .9; }
.btn-danger { background: rgba(239,68,68,.15); border-color: rgba(239,68,68,.3); color: #fca5a5; }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ---------- 表单 ---------- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-muted); }
.form-control, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 7px;
  font-family: inherit;
  font-size: 13px;
  transition: border-color .2s;
}
.form-control:focus, select:focus, textarea:focus {
  outline: 0; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
textarea { resize: vertical; min-height: 100px; }
.form-tip { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- 表格 ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td {
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.table th { color: var(--text-muted); font-weight: 500; font-size: 12px; }
.table tbody tr:hover { background: var(--bg-3); }

/* ---------- 提示 ---------- */
.toast-wrap {
  position: fixed; top: 20px; left: 50%;
  transform: translateX(-50%); z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--bg-2); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: toastIn .3s;
}
.toast.success { border-color: var(--success); color: #6ee7b7; }
.toast.error { border-color: var(--danger); color: #fca5a5; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; } }

/* ---------- 状态徽章 ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px;
}
.badge-success { background: rgba(16,185,129,.15); color: #6ee7b7; }
.badge-pending { background: rgba(245,158,11,.15); color: #fcd34d; }
.badge-fail { background: rgba(239,68,68,.15); color: #fca5a5; }
.badge-info { background: rgba(99,102,241,.15); color: #a5b4fc; }

/* ---------- 首页 / 登录页 ---------- */
.hero {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at top, rgba(99,102,241,.12), transparent 50%),
    radial-gradient(ellipse at bottom, rgba(236,72,153,.1), transparent 50%),
    var(--bg);
  padding: 24px;
}
.hero-content { max-width: 1080px; width: 100%; text-align: center; }
.hero h1 {
  font-size: 56px; font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 18px; line-height: 1.15;
}
.hero p { font-size: 17px; color: var(--text-muted); margin-bottom: 32px; }
.hero-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.hero-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px,1fr));
  gap: 20px; margin-top: 60px;
}
.feature-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 22px;
  text-align: left;
  transition: transform .2s, border-color .2s;
}
.feature-card:hover { transform: translateY(-4px); border-color: var(--primary); }
.feature-card .icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--gradient-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; margin-bottom: 14px;
}
.feature-card h3 { font-size: 16px; margin-bottom: 6px; }
.feature-card p { color: var(--text-muted); font-size: 13px; }

.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at top, rgba(99,102,241,.15), transparent 50%),
    var(--bg);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.auth-card h2 {
  text-align: center; margin-bottom: 8px;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.auth-card .auth-sub { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 28px; }
.auth-card .auth-foot { text-align: center; color: var(--text-muted); font-size: 13px; margin-top: 16px; }

/* ---------- 仪表盘 ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px,1fr));
  gap: 14px; margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  position: relative; overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--gradient);
}
.stat-card .label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 700; }
.stat-card .extra { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- 对话页 ---------- */
.chat-layout {
  display: grid; grid-template-columns: minmax(0,1fr) 320px;
  gap: 20px; height: calc(100vh - 60px - 48px);
}
.chat-panel { display: flex; flex-direction: column; }
.chat-box {
  flex: 1; overflow-y: auto;
  padding: 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
  min-height: 300px;
}
.chat-empty {
  height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 14px;
}
.chat-msg { display: flex; margin-bottom: 14px; gap: 10px; }
.chat-msg.user { flex-direction: row-reverse; }
.chat-bubble {
  max-width: 75%;
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg-3);
  border: 1px solid var(--border);
}
.chat-msg.user .chat-bubble {
  background: var(--gradient); color: #fff; border: 0;
}
.chat-msg.loading .chat-bubble { color: var(--text-muted); font-style: italic; }
.chat-input-area { display: flex; gap: 10px; align-items: flex-start; }
.chat-input-area textarea { flex: 1; min-height: 60px; }

/* ---------- 生图页 ---------- */
.image-layout {
  display: grid; grid-template-columns: minmax(0,1.1fr) 380px;
  gap: 20px;
}
.size-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 16px; }
.size-card {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 10px;
  padding: 14px 12px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
}
.size-card.active {
  border-color: var(--primary);
  background: var(--gradient-soft);
}
.size-card .label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.size-card .value { font-size: 16px; font-weight: 600; }
.size-card .price { font-size: 12px; color: var(--primary-2); margin-top: 4px; }

.mode-tabs { display: inline-flex; gap: 4px; margin-bottom: 14px; background: var(--bg); padding: 4px; border-radius: 8px; border: 1px solid var(--border); }
.mode-tab {
  padding: 6px 18px; border: 0; background: transparent; color: var(--text-muted);
  border-radius: 6px; font-size: 13px;
}
.mode-tab.active { background: var(--gradient); color: #fff; }

.image-result {
  margin-top: 18px; padding: 18px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 10px;
  min-height: 200px;
}
.progress-track { height: 8px; background: var(--bg-3); border-radius: 4px; overflow: hidden; margin-top: 12px; }
.progress-bar { height: 100%; background: var(--gradient); transition: width .3s; }
.progress-info { display: flex; justify-content: space-between; font-size: 13px; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px,1fr));
  gap: 12px;
}
.gallery-item {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.gallery-item img { width: 100%; height: 220px; object-fit: cover; display: block; }
.gallery-item .meta { padding: 10px 12px; font-size: 12px; }
.gallery-item .actions { display: flex; gap: 4px; padding: 0 12px 12px; }

.history-list { max-height: 600px; overflow-y: auto; }
.history-item {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: var(--bg);
}
.history-item img, .history-thumb {
  width: 80px; height: 80px;
  object-fit: cover; border-radius: 6px;
  background: var(--bg-3);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--text-muted);
}
.history-meta { min-width: 0; }
.history-prompt {
  font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 4px;
}
.history-info { font-size: 11px; color: var(--text-muted); }
.history-actions { margin-top: 6px; display: flex; gap: 8px; font-size: 12px; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .sidebar { width: 64px; padding: 16px 8px; }
  .sidebar .logo span, .nav-item .label, .sidebar-section { display: none; }
  .nav-item { justify-content: center; padding: 10px 6px; }
  .chat-layout, .image-layout { grid-template-columns: 1fr; height: auto; }
  .hero h1 { font-size: 36px; }
  .content { padding: 16px; }
}
