/* chocoSecure — UI (light by default, dark via [data-theme="dark"]) */

:root {
  --font: "Inter", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  --bg: #eef0f8;
  --panel: #ffffff;
  --panel-2: #f7f8fc;
  --surface: #ffffff;
  --surface-2: #f1f3fa;
  --surface-3: #e7eaf5;
  --rail: #1c1f3c;
  --rail-2: #252950;
  --text: #1f233b;
  --text-soft: #5d6480;
  --text-mute: #9aa1b9;
  --border: #e7eaf3;
  --border-strong: #d9ddee;
  --brand: #6c5ce7;
  --brand-2: #9282ff;
  --brand-soft: #f1eeff;
  --danger: #e25570;
  --danger-soft: #fff0f3;
  --green: #2cb98b;
  --green-soft: #e8faf3;
  --shadow-sm: 0 2px 10px rgba(35, 40, 85, .05);
  --shadow: 0 8px 28px rgba(35, 40, 85, .09);
  --shadow-lg: 0 26px 70px rgba(24, 27, 60, .2);
  --radius: 16px;
}

html[data-theme="dark"] {
  --bg: #121427;
  --panel: #1b1e35;
  --panel-2: #20233c;
  --surface: #242840;
  --surface-2: #2c3050;
  --surface-3: #363b60;
  --rail: #101224;
  --rail-2: #1a1d38;
  --text: #eef0fb;
  --text-soft: #b2b9d6;
  --text-mute: #7f87aa;
  --border: #2c3050;
  --border-strong: #3a3f66;
  --brand: #9c8cff;
  --brand-2: #b7a6ff;
  --brand-soft: #2b2852;
  --danger-soft: #3a2030;
  --green-soft: #173a33;
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, .2);
  --shadow: 0 8px 28px rgba(0, 0, 0, .3);
  --shadow-lg: 0 26px 70px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea { font-family: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-mute); background-clip: padding-box; }

/* ================================================================== */
/* auth                                                               */
/* ================================================================== */

.auth-screen { display: grid; grid-template-columns: minmax(360px, 46%) 1fr; height: 100vh; }

.auth-brand {
  position: relative;
  overflow: hidden;
  background: linear-gradient(150deg, #6553e8 0%, #7a5bea 42%, #a35fd8 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 54px 60px 40px;
}
.auth-brand::before, .auth-brand::after {
  content: ''; position: absolute; border-radius: 50%; pointer-events: none;
}
.auth-brand::before { width: 540px; height: 540px; right: -230px; top: -210px; background: rgba(255,255,255,.1); }
.auth-brand::after { width: 380px; height: 380px; left: -170px; bottom: -160px; background: rgba(255,255,255,.07); }
.brand-glow { position: absolute; width: 320px; height: 320px; left: 30%; bottom: -120px; background: rgba(255,190,120,.16); filter: blur(60px); border-radius: 50%; }
.auth-brand-inner { position: relative; z-index: 1; }
.brand-logo {
  width: 56px; height: 56px; border-radius: 17px;
  background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.3);
  display: grid; place-items: center; backdrop-filter: blur(8px);
  box-shadow: 0 12px 30px rgba(30,20,90,.18);
}
.brand-logo svg { width: 28px; height: 28px; stroke-width: 2; }
.auth-brand h1 { font-size: 40px; letter-spacing: -1.2px; margin: 26px 0 8px; font-weight: 750; }
.brand-tagline { font-size: 16px; opacity: .82; margin: 0 0 52px; letter-spacing: .3px; }
.brand-features { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 26px; }
.brand-features li { display: flex; gap: 16px; align-items: flex-start; }
.brand-features li > svg {
  width: 38px; height: 38px; padding: 9px; border-radius: 12px;
  background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.2); stroke-width: 1.9;
}
.brand-features strong { display: block; font-size: 15px; font-weight: 650; margin-bottom: 4px; }
.brand-features span { display: block; font-size: 12.5px; opacity: .75; line-height: 1.5; }
.brand-foot { position: relative; z-index: 1; font-size: 12px; opacity: .62; letter-spacing: 1.2px; }

