:root {
  color-scheme: light;
  --blue: #2367d1;
  --blue-deep: #174fae;
  --blue-soft: #eaf2ff;
  --ink: #1d2738;
  --muted: #748095;
  --line: #e5eaf1;
  --surface: #ffffff;
  --bg: #f4f7fb;
  --danger: #d63d4d;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { overscroll-behavior: none; }
button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.visually-hidden { position: fixed; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.login-view { min-height: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% -10%, #dbeaff 0, #f4f7fb 47%); }
.login-card { width: min(100%, 390px); padding: 32px 26px 25px; border-radius: 24px; background: rgba(255,255,255,.96); box-shadow: 0 18px 55px rgba(35,76,139,.15); }
.brand-mark { width: 58px; height: 58px; margin: 0 auto 14px; display: grid; place-items: center; border-radius: 18px; color: #fff; font-size: 28px; font-weight: 800; background: linear-gradient(145deg, #3d83ed, #174fae); box-shadow: 0 9px 22px rgba(35,103,209,.28); }
.login-card h1 { margin: 0; text-align: center; font-size: 25px; }
.subtle { margin: 7px 0 25px; text-align: center; color: var(--muted); font-size: 14px; }
.login-card label:not(.remember) { display: block; margin: 14px 0 0; color: #4d5b70; font-size: 13px; font-weight: 650; }
input, textarea { border: 1px solid #d7dfeb; outline: none; background: #fff; color: var(--ink); transition: border-color .18s, box-shadow .18s; }
input:focus, textarea:focus { border-color: #6da0ea; box-shadow: 0 0 0 3px rgba(35,103,209,.11); }
.login-card input:not([type=checkbox]) { width: 100%; height: 48px; margin-top: 7px; padding: 0 13px; border-radius: 12px; font-size: 16px; }
.remember { display: flex; align-items: center; gap: 7px; margin: 15px 0; color: #536176; font-size: 14px; }
.remember input { width: 18px; height: 18px; accent-color: var(--blue); }
.security-note { margin: 16px 0 0; color: #8b95a5; text-align: center; font-size: 12px; }

.primary, .soft-button, .danger-button, .text-button, .tool-button { border: 0; border-radius: 11px; min-height: 40px; padding: 0 14px; cursor: pointer; font-weight: 650; }
.primary { color: #fff; background: linear-gradient(135deg, #347ce6, #1856ba); box-shadow: 0 7px 16px rgba(35,103,209,.22); }
.primary:disabled { opacity: .55; box-shadow: none; }
.wide { width: 100%; height: 48px; }
.soft-button { color: #285b9e; background: var(--blue-soft); }
.danger-button { color: #fff; background: var(--danger); }
.text-button { padding: 0 7px; color: #537099; background: transparent; }

.app-shell { width: min(100%, 760px); height: 100%; margin: 0 auto; background: var(--bg); box-shadow: 0 0 45px rgba(23,44,76,.08); }
.page { height: 100%; overflow: auto; scrollbar-gutter: stable; }
.topbar { position: sticky; z-index: 20; top: 0; min-height: 70px; padding: max(12px, env(safe-area-inset-top)) 14px 10px; display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.94); border-bottom: 1px solid rgba(224,230,239,.9); backdrop-filter: blur(14px); }
.topbar h1 { margin: 0; font-size: 22px; line-height: 1.2; }
.header-subtitle { margin-top: 3px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { margin-left: auto; display: flex; gap: 6px; }
.icon-button { width: 38px; height: 38px; padding: 0; border: 0; border-radius: 12px; color: #3c5578; background: #edf2f8; font-size: 17px; font-weight: 750; cursor: pointer; }
.icon-button:active { transform: scale(.96); }
.sound-button { position: relative; }
.sound-button.needs-unlock { color: var(--danger); background: #fff0f2; }
.sound-button.needs-unlock::after { content: ''; position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 3px rgba(214,61,77,.12); }
.danger-text { color: var(--danger); }
.toolbar-card { margin: 12px 12px 8px; padding: 11px; border-radius: 17px; background: var(--surface); box-shadow: 0 4px 18px rgba(38,63,96,.06); }
.search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 7px; align-items: center; }
.search-row input { min-width: 0; flex: 1; height: 42px; padding: 0 13px; border-radius: 12px; }
.search-row > button { min-height: 42px; padding: 0 10px; white-space: nowrap; font-size: 13px; }
.batch-actions { display: flex; align-items: center; justify-content: flex-end; gap: 5px; }
.batch-actions button { min-height: 34px; font-size: 13px; }

.session-list { padding: 3px 12px calc(16px + var(--safe-bottom)); }
.session-card { position: relative; margin: 8px 0; padding: 13px 12px; display: grid; grid-template-columns: auto 1fr auto; gap: 11px; align-items: center; border: 1px solid transparent; border-radius: 17px; background: var(--surface); box-shadow: 0 4px 18px rgba(38,63,96,.06); cursor: pointer; touch-action: pan-y; transition: transform .18s ease; }
.session-card.dragging { transition: none; }
.session-swipe { position: relative; margin: 8px 0; overflow: hidden; border-radius: 17px; }
.session-swipe .session-card { z-index: 1; margin: 0; }
.swipe-actions { position: absolute; z-index: 0; inset: 0 0 0 auto; width: 210px; display: grid; grid-template-columns: 82px 64px 64px; overflow: hidden; border-radius: 0 17px 17px 0; }
.swipe-action { min-width: 0; padding: 0 5px; border: 0; color: #fff; font-size: 13px; font-weight: 750; cursor: pointer; }
.pin-action { background: #ee962f; }
.remark-action { background: #3478cf; }
.delete-action { background: var(--danger); }
.session-card.unread { border-color: #d9e7fb; background: linear-gradient(100deg, #fff, #f8fbff); }
.session-card.selected { border-color: #7ca8e9; }
.avatar { width: 48px; height: 48px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 15px; color: #fff; font-weight: 800; font-size: 16px; text-shadow: 0 1px 2px rgba(0,0,0,.12); }
.avatar.small { width: 38px; height: 38px; border-radius: 12px; font-size: 13px; }
.session-main { min-width: 0; }
.session-title-row { display: flex; align-items: center; gap: 6px; }
.session-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 700; }
.pin { color: #ed8c23; font-size: 12px; }
.session-preview { margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #788397; font-size: 13px; }
.session-meta { align-self: stretch; display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; gap: 6px; }
.session-time { color: #9aa3b1; font-size: 11px; white-space: nowrap; }
.badge { min-width: 21px; height: 21px; padding: 0 6px; display: grid; place-items: center; border-radius: 11px; color: #fff; background: #e43b4f; font-size: 11px; font-weight: 750; }
.select-box { width: 22px; height: 22px; accent-color: var(--blue); }
.empty-state { padding: 80px 20px; text-align: center; color: var(--muted); }

.chat-page { display: flex; flex-direction: column; overflow: hidden; background: #eef2f7; }
.chat-topbar { flex: 0 0 auto; }
.back-button { font-size: 30px; line-height: 1; }
.chat-heading { min-width: 0; }
.chat-heading h1 { max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 17px; }
.message-list { flex: 1; overflow-y: auto; padding: 13px 12px 20px; scroll-behavior: smooth; overflow-anchor: auto; }
.load-older { flex: 0 0 auto; align-self: center; margin: 8px 0 0; padding: 6px 15px; border: 0; border-radius: 14px; color: #50709a; background: #dfe8f4; }
.message-row { margin: 9px 0; display: flex; align-items: flex-start; gap: 7px; }
.message-row.sent { justify-content: flex-end; }
.member-avatar { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 10px; color: #fff; font-size: 11px; font-weight: 800; }
.message-stack { max-width: min(78%, 530px); min-width: 0; }
.sender-name { margin: 0 0 3px 3px; color: #7e8999; font-size: 11px; }
.bubble { position: relative; padding: 9px 11px; border-radius: 15px 15px 15px 5px; background: #fff; box-shadow: 0 2px 9px rgba(28,48,76,.06); word-break: break-word; white-space: pre-wrap; user-select: text; }
.sent .bubble { color: #fff; background: linear-gradient(145deg, #3980e7, #2464c7); border-radius: 15px 15px 5px 15px; }
.bubble.recalled { color: #8d96a5; background: transparent; border: 1px dashed #cbd3dd; box-shadow: none; font-style: italic; }
.quote { margin-bottom: 7px; padding: 6px 8px; border-left: 3px solid #86a8d9; border-radius: 5px; color: #5f6c7d; background: rgba(221,232,246,.72); font-size: 12px; }
.sent .quote { color: #eef5ff; background: rgba(255,255,255,.14); border-color: #d9e9ff; }
.message-time { margin-top: 5px; color: #9aa4b1; font-size: 10px; text-align: right; }
.sent .message-time { color: #dce9fb; }
.image-shell { position: relative; width: min(235px, 58vw); aspect-ratio: 4 / 3; display: grid; place-items: center; overflow: hidden; border-radius: 10px; background: #e5e9ef; }
.image-loading { position: absolute; z-index: 0; color: #7b8798; font-size: 12px; }
.chat-image { position: relative; z-index: 1; display: block; width: 100%; height: 100%; object-fit: contain; cursor: zoom-in; opacity: 0; transition: opacity .16s; }
.image-shell.loaded .chat-image { opacity: 1; }
.image-shell.loaded .image-loading { display: none; }
.image-shell.failed { cursor: pointer; }
.bubble.media-bubble { padding: 5px; }
.video-shell { position: relative; width: min(290px, 68vw); aspect-ratio: 16 / 9; display: grid; place-items: center; overflow: hidden; border-radius: 10px; background: #111; }
.video-loading { position: absolute; z-index: 0; color: #e3e8ef; font-size: 12px; }
.video-shell video { position: relative; z-index: 1; display: block; width: 100%; height: 100%; object-fit: contain; opacity: 0; }
.video-shell.loaded video { opacity: 1; }
.video-shell.loaded .video-loading { display: none; }
.video-shell.failed { cursor: pointer; }
.bubble audio { display: block; width: min(285px, 69vw); height: 38px; }
.transfer-card { width: min(260px, 68vw); padding: 12px; border-radius: 12px; color: #fff; background: linear-gradient(135deg, #f6a83e, #ed7f26); cursor: pointer; }
.transfer-amount { font-size: 20px; font-weight: 800; }
.transfer-status { margin-top: 7px; padding-top: 7px; border-top: 1px solid rgba(255,255,255,.35); font-size: 12px; }
.message-menu { margin-top: 4px; display: flex; justify-content: flex-end; }
.recall-button { padding: 2px 5px; border: 0; color: #8590a1; background: transparent; font-size: 11px; }
.composer { flex: 0 0 auto; padding: 8px 10px calc(8px + var(--safe-bottom)); background: rgba(255,255,255,.97); border-top: 1px solid var(--line); }
.composer-tools { display: flex; gap: 8px; margin-bottom: 7px; }
.tool-button { min-height: 32px; padding: 0 11px; color: #46668f; background: #edf2f8; font-size: 13px; }
.send-row { display: flex; align-items: flex-end; gap: 8px; }
.send-row textarea { flex: 1; max-height: 112px; min-height: 43px; padding: 10px 12px; resize: none; border-radius: 13px; line-height: 21px; }
.send-button { height: 43px; min-width: 67px; }

dialog { border: 0; color: var(--ink); }
dialog::backdrop { background: rgba(13,24,40,.52); backdrop-filter: blur(2px); }
.sheet-dialog { width: min(100% - 20px, 720px); height: min(82vh, 760px); margin: auto auto 0; padding: 0; border-radius: 22px 22px 0 0; background: var(--bg); }
.sheet-header { height: 62px; padding: 0 14px 0 18px; display: flex; align-items: center; border-bottom: 1px solid var(--line); background: #fff; }
.sheet-header h2 { margin: 0; font-size: 18px; }
.sheet-header button { margin-left: auto; font-size: 24px; }
.sheet-body { height: calc(100% - 62px); overflow: auto; padding: 12px; }
.reply-tabs { display: flex; gap: 8px; padding: 9px 13px; background: #fff; }
.reply-tabs button { flex: 1; height: 37px; border: 0; border-radius: 10px; color: #68758a; background: #eff3f8; font-weight: 700; }
.reply-tabs button.active { color: #fff; background: var(--blue); }
#quickDialog .sheet-body { height: calc(100% - 117px); }
.status-card, details.reply-group { margin-bottom: 9px; border-radius: 15px; background: #fff; box-shadow: 0 3px 13px rgba(30,55,87,.06); }
.status-card { padding: 12px; display: flex; align-items: center; gap: 10px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #a4acb8; }
.status-dot.online { background: #2fbb70; box-shadow: 0 0 0 4px rgba(47,187,112,.12); }
.status-name { flex: 1; min-width: 0; }
.status-name strong, .status-name span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-name span { margin-top: 3px; color: var(--muted); font-size: 12px; }
details.reply-group { padding: 0 10px 9px; }
details.reply-group > summary { padding: 13px 4px; cursor: pointer; color: #385777; font-weight: 750; }
.reply-item { width: 100%; margin: 4px 0; padding: 10px; display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 12px; background: #fff; text-align: left; cursor: pointer; }
.reply-item-main { flex: 1; min-width: 0; }
.reply-item-title { font-weight: 700; }
.reply-item-preview { margin-top: 3px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-send { color: var(--blue); font-size: 13px; font-weight: 750; }
.image-dialog { width: 100vw; max-width: none; height: 100vh; max-height: none; margin: 0; padding: 0; background: #0d1118; }
.image-dialog img { width: 100%; height: calc(100% - 58px); object-fit: contain; }
.image-actions { height: 58px; padding: max(8px, env(safe-area-inset-top)) 12px 7px; display: flex; justify-content: flex-end; gap: 8px; }
.image-actions a { display: grid; place-items: center; text-decoration: none; }
.confirm-dialog { width: min(90%, 380px); padding: 22px; border-radius: 18px; }
.confirm-dialog h2 { margin: 0 0 10px; font-size: 19px; }
.confirm-dialog p { color: #647186; line-height: 1.6; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-input { width: 100%; height: 46px; margin: 5px 0 18px; padding: 0 12px; border-radius: 11px; font-size: 16px; }
.session-action-buttons { display: grid; gap: 8px; }
.session-action-buttons button { width: 100%; min-height: 43px; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(22px + var(--safe-bottom)); max-width: min(90vw, 460px); padding: 10px 15px; border-radius: 12px; color: #fff; background: rgba(22,31,44,.92); box-shadow: 0 8px 24px rgba(0,0,0,.2); opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: .2s; font-size: 14px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.loading-card { padding: 40px 10px; text-align: center; color: var(--muted); }

@media (min-width: 761px) {
  .app-shell { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .sheet-dialog { margin-bottom: 4vh; border-radius: 22px; }
}
@media (max-width: 430px) {
  .topbar { padding-left: 10px; padding-right: 10px; }
  .top-actions { gap: 3px; }
  .icon-button { width: 36px; height: 36px; }
  .chat-heading h1 { max-width: 120px; }
  .message-stack { max-width: 82%; }
  .toolbar-card { margin-left: 8px; margin-right: 8px; padding: 8px; }
  .search-row { gap: 4px; }
  .search-row input { padding: 0 9px; font-size: 13px; }
  .search-row > button { padding: 0 7px; font-size: 12px; }
  .batch-actions { gap: 3px; }
  .batch-actions button { padding: 0 6px; font-size: 12px; }
}
