* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; min-height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif; color: #16212b; background: #eef5f8; }
body.user-page { height: 100vh; height: 100dvh; overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { border: 0; cursor: pointer; }
.hidden { display: none !important; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
    linear-gradient(135deg, rgba(238,249,251,.25), rgba(246,242,255,.20) 52%, rgba(255,248,234,.25)),
    var(--login-bg-desktop, linear-gradient(135deg, #eef9fb 0%, #f6f2ff 52%, #fff8ea 100%)),
    linear-gradient(135deg, #eef9fb 0%, #f6f2ff 52%, #fff8ea 100%);
    background-size: cover; background-position: center; background-repeat: no-repeat; }
.auth-panel { width: min(440px, 100%); background: rgba(255,255,255,.88); border: 1px solid rgba(255,255,255,.78); border-radius: 8px; padding: 30px; box-shadow: 0 24px 70px rgba(23, 107, 135, .18); backdrop-filter: blur(14px); }
.auth-panel h1 { margin: 8px 0 22px; font-size: 28px; letter-spacing: 0; }
.brand-mark { display: inline-flex; align-items: center; gap: 9px; color: #176b87; font-weight: 900; }
.brand-mark span { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, #24b7a8, #176b87 58%, #ffbf4d); box-shadow: 0 8px 22px rgba(23,107,135,.22); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; background: #edf3f6; padding: 4px; border-radius: 8px; }
.tab { height: 38px; border-radius: 6px; background: transparent; color: #536471; }
.tab.active { background: #176b87; color: #fff; }
.auth-form { display: grid; gap: 14px; }
label { display: grid; gap: 7px; color: #536471; font-size: 13px; }
input, textarea, select { width: 100%; border: 1px solid #d7e0e5; border-radius: 6px; background: #fff; color: #1f2933; outline: 0; }
input, textarea, select { font-size: 16px; }
input, select { height: 42px; padding: 0 12px; }
textarea { min-height: 88px; resize: vertical; padding: 10px 12px; }
input:focus, textarea:focus, select:focus { border-color: #176b87; box-shadow: 0 0 0 3px rgba(23, 107, 135, .12); }
.primary { height: 44px; border-radius: 6px; background: linear-gradient(135deg, #176b87, #24b7a8); color: #fff; font-weight: 800; box-shadow: 0 10px 24px rgba(23,107,135,.18); }
.ghost { height: 40px; border-radius: 6px; background: #eef3f6; color: #176b87; margin-top: 12px; }
.danger { height: 40px; border-radius: 6px; background: #b42318; color: #fff; margin-top: 12px; }
.error-line { min-height: 20px; color: #b42318; font-size: 13px; margin: 12px 0 0; }

.chat-shell { position: relative; height: 100vh; height: 100dvh; min-height: 0; max-width: 760px; margin: 0 auto; background: #f7fafc; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; border-left: 1px solid #dce5ea; border-right: 1px solid #dce5ea; overflow: hidden; }
body.user-page .chat-shell { position: fixed; inset: 0; width: 100%; max-width: 760px; height: auto; margin: 0 auto; }
.chat-header { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; background: linear-gradient(135deg, #ffffff, #f4fbfb); border-bottom: 1px solid #dce5ea; box-shadow: 0 10px 28px rgba(31,41,51,.05); z-index: 2; }
.chat-header strong { display: block; font-size: 16px; }
.chat-header small { display: block; margin-top: 3px; color: #697985; font-size: 12px; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn { width: 36px; height: 36px; border-radius: 6px; background: #eef7f8; color: #176b87; font-weight: 900; display: inline-grid; place-items: center; transition: transform .16s ease, background .16s ease; }
.icon-btn:hover, .tool-btn:hover { transform: translateY(-1px); background: #dff2f2; }
.drawer-toggle { display: none; flex: 0 0 auto; }
.conversation-strip { display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px; background: #edf6f7; border-bottom: 1px solid #dce5ea; }
.conversation-pill { min-width: 134px; border: 1px solid #d8e2e7; background: #fff; border-radius: 8px; padding: 10px 11px; text-align: left; position: relative; color: #1f2933; box-shadow: 0 7px 18px rgba(31,41,51,.04); }
.conversation-pill.active { border-color: #24b7a8; box-shadow: inset 0 0 0 1px #24b7a8, 0 10px 22px rgba(36,183,168,.13); }
.conversation-pill.group-conversation { background: linear-gradient(135deg, #fff7e8, #fff); border-color: #ffd59d; }
.conversation-pill.group-conversation.active { border-color: #ff9f43; box-shadow: inset 0 0 0 1px #ff9f43, 0 10px 22px rgba(255,159,67,.18); }
.conversation-pill.group-conversation span::before { content: "群"; display: inline-grid; place-items: center; width: 20px; height: 20px; margin-right: 6px; border-radius: 6px; background: #ff9f43; color: #fff; font-size: 12px; }
.conversation-pill span { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-pill small { color: #6b7b86; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #d92d20; color: #fff; font-size: 12px; display: inline-grid; place-items: center; }
.conversation-pill .badge { position: absolute; top: -6px; right: -4px; }

.message-list { min-height: 0; overflow-y: auto; overflow-anchor: none; padding: 20px 14px max(28px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; background:
    linear-gradient(180deg, rgba(255,255,255,.48), rgba(255,255,255,0)),
    radial-gradient(circle at 20px 20px, rgba(23,107,135,.05) 1px, transparent 1px);
    background-size: auto, 22px 22px; }
body.user-page .message-list { padding-bottom: max(118px, calc(96px + env(safe-area-inset-bottom))); scroll-padding-bottom: max(118px, calc(96px + env(safe-area-inset-bottom))); }
.empty-state { margin: auto; color: #8a98a3; flex: 0 0 auto; }
.time-row { align-self: center; flex: 0 0 auto; background: #dfe8ed; color: #647681; border-radius: 10px; padding: 3px 10px; font-size: 12px; }
.msg { max-width: min(76%, 520px); display: grid; gap: 4px; flex: 0 0 auto; min-height: max-content; }
.msg, .time-row { overflow-anchor: none; }
.scroll-end { flex: 0 0 1px; height: 1px; overflow-anchor: none; }
.msg.mine { align-self: flex-end; }
.msg.theirs { align-self: flex-start; }
.bubble { border-radius: 8px; padding: 10px 12px; background: #fff; border: 1px solid #dce5ea; line-height: 1.5; word-break: break-word; box-shadow: 0 8px 22px rgba(31, 41, 51, .07); }
.mine .bubble { background: linear-gradient(135deg, #176b87, #24b7a8); color: #fff; border-color: #24b7a8; }
.staff-tag { display: inline-block; width: fit-content; background: linear-gradient(135deg, #ffe08a, #f4b740); color: #4a3100; border-radius: 4px; padding: 1px 7px; font-size: 12px; font-weight: 900; box-shadow: 0 4px 12px rgba(244,183,64,.28); }
.message-image { max-width: 220px; max-height: 260px; border-radius: 8px; display: block; cursor: zoom-in; }
.message-video { width: min(260px, 70vw); max-height: 260px; border-radius: 8px; display: block; background: #111; cursor: pointer; }
.card-link { display: grid; gap: 4px; min-width: 210px; text-decoration: none; color: inherit; }
.rich-card { width: min(330px, 74vw); grid-template-columns: 56px minmax(0, 1fr); gap: 12px; align-items: center; color: #16212b; background: linear-gradient(135deg, #ffffff, #f7fbfc); border: 1px solid #d8e8ec; border-radius: 8px; padding: 10px; box-shadow: 0 10px 26px rgba(31,41,51,.08); }
.mine .rich-card { color: #16212b; background: linear-gradient(135deg, #ffffff, #f3fbf9); border-color: rgba(255,255,255,.82); }
.rich-card:hover { transform: translateY(-1px); box-shadow: 0 14px 30px rgba(31,41,51,.12); }
.rich-card img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; background: #eef3f6; border: 1px solid #dce5ea; }
.rich-card span { min-width: 0; display: grid; gap: 5px; }
.rich-card b, .rich-card em { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rich-card b { color: #12313b; font-size: 15px; font-weight: 900; letter-spacing: 0; }
.rich-card em { color: #657681; font-style: normal; font-size: 13px; line-height: 1.35; }

.composer { align-self: end; background: rgba(255,255,255,.96); border-top: 1px solid #dce5ea; padding: 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); display: grid; gap: 8px; box-shadow: 0 -16px 34px rgba(31,41,51,.06); z-index: 2; min-width: 0; }
.composer-tools { display: flex; gap: 8px; align-items: center; min-width: 0; flex-wrap: nowrap; }
.tool-btn, label.tool-btn { width: 36px; height: 36px; min-width: 36px; padding: 0; display: inline-grid; place-items: center; background: #eef7f8; color: #176b87; border-radius: 6px; font-weight: 900; font-size: 16px; line-height: 1; }
.camera-btn { font-size: 18px; }
.send-form { display: grid; grid-template-columns: minmax(0, 1fr) 72px; gap: 8px; min-width: 0; }
.send-form input { min-width: 0; }
.send-form button { border-radius: 6px; background: linear-gradient(135deg, #176b87, #24b7a8); color: #fff; font-weight: 800; }
.readonly-hint { display: none; height: 40px; align-items: center; justify-content: center; border-radius: 8px; background: #fff7e8; border: 1px solid #ffd59d; color: #9a5b12; font-weight: 900; font-size: 14px; }
.composer.readonly { padding-top: 10px; }
.composer.readonly .composer-tools, .composer.readonly .emoji-row, .composer.readonly .send-form { display: none; }
.composer.readonly .readonly-hint { display: flex; }
.emoji-row { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; padding: 8px; background: #f0f5f8; border-radius: 8px; }
.emoji-row button { height: 32px; border-radius: 6px; background: #fff; border: 1px solid #dce5ea; font-size: 18px; }

.modal { position: fixed; inset: 0; z-index: 20; background: rgba(9, 20, 27, .42); display: grid; place-items: center; padding: 18px; }
.modal-card { width: min(440px, 100%); max-height: 90vh; overflow: auto; background: #fff; border-radius: 8px; padding: 22px; position: relative; box-shadow: 0 24px 70px rgba(0,0,0,.22); border: 1px solid rgba(255,255,255,.74); }
.modal-card.wide { width: min(620px, 100%); }
.modal-card.compact { width: min(380px, 100%); }
.modal-card h2 { margin: 0 0 16px; font-size: 20px; }
.modal-card form { display: grid; gap: 12px; margin-bottom: 16px; }
.modal-close { position: absolute; right: 12px; top: 10px; width: 32px; height: 32px; border-radius: 6px; background: #eef3f6; color: #176b87; font-size: 22px; }
.info-table { display: grid; gap: 8px; font-size: 14px; }
.info-table div { display: grid; grid-template-columns: 96px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid #edf2f5; }
.info-table b { color: #536471; }
.inline-editor { display: grid; grid-template-columns: minmax(0, 1fr) 104px; gap: 10px; align-items: end; margin-top: 14px; padding: 12px; border-radius: 8px; background: #f4fafb; border: 1px solid #dcebee; }
.inline-editor .primary { height: 42px; }
.card-icon-preview { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px dashed #c7d7de; border-radius: 8px; background: #f8fbfc; color: #647681; font-size: 13px; }
.card-icon-preview img { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; background: #eef3f6; border: 1px solid #dce5ea; }

.preview { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 20px; }
.preview img { max-width: 96vw; max-height: 92vh; object-fit: contain; cursor: zoom-out; }
.preview video { width: min(960px, 96vw); max-height: 82vh; background: #000; }
.preview .back { position: absolute; left: 16px; top: 16px; width: 44px; height: 38px; border-radius: 6px; background: #fff; color: #111; font-weight: 800; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.modal-actions .ghost { margin-top: 0; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 60; max-width: min(420px, calc(100vw - 32px)); background: rgba(20,32,40,.94); color: #fff; border-radius: 8px; padding: 10px 14px; box-shadow: 0 16px 44px rgba(0,0,0,.28); font-size: 14px; }
.new-message-btn { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 5; height: 34px; padding: 0 14px; border-radius: 17px; background: linear-gradient(135deg, #ffbf4d, #ff8f5a); color: #4a2600; font-weight: 900; box-shadow: 0 12px 28px rgba(255,143,90,.28); }
.floating-gif-ad { position: absolute; left: 12px; bottom: 108px; z-index: 4; width: 150px; height: 150px; display: grid; align-items: end; justify-items: start; }
.floating-gif-ad img { display: block; max-width: 150px; max-height: 150px; object-fit: contain; filter: drop-shadow(0 12px 20px rgba(31,41,51,.16)); }
.floating-gif-ad.no-link { cursor: default; }
.staff-new { position: fixed; bottom: 96px; }
.drawer-mask { position: fixed; inset: 0; z-index: 11; background: rgba(11,22,30,.38); }

.open-guide { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.86); color: #fff; }
.guide-top { height: 30px; padding: 6px 10px; display: flex; justify-content: space-between; font-size: 13px; }
.guide-arrow { position: absolute; right: 34px; top: 46px; font-size: 72px; transform: rotate(-20deg); color: #fff; }
.guide-box { width: min(330px, calc(100vw - 44px)); margin: 150px auto 0; background: rgba(255,255,255,.12); padding: 20px 16px; border-radius: 8px; display: grid; gap: 18px; }
.guide-box div { display: flex; align-items: center; gap: 12px; font-size: 20px; }
.guide-box b { width: 30px; height: 30px; border-radius: 50%; background: #ff3b00; display: grid; place-items: center; font-size: 18px; }
.guide-box em { background: #56636c; border: 1px solid #84909a; border-radius: 6px; padding: 5px 10px; font-style: normal; }

.staff-shell { height: 100vh; display: grid; grid-template-columns: 330px 1fr; background: linear-gradient(135deg, #eef9fb, #f8f4ff 52%, #fff8ea); }
.staff-sidebar { min-width: 0; border-right: 1px solid #dce5ea; background: rgba(255,255,255,.92); display: grid; grid-template-rows: auto auto auto 1fr auto auto; overflow: hidden; box-shadow: 12px 0 34px rgba(31,41,51,.06); z-index: 12; }
.side-head { height: 64px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; border-bottom: 1px solid #dce5ea; background: linear-gradient(135deg, #fff, #f4fbfb); }
.side-head strong { font-size: 18px; }
.search-input { margin: 12px; width: calc(100% - 24px); }
.side-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 12px 12px; }
.side-actions button, #addMemberBtn { height: 34px; border-radius: 6px; background: #eef3f6; color: #176b87; font-weight: 700; }
.group-list { overflow-y: auto; padding: 0 10px 12px; }
.user-group { border: 1px solid #e2edf1; border-radius: 8px; padding: 8px; margin-top: 8px; min-height: 54px; background: #f8fbfc; transition: border-color .16s ease, background .16s ease; }
.user-group.drop-target { border-color: #24b7a8; background: #e9fbf7; }
.group-name { min-height: 34px; color: #22515c; font-size: 13px; font-weight: 900; padding: 4px; display: flex; align-items: center; gap: 6px; background: linear-gradient(135deg, #dff6f2, #fff7df); border-radius: 8px; }
.group-name span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-name em { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: #176b87; color: #fff; font-style: normal; display: inline-grid; place-items: center; font-size: 12px; }
.group-toggle, .group-edit, .group-delete { height: 24px; min-width: 24px; border-radius: 6px; background: rgba(255,255,255,.78); color: #176b87; font-weight: 900; }
.group-edit, .group-delete { padding: 0 7px; font-size: 12px; }
.group-delete { color: #b42318; }
.group-members { display: grid; gap: 4px; padding-top: 6px; }
.user-group.collapsed .group-members { display: none; }
.user-item, .chat-group-item { width: 100%; text-align: left; border-radius: 8px; padding: 11px; background: #fff; color: #1f2933; display: grid; gap: 4px; position: relative; border: 1px solid transparent; }
.user-item:hover, .chat-group-item:hover, .user-item.active, .chat-group-item.active { background: #eef8f8; border-color: #c8eeee; }
.user-item.dragging { opacity: .62; transform: scale(.98); }
.user-item strong, .chat-group-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-item small, .chat-group-item small { color: #6b7b86; font-size: 12px; }
.online { color: #027a48; }
.offline { color: #8a98a3; }
.user-item .badge { position: absolute; top: 9px; right: 9px; }
.chat-group-title { padding: 10px 12px 6px; color: #536471; font-weight: 800; font-size: 13px; border-top: 1px solid #edf2f5; }
.chat-group-list { padding: 0 10px 12px; overflow-y: auto; max-height: 30vh; }
.chat-group-item { padding-right: 62px; }
.chat-edit { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); height: 24px; line-height: 24px; padding: 0 8px; border-radius: 6px; background: #fff0d9; color: #b45f06; font-style: normal; font-size: 12px; font-weight: 900; }
.staff-chat { min-width: 0; display: grid; grid-template-rows: auto 1fr auto; height: 100vh; }
#memberGroupSelect { width: 160px; }

@media (max-width: 820px), (orientation: portrait) {
    .auth-shell { background-image:
        linear-gradient(135deg, rgba(238,249,251,.25), rgba(246,242,255,.20) 52%, rgba(255,248,234,.25)),
        var(--login-bg-mobile, linear-gradient(135deg, #eef9fb 0%, #f6f2ff 52%, #fff8ea 100%)),
        linear-gradient(135deg, #eef9fb 0%, #f6f2ff 52%, #fff8ea 100%); }
    .drawer-toggle { display: inline-grid; }
    .conversation-strip { position: fixed; z-index: 12; left: 0; top: 0; bottom: 0; width: min(82vw, 320px); display: block; padding: 76px 12px 16px; border-right: 1px solid #dce5ea; border-bottom: 0; background: rgba(255,255,255,.96); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 16px 0 46px rgba(31,41,51,.18); }
    body.drawer-open .conversation-strip { transform: translateX(0); }
    body.drawer-open #drawerMask { display: block !important; }
    .conversation-pill { width: 100%; margin-bottom: 8px; }
    .staff-shell { grid-template-columns: 1fr; }
    .staff-sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(84vw, 340px); transform: translateX(-105%); transition: transform .2s ease; border-right: 1px solid #dce5ea; border-bottom: 0; }
    body.staff-drawer-open .staff-sidebar { transform: translateX(0); }
    body.staff-drawer-open #staffDrawerMask { display: block !important; }
    .chat-shell { border: 0; }
    .staff-chat { height: 100vh; }
}

@media (max-width: 520px) {
    .auth-panel { padding: 22px; }
    .msg { max-width: 84%; }
    .emoji-row { grid-template-columns: repeat(5, 1fr); }
    .chat-header { min-height: 56px; }
    .composer { gap: 7px; padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
    .composer-tools { gap: 7px; overflow-x: auto; padding-bottom: 1px; }
    .tool-btn, label.tool-btn { width: 34px; height: 34px; min-width: 34px; }
    .send-form { grid-template-columns: minmax(0, 1fr) 64px; gap: 7px; }
    .send-form input { height: 40px; padding: 0 10px; }
    .send-form button { min-width: 64px; height: 40px; padding: 0; }
    .readonly-hint { height: 38px; font-size: 13px; }
    .floating-gif-ad { left: 10px; bottom: 102px; width: 128px; height: 128px; }
    .floating-gif-ad img { max-width: 128px; max-height: 128px; }
}