.auth-panel { display: grid; place-items: center; padding: 30px; background: var(--panel); overflow: auto; }
.auth-card { width: min(400px, 100%); }
.auth-tabs { position: relative; display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 34px; }
.auth-tabs button { flex: 1; border: 0; background: transparent; padding: 10px; font-size: 13.5px; font-weight: 600; color: var(--text-mute); border-radius: 9px; position: relative; z-index: 1; transition: color .2s; }
.auth-tabs button.active { color: var(--brand); }
#authTabIndicator { position: absolute; top: 4px; left: 4px; width: calc(50% - 4px); height: calc(100% - 8px); background: var(--surface); border-radius: 9px; box-shadow: var(--shadow-sm); transition: transform .25s cubic-bezier(.2,.8,.2,1); }
.auth-tabs.register #authTabIndicator { transform: translateX(100%); }
.auth-card h2 { font-size: 27px; margin: 0 0 7px; letter-spacing: -.5px; }
.auth-sub { color: var(--text-mute); font-size: 13px; margin: 0 0 28px; }
.field { display: block; margin-bottom: 15px; }
.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--text-soft); margin-bottom: 7px; }
.field input {
  width: 100%; padding: 12px 14px; font-size: 14px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px;
  outline: none; transition: border-color .2s, box-shadow .2s;
}
.field input::placeholder { color: var(--text-mute); }
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 13%, transparent); }
.auth-error { font-size: 12.5px; color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; line-height: 1.5; }
.primary-btn {
  width: 100%; margin-top: 8px; padding: 13px; border: 0; border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
  font-size: 14.5px; font-weight: 650; letter-spacing: 1px;
  box-shadow: 0 10px 24px color-mix(in srgb, var(--brand) 34%, transparent);
  transition: transform .18s, filter .18s;
}
.primary-btn:hover { filter: brightness(1.07); transform: translateY(-1px); }
.primary-btn:active { transform: scale(.99); }
.auth-note { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 22px; font-size: 11.5px; color: var(--text-mute); line-height: 1.5; }
.auth-note svg { width: 14px; height: 14px; }

/* ================================================================== */
/* app shell                                                          */
/* ================================================================== */

.app { display: grid; grid-template-columns: 68px 306px 1fr; height: 100vh; background: var(--bg); }

