/* PAS PWA 样式：现代简约 · 高分辨率适配 */

:root {
  --bg: #f0f2f7;
  --surface: #ffffff;
  --primary: #5b6af0;
  --primary-dark: #4451d9;
  --primary-light: #eef0ff;
  --text: #1a1d2e;
  --text-soft: #8b8fa3;
  --text-muted: #b0b4c5;
  --border: #e8eaf0;
  --user-bubble: #5b6af0;
  --user-text: #ffffff;
  --ai-bubble: #ffffff;
  --danger: #e24a4a;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --chat-max: 800px;
  --bubble-max: 70%;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app { height: 100%; display: flex; flex-direction: column; position: relative; z-index: 1; }
.view { flex: 1; min-height: 0; }
.view-chat { background: transparent; }
.view-auth { background: linear-gradient(135deg, #eef0ff 0%, #f0f2f7 50%, #faf5ff 100%); }

/* ----------------------- 认证视图 ----------------------- */
.view-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: transparent;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: rgba(255,255,255,0.82);
  backdrop-filter: blur(12px);
  border-radius: 24px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.06), 0 2px 8px rgba(0,0,0,0.04);
  padding: 36px 28px 28px;
}

.brand { text-align: center; margin-bottom: 24px; }
.brand-logo { width: 48px; height: 48px; }
.brand h1 { margin: 10px 0 2px; font-size: 26px; font-weight: 700; letter-spacing: 3px; background: linear-gradient(135deg, var(--primary), #8b5cf6); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.brand-sub { margin: 0; color: var(--text-soft); font-size: 13px; line-height: 1.5; }

.tabs {
  display: flex;
  background: var(--bg);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 20px;
}
.tab {
  flex: 1; border: none; background: transparent;
  padding: 10px 0; border-radius: 10px;
  font-size: 14px; font-weight: 500; color: var(--text-soft);
  cursor: pointer; transition: all .2s;
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: var(--text-soft); }
.auth-form input, .auth-form select,
.settings-form input, .settings-form select, .settings-form textarea,
.composer textarea {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text);
  background: #fafbfc;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  font-family: inherit;
}
.auth-form input:focus, .auth-form select:focus,
.composer textarea:focus,
.settings-form input:focus, .settings-form select:focus, .settings-form textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,106,240,0.1);
  background: var(--surface);
}

.checkbox { flex-direction: row !important; align-items: center; gap: 8px; font-weight: 400 !important; }
.checkbox input { width: auto; accent-color: var(--primary); }
.checkbox a { color: var(--primary); text-decoration: none; font-weight: 500; }

