* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

:root {
    --app-height: 100vh;
    --app-height: 100svh;
    --app-top: 0px;
    --composer-height: 56px;

    --wx-green: #07c160;
    --wx-green-pressed: #06ad56;
    --wx-bubble: #95ec69;
    --wx-bg: #ededed;
    --wx-bar: #f7f7f7;
    --wx-line: #e5e5e5;
    --wx-text: #111111;
    --wx-muted: #888888;
    --wx-danger: #fa5151;

    --ease-standard: cubic-bezier(0.2, 0, 0, 1);
}

html {
    height: var(--app-height);
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    width: 100%;
    height: var(--app-height);
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
    background: var(--wx-bg);
    color: var(--wx-text);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Segoe UI", sans-serif;
}

body.modal-open,
body.keyboard-open {
    overflow: hidden;
}

button,
input,
textarea {
    min-width: 0;
    border: 0;
    font: inherit;
}

input,
textarea,
button,
a,
label,
.composer,
.chat-panel,
.messages {
    touch-action: manipulation;
}

input,
textarea {
    width: 100%;
    color: var(--wx-text);
    background: #fff;
    outline: none;
}

input {
    height: 44px;
    padding: 0 12px;
    border-radius: 4px;
    font-size: 16px;
}

textarea {
    min-height: 36px;
    max-height: 120px;
    height: 36px;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 16px;
    line-height: 20px;
    resize: none;
    overflow-x: hidden;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

input::placeholder,
textarea::placeholder {
    color: #b2b2b2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

button {
    padding: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

button:disabled,
input:disabled,
textarea:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.shell {
    width: 100%;
    height: var(--app-height);
    display: grid;
    place-items: center;
}

.page {
    display: none;
    width: min(480px, 100%);
    min-height: 0;
}

.page.active {
    display: flex;
    flex-direction: column;
}

.entry-card.active {
    display: grid;
}

.entry-card,
.chat-card {
    min-height: 0;
    background: #fff;
}

.entry-card {
    width: min(420px, 100%);
    height: min(640px, var(--app-height));
    padding: 48px 28px 28px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    align-content: start;
    background: #fff;
}

.entry-hero {
    display: grid;
    gap: 28px;
    min-height: 0;
}

.entry-copy {
    display: grid;
    gap: 8px;
}

.entry-kicker,
.entry-note,
.status {
    margin: 0;
}

.entry-kicker {
    color: var(--wx-green);
    font-size: 13px;
    font-weight: 600;
}

.entry-copy h1 {
    margin: 0;
    font-size: 32px;
    font-weight: 700;
    line-height: 1.2;
}

.entry-note {
    color: var(--wx-muted);
    font-size: 14px;
}

.join-form {
    display: grid;
    gap: 20px;
}

.form-fields {
    display: grid;
    gap: 16px;
}

.field {
    display: grid;
    gap: 8px;
}

.field span {
    color: #111;
    font-size: 14px;
    font-weight: 600;
}

.join-form input {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 48px;
    padding: 0 14px;
    border: 1px solid #d0d0d0;
    border-radius: 8px;
    background: #f7f7f7;
    color: #111;
    font-size: 16px;
    line-height: 48px;
    opacity: 1;
}

.join-form input::placeholder {
    color: #8a8a8a;
    opacity: 1;
}

.join-form input:focus {
    background: #fff;
    border-color: var(--wx-green);
    box-shadow: 0 0 0 3px rgba(7, 193, 96, 0.15);
}

.join-form button[type="submit"] {
    height: 48px;
    border-radius: 8px;
    background: var(--wx-green);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
}

.join-form button[type="submit"]:hover {
    background: var(--wx-green-pressed);
}

.chat-card {
    width: min(480px, 100%);
    height: var(--app-height);
    background: var(--wx-bg);
}

.chat-card.active {
    display: flex;
    flex-direction: column;
}

.chat-head {
    display: grid;
    flex: none;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    align-items: center;
    min-height: 48px;
    padding: max(6px, env(safe-area-inset-top)) 4px 6px;
    border-bottom: 1px solid var(--wx-line);
    background: var(--wx-bar);
}

.nav-button {
    width: 44px;
    height: 44px;
    color: #191919;
    font-size: 32px;
    line-height: 1;
}

.more-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    overflow: hidden;
}

.more-dot {
    width: 4px;
    height: 4px;
    flex: none;
    border-radius: 50%;
    background: #191919;
}

.chat-head-main {
    min-width: 0;
    text-align: center;
}

.chat-title {
    margin: 0;
    overflow: hidden;
    font-size: 16px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status {
    overflow: hidden;
    color: var(--wx-muted);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-bar {
    display: flex;
    flex: none;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--wx-bar);
    border-bottom: 1px solid var(--wx-line);
}

.search-bar input {
    height: 36px;
    background: #fff;
}

.search-cancel {
    flex: none;
    height: 36px;
    padding: 0 4px;
    color: #576b95;
    font-size: 15px;
}

.chat-layout,
.chat-panel {
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-panel {
    min-height: 0;
}

.messages-wrap {
    position: relative;
    min-height: 0;
    flex: 1;
}

.message-text {
    user-select: text;
    -webkit-user-select: text;
}

.attachment-image,
.image-modal-image {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.messages {
    height: 100%;
    overflow: auto;
    padding: 12px 10px 8px;
    -webkit-overflow-scrolling: touch;
}

.new-message-button {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 10;
    height: 32px;
    padding: 0 12px;
    border-radius: 16px;
    background: #fff;
    color: #576b95;
    font-size: 13px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.typing-indicator {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 8px;
    z-index: 9;
    margin: 0;
    color: var(--wx-muted);
    font-size: 12px;
    pointer-events: none;
}

.messages-wrap:has(.typing-indicator:not([hidden])) .messages {
    padding-bottom: 28px;
}

.upload-progress {
    padding: 8px 12px 0;
}

.upload-progress-bar {
    height: 3px;
    overflow: hidden;
    border-radius: 99px;
    background: #ddd;
}

.upload-progress-fill {
    height: 100%;
    width: 0;
    background: var(--wx-green);
}

.upload-progress-label {
    display: block;
    margin-top: 4px;
    color: var(--wx-muted);
    font-size: 11px;
    text-align: center;
}

.quote-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 12px 0;
    padding: 8px 10px;
    border-left: 3px solid var(--wx-green);
    border-radius: 4px;
    background: #fff;
}

.quote-preview[hidden] {
    display: none !important;
}

.quote-preview-body {
    min-width: 0;
    flex: 1;
    display: grid;
    gap: 2px;
    color: var(--wx-muted);
    font-size: 12px;
}

.quote-preview-body strong {
    color: #191919;
    font-weight: 600;
}

.quote-preview-body span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quote-preview-clear {
    width: 28px;
    height: 28px;
    flex: none;
    color: #999;
    font-size: 22px;
    line-height: 1;
}

.composer-dock {
    flex: none;
    background: var(--wx-bar);
    border-top: 1px solid #d9d9d9;
    padding-bottom: env(safe-area-inset-bottom);
}

.composer {
    position: relative;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    align-items: end;
    gap: 8px;
    padding: 8px 8px 8px 6px;
}

.icon-button {
    width: 40px;
    height: 40px;
    color: #191919;
    font-size: 26px;
    line-height: 1;
}

.plus-button {
    font-size: 32px;
    font-weight: 300;
}

.send-button {
    min-width: 56px;
    height: 32px;
    margin-bottom: 4px;
    padding: 0 10px;
    border-radius: 4px;
    background: var(--wx-green);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
}

.send-button:hover:not(:disabled) {
    background: var(--wx-green-pressed);
}

.plus-panel {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px 8px;
    padding: 18px 16px 20px;
}

.plus-tile {
    display: grid;
    justify-items: center;
    gap: 8px;
    color: #191919;
    font-size: 12px;
}

.plus-tile-icon {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: #fff;
    font-size: 26px;
}

.plus-tile:active .plus-tile-icon {
    background: #f0f0f0;
}

.emoji-panel {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    height: 220px;
    overflow: auto;
    padding: 8px 8px 12px;
}

.emoji-item {
    height: 40px;
    font-size: 24px;
}

.date-divider,
.time-divider {
    margin: 12px auto;
    width: fit-content;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.08);
    color: #fff;
    font-size: 12px;
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 12px;
    max-width: 100%;
}

.message.continued {
    margin-top: -6px;
    margin-bottom: 6px;
}

.message.continued .message-avatar {
    visibility: hidden;
}

.message.continued .message-name {
    display: none;
}

.message.mentioned .message-bubble {
    box-shadow: inset 0 0 0 1px #f5a623;
}

.message.quote-flash .message-bubble {
    box-shadow: inset 0 0 0 1px var(--wx-green);
}

.message.self {
    flex-direction: row-reverse;
}

.message.system {
    display: block;
    margin: 8px auto 12px;
    max-width: 86%;
    padding: 0;
    text-align: center;
}

.message.system p {
    display: inline-block;
    margin: 0;
    padding: 3px 8px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.08);
    color: #fff;
    font-size: 12px;
    line-height: 1.4;
}

.message-avatar {
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 4px;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    line-height: 40px;
    text-align: center;
}

.message-main {
    min-width: 0;
    max-width: calc(100% - 96px);
    display: grid;
    gap: 4px;
}

.message.self .message-main {
    justify-items: end;
}

.message-name {
    padding: 0 4px;
    color: #b2b2b2;
    font-size: 12px;
    line-height: 1;
}

.message.self .message-name {
    display: none;
}

.message-bubble {
    position: relative;
    width: fit-content;
    max-width: 100%;
    padding: 9px 12px;
    border-radius: 4px;
    background: #fff;
    color: var(--wx-text);
    font-size: 16px;
    line-height: 1.45;
    word-break: break-word;
    -webkit-touch-callout: none;
    user-select: none;
}

.message.self .message-bubble {
    background: var(--wx-bubble);
}

.message-bubble::before {
    content: "";
    position: absolute;
    top: 12px;
    left: -6px;
    border: 6px solid transparent;
    border-left: 0;
    border-right-color: #fff;
}

.message.self .message-bubble::before {
    left: auto;
    right: -6px;
    border: 6px solid transparent;
    border-right: 0;
    border-left-color: var(--wx-bubble);
}

.message p {
    margin: 0;
}

.message p a {
    color: #576b95;
}

.message-text.collapsed {
    display: -webkit-box;
    -webkit-line-clamp: 8;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.message-time {
    padding: 0 4px;
    color: #b2b2b2;
    font-size: 11px;
    line-height: 1;
}

.message-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 0 4px;
}

.message.self .message-meta {
    justify-content: flex-end;
}

.message-status {
    padding: 0;
    color: #b2b2b2;
    font-size: 11px;
    line-height: 1;
    background: transparent;
}

.message-status[data-status="failed"] {
    color: var(--wx-danger);
}

.message-status[data-status="read"] {
    color: #1aad19;
}

.message-mention {
    color: #576b95;
}

.message-mention.me {
    font-weight: 600;
}

.quote-card {
    display: grid;
    gap: 2px;
    width: 100%;
    margin-bottom: 6px;
    padding: 6px 8px;
    border: 0;
    border-left: 2px solid rgba(0, 0, 0, 0.18);
    border-radius: 2px;
    background: rgba(0, 0, 0, 0.05);
    color: inherit;
    text-align: left;
}

.quote-card strong {
    color: #576b95;
    font-size: 12px;
    font-weight: 600;
}

.quote-card span {
    overflow: hidden;
    color: var(--wx-muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message.self .quote-card {
    background: rgba(0, 0, 0, 0.06);
}

.message-expand {
    display: inline-block;
    margin-top: 4px;
    color: #576b95;
    font-size: 13px;
}

.message.failed .message-bubble {
    outline: 1px solid var(--wx-danger);
}

.message.failed::after {
    content: "!";
    align-self: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--wx-danger);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

.search-highlight {
    background: #fde047;
}

.image-preview-button {
    padding: 0;
    background: transparent;
}

.attachment-image {
    display: block;
    min-width: 96px;
    min-height: 72px;
    max-width: min(180px, 56vw);
    max-height: 240px;
    border-radius: 4px;
    object-fit: contain;
    background: #f0f0f0;
}

.attachment-image.broken {
    display: none;
}

.attachment-expired {
    display: block;
    min-width: 96px;
    padding: 18px 12px;
    color: var(--wx-muted);
    font-size: 12px;
    text-align: center;
}

.message-bubble:has(.attachment-image) {
    padding: 4px;
    background: #fff;
}

.message.self .message-bubble:has(.attachment-image) {
    background: var(--wx-bubble);
}

.message-bubble:has(.attachment-image)::before,
.message.self .message-bubble:has(.attachment-image)::before {
    display: none;
}

.attachment-link.file {
    display: grid;
    min-width: 168px;
    gap: 4px;
    padding: 8px 10px;
    color: inherit;
    text-decoration: none;
}

.attachment-link.file span {
    color: var(--wx-muted);
    font-size: 12px;
}

.at-panel {
    position: absolute;
    left: 48px;
    right: 12px;
    bottom: calc(100% + 6px);
    z-index: 30;
    max-height: 180px;
    overflow: auto;
    padding: 4px;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.at-item {
    display: block;
    width: 100%;
    min-height: 40px;
    padding: 0 10px;
    text-align: left;
    font-size: 15px;
}

.at-item:active {
    background: #f5f5f5;
}

.message-menu-item:active {
    background: #3a3a3a;
}

.member-drawer {
    position: fixed;
    inset: 0;
    z-index: 100;
}

.member-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.member-drawer-panel {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow: auto;
    padding: 0 0 max(16px, env(safe-area-inset-bottom));
    background: #ededed;
}

.member-drawer-header {
    display: grid;
    flex: none;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    align-items: center;
    min-height: 48px;
    padding: max(6px, env(safe-area-inset-top)) 4px 6px;
    border-bottom: 1px solid var(--wx-line);
    background: var(--wx-bar);
}

.member-drawer-header h3 {
    margin: 0;
    overflow: hidden;
    font-size: 17px;
    font-weight: 600;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.member-drawer-header-space {
    width: 44px;
    height: 44px;
}

.member-drawer-close {
    font-size: 32px;
}

.info-card {
    margin: 12px 12px 0;
    overflow: hidden;
    border-radius: 8px;
    background: #fff;
}

.info-row {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 14px 16px;
    border-bottom: 1px solid #f0f0f0;
}

.info-row:last-child {
    border-bottom: 0;
}

.info-label {
    flex: none;
    width: 72px;
    color: #111;
    font-size: 16px;
    line-height: 1.4;
}

.info-value {
    min-width: 0;
    flex: 1;
    color: #111;
    font-size: 16px;
    line-height: 1.45;
    text-align: right;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: pre-wrap;
}

.member-section-title {
    margin: 18px 16px 8px;
    color: var(--wx-muted);
    font-size: 13px;
    font-weight: 400;
}

.member-drawer-list {
    display: grid;
    gap: 0;
    margin: 0 12px;
    overflow: visible;
    border-radius: 8px;
    background: #fff;
}

.member-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
}

.member-item:last-child {
    border-bottom: 0;
}

.member-avatar {
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 4px;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    line-height: 40px;
    text-align: center;
}

.member-name {
    min-width: 0;
    flex: 1;
    color: #111;
    font-size: 16px;
    line-height: 1.45;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: pre-wrap;
}

.member-me {
    flex: none;
    margin-top: 2px;
    padding: 1px 6px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    color: var(--wx-muted);
    font-size: 11px;
    line-height: 1.4;
}

.presence-item {
    display: flex;
    align-items: center;
    min-height: 52px;
    padding: 0 14px;
    background: #fff;
    font-size: 16px;
}

.message-menu {
    position: fixed;
    z-index: 200;
    display: flex;
    min-width: 88px;
    overflow: hidden;
    border-radius: 8px;
    background: #4c4c4c;
}

.message-menu[hidden] {
    display: none !important;
}

.message-menu-item {
    display: block;
    min-width: 64px;
    height: 44px;
    padding: 0 14px;
    color: #fff;
    font-size: 14px;
}

.message.menu-open .message-bubble {
    filter: brightness(0.92);
}

.disconnect-banner {
    position: sticky;
    top: 0;
    z-index: 50;
    padding: 8px 12px;
    background: #e64340;
    color: #fff;
    font-size: 13px;
    text-align: center;
}

.image-modal {
    position: fixed;
    inset: 0;
    z-index: 120;
    width: 100%;
    height: var(--app-height);
    background: #000;
    touch-action: none;
}

.image-modal-stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
    touch-action: none;
}

.image-modal-image {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 1;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    transform: translate(-50%, -50%);
    transform-origin: center center;
    will-change: transform;
    user-select: none;
    -webkit-user-drag: none;
}

.image-nav {
    position: absolute;
    top: 50%;
    z-index: 3;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font-size: 32px;
    line-height: 1;
    transform: translateY(-50%);
}

.image-nav-prev {
    left: 8px;
}

.image-nav-next {
    right: 8px;
}

.image-modal-toolbar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px max(16px, env(safe-area-inset-bottom));
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
    color: #fff;
    touch-action: manipulation;
}

.image-modal-counter {
    flex: none;
    color: rgba(255, 255, 255, 0.9);
    font-size: 13px;
}

.image-modal-title {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-modal-download,
.image-modal-close {
    flex: none;
    height: 32px;
    padding: 0 10px;
    color: #fff;
    font-size: 15px;
}

.image-modal-close {
    font-size: 24px;
}

@media (min-width: 821px) {
    .chat-card,
    .page {
        width: min(420px, 100%);
        box-shadow: 0 0 0 1px #e5e5e5;
    }

    .shell {
        background: #f0f0f0;
    }

    .entry-card {
        height: min(620px, calc(var(--app-height) - 48px));
        border-radius: 8px;
    }
}

@media (max-width: 820px) {
    .shell {
        display: block;
    }

    .page,
    .entry-card,
    .chat-card {
        width: 100%;
        height: var(--app-height);
        border-radius: 0;
        box-shadow: none;
    }

    .entry-card {
        overflow: auto;
        padding: max(36px, env(safe-area-inset-top)) 24px 24px;
    }

    body.keyboard-open.chat-open .status {
        display: none;
    }
}