.rail {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 0 14px;
  background: linear-gradient(170deg, var(--rail-2), var(--rail));
  border-right: 1px solid rgba(255,255,255,.05);
  -webkit-app-region: drag;
}
.rail button { -webkit-app-region: no-drag; }
.rail-logo {
  width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; box-shadow: 0 8px 20px rgba(108,92,231,.4); margin-bottom: 28px;
}
.rail-logo svg { width: 21px; height: 21px; stroke-width: 2; }
.rail-nav { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.rail-btn {
  position: relative; width: 42px; height: 42px; border: 0; border-radius: 12px;
  background: transparent; color: rgba(255,255,255,.45); display: grid; place-items: center;
  transition: background .2s, color .2s, transform .2s;
}
.rail-btn:hover { background: rgba(255,255,255,.09); color: #fff; }
.rail-btn.active { background: rgba(255,255,255,.14); color: #fff; box-shadow: inset 0 0 0 1px rgba(255,255,255,.1); }
.rail-btn.active::before { content: ''; position: absolute; left: -13px; width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--brand-2); }
.rail-badge { position: absolute; top: 4px; right: 3px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--rail-2); }
.rail-bottom { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.rail-avatar {
  width: 38px; height: 38px; border-radius: 12px; border: 2px solid rgba(255,255,255,.2);
  color: #fff; font-size: 13px; font-weight: 700; margin-top: 4px;
  background: linear-gradient(135deg, #f0986e, #e86fa3);
}

/* list pane */
.list-pane { display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--border); min-width: 0; }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 22px 20px 14px; }
.list-title { font-size: 19px; font-weight: 700; letter-spacing: -.3px; }
.list-count { font-size: 11.5px; color: var(--text-mute); margin-top: 3px; }
.add-btn { width: 32px; height: 32px; border: 0; border-radius: 10px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; transition: transform .18s, background .18s; }
.add-btn:hover { transform: rotate(90deg); background: color-mix(in srgb, var(--brand) 20%, transparent); }
.add-btn svg { width: 17px; height: 17px; stroke-width: 2.2; }
.search-box { margin: 0 16px 12px; display: flex; align-items: center; gap: 9px; padding: 9px 12px; background: var(--surface-2); border: 1px solid transparent; border-radius: 11px; transition: border-color .2s; }
.search-box:focus-within { border-color: var(--brand); }
.search-box svg { width: 16px; height: 16px; color: var(--text-mute); }
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 12.5px; }
.search-box input::placeholder { color: var(--text-mute); }
.list-scroll { flex: 1; overflow-y: auto; padding: 0 10px 14px; }
.list-section { font-size: 10.5px; font-weight: 700; letter-spacing: 1.2px; color: var(--text-mute); padding: 14px 10px 8px; text-transform: uppercase; }
.list-item {
  width: 100%; display: flex; align-items: center; gap: 11px; padding: 10px;
  border: 0; border-radius: 12px; background: transparent; color: var(--text);
  text-align: left; transition: background .16s; margin-bottom: 2px;
}
.list-item:hover { background: var(--surface-2); }
.list-item.active { background: var(--brand-soft); }
.avatar { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px; flex: 0 0 auto; box-shadow: var(--shadow-sm); }
.avatar.sm { width: 34px; height: 34px; border-radius: 11px; font-size: 13px; }
.avatar.xs { width: 28px; height: 28px; border-radius: 9px; font-size: 11px; }
.li-body { flex: 1; min-width: 0; }
.li-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.li-name { font-size: 13.5px; font-weight: 620; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-time { font-size: 10.5px; color: var(--text-mute); flex: 0 0 auto; }
.li-sub { font-size: 11.5px; color: var(--text-mute); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; }
.li-actions { display: flex; gap: 6px; }
.mini-btn { padding: 6px 11px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-soft); font-size: 11.5px; font-weight: 600; transition: all .18s; }
.mini-btn:hover { border-color: var(--brand); color: var(--brand); }
.mini-btn.solid { background: var(--brand); border-color: var(--brand); color: #fff; }
.mini-btn.solid:hover { filter: brightness(1.08); color: #fff; }
.mini-btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.list-empty { padding: 46px 18px; text-align: center; color: var(--text-mute); font-size: 12.5px; line-height: 1.7; }
.list-empty svg { width: 34px; height: 34px; opacity: .4; margin-bottom: 10px; }
.list-foot { display: flex; align-items: center; gap: 7px; padding: 11px 18px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-mute); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-mute); }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.status-dot.offline { background: var(--danger); }
.e2ee-mini { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; color: var(--green); font-weight: 650; letter-spacing: .5px; }
.e2ee-mini svg { width: 12px; height: 12px; stroke-width: 2.2; }

/* ================================================================== */
/* chat pane                                                          */
/* ================================================================== */

.chat-pane { min-width: 0; display: flex; flex-direction: column; background: var(--bg); position: relative; }
.empty-state { margin: auto; text-align: center; padding: 30px; }
.empty-art { width: 82px; height: 82px; margin: 0 auto 22px; border-radius: 26px; display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); color: var(--brand); }
.empty-art svg { width: 38px; height: 38px; stroke-width: 1.5; }
.empty-state h3 { font-size: 18px; margin: 0 0 9px; font-weight: 650; }
.empty-state p { color: var(--text-mute); font-size: 13px; line-height: 1.8; margin: 0 0 26px; }
.empty-chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.empty-chips span { display: inline-flex; align-items: center; gap: 5px; padding: 7px 11px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; font-size: 11px; color: var(--text-soft); font-weight: 600; }
.empty-chips svg { width: 12px; height: 12px; color: var(--brand); }

