/* 参照微信网页版文件传输助手的配色与布局 */
:root {
  --page: #e5e5e5;
  --window: #f5f5f5;
  --border: #e7e7e7;
  --text: #191919;
  --muted: #999999;
  --mine: #95ec69;
  --mine-text: #191919;
  --theirs: #ffffff;
  --card: #ffffff;
  --accent: #07c160;
  --accent-text: #ffffff;
  --danger: #fa5151;
  --composer: #ffffff;
  --link: #576b95;
  --progress-bg: #ededed;
  --shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --window: #111111;
    --border: #262626;
    --text: #e5e5e5;
    --muted: #7a7a7a;
    --mine: #3eb575;
    --mine-text: #0b0b0b;
    --theirs: #2c2c2c;
    --card: #2c2c2c;
    --composer: #191919;
    --link: #7d90a9;
    --progress-bg: #333333;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--page);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- 登录 ---------- */
.login {
  flex: 1;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: min(360px, 100%);
  padding: 40px 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  background: var(--window);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.login-icon { width: 64px; height: 64px; margin: 0 auto; }
.login-card h1 { margin: 0 0 10px; font-size: 18px; font-weight: 500; }
.login-card input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--composer);
  color: var(--text);
  font-size: 16px;
}
.login-card button {
  padding: 10px;
  border: 0;
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 15px;
  cursor: pointer;
}
.login-error { min-height: 1.5em; margin: 0; color: var(--danger); font-size: 13px; }

/* ---------- 聊天窗口：桌面端居中，手机端全屏 ---------- */
.chat {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--window);
}
@media (min-width: 760px) {
  body { display: flex; align-items: center; justify-content: center; }
  .chat {
    flex: none;
    width: min(960px, calc(100vw - 48px));
    height: min(820px, calc(100dvh - 48px));
    border-radius: 6px;
    overflow: hidden;
    box-shadow: var(--shadow);
  }
}

