/* tg-web 视觉系统
 
 目标设备：Listeneer K9，480×640 @240dpi（约 320×427 CSS px）的灰阶墨水屏。
 三条硬约束决定了这里的每一个选择：

 1. 纯中性灰，不用任何带色相的灰。墨水屏是 16 级灰阶，暖灰/冷灰会被抖动成噪点。
 2. 零动画、零阴影。墨水屏刷一次整屏要几百毫秒，过渡只会留下残影，
    层次一律用「发丝线 + 浅填充 + 字重」表达。
 3. 触控区不小于 44px，正文 15px 起。屏幕小、刷新慢，误触的代价比密集排版大。

 形状规则（全局唯一一套，不混用）：
   圆角 8px —— 卡片、气泡、按钮、输入框
   全圆     —— 头像、文件夹胶囊、未读徽章
 字号：21 / 17 / 15 / 13 / 12 / 11
 */

:root {
  --ink: #0f0f0f;
  --ink2: #464646;
  --ink3: #6e6e6e;
  --ink4: #9a9a9a;
  --line: #d4d4d4;
  --line2: #e8e8e8;
  --fill: #f2f2f2;
  --fill2: #fafafa;
  --paper: #fff;
  --r: 8px;
  /* 这台设备上浏览器把屏幕右侧约 55 CSS px 留给了自己的手势区，
     落在里面的点击会被吞掉。右上角的刷新按钮一开始就是这么变死键的：
     实测图标中心在 x=377 时能点、移到 410 就点不动了。
     所以所有交互控件的右边缘都收在 --gutter 之外（320 - 60 = 260）。 */
  --gutter: 60px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* .bar / .replybar 都设了 display:flex，会盖掉 hidden 属性的浏览器默认样式，
   所以这里显式兜底，否则搜索栏和回复条永远显示。 */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
  -webkit-user-select: none;
  user-select: none;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.grow {
  flex: 1;
}

/* ---------- 图标：纯几何线条，统一 1.8 描边 ---------- */
.ico {
  display: block;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ico-sm {
  width: 15px;
  height: 15px;
  stroke-width: 2;
}

.ico-dim {
  stroke: var(--ink4);
}

/* ---------- 视图容器 ---------- */
.view {
  display: none;
  flex-direction: column;
  height: 100%;
}

.view.on {
  display: flex;
}

/* ---------- 顶部栏 ---------- */
.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 52px;
  padding: 0 var(--gutter) 0 6px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.bar .ttl {
  flex: 1;
  min-width: 0;
  padding-left: 6px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.bar .t1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar .sub {
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink4);
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.iconbtn {
  position: relative;
  flex: none;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r);
  color: var(--ink);
}

.iconbtn:active {
  background: var(--fill);
}

.iconbtn .dot {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink);
}

/* 文件夹胶囊：全圆，是全局唯一使用胶囊形状的控件 */
.chip {
  max-width: 62%;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 10px 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip:active {
  background: var(--fill);
}

.chip .ico {
  flex: none;
  color: var(--ink3);
}

/* 搜索栏 */
.bar-search {
  gap: 4px;
  padding: 0 var(--gutter) 0 12px;
}

.bar-search input {
  flex: 1;
  min-width: 0;
  height: 44px;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  -webkit-appearance: none;
}

.bar-search input::placeholder {
  color: var(--ink4);
}

.bar-search input::-webkit-search-cancel-button {
  display: none;
}

/* 关闭搜索用文字按钮而不是小叉号：这台设备手指精度差，文字更好点中 */
.bar-search .cancel {
  flex: none;
  height: 40px;
  min-width: 52px;
  padding: 0 8px;
  border-radius: var(--r);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.bar-search .cancel:active {
  background: var(--fill);
}

/* ---------- 会话列表 ---------- */
.list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.row {
  -webkit-user-select: none;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 8px 12px 8px 10px;
  border-bottom: 1px solid var(--line2);
}

.row:active {
  background: var(--fill);
}

.av {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  background: var(--fill);
  color: var(--ink);
}

/* 头像底色按标题散列出三档灰，让列表可被扫读；不要靠描边，细线在墨水屏上会糊 */
.av-1 {
  background: #ebebeb;
}

.av-2 {
  background: #d2d2d2;
}

.av-3 {
  background: #b0b0b0;
  color: #fff;
}

.row .body {
  flex: 1;
  min-width: 0;
}

.row .name {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.row .name .txt {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row.unread .name .txt {
  font-weight: 700;
}

.row .name .time {
  flex: none;
  font-size: 11px;
  color: var(--ink4);
  font-variant-numeric: tabular-nums;
}

.row .preview {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--ink3);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.row.unread .preview {
  color: var(--ink2);
}

.row .preview .ptxt {
  overflow: hidden;
  text-overflow: ellipsis;
}

.row .preview .sep {
  flex: none;
  color: var(--ink4);
  font-size: 11px;
}

.badge {
  flex: none;
  min-width: 24px;
  height: 19px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 19px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* 静音会话的未读用描边而不是实心，一眼能分出「需要看」和「被折叠的」 */
.badge.quiet {
  background: var(--paper);
  color: var(--ink3);
  border: 1px solid var(--line);
  line-height: 17px;
}

.listfoot {
  flex: none;
  padding: 7px 12px;
  border-top: 1px solid var(--line2);
  font-size: 11px;
  color: var(--ink4);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* 骨架屏：静止灰块，不做脉冲，避免墨水屏整屏闪 */
.skel-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line2);
}

.skel-av {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--fill);
}

.skel-row span {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.skel-b {
  display: block;
  height: 10px;
  border-radius: 3px;
  background: var(--fill);
}

.w40 {
  width: 40%;
}

.w50 {
  width: 50%;
}

.w60 {
  width: 60%;
}

.w70 {
  width: 70%;
}

.w80 {
  width: 80%;
}

.w90 {
  width: 90%;
}

/* ---------- 聊天 ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--fill2);
}

.daysep {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--ink4);
}

.daysep i {
  flex: 1;
  height: 1px;
  background: var(--line2);
}

/* 「上次看到这里」的地标。爬楼时最需要一条明确的横线，
   否则滑几下就分不清哪些是上次看过、哪些是新的。 */
.here {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0 8px;
}

.here i {
  flex: 1;
  height: 1px;
  background: var(--ink3);
  opacity: 0.55;
}

.here span {
  font-size: 11px;
  color: var(--ink3);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.here-jump {
  font-family: inherit;
  font-size: 11px;
  color: var(--ink2);
  background: none;
  border: 1px solid var(--line2);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

.msg {
  align-self: flex-start;
  max-width: 88%;
  padding: 6px 9px 7px;
  border: 1px solid var(--line2);
  border-radius: var(--r);
  background: var(--paper);
}

.msg.out {
  align-self: flex-end;
  background: var(--fill);
  border-color: #e4e4e4;
}

/* 同一个人连续发言时收紧间距，消息列表才读得下去 */
.msg.grp {
  margin-top: -3px;
}

.msg .meta {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 2px;
  font-size: 11px;
  color: var(--ink4);
  font-variant-numeric: tabular-nums;
}

.msg .meta .who {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink2);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 自己发的消息时间贴右边，收到的消息时间跟在名字后面——否则单独一个时间
   飘在气泡右上角，孤零零的，看着像没对齐 */
.msg.out .meta .tm {
  margin-left: auto;
}

.msg .txt {
  -webkit-user-select: text;
  user-select: text;
  font-size: 15px;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg .replyref {
  margin-bottom: 4px;
  padding: 2px 0 2px 7px;
  border-left: 2px solid var(--line);
  font-size: 12px;
  color: var(--ink3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg.sel {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.msg .media {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  background: var(--fill);
  color: var(--ink2);
  font-size: 12px;
  text-align: center;
}

.msg .media b {
  display: block;
  padding: 22px 8px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.msg img.thumb {
  display: block;
  width: 100%;
  margin-top: 5px;
  border-radius: var(--r);
}

.msg .media-static {
  margin-top: 5px;
  font-size: 12px;
  color: var(--ink3);
}

.loadmore {
  display: block;
  width: 100%;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--paper);
  font-size: 13px;
  color: var(--ink2);
  text-align: center;
}

.loadmore:active {
  background: var(--fill);
}

/* ---------- 输入区 ---------- */
.composer {
  flex: none;
  border-top: 1px solid var(--line);
  background: var(--paper);
}

.replybar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px var(--gutter) 6px 12px;
  border-bottom: 1px solid var(--line2);
  background: var(--fill2);
  font-size: 12px;
  color: var(--ink3);
}

.replybar .rb-label {
  flex: none;
  font-weight: 600;
  color: var(--ink2);
}

.replybar .rb-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rb-x {
  flex: none;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r);
  color: var(--ink3);
}

.rb-x:active {
  background: var(--line2);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px var(--gutter) 8px 8px;
}

.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 104px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  outline: none;
}

.composer textarea:focus {
  border-color: var(--ink3);
}

.send {
  flex: none;
  width: 48px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r);
  background: var(--ink);
  color: #fff;
}

.send:disabled {
  background: #ededed;
  border: 1px solid #e0e0e0;
  color: var(--ink4);
}

.send:active:not(:disabled) {
  transform: translateY(1px);
}

/* ---------- 登录 ---------- */
.auth {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 18px;
  overflow-y: auto;
}

.auth .lead {
  margin: 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink3);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field .label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink3);
}

.field input {
  width: 100%;
  height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  outline: none;
}

.field input:focus {
  border-color: var(--ink3);
}

.btn-primary {
  height: 48px;
  border-radius: var(--r);
  background: var(--ink);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.btn-primary:disabled {
  background: #ededed;
  color: var(--ink4);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(1px);
}

.err {
  min-height: 17px;
  font-size: 12px;
  color: #8c1010;
}

/* ---------- 空态 ---------- */
.empty {
  padding: 44px 24px;
  text-align: center;
}

.empty b {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink2);
}

.empty span {
  display: block;
  margin-top: 5px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink4);
}

/* ---------- 底部抽屉 ---------- */
.sheet-wrap {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 20;
}

.sheet-backdrop {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.22);
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 78%;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
  border-radius: var(--r) var(--r) 0 0;
  background: var(--paper);
}

.sheet-head {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 13px 16px 10px;
  border-bottom: 1px solid var(--line2);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.sheet-hint {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  font-weight: 400;
  color: var(--ink4);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
}

.sheet-item {
  -webkit-user-select: none;
  user-select: none;
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  /* 整行本身就是一个按钮，右边那截死区不影响使用（点文字照样能选中），
     所以这里按普通边距排版，视觉上才左右平衡 */
  padding: 0 16px;
  border-bottom: 1px solid var(--line2);
  font-size: 15px;
  text-align: left;
}

.sheet-item:active {
  background: var(--fill);
}

.sheet-item .cnt {
  margin-left: auto;
  font-size: 12px;
  color: var(--ink4);
  font-variant-numeric: tabular-nums;
}

.sheet-item .mark {
  flex: none;
  width: 18px;
  color: var(--ink);
}

.sheet-item.on {
  background: var(--fill2);
}

.sheet-item.on .lbl {
  font-weight: 600;
}