.chat-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head {
  height: 72px; flex: 0 0 auto; display: flex; align-items: center; gap: 13px;
  padding: 0 24px; background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(14px); border-bottom: 1px solid var(--border);
  -webkit-app-region: drag;
}
.chat-head button { -webkit-app-region: no-drag; }
.chat-avatar { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.chat-head-meta { min-width: 0; }
.chat-name { font-size: 15px; font-weight: 680; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { font-size: 11.5px; color: var(--text-mute); margin-top: 3px; }
.chat-head-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.enc-badge { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid color-mix(in srgb, var(--green) 30%, transparent); background: var(--green-soft); color: var(--green); border-radius: 999px; font-size: 11.5px; font-weight: 650; transition: filter .18s; }
.enc-badge:hover { filter: brightness(.97); }
.enc-badge svg { width: 13px; height: 13px; stroke-width: 2.2; }
.head-icon { width: 34px; height: 34px; border: 1px solid var(--border); background: var(--surface); color: var(--text-soft); border-radius: 10px; display: grid; place-items: center; transition: all .18s; }
.head-icon:hover { color: var(--brand); border-color: var(--brand); }
.head-icon svg { width: 16px; height: 16px; }

.messages { flex: 1; overflow-y: auto; padding: 24px 30px 16px; scroll-behavior: smooth; }
.day-sep { text-align: center; margin: 14px 0 20px; }
.day-sep span { display: inline-block; padding: 5px 13px; background: var(--surface-3); color: var(--text-mute); font-size: 10.5px; border-radius: 999px; }
.msg-row { display: flex; gap: 10px; margin-bottom: 16px; align-items: flex-end; animation: msg-in .26s cubic-bezier(.2,.8,.25,1) both; }
@keyframes msg-in { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: none; } }
.msg-row.mine { flex-direction: row-reverse; }
.msg-col { max-width: min(66%, 620px); min-width: 0; }
.msg-meta { font-size: 10.5px; color: var(--text-mute); margin: 0 5px 5px; display: flex; gap: 8px; align-items: center; }
.msg-row.mine .msg-meta { justify-content: flex-end; }
.msg-meta strong { color: var(--text-soft); font-weight: 620; }
.bubble {
  padding: 10px 15px; font-size: 14px; line-height: 1.65; word-break: break-word;
  border-radius: 17px 17px 17px 5px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm); white-space: pre-wrap;
}
.msg-row.mine .bubble {
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-color: transparent;
  border-radius: 17px 17px 5px 17px; box-shadow: 0 8px 20px color-mix(in srgb, var(--brand) 24%, transparent);
}
.bubble.bad { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); font-size: 12.5px; }
.msg-time { font-size: 10px; color: var(--text-mute); margin: 5px 5px 0; text-align: left; }
.msg-row.mine .msg-time { text-align: right; }
.msg-lock { display: inline-flex; align-items: center; gap: 3px; margin-left: 5px; opacity: .6; }
.msg-lock svg { width: 10px; height: 10px; }
.system-msg { text-align: center; font-size: 11.5px; color: var(--text-mute); padding: 8px 0 18px; }

/* encrypted image bubbles */
.bubble-image { padding: 6px !important; background: var(--surface) !important; border-color: var(--border) !important; }
.msg-row.mine .bubble-image { background: color-mix(in srgb, var(--brand) 12%, var(--surface)) !important; border-color: color-mix(in srgb, var(--brand) 22%, transparent) !important; }
.img-bubble { min-width: 190px; min-height: 108px; max-width: 100%; border-radius: 12px; overflow: hidden; display: grid; place-items: center; background: var(--surface-2); }
.img-bubble.loaded { min-height: 0; }
.img-loading, .img-fail { display: flex; align-items: center; gap: 8px; color: var(--text-mute); font-size: 11.5px; padding: 26px 18px; }
.img-loading svg { width: 16px; height: 16px; animation: img-pulse 1.4s ease-in-out infinite; }
@keyframes img-pulse { 0%,100% { opacity: .35; } 50% { opacity: 1; } }
.img-fail { color: var(--danger); }
.chat-image { display: block; max-width: min(340px, 52vw); max-height: 320px; border-radius: 9px; cursor: zoom-in; object-fit: contain; transition: filter .18s; }
.chat-image:hover { filter: brightness(.94); }
.img-foot { display: flex; align-items: center; gap: 5px; padding: 6px 5px 2px; font-size: 10px; color: var(--text-mute); }
.img-foot svg { width: 11px; height: 11px; }
.lightbox { display: grid; place-items: center; padding: 12px; border-radius: 13px; background: var(--surface-2); }
.lightbox img { max-width: 100%; max-height: 62vh; border-radius: 9px; object-fit: contain; }