.topbar {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
}
.title { display: flex; flex-direction: column; align-items: center; text-align: center; }
.title span { font-size: 16px; font-weight: 500; }
.title small { color: var(--muted); font-size: 12px; line-height: 1.3; }
.top-actions { display: flex; justify-content: flex-end; gap: 2px; }
.link-btn {
  border: 0;
  background: none;
  padding: 4px 6px;
  color: var(--link);
  font-size: 13px;
  cursor: pointer;
  max-width: 28vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scroller {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 20px 16px;
}
.older, .empty { text-align: center; color: var(--muted); font-size: 12px; margin: 10px 0; }
.empty { margin-top: 28vh; line-height: 1.9; }

.list { display: flex; flex-direction: column; }
.row { display: flex; flex-direction: column; padding-top: 14px; }
.time {
  align-self: center;
  margin-bottom: 10px;
  padding: 1px 6px;
  font-size: 12px;
  color: var(--muted);
}

.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 70%; align-self: flex-start; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.meta { font-size: 12px; color: var(--muted); margin: 0 0 4px 2px; }

/* 气泡（带小尖角） */
.bubble {
  position: relative;
  padding: 9px 12px;
  border-radius: 4px;
  background: var(--theirs);
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.bubble::before {
  content: "";
  position: absolute;
  top: 12px;
  left: -5px;
  border: 5px solid transparent;
  border-left: 0;
  border-right-color: var(--theirs);
}
.mine .bubble { background: var(--mine); color: var(--mine-text); }
.mine .bubble::before {
  left: auto;
  right: -5px;
  border-right: 0;
  border-left: 5px solid var(--mine);
}
.bubble a { color: var(--link); }
.mine .bubble a { color: #1d4f8a; }

/* 文件卡片 */
.file {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(250px, 66vw);
  padding: 12px 12px 12px 14px;
  border-radius: 4px;
  background: var(--card);
  color: var(--text);
  text-decoration: none;
}
.file-info { flex: 1; min-width: 0; }
.file-name {
  font-size: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.file-size { font-size: 12px; color: var(--muted); margin-top: 4px; }
.file-badge {
  flex: none;
  width: 38px;
  height: 44px;
  border-radius: 3px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: #8c99a8;
}
.file-badge.zip { background: #8a6dd1; }
.file-badge.pdf { background: #e5534b; }
.file-badge.doc { background: #3b7ddd; }
.file-badge.xls { background: #1f9d55; }
.file-badge.ppt { background: #e8833a; }
.file-badge.media { background: #10a3a3; }
.file.expired { opacity: 0.5; }
a.file:hover { background: color-mix(in srgb, var(--card) 92%, #000); }

.preview {
  display: block;
  max-width: min(240px, 60vw);
  max-height: 300px;
  border-radius: 4px;
  background: var(--card);
}
video.preview { width: min(260px, 66vw); }

/* 复制 / 删除：桌面端悬停时显示，手机端常显 */
.actions { display: flex; gap: 2px; margin-top: 2px; min-height: 20px; }
.actions button, .actions a {
  border: 0;
  background: none;
  padding: 1px 5px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
}
.actions button:hover, .actions a:hover { color: var(--link); }
.actions .del:hover { color: var(--danger); }
@media (hover: hover) {
  .actions:not(.show) { visibility: hidden; }
  .msg:hover .actions { visibility: visible; }
}

/* 上传进度 */
.progress { height: 3px; border-radius: 2px; background: var(--progress-bg); overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.upload-status { font-size: 12px; color: var(--muted); margin-top: 4px; }
.upload-status.error { color: var(--danger); }

/* ---------- 输入区 ---------- */
.composer {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "tools tools" "input input" ". send";
  padding: 6px 16px 12px;
  background: var(--composer);
  border-top: 1px solid var(--border);
}
.toolbar { grid-area: tools; display: flex; align-items: center; gap: 8px; }
.toolbar-hint { font-size: 12px; color: var(--muted); }
.icon-btn {
  border: 0;
  background: none;
  padding: 6px 4px;
  color: #7f7f7f;
  cursor: pointer;
  line-height: 0;
}
.icon-btn:hover { color: var(--text); }
#input {
  grid-area: input;
  min-width: 0;
  height: 96px;
  resize: none;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
}
.send-btn {
  grid-area: send;
  border: 0;
  border-radius: 4px;
  padding: 6px 22px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
.send-btn:disabled { background: #e9e9e9; color: #b2b2b2; cursor: default; }

/* 手机端：单行输入 + 右侧发送 */
@media (max-width: 759px) {
  .scroller { padding: 4px 12px 14px; }
  .msg { max-width: 80%; }
  .composer {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "tools input send";
    align-items: end;
    gap: 8px;
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    background: var(--window);
  }
  .toolbar-hint { display: none; }
  .icon-btn { padding: 7px 2px; }
  #input {
    height: auto;
    max-height: 120px;
    padding: 8px 10px;
    border-radius: 4px;
    background: var(--composer);
    font-size: 16px;
  }
  .send-btn { padding: 8px 14px; }
}

@media (prefers-color-scheme: dark) {
  .send-btn:disabled { background: #2c2c2c; color: #5c5c5c; }
}

/* ---------- 多选模式 ---------- */
.row { position: relative; }
.check { display: none; }
.selecting .row { padding-left: 34px; cursor: pointer; }
.selecting .check {
  display: block;
  position: absolute;
  left: 4px;
  bottom: 26px;
  width: 20px;
  height: 20px;
  border: 1.5px solid #b2b2b2;
  border-radius: 50%;
  background: var(--composer);
}
.selecting .row.selected .check { border-color: var(--accent); background: var(--accent); }
.selecting .row.selected .check::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.selecting .actions { visibility: hidden !important; }
.selecting .msg * { pointer-events: none; }

.select-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--composer);
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.select-actions { display: flex; align-items: center; gap: 6px; }
.link-btn.danger { color: var(--danger); }
.send-btn.danger-btn { background: var(--danger); }
.send-btn.danger-btn:disabled { background: #e9e9e9; color: #b2b2b2; }

/* 拖拽和提示 */
.drop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(7, 193, 96, 0.1);
  border: 3px dashed var(--accent);
  font-size: 18px;
  color: var(--accent);
  pointer-events: none;
  z-index: 10;
}
.toast {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 14px;
  z-index: 20;
}