.primary {
  background: var(--primary);
  color: #fff; border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 15px; font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(91,106,240,0.3); }
.primary:active { transform: translateY(0); }
.primary:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

.ghost {
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px; color: var(--danger);
  cursor: pointer; width: 100%;
  font-size: 14px; font-weight: 500;
  transition: all .2s;
}
.ghost:hover { background: #fef2f2; border-color: var(--danger); }

.msg { font-size: 13px; min-height: 18px; margin: 8px 0 0; text-align: center; }
.msg.error { color: var(--danger); }
.msg.ok { color: #22c55e; }

.security-notice {
  text-align: center;
  font-size: 12px;
  color: #d97706;
  margin-top: 12px;
  padding: 8px 12px;
  background: #fef3c7;
  border-radius: 8px;
  line-height: 1.5;
}

/* ----------------------- 对话视图 ----------------------- */
.view-chat {
  display: flex; flex-direction: column;
  max-width: var(--chat-max);
  width: 100%; margin: 0 auto;
  background: rgba(255,255,255,0.6);
  backdrop-filter: blur(12px);
  border-radius: 0;
}

/* 小屏全宽，大屏留白 */
@media (max-width: 840px) {
  .view-chat { max-width: 100%; box-shadow: none; }
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(200,205,220,0.2);
  padding-top: max(14px, env(safe-area-inset-top));
  z-index: 5;
}
.chat-title { display: flex; flex-direction: column; gap: 2px; }
#persona-name { font-weight: 700; font-size: 15px; }
.conn-status { font-size: 11px; }
.conn-status { color: var(--text-muted); }
.conn-status.online { color: #22c55e; }
.conn-status.offline { color: var(--danger); }

.chat-actions { display: flex; gap: 4px; }
.icon-btn {
  border: none; background: transparent;
  border-radius: 8px; width: 36px; height: 36px;
  font-size: 18px; cursor: pointer; color: var(--text-soft);
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
  line-height: 1;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn svg { vertical-align: middle; }

.messages {
  flex: 1; overflow-y: auto;
  padding: 20px var(--pad, 20px);
  display: flex; flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
  background: transparent;
}

/* 高分辨率下收紧消息区两侧留白 */
@media (min-width: 900px) {
  .messages { --pad: 40px; }
}
@media (min-width: 1200px) {
  .messages { --pad: 80px; }
}

.bubble {
  max-width: var(--bubble-max);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  animation: bubbleIn .25s ease;
}
@keyframes bubbleIn { from { opacity: 0; transform: translateY(8px); } }

.bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 8px rgba(91,106,240,0.25);
}
.bubble.ai {
  align-self: flex-start;
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(200,205,220,0.2);
  border-bottom-left-radius: 6px;
  box-shadow: none;
}
.bubble.error {
  align-self: center;
  background: #fef2f2;
  color: var(--danger);
  box-shadow: none;
  font-size: 13px;
  max-width: 85%;
}

.bubble.typing::after { content: "▊"; animation: blink 1s steps(2) infinite; margin-left: 2px; color: var(--primary); }
@keyframes blink { 50% { opacity: 0; } }

/* 思考中三点跳动 */
.bubble.thinking {
  padding: 14px 22px;
  min-width: 60px;
  display: flex; align-items: center;
}
.dot-pulse {
  display: flex; gap: 5px; align-items: center; height: 8px;
}
.dot-pulse i {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0.3;
  animation: dotBounce 1.4s infinite ease-in-out both;
}
.dot-pulse i:nth-child(1) { animation-delay: 0s; }
.dot-pulse i:nth-child(2) { animation-delay: 0.16s; }
.dot-pulse i:nth-child(3) { animation-delay: 0.32s; }
@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

.composer {
  display: flex;
  gap: 8px; align-items: flex-end;
  padding: 14px 20px;
  background: rgba(255,255,255,0.6);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(200,205,220,0.2);
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 5;
}
.composer textarea {
  flex: 1; resize: none; max-height: 120px;
  min-height: 44px; line-height: 1.5;
  background: var(--bg);
  border-radius: 20px;
  padding: 10px 18px;
}
.composer .primary {
  padding: 10px 22px;
  border-radius: 20px;
  font-size: 14px;
  white-space: nowrap;
}

/* ----------------------- 抽屉 / 弹窗 ----------------------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(15,20,40,0.4);
  backdrop-filter: blur(4px);
  display: flex; justify-content: flex-end;
  z-index: 20;
}
.drawer {
  width: 100%; max-width: 380px; height: 100%;
  background: var(--surface);
  padding: 20px 22px; overflow-y: auto;
  box-shadow: -4px 0 24px rgba(0,0,0,0.06);
  animation: slidein .25s ease;
}
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }
.drawer-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.drawer-header h2 { font-size: 17px; font-weight: 700; margin: 0; }
.settings-form { display: flex; flex-direction: column; gap: 16px; }
.settings-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: var(--text-soft); }
.settings-form textarea { resize: vertical; }
.danger-zone { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--border); }

.modal {
  margin: auto; width: 100%; max-width: 500px; max-height: 80vh;
  background: var(--surface); border-radius: 20px;
  padding: 22px; overflow-y: auto; align-self: center;
  box-shadow: 0 16px 48px rgba(0,0,0,0.12);
}
.overlay:has(.modal) { justify-content: center; align-items: center; padding: 24px; }
.pipl-text {
  white-space: pre-wrap; word-break: break-word;
  font-family: inherit; font-size: 13px; line-height: 1.7;
  color: var(--text); margin: 0;
}

/* ----------------------- 管理员面板 ----------------------- */
.admin-list { display: flex; flex-direction: column; gap: 10px; }
.admin-card {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  gap: 10px;
}
.admin-card .info { flex: 1; min-width: 0; }
.admin-card .email { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-card .meta { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.admin-card .approve-btn {
  background: var(--primary);
  color: #fff; border: none;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.admin-card .approve-btn:hover { background: var(--primary-dark); }
.admin-card .approve-btn:disabled { opacity: .5; cursor: not-allowed; }
.admin-card .approved { font-size: 12px; color: #22c55e; white-space: nowrap; }

/* ----------------------- 滚动条 ----------------------- */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ----------------------- 天空云层背景（1:1 复刻原站） ----------------------- */
.sky-bg {
  position: fixed; inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .8s;
  overflow: hidden;
}
.sky-bg.active { opacity: 1; }

/* 窄屏（手机）不显示背景，节省资源 */
@media (max-width: 768px) {
  .sky-bg { display: none; }
  .view-chat { background: var(--surface); }
  .chat-header { background: var(--surface); }
  .bubble.ai { background: var(--ai-bubble); border-color: var(--border); backdrop-filter: none; }
  .composer { background: var(--surface); }
}

.satic-layer {
  position: absolute;
  width: 100%; height: 100%;
  top: 0; left: 0;
  background: url('img/poster-about.jpg') no-repeat center;
  background-size: cover;
}

.cloud-layer {
  position: absolute;
  width: 100%; height: 100%;
  top: 0; left: 0;
}
.cloud-1 {
  background: url('img/poster-drop-animate2.png') repeat-x 0 0;
  background-size: cover;
  animation: cloudDrift1 6000s linear infinite;
}
.cloud-2 {
  background: url('img/poster-drop-animate1.png') repeat-x 0 0;
  background-size: cover;
  animation: cloudDrift2 8000s linear infinite;
}

@keyframes cloudDrift1 {
  from { background-position: 0 0; }
  to { background-position: 4000% 0; }
}
@keyframes cloudDrift2 {
  from { background-position: 0 0; }
  to { background-position: 30000% 0; }
}