.composer { flex: 0 0 auto; margin: 0 20px 18px; padding: 12px 14px 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }
.composer-tools { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.tool-btn { width: 28px; height: 28px; border: 0; border-radius: 8px; background: transparent; color: var(--text-mute); display: grid; place-items: center; }
.tool-btn:hover { background: var(--surface-2); color: var(--brand); }
.tool-btn svg { width: 17px; height: 17px; }
.composer-secure { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--text-mute); }
.composer-secure svg { width: 11px; height: 11px; color: var(--green); }
.composer textarea { width: 100%; border: 0; outline: 0; resize: none; background: transparent; color: var(--text); font-size: 14px; line-height: 1.6; min-height: 46px; max-height: 130px; padding: 4px 2px; }
.composer textarea::placeholder { color: var(--text-mute); }
.composer-bottom { display: flex; align-items: center; justify-content: space-between; }
.composer-hint { font-size: 10.5px; color: var(--text-mute); }
.send-btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 18px; border: 0; border-radius: 11px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-size: 13px; font-weight: 650; box-shadow: 0 7px 18px color-mix(in srgb, var(--brand) 30%, transparent); transition: transform .18s, filter .18s; }
.send-btn:hover { transform: translateY(-1px); filter: brightness(1.07); }
.send-btn:active { transform: scale(.97); }
.send-btn svg { width: 15px; height: 15px; }

/* ================================================================== */
/* modal & toast                                                      */
/* ================================================================== */

.modal-mask { position: fixed; inset: 0; z-index: 100; background: rgba(18, 20, 42, .45); backdrop-filter: blur(5px); display: grid; place-items: center; padding: 20px; animation: fade-in .2s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal { width: min(460px, 100%); max-height: 86vh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg); overflow: hidden; animation: modal-in .26s cubic-bezier(.2,.8,.25,1) both; }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.modal.wide { width: min(560px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px 14px; }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-head p { margin: 4px 0 0; font-size: 11.5px; color: var(--text-mute); }
.modal-close { width: 30px; height: 30px; border: 0; border-radius: 9px; background: var(--surface-2); color: var(--text-soft); display: grid; place-items: center; }
.modal-close:hover { color: var(--danger); }
.modal-close svg { width: 15px; height: 15px; }
.modal-body { padding: 0 22px 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 22px 20px; border-top: 1px solid var(--border); }
.btn { padding: 10px 18px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-soft); font-size: 13px; font-weight: 600; transition: all .18s; }
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.07); color: #fff; }
.btn.danger { color: var(--danger); }
.modal-label { font-size: 11.5px; font-weight: 650; color: var(--text-soft); margin: 16px 0 7px; display: block; }
.modal-input { width: 100%; padding: 11px 13px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); border-radius: 10px; font-size: 13.5px; outline: 0; }
.modal-input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 12%, transparent); }
.search-results { margin-top: 12px; max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 12px; }
.result-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--border); background: transparent; color: var(--text); text-align: left; }
.result-row:last-child { border-bottom: 0; }
.result-row:hover { background: var(--surface-2); }
.result-row.selected { background: var(--brand-soft); }
.result-row .r-body { flex: 1; min-width: 0; }
.result-row .r-name { font-size: 13px; font-weight: 620; }
.result-row .r-sub { font-size: 11px; color: var(--text-mute); margin-top: 2px; }
.result-check { width: 18px; height: 18px; border-radius: 6px; border: 1.5px solid var(--border-strong); display: grid; place-items: center; color: #fff; }
.result-row.selected .result-check { background: var(--brand); border-color: var(--brand); }
.result-check svg { width: 12px; height: 12px; stroke-width: 3; }
.option-grid { display: flex; flex-direction: column; gap: 9px; padding: 2px 0 6px; }
.option-card { display: flex; align-items: center; gap: 13px; width: 100%; padding: 13px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-2); color: var(--text); text-align: left; transition: all .18s; }
.option-card:hover { border-color: var(--brand); background: var(--brand-soft); transform: translateY(-1px); }
.option-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.option-card strong { display: block; font-size: 13.5px; font-weight: 650; }
.option-card small { display: block; font-size: 11px; color: var(--text-mute); margin-top: 3px; }
.hint-box { display: flex; gap: 9px; padding: 11px 13px; border-radius: 10px; background: var(--green-soft); color: var(--green); font-size: 11.5px; line-height: 1.6; margin-top: 14px; }
.hint-box svg { width: 15px; height: 15px; margin-top: 1px; }
.hint-box.warn { background: var(--brand-soft); color: var(--brand); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--text-mute); }
.kv .v { font-weight: 600; text-align: right; word-break: break-all; }
.fingerprint { margin: 16px 0 4px; padding: 16px; border-radius: 12px; background: var(--surface-2); text-align: center; font-size: 16px; font-weight: 700; letter-spacing: 2px; color: var(--brand); font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 11.5px; word-break: break-all; color: var(--text-soft); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; padding: 8px 0; }
.emoji-grid button { border: 0; background: transparent; font-size: 20px; padding: 6px 0; border-radius: 8px; }
.emoji-grid button:hover { background: var(--surface-2); }

