:root {
  --bg-main: #0b0f19;
  --bg-gradient: radial-gradient(circle at 50% 0%, #1e1b4b 0%, #0f172a 60%, #0b0f19 100%);
  --glass-bg: rgba(17, 24, 39, 0.75);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.35);
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-sub: #6b7280;

  --bubble-mine-bg: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  --bubble-mine-color: #ffffff;
  
  --bubble-other-bg: rgba(255, 255, 255, 0.07);
  --bubble-other-border: rgba(255, 255, 255, 0.08);
  --bubble-other-color: #e5e7eb;

  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --danger-color: #fca5a5;

  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-main);
  background-image: var(--bg-gradient);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--text-main);
  padding: 16px;
  overflow-x: hidden;
}

.app-container {
  width: 100%;
  max-width: 480px;
  display: flex;
  justify-content: center;
}

.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: var(--radius-lg);
}

.card {
  width: 100%;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 认证卡片 */
#auth-card {
  padding: 36px 28px;
}

.card-header {
  text-align: center;
  margin-bottom: 20px;
}

.logo-icon {
  font-size: 42px;
  margin-bottom: 12px;
  display: inline-block;
  filter: drop-shadow(0 4px 12px var(--primary-glow));
}

.card-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.5px;
}

.card-header .subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 6px;
}

.quota-badge-container {
  text-align: center;
  margin-bottom: 24px;
}

.badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.badge.full {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.3);
}

.auth-form {
  display: flex;
  flex-direction: column;
}

.form-title {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.input-group {
  margin-bottom: 18px;
}

.input-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-group input,
.input-wrapper input {
  width: 100%;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 15px;
  outline: none;
  transition: all 0.2s ease;
}

.input-wrapper input {
  padding-right: 46px;
}

.input-group input:focus,
.input-wrapper input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  background: rgba(0, 0, 0, 0.4);
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.icon-btn {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.icon-btn:hover {
  opacity: 1;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-block {
  width: 100%;
}

.form-switch-link {
  margin-top: 18px;
  text-align: center;
  font-size: 13px;
  color: var(--text-sub);
}

.form-switch-link a {
  color: #818cf8;
  text-decoration: none;
  font-weight: 600;
}

.form-switch-link a:hover {
  text-decoration: underline;
}

.error-msg {
  margin-top: 14px;
  padding: 10px 14px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 13px;
  text-align: center;
}

.success-msg {
  margin-top: 14px;
  padding: 10px 14px;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius-sm);
  color: #6ee7b7;
  font-size: 13px;
  text-align: center;
}

/* 模态弹窗样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  padding: 24px 24px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
}

.close-btn:hover {
  color: #fff;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

/* 聊天卡片 */
.chat-card {
  height: 85vh;
  max-height: 750px;
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0; /* 防止溢出 */
  flex-shrink: 1;
}

.avatar {
  width: 40px;
  height: 40px;
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.user-name-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-name-wrapper h3 {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  padding: 1px 6px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}

.pulse-dot {
  width: 5px;
  height: 5px;
  background: #34d399;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(52, 211, 153, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

.user-role {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.btn-icon-text {
  padding: 7px 10px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-icon-text:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.btn-danger-soft {
  padding: 7px 10px;
  font-size: 12px;
  background: var(--danger-bg);
  color: var(--danger-color);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-danger-soft:hover {
  background: rgba(239, 68, 68, 0.25);
}

/* 消息流区域 */
.messages-container {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar {
  width: 5px;
}

.messages-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
}

.welcome-banner {
  text-align: center;
  margin: 10px 0 20px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-md);
  border: 1px dashed rgba(255, 255, 255, 0.1);
}

.welcome-icon {
  font-size: 28px;
  margin-bottom: 6px;
}

.welcome-banner h4 {
  font-size: 14px;
  color: #fff;
}

.welcome-banner p {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 4px;
}

/* 消息气泡项 */
.msg-item {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: fadeInMsg 0.25s ease-out forwards;
}

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

.msg-item.mine {
  align-self: flex-end;
}

.msg-item.other {
  align-self: flex-start;
}

.msg-meta {
  font-size: 11px;
  color: var(--text-sub);
  margin-bottom: 4px;
  display: flex;
  gap: 6px;
}

.msg-item.mine .msg-meta {
  justify-content: flex-end;
}

.msg-bubble {
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.msg-item.mine .msg-bubble {
  background: var(--bubble-mine-bg);
  color: var(--bubble-mine-color);
  border-radius: 18px 18px 4px 18px;
}

.msg-item.other .msg-bubble {
  background: var(--bubble-other-bg);
  border: 1px solid var(--bubble-other-border);
  color: var(--bubble-other-color);
  border-radius: 18px 18px 18px 4px;
}

/* 底部发送栏 */
.chat-footer {
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.25);
  border-top: 1px solid var(--glass-border);
}

.send-form {
  display: flex;
  gap: 8px;
}

.send-form input {
  flex: 1;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 15px;
  outline: none;
  transition: all 0.2s;
}

.send-form input:focus {
  border-color: var(--primary);
  background: rgba(0, 0, 0, 0.45);
}

.send-btn {
  padding: 12px 18px;
  white-space: nowrap;
}

.send-icon {
  font-size: 14px;
}

/* 响应式适配：移动端/窄屏极简优雅优化 */
@media (max-width: 480px) {
  body {
    padding: 0;
  }

  .app-container {
    max-width: 100vw;
  }

  .glass {
    border-radius: 0;
  }

  .chat-card {
    height: 100vh;
    max-height: 100vh;
  }

  .chat-header {
    padding: 10px 12px;
  }

  .avatar {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .btn-icon-text, .btn-danger-soft {
    padding: 6px 8px;
    font-size: 11px;
    border-radius: 8px;
  }

  /* 移动端如果文字依然较宽，允许自动隐去文字仅保留 Icon */
  .btn-text {
    display: inline;
  }
}

/* 极窄屏幕防变形 */
@media (max-width: 380px) {
  .btn-text {
    display: none; /* 在超窄手机屏上只显示精致图标，绝对防变形 */
  }
}

/* 辅助类 */
.hidden {
  display: none !important;
}

.animate-fade-in {
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}
