:root {
  --accent: #3390ec;
  --accent-hover: #2b7fd6;
  --bg: #ffffff;
  --chat-bg: #dde4ea;
  --ink: #16181b;
  --muted: #8a949e;
  --line: #e9ebee;
  --hover: #f3f4f6;
  --mine: #eeffde;
  --theirs: #ffffff;
  --online: #4dcd5e;
  --danger: #e4572e;
  --ok: #2f9e63;
  --bad: #e0564a;
  --warn: #c08a2d;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }
.empty { color: var(--muted); font-size: 13px; padding: 20px 16px; line-height: 1.7; }

button {
  font: inherit; padding: 8px 16px; border: none;
  background: var(--accent); color: #fff;
  border-radius: 8px; cursor: pointer; transition: background .15s;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
button.small { padding: 4px 11px; font-size: 12px; }
button.danger { background: var(--danger); }
button.danger:hover:not(:disabled) { background: #c8431f; }
input, textarea {
  font: inherit; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }
.modal-card.small > input, .modal-card.small > textarea { display: block; width: 100%; }

/* 登录 */
.login { display: grid; place-items: center; height: 100vh; background: var(--chat-bg); }
.login-card {
  display: flex; flex-direction: column; gap: 14px; width: 320px;
  padding: 32px 28px; background: #fff; border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.12);
}
.login-card h1 { margin: 0 0 6px; font-size: 22px; text-align: center; font-weight: 600; }
.login-card input { padding: 11px 13px; }

/* 布局 */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 0 16px; height: 56px;
  background: #fff; border-bottom: 1px solid var(--line); flex: none;
}
.brand { font-weight: 600; font-size: 16px; }
.spacer { flex: 1; }
#whoami { font-size: 13px; }
.main { flex: 1; display: grid; grid-template-columns: 320px 270px 1fr; min-height: 0; }
.col { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; background: #fff; }
.col.chat { border-right: none; background: var(--chat-bg); }
.col-head {
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px; height: 54px; font-weight: 600; flex: none;
  border-bottom: 1px solid var(--line); background: #fff;
}
.col-head .spacer, .col-head #convTitle, .col-head #chatHead { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list { overflow-y: auto; flex: 1; }
.back {
  display: none; background: transparent; color: var(--accent);
  font-size: 22px; line-height: 1; padding: 4px 8px 6px; border-radius: 8px;
}

/* 头像 */
.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: none; position: relative;
  color: #fff; font-size: 19px; font-weight: 600;
  display: grid; place-items: center; user-select: none;
}
.avatar .dot {
  position: absolute; right: 0; bottom: 1px; width: 13px; height: 13px;
  border-radius: 50%; background: var(--online); border: 2px solid #fff;
}

/* 设备 / 会话项 */
.device, .conv {
  display: flex; gap: 11px; align-items: center;
  padding: 8px 12px; cursor: pointer;
}
.device:hover, .conv:hover { background: var(--hover); }
.device.active, .conv.active { background: var(--accent); }
.device-body, .conv-body { flex: 1; min-width: 0; }
.device-top, .conv-top { display: flex; align-items: center; gap: 8px; }
.device-name, .conv-peer { font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-sub { font-size: 12px; color: var(--muted); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sim-line { font-size: 11px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.active .sim-line { color: rgba(255,255,255,.82); }
.conv-time { font-size: 12px; color: var(--muted); flex: none; }
.conv-last { font-size: 13px; color: var(--muted); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 选中(蓝底)时文字转白 */
.active .device-name, .active .conv-peer { color: #fff; }
.active .device-sub, .active .conv-last, .active .conv-time { color: rgba(255,255,255,.82); }

.lights { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.light {
  font-size: 11px; padding: 1px 7px; border-radius: 10px;
  border: 1px solid var(--line); color: var(--muted); background: #fff;
}
.light.ok { color: var(--ok); border-color: #bfe3cd; background: #f0faf4; }
.light.bad { color: var(--bad); border-color: #eccac6; background: #fcf2f1; }
.light.warn { color: var(--warn); border-color: #ecdcb8; background: #fcf7ec; }
.active .light { background: rgba(255,255,255,.2); color: #fff; border-color: transparent; }

/* 会话栏底部常驻「新建」composer */
.new-conv-bar { flex: none; border-top: 1px solid var(--line); padding: 8px 10px; background: #fff; }
.new-conv-bar input { width: 100%; border: none; background: var(--hover); border-radius: 16px; padding: 8px 12px; }
.new-conv-bar input:focus { background: #eef0f2; }
.new-conv-bar input:disabled { opacity: .5; }
.nc-row { display: flex; gap: 6px; margin-top: 6px; }
.nc-row input { flex: 1; min-width: 0; }
.nc-send { flex: none; border-radius: 16px; padding: 8px 14px; }

.badge {
  background: var(--accent); color: #fff; border-radius: 11px;
  font-size: 11px; padding: 0 6px; min-width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.active .badge { background: #fff; color: var(--accent); }

/* 聊天 */
.messages { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 4px; }
.bubble-row { display: flex; margin-top: 4px; }
.bubble-row.out { justify-content: flex-end; }
.bubble {
  max-width: 72%; padding: 7px 11px 6px; border-radius: 12px;
  background: var(--theirs); white-space: pre-wrap; word-break: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,.09); border-bottom-left-radius: 4px;
}
.bubble-row.out .bubble { background: var(--mine); border-radius: 12px; border-bottom-right-radius: 4px; }
.meta { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }
.meta .st-ok { color: var(--ok); }
.meta .st-bad { color: var(--bad); }
.meta .st-warn { color: var(--warn); }

.send-bar { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); background: #fff; flex: none; }
.send-bar input {
  flex: 1; border: none; background: var(--hover); border-radius: 20px; padding: 11px 16px;
}
.send-bar input:focus { background: #eef0f2; }
.sim-select {
  flex: none; border: none; background: var(--hover); border-radius: 16px;
  padding: 8px 10px; color: var(--ink); max-width: 118px; font: inherit; cursor: pointer;
}
.sim-select:focus { outline: none; background: #eef0f2; }
.send-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%; padding: 0;
  display: grid; place-items: center;
}
.send-btn svg { margin-left: 2px; }

/* 弹窗 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 10; padding: 16px; }
.modal-card { background: #fff; border-radius: 14px; width: 560px; max-width: 100%; max-height: 86vh; overflow-y: auto; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal-card.small { width: 380px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; font-weight: 600; font-size: 16px; }
.admin-sec { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }
.admin-sec:first-of-type { border-top: none; margin-top: 0; padding-top: 0; }
.admin-sec h3 { margin: 0 0 10px; font-size: 15px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row input { flex: 1; min-width: 100px; }
.chk { display: flex; align-items: center; gap: 4px; font-size: 13px; white-space: nowrap; }
.acc-list { display: flex; flex-direction: column; gap: 6px; }
.acc-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.acc-row .spacer { flex: 1; }

/* 今日收发 */
.stat-list { display: flex; flex-direction: column; }
.stat-row { display: flex; align-items: center; gap: 8px; padding: 7px 2px; border-bottom: 1px solid var(--line); }
.stat-row:last-child { border-bottom: none; }
.stat-head { color: var(--muted); font-size: 12px; font-weight: 600; }
.stat-name { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-name .avatar { width: 30px; height: 30px; font-size: 13px; }
.stat-num { width: 58px; text-align: center; flex: none; }
.stat-sent { color: var(--accent); font-weight: 600; }
.stat-recv { color: var(--ok); font-weight: 600; }
.stat-head .stat-sent, .stat-head .stat-recv { color: var(--muted); font-weight: 600; }

/* 手机端:单栏下钻 */
@media (max-width: 760px) {
  .main { grid-template-columns: 1fr; }
  .col { grid-area: 1 / 1; display: none; border-right: none; }
  body[data-view="devices"] .col.devices,
  body[data-view="convs"]   .col.convs,
  body[data-view="chat"]    .col.chat { display: flex; }
  .back { display: inline-flex; }
  .bubble { max-width: 82%; }
}