#toastRoot { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { padding: 11px 18px; border-radius: 12px; background: var(--rail); color: #fff; font-size: 12.5px; box-shadow: var(--shadow-lg); animation: toast-in .24s ease both; max-width: 420px; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

/* ================================================================== */
/* mobile-only chrome (hidden on desktop)                              */
/* ================================================================== */

.tabbar, .mobile-back { display: none; }
.pwa-install {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 150;
  display: flex; align-items: center; gap: 11px; width: min(420px, calc(100% - 24px));
  padding: 11px 10px 11px 13px; border-radius: 16px; background: var(--rail);
  color: #fff; box-shadow: var(--shadow-lg); animation: toast-in .3s ease both;
}
.pwa-install-icon { width: 36px; height: 36px; flex: 0 0 auto; border-radius: 11px; display: grid; place-items: center; background: rgba(255,255,255,.14); }
.pwa-install-icon svg { width: 18px; height: 18px; }
.pwa-install-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pwa-install-text strong { font-size: 12.5px; font-weight: 650; }
.pwa-install-text span { font-size: 10.5px; opacity: .7; line-height: 1.4; }
.pwa-install-go { border: 0; border-radius: 9px; padding: 8px 13px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-size: 12px; font-weight: 650; }
.pwa-install-x { border: 0; background: transparent; color: rgba(255,255,255,.6); display: grid; place-items: center; padding: 6px; }
.pwa-install-x svg { width: 15px; height: 15px; }

