/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --header-bg: #2c2c2e;
  --header-fg: #ffffff;
  --chat-bg: #ece5d8;
  --bubble-other: #ffffff;
  --bubble-self: #9eea6a;
  --text-primary: #1d1d1f;
  --text-secondary: #888888;
  --border-color: #e0e0e0;
  --danger: #e74c3c;
  --primary: #576b95;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--chat-bg);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
}

/* === App Layout === */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--chat-bg);
}

/* === Header === */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  background: var(--header-bg);
  color: var(--header-fg);
  font-size: 17px;
  font-weight: 600;
  flex-shrink: 0;
  position: relative;
  padding: 0 12px;
  letter-spacing: -0.3px;
}

.logout-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--header-fg);
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  padding: 3px 10px;
  cursor: pointer;
  opacity: 0.8;
}

.logout-btn:active {
  opacity: 1;
  background: rgba(255,255,255,0.1);
}

/* === Chat Body === */
.chat-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 8px 10px 8px;
  display: flex;
  flex-direction: column;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* === States === */
.chat-loading,
.chat-empty,
.chat-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
}

.chat-error {
  color: var(--danger);
  font-size: 13px;
}

.chat-error .btn-retry {
  font-size: 12px;
  color: var(--primary);
  background: none;
  border: 1px solid var(--primary);
  border-radius: 6px;
  padding: 4px 16px;
  cursor: pointer;
  margin-top: 4px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === Message Row === */
.chat-row {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  width: fit-content;
}

.chat-meta {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 2px;
}

.chat-actor {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.chat-channel-tag {
  font-size: 11px;
  padding: 0 5px;
  border-radius: 4px;
  color: #fff;
}
.ch-3 { background: #B8860B; }  /* 战盟-深橘黄 */
.ch-7 { background: #CC4400; }  /* 神国-深橘红 */
.ch-9 { background: #2E6B2E; }  /* 连服-深绿 */

.chat-time {
  font-size: 11px;
  color: var(--text-secondary);
}

.chat-bubble {
  background: var(--bubble-other);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 15px;
  color: var(--text-primary);
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.6;
  width: fit-content;
  /* 微信气泡尾巴效果 */
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  position: relative;
}

.chat-row-self {
  align-self: flex-end;
  align-items: flex-end;
}
.chat-row-self .chat-meta {
  flex-direction: row-reverse;
}
.chat-row-self .chat-bubble {
  background: #b5e7a0;
}

/* === Chat Footer === */
.chat-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: var(--header-bg);
  flex-shrink: 0;
}

.channel-select {
  width: 64px;
  flex-shrink: 0;
  height: 34px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  padding: 0 6px;
  outline: none;
  -webkit-appearance: none;
}

.channel-select option {
  background: #2c2c2e;
  color: #fff;
}

.msg-input {
  flex: 1;
  height: 34px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  color: #fff;
  font-size: 14px;
  padding: 0 10px;
  outline: none;
  -webkit-appearance: none;
}

.msg-input::placeholder {
  color: rgba(255,255,255,0.4);
}

.msg-input:focus {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.4);
}

.send-btn {
  width: 54px;
  height: 34px;
  flex-shrink: 0;
  background: #07c160;
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.send-btn:active {
  opacity: 0.85;
}

.send-btn:disabled {
  background: #5a9952;
  cursor: not-allowed;
}

/* === Login Page === */
.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  height: 100dvh;
  background: #f7f7f7;
}

.login-logo {
  font-size: 52px;
  margin-bottom: 8px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: #1d1d1f;
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 13px;
  color: #888;
  margin-bottom: 32px;
}

.login-form {
  width: 100%;
  max-width: 280px;
  display: flex;
  flex-direction: column;
}

.login-input {
  width: 100%;
  font-size: 15px;
  padding: 11px 14px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: #1d1d1f;
  -webkit-appearance: none;
}

.login-input:focus {
  border-color: #576b95;
}

.login-error {
  font-size: 13px;
  color: var(--danger);
  text-align: center;
  min-height: 18px;
  margin-top: 8px;
}

.login-btn {
  margin-top: 12px;
  height: 44px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  background: #07c160;
  color: #fff;
  border: none;
  cursor: pointer;
}

.login-btn:active {
  opacity: 0.85;
}

/* === Scrollbar === */
.chat-body::-webkit-scrollbar {
  width: 4px;
}
.chat-body::-webkit-scrollbar-track {
  background: transparent;
}
.chat-body::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: 2px;
}