/* ============================================================
   聊天室 · 样式（白色背景 / 简约 / 微信风格气泡 / 移动端适配）
   ============================================================ */

:root {
  --bg:       #ffffff;
  --line:     #ececec;
  --text:     #1f1f1f;
  --muted:    #8a8a8a;
  --green:    #95ec69;
  --accent:   #07c160;
  --accent-d: #06ad56;
  --danger:   #e53935;
  --header:   #f7f7f7;
  --soft:     #fafafa;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
}

/* ==================== 按钮与表单 ==================== */

.btn {
  border: 1px solid #dcdcdc;
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn:disabled {
  cursor: not-allowed;
  color: #b5b5b5;
  background: #f7f7f7;
  border-color: #ececec;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-d);
  border-color: var(--accent-d);
  color: #fff;
}

.btn-block {
  display: block;
  width: 100%;
  padding: 10px 14px;
  font-size: 15px;
}

.text-input {
  width: 100%;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
}

.text-input:focus {
  border-color: var(--accent);
}

/* ==================== 登录页 / 无权页 通用 ==================== */

.center-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.card {
  width: 100%;
  max-width: 340px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 24px;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .05);
}

.card-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
  text-align: center;
}

.card-sub {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-error {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--danger);
  text-align: center;
}

/* ==================== 无权访问页 ==================== */

.deny-box {
  text-align: center;
  max-width: 360px;
}

.deny-title {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 600;
}

.deny-desc {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--muted);
}

.countdown {
  font-size: 64px;
  font-weight: 700;
  line-height: 1;
  color: var(--danger);
  font-variant-numeric: tabular-nums;
}

.deny-tip {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.deny-link {
  margin: 8px 0 0;
  font-size: 13px;
}

.deny-link a {
  color: var(--muted);
  text-decoration: none;
}

.deny-link a:hover {
  color: var(--accent);
}

/* ==================== 聊天页骨架 ==================== */

.chat-page {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--header);
  border-bottom: 1px solid var(--line);
}

.chat-title {
  font-size: 16px;
  font-weight: 600;
}

.chat-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

.user-name {
  color: var(--text);
}

.logout {
  color: var(--muted);
  text-decoration: none;
}

.logout:hover {
  color: var(--danger);
}

/* ---- 上传开关（仅 User 可见） ---- */

.switch-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--muted);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.switch-label {
  color: var(--text);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border: 1px solid #dcdcdc;
  border-radius: 999px;
  background: #f2f2f2;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.switch-knob {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #d0d0d0;
  transition: transform .15s, background-color .15s;
}

.switch.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.switch.on .switch-knob {
  background: #fff;
  border-color: #fff;
  transform: translateX(2px);
}

.switch:disabled {
  opacity: .6;
  cursor: wait;
}

/* ---- 消息区 ---- */

.msg-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.msg-list {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 16px 10px;
  -webkit-overflow-scrolling: touch;
}

.empty-tip {
  padding: 24px 0;
  text-align: center;
  font-size: 13px;
  color: #c0c0c0;
}

.msg-row {
  display: flex;
  margin-bottom: 14px;
}

.msg-row.me {
  justify-content: flex-end;
}

.msg-row.other {
  justify-content: flex-start;
}

.msg-body {
  display: flex;
  flex-direction: column;
  max-width: min(76%, 560px);
}

.msg-row.me .msg-body {
  align-items: flex-end;
}

.msg-row.other .msg-body {
  align-items: flex-start;
}

.bubble {
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}

.msg-row.me .bubble {
  background: var(--green);
  color: #1f1f1f;
}

.msg-row.other .bubble {
  background: #fff;
  border: 1px solid #e2e2e2;
}

.msg-time {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

/* ---- 文件卡片（仅预览，无下载） ---- */

.bubble-file {
  padding: 10px;
  min-width: 240px;
}

.file-card {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  grid-template-areas:
    "thumb meta"
    "thumb action";
  gap: 8px 12px;
  align-items: start;
}

.file-thumb {
  grid-area: thumb;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid #ececec;
  border-radius: 6px;
  background: #f5f5f5;
  color: #bdbdbd;
}

.file-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-meta {
  grid-area: meta;
  min-width: 0;
}

.file-name {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.file-size {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.file-expire {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--danger);
}

.file-expire::before {
  content: "";
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--danger);
}

.file-expire.is-expired {
  font-weight: 600;
}

.btn-preview {
  grid-area: action;
  justify-self: start;
  margin-top: 2px;
  padding: 4px 14px;
  font-size: 13px;
}

/* ---- 新消息提示 ---- */

.new-notice {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 6px 16px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
}

/* ---- 输入区 ---- */

.input-area {
  flex: 0 0 auto;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--soft);
  border-top: 1px solid var(--line);
}

.input-area form {
  max-width: 900px;
  margin: 0 auto;
}

.msg-input {
  display: block;
  width: 100%;
  max-height: 120px;
  padding: 8px 10px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  resize: none;
  outline: none;
}

.msg-input:focus {
  border-color: var(--accent);
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.counter {
  margin-right: auto;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.counter.full {
  color: var(--danger);
}

/* ==================== 预览弹层 ==================== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, .72);
}

.modal-inner {
  position: relative;
  max-width: 92vw;
  max-height: 90vh;
}

.modal-body img {
  display: block;
  max-width: 92vw;
  max-height: 84vh;
  border-radius: 6px;
  background: #fff;
}

.modal-text {
  padding: 26px 34px;
  border-radius: 8px;
  background: #fff;
  font-size: 15px;
  color: var(--text);
}

.modal-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #fff;
  color: #333;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}

/* ==================== 轻提示 ==================== */

.toast {
  position: fixed;
  left: 50%;
  top: 22px;
  z-index: 60;
  transform: translateX(-50%);
  max-width: 80vw;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .78);
  color: #fff;
  font-size: 13px;
}

.toast.error {
  background: var(--danger);
}

/* ==================== 移动端适配 ==================== */

@media (max-width: 600px) {
  body {
    font-size: 15px;
  }

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

  .switch-bar {
    padding: 8px 12px;
  }

  .msg-list {
    padding: 12px 12px 8px;
  }

  .msg-body {
    max-width: 82%;
  }

  .bubble-file {
    min-width: 0;
  }

  .file-card {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 6px 10px;
  }

  .file-thumb {
    width: 64px;
    height: 64px;
  }

  .file-name {
    font-size: 13px;
  }

  .input-actions {
    gap: 6px;
  }

  .btn {
    padding: 6px 10px;
    font-size: 13px;
  }

  .btn-preview {
    padding: 4px 12px;
  }

  .countdown {
    font-size: 56px;
  }
}
