* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f3f4f6;
  color: #111827;
}
.hidden { display: none !important; }

.app-version {
  font-size: .7rem; font-weight: 400; margin-left: 8px;
  color: #6b7280; white-space: nowrap; user-select: none; vertical-align: middle;
}

/* ===== 登录 ===== */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; background: #111827; }
.login-box {
  width: 320px; max-width: 90vw; padding: 32px 28px; border-radius: 16px;
  background: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.login-box h1 { font-size: 22px; text-align: center; }
.login-sub { text-align: center; color: #6b7280; font-size: 13px; margin: 8px 0 20px; }
.login-box input {
  width: 100%; padding: 11px 12px; margin-bottom: 12px; border: 1px solid #d1d5db;
  border-radius: 8px; font-size: 15px;
}
.login-box input:focus { outline: 2px solid #6d28d9; border-color: transparent; }
#login-btn {
  width: 100%; padding: 11px; border: 0; border-radius: 8px; background: #6d28d9;
  color: #fff; font-size: 15px; cursor: pointer;
}
#login-btn:hover { background: #5b21b6; }
.msg { text-align: center; color: #ef4444; font-size: 13px; margin-top: 12px; min-height: 16px; }

/* ===== 应用布局 ===== */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 52px; padding: 0 16px; background: #111827; color: #fff;
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand { font-weight: 600; }
.brand .app-version { color: #9ca3af; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.balance { font-size: 13px; color: #fff; background: rgba(255,255,255,.12); padding: 4px 10px; border-radius: 999px; }
button.ghost { background: transparent; border: 1px solid rgba(255,255,255,.25); color: #fff; padding: 5px 12px; border-radius: 7px; cursor: pointer; font-size: 13px; }
button.ghost:hover { background: rgba(255,255,255,.1); }

.body { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 240px; background: #1f2937; color: #e5e7eb; padding: 12px;
  display: flex; flex-direction: column; gap: 10px; overflow-y: auto;
  transition: width .2s ease, padding .2s ease;
}
.app.sidebar-hidden .sidebar { width: 0; padding: 0; overflow: hidden; }
.new-chat {
  padding: 10px; border: 1px dashed rgba(255,255,255,.25); background: transparent;
  color: #e5e7eb; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.new-chat:hover { background: rgba(255,255,255,.06); }
.sessions { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.sessions li {
  padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative;
}
.sessions li:hover { background: rgba(255,255,255,.08); }
.sessions li.active { background: rgba(109,40,217,.4); }
.sessions li .del {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: transparent; border: 0; color: #9ca3af; cursor: pointer; display: none; font-size: 14px;
}
.sessions li:hover .del { display: inline; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #fff; }
.chat { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 14px; }
.msg-row { display: flex; }
.msg-row.user { justify-content: flex-end; }
.bubble {
  max-width: 78%; padding: 10px 14px; border-radius: 14px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word; font-size: 15px;
}
.msg-row.user .bubble { background: #6d28d9; color: #fff; border-bottom-right-radius: 4px; }
.msg-row.assistant .bubble { background: #f3f4f6; color: #111827; border-bottom-left-radius: 4px; }

.composer {
  display: flex; flex-direction: column; gap: 8px; padding: 12px 16px; border-top: 1px solid #e5e7eb; background: #fff;
}
.composer-row { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid #d1d5db; border-radius: 10px; padding: 11px 12px;
  font-size: 15px; font-family: inherit; max-height: 160px; line-height: 1.5;
}
.composer textarea:focus { outline: 2px solid #6d28d9; border-color: transparent; }
.attach-bar { display: flex; flex-wrap: wrap; gap: 8px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f3f4f6; border: 1px solid #d1d5db; border-radius: 10px;
  padding: 4px 8px 4px 4px; max-width: 100%;
}
.image-preview { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; flex: 0 0 auto; }
.attach-name { font-size: 13px; color: #374151; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach-x {
  background: transparent; border: 0; color: #6b7280; font-size: 17px;
  cursor: pointer; line-height: 1; padding: 2px 4px; border-radius: 6px;
}
.attach-x:hover { color: #111827; background: #e5e7eb; }
.image-btn {
  width: 42px; height: 42px; padding: 0; font-size: 24px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: #f3f4f6; border: 1px solid #d1d5db; color: #111827; border-radius: 10px;
}
.image-btn:active { background: #e5e7eb; }

.msg-row { position: relative; }
.bubble-img { max-width: 200px; max-height: 200px; border-radius: 10px; margin-bottom: 6px; display: block; width: auto; height: auto; object-fit: contain; }
.bubble-del {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; line-height: 22px; text-align: center;
  background: rgba(0,0,0,.5); color: #fff; border: 0; border-radius: 50%;
  font-size: 15px; cursor: pointer; display: none; z-index: 2;
}
.msg-row:hover .bubble-del { display: block; }
.bubble-text { white-space: pre-wrap; word-break: break-word; }
.send { padding: 12px 22px; min-width: 84px; border: 0; border-radius: 10px; background: #6d28d9; color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; }
.send:hover { background: #5b21b6; }
.send:disabled { background: #c4b5fd; cursor: default; }
.hint { color: #6b7280; font-size: 13px; text-align: center; padding: 8px; }

/* ===== 管理后台 ===== */
.admin-wrap { max-width: 960px; margin: 0 auto; padding: 24px; }
.admin-card { background: #fff; border-radius: 12px; padding: 16px 20px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.admin-card h2 { font-size: 17px; margin-bottom: 12px; }
.admin-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.admin-form input, .admin-form select, .admin-form button { padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 7px; font-size: 14px; }
.admin-form button { background: #6d28d9; color: #fff; border: 0; cursor: pointer; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td { padding: 8px 10px; border-bottom: 1px solid #f0f0f0; text-align: left; }
.admin-table th { color: #6b7280; font-weight: 500; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.tag.active { background: #dcfce7; color: #166534; }
.tag.disabled, .tag.expired { background: #fee2e2; color: #991b1b; }
.admin-login { max-width: 320px; margin: 80px auto; }