@media (max-width: 1000px) {
  .app { grid-template-columns: 62px 264px 1fr; }
  .auth-screen { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
}

/* ================================================================== */
/* phone: single column, list ⇄ chat, bottom tabs                      */
/* ================================================================== */

@media (max-width: 700px) {
  html, body { overscroll-behavior-y: none; }
  body { -webkit-tap-highlight-color: transparent; }
  .app, .auth-screen { height: 100vh; height: 100dvh; }

  /* ---- login ---- */
  .auth-screen {
    display: block; overflow-y: auto;
    padding: max(20px, env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
  }
  .auth-panel { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 0; background: transparent; }
  .auth-card { width: 100%; max-width: 420px; padding: 24px 20px 26px; background: var(--panel); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); }
  .auth-tabs { margin-bottom: 24px; }
  .auth-card h2 { font-size: 24px; }
  .auth-sub { margin-bottom: 22px; }
  .field input { font-size: 16px; padding: 13px 14px; }   /* 16px 防 iOS 聚焦时自动放大 */
  .primary-btn { padding: 14px; font-size: 15px; }

  /* ---- shell ---- */
  .app {
    display: flex; flex-direction: column; position: relative;
    padding-top: env(safe-area-inset-top); background: var(--bg);
  }
  .rail { display: none; }
  .list-pane, .chat-pane { flex: 1 1 auto; min-height: 0; }
  .list-pane { border-right: 0; }
  body[data-mobile-view="list"] .chat-pane { display: none; }
  body[data-mobile-view="chat"] .list-pane { display: none; }
  body[data-mobile-view="chat"] .tabbar { display: none; }

  /* ---- bottom tabs ---- */
  .tabbar {
    display: flex; flex: 0 0 auto; align-items: stretch; justify-content: space-around;
    height: calc(58px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel); border-top: 1px solid var(--border);
    box-shadow: 0 -4px 18px rgba(30, 34, 70, .04);
  }
  .tab-btn {
    position: relative; flex: 1; border: 0; background: transparent; color: var(--text-mute);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font-size: 10.5px; font-weight: 600; padding: 4px 0;
  }
  .tab-btn svg { width: 21px; height: 21px; stroke-width: 1.9; }
  .tab-btn.active { color: var(--brand); }
  .tab-btn.active svg { stroke-width: 2.3; }
  .tab-badge {
    position: absolute; top: 4px; left: 50%; margin-left: 5px; min-width: 16px; height: 16px;
    padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff;
    font-size: 9.5px; font-weight: 700; font-style: normal; display: grid; place-items: center;
    border: 2px solid var(--panel);
  }

  /* ---- list ---- */
  .list-head { padding: 16px 16px 10px; }
  .list-title { font-size: 20px; }
  .add-btn { width: 38px; height: 38px; }
  .search-box { margin: 0 14px 10px; }
  .search-box input { font-size: 16px; }
  .list-item { padding: 12px 10px; min-height: 62px; gap: 12px; }
  .list-foot { padding: 9px 16px; }

  /* ---- chat head ---- */
  .chat-head { height: 58px; padding: 0 10px; gap: 9px; -webkit-app-region: no-drag; }
  .mobile-back {
    display: grid; place-items: center; flex: 0 0 auto; width: 38px; height: 38px;
    border: 0; border-radius: 11px; background: transparent; color: var(--text-soft);
  }
  .mobile-back svg { width: 22px; height: 22px; stroke-width: 2.2; }
  .chat-avatar { width: 36px; height: 36px; border-radius: 12px; font-size: 14px; }
  .chat-name { font-size: 14.5px; }
  .chat-sub { font-size: 10.5px; }
  .chat-head-actions { gap: 6px; }
  .enc-badge { padding: 8px; border-radius: 10px; }
  .enc-badge span { display: none; }
  .enc-badge svg { width: 15px; height: 15px; }
  .head-icon { width: 36px; height: 36px; }

  /* ---- messages ---- */
  .messages { padding: 14px 12px 8px; }
  .msg-col { max-width: 84%; }
  .bubble { font-size: 15px; padding: 9px 13px; }
  .chat-image { max-width: min(260px, 68vw); max-height: 280px; }
  .empty-chips { gap: 6px; }
  .empty-chips span { font-size: 10px; padding: 6px 9px; }

  /* ---- composer ---- */
  .composer { margin: 0 8px 8px; padding: 7px 10px 9px; border-radius: 14px; }
  .composer-tools { gap: 4px; margin-bottom: 2px; }
  .tool-btn { width: 38px; height: 38px; }
  .tool-btn svg { width: 20px; height: 20px; }
  .composer-secure { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: calc(100% - 88px); }
  .composer textarea { font-size: 16px; min-height: 40px; max-height: 96px; }
  .composer-hint { display: none; }
  .send-btn { padding: 10px 17px; min-height: 42px; }

  /* ---- modal / toast ---- */
  .modal-mask { padding: 0; place-items: end center; }
  .modal, .modal.wide { width: 100%; max-width: none; max-height: 90dvh; border-radius: 20px 20px 0 0; }
  .modal-foot { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .emoji-grid { grid-template-columns: repeat(6, 1fr); }
  .lightbox img { max-height: 55dvh; }
  #toastRoot { top: calc(12px + env(safe-area-inset-top)); width: 100%; }
  .toast { max-width: calc(100% - 32px); font-size: 12px; }
  .pwa-install { bottom: calc(70px + env(safe-area-inset-bottom)); }
}
