:root {
    --bg-main: linear-gradient(180deg, #131f43 0%, #182a59 48%, #1d3472 100%);
    --bg-surface: rgba(240, 246, 255, 0.94);
    --bg-surface-strong: rgba(255, 255, 255, 0.98);
    --bg-soft: rgba(227, 237, 255, 0.82);
    --bg-soft-2: rgba(213, 228, 255, 0.92);
    --panel-line: rgba(66, 111, 201, 0.12);
    --panel-line-strong: rgba(70, 113, 199, 0.2);
    --text-main: #17305c;
    --text-soft: #5a7098;
    --text-faint: #7c8fb3;
    --accent: #2f80ed;
    --accent-2: #5aa4f3;
    --accent-soft: rgba(47, 128, 237, 0.12);
    --accent-soft-2: rgba(90, 164, 243, 0.16);
    --bubble-mine: linear-gradient(135deg, #2f80ed 0%, #5aa4f3 100%);
    --bubble-other: #ffffff;
    --shadow-lg: 0 28px 70px rgba(11, 30, 68, 0.16);
    --shadow-md: 0 16px 36px rgba(17, 43, 95, 0.1);
    --radius-xl: 32px;
    --radius-lg: 24px;
    --radius-md: 18px;
    --radius-sm: 14px;
    --font: Tahoma, "Segoe UI", sans-serif;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --warning: #d17800;
    --danger: #b42318;
    --danger-soft: rgba(180, 35, 24, 0.12);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font);
    background: var(--bg-main);
    background-color: #131f43;
    color: var(--text-main);
    direction: ltr;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    min-height: 100svh;
    overflow: hidden;
}

body.theme-dark-body {
    background: linear-gradient(180deg, #071126 0%, #0d1835 50%, #132754 100%);
    background-color: #071126;
}

button,
input,
textarea {
    font: inherit;
    appearance: none;
    -webkit-appearance: none;
}

button {
    cursor: pointer;
    border: 0;
}

button:disabled {
    cursor: wait;
    opacity: 0.72;
}

img {
    max-width: 100%;
    display: block;
}

.hidden {
    display: none !important;
}

.card {
    background: var(--bg-surface);
    border: 1px solid var(--panel-line);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(18px);
}

.app-shell {
    min-height: 100svh;
    padding: max(1rem, var(--safe-top)) max(1rem, var(--safe-right)) max(1rem, var(--safe-bottom)) max(1rem, var(--safe-left));
    overflow: hidden;
}

#messageInput {
    color: var(--text-main);
    caret-color: var(--text-main);
}

.app-shell.theme-dark {
    --bg-main: linear-gradient(180deg, #0a1228 0%, #101b3c 48%, #142655 100%);
    --bg-surface: rgba(16, 24, 45, 0.94);
    --bg-surface-strong: rgba(20, 29, 54, 0.98);
    --bg-soft: rgba(24, 35, 66, 0.88);
    --bg-soft-2: rgba(30, 43, 81, 0.92);
    --panel-line: rgba(112, 153, 255, 0.16);
    --panel-line-strong: rgba(112, 153, 255, 0.28);
    --text-main: #e7efff;
    --text-soft: #9bb3e3;
    --text-faint: #7f95bf;
    --accent-soft: rgba(47, 128, 237, 0.18);
    --accent-soft-2: rgba(90, 164, 243, 0.22);
    --bubble-other: #182443;
    --shadow-lg: 0 28px 70px rgba(2, 8, 23, 0.42);
    --shadow-md: 0 16px 36px rgba(2, 8, 23, 0.3);
    --danger-soft: rgba(180, 35, 24, 0.22);
    background-color: #071126;
    background: linear-gradient(180deg, #071126 0%, #0d1835 50%, #132754 100%);
}

.auth-page,
.mobile-app {
    width: min(100%, 1180px);
    margin: 0 auto;
}

.auth-page {
    min-height: calc(100svh - 2rem);
    display: grid;
    align-items: center;
    overflow: hidden;
}

.auth-card {
    display: grid;
    grid-template-columns: minmax(280px, 420px);
    justify-content: center;
    gap: 1rem;
    width: min(100%, 520px);
    margin: 0 auto;
    padding: clamp(1.2rem, 3vw, 2rem);
    background:
        radial-gradient(circle at top right, rgba(90, 164, 243, 0.16), transparent 34%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(243, 248, 255, 0.95));
}

.auth-copy {
    display: grid;
    align-content: start;
    gap: 0.85rem;
    padding: 0;
}

.brand-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    padding: 0.48rem 0.9rem;
    border-radius: 999px;
    color: var(--accent);
    background: rgba(47, 128, 237, 0.12);
    font-size: 0.92rem;
    font-weight: 700;
}

.auth-brand {
    display: grid;
    gap: 1rem;
}

.auth-brand h1 {
    margin: 0;
    font-size: clamp(2.2rem, 5vw, 4rem);
    line-height: 1.28;
    color: var(--text-main);
}

.auth-panel {
    display: grid;
    gap: 1rem;
    align-content: start;
    padding: clamp(1rem, 2vw, 1.3rem);
    border-radius: 28px;
    background: linear-gradient(180deg, rgba(231, 241, 255, 0.94), rgba(221, 235, 255, 0.86));
    border: 1px solid rgba(69, 113, 201, 0.12);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.app-shell.theme-dark .auth-card {
    background:
        radial-gradient(circle at top right, rgba(90, 164, 243, 0.18), transparent 34%),
        linear-gradient(180deg, rgba(17, 27, 52, 0.98), rgba(13, 22, 43, 0.95));
}

.app-shell.theme-dark .auth-panel,
.app-shell.theme-dark .mobile-sidebar,
.app-shell.theme-dark .mobile-content,
.app-shell.theme-dark .mobile-main,
.app-shell.theme-dark .chat-sheet,
.app-shell.theme-dark .settings-card,
.app-shell.theme-dark .image-preview,
.app-shell.theme-dark .composer-context,
.app-shell.theme-dark .message-menu {
    background: rgba(15, 24, 46, 0.92);
    border-color: var(--panel-line);
}

.app-shell.theme-dark .phone-frame,
.app-shell.theme-dark .chat-body {
    background:
        radial-gradient(circle at top, rgba(47, 128, 237, 0.12), transparent 30%),
        linear-gradient(180deg, rgba(14, 24, 47, 0.98), rgba(11, 19, 38, 0.96));
}

.app-shell.theme-dark input,
.app-shell.theme-dark textarea,
.app-shell.theme-dark .conversation-item,
.app-shell.theme-dark .search-result,
.app-shell.theme-dark .ghost-button,
.app-shell.theme-dark .tab-btn,
.app-shell.theme-dark .reply-preview,
.app-shell.theme-dark .message-reaction-chip {
    background: rgba(24, 35, 66, 0.96);
    color: var(--text-main);
    border-color: rgba(112, 153, 255, 0.16);
}

.app-shell.theme-dark .conversation-item.active,
.app-shell.theme-dark .conversation-item:hover,
.app-shell.theme-dark .search-result:hover,
.app-shell.theme-dark .tab-btn.active,
.app-shell.theme-dark .message-menu-item:hover,
.app-shell.theme-dark .message-menu-reaction:hover {
    background: rgba(31, 50, 93, 0.98);
    border-color: rgba(90, 164, 243, 0.24);
}

.app-shell.theme-dark .message-day-divider span {
    background: rgba(15, 24, 46, 0.84);
    border-color: rgba(112, 153, 255, 0.16);
    color: var(--text-soft);
    box-shadow: 0 8px 20px rgba(2, 8, 23, 0.24);
}

.app-shell.theme-dark .message-bubble,
.message-bubble * {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.message-group.other .message-bubble {
    background: var(--bubble-other);
    color: var(--text-main);
}

.app-shell.theme-dark .message-footer,
.app-shell.theme-dark .timestamp,
.app-shell.theme-dark .message-status,
.app-shell.theme-dark .message-status.read {
    color: var(--text-soft);
}

.app-shell.theme-dark .brand-pill {
    background: rgba(47, 128, 237, 0.18);
}

.app-shell.theme-dark input::placeholder,
.app-shell.theme-dark textarea::placeholder {
    color: #7f95bf;
}

.app-shell.theme-dark #messageInput {
    background: rgba(24, 35, 66, 0.98);
    color: #eef4ff;
    caret-color: #eef4ff;
    border-color: rgba(112, 153, 255, 0.2);
}

.auth-panels {
    display: grid;
    gap: 1rem;
}

.form-card {
    display: none;
    gap: 0.9rem;
}

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

.form-card h2,
.section-header h2,
.chat-sheet-header h3 {
    margin: 0;
}

.form-card h2 {
    font-size: 1.5rem;
    color: var(--text-main);
}

.form-note {
    margin: -0.15rem 0 0.35rem;
    color: var(--text-soft);
    font-size: 0.95rem;
    line-height: 1.8;
}

label {
    display: grid;
    gap: 0.5rem;
    min-width: 0;
}

label > span {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-soft);
}

input,
textarea {
    width: 100%;
    min-width: 0;
    border: 1px solid rgba(99, 132, 198, 0.16);
    background: rgba(255, 255, 255, 0.95);
    color: var(--text-main);
    border-radius: 18px;
    padding: 0.95rem 1rem;
    resize: none;
    text-align: left;
    box-shadow: inset 0 1px 2px rgba(18, 44, 98, 0.04);
}

input::placeholder,
textarea::placeholder {
    color: #8aa0c2;
}

input:focus,
textarea:focus {
    outline: 0;
    border-color: rgba(47, 128, 237, 0.45);
    box-shadow: 0 0 0 4px rgba(47, 128, 237, 0.12);
}

button[type="submit"],
#sendBtn,
.upload-button {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
    color: #fff;
    border-radius: 18px;
    padding: 0.95rem 1.2rem;
    font-weight: 700;
}

.ghost-button,
.link-button,
.tab-btn {
    background: rgba(255, 255, 255, 0.7);
    color: var(--text-main);
    border-radius: 16px;
    padding: 0.75rem 1rem;
}

.link-button {
    padding: 0;
    background: transparent;
    color: var(--accent);
}

.ghost-button.small,
.tab-btn {
    padding: 0.65rem 0.9rem;
}

.ghost-button.danger {
    color: var(--danger);
    background: var(--danger-soft);
}

.switch-text,
.build-love,
.section-header p,
.mobile-brand span,
.chat-sheet-header p,
.form-hint {
    color: var(--text-soft);
}

.switch-text {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.45rem;
    flex-wrap: wrap;
    margin: 0;
}

.build-love {
    margin: 0.25rem 0 0;
    font-size: 0.92rem;
    text-align: center;
}

.mobile-app {
    min-height: calc(100svh - 2rem);
    overflow: hidden;
}

.phone-frame {
    width: min(100%, 1180px);
    min-height: calc(100svh - 2rem);
    height: calc(100svh - 2rem);
    margin: 0 auto;
    padding: 1rem;
    display: grid;
    grid-template-columns: minmax(290px, 330px) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 1rem;
    background:
        linear-gradient(180deg, rgba(248, 251, 255, 0.96), rgba(237, 244, 255, 0.94));
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.mobile-sidebar,
.mobile-content,
.mobile-main {
    min-width: 0;
    border-radius: 26px;
    border: 1px solid var(--panel-line);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(18px);
}

.mobile-sidebar {
    display: grid;
    grid-column: 1;
    grid-row: 1;
    grid-template-rows: auto auto auto;
    gap: 0.9rem;
    padding: 0.9rem;
    background:
        linear-gradient(180deg, rgba(247, 251, 255, 0.96), rgba(236, 244, 255, 0.92));
}

.mobile-content {
    grid-column: 1;
    grid-row: 2;
    position: relative;
    min-height: 0;
    padding: 0.9rem;
    overflow: hidden;
}

.mobile-main {
    grid-column: 2;
    grid-row: 1 / span 2;
    display: grid;
    min-height: 0;
    padding: 0.9rem;
    background:
        linear-gradient(180deg, rgba(250, 252, 255, 0.95), rgba(240, 246, 255, 0.92));
    overflow: hidden;
}

.mobile-topbar,
.mobile-brand,
.chat-sheet-header,
.news-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.mobile-topbar {
    padding: 0.25rem 0.1rem 0.55rem;
    border-bottom: 1px solid rgba(66, 111, 201, 0.1);
    min-width: 0;
}

.sidebar-profile,
.mobile-brand,
.chat-sheet-heading {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.mobile-brand div {
    min-width: 0;
    flex: 1;
}

.sidebar-profile {
    flex: 1;
    overflow: hidden;
}

.mobile-brand {
    flex: 1;
    overflow: hidden;
}

.sidebar-avatar {
    width: 3rem;
    height: 3rem;
    flex: 0 0 3rem;
    background: linear-gradient(135deg, #2f80ed 0%, #66b3ff 100%);
    color: #fff;
    box-shadow: 0 12px 26px rgba(47, 128, 237, 0.22);
}

.mobile-brand strong {
    display: block;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mobile-brand span {
    display: block;
    margin-top: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-intro {
    display: grid;
    gap: 0.3rem;
    padding: 0.2rem 0.15rem 0.1rem;
}

.sidebar-intro strong {
    color: var(--text-main);
    font-size: 1rem;
}

.sidebar-intro p {
    margin: 0;
    color: var(--text-soft);
    font-size: 0.9rem;
    line-height: 1.8;
}

.sidebar-tabs {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.55rem;
}

.tab-view,
.chat-sheet {
    position: absolute;
    inset: 0;
    display: none;
    gap: 0.9rem;
    min-height: 0;
}

.tab-view.active,
.chat-sheet.active {
    display: grid;
}

#tabChats,
#tabSearch,
#tabSettings {
    grid-template-rows: auto minmax(0, 1fr);
}

#tabSettings {
    overflow-y: auto;
    align-content: start;
    padding-right: 0.2rem;
}

.section-header {
    display: grid;
    gap: 0.24rem;
}

.section-header h2,
.chat-sheet-header h3 {
    color: var(--text-main);
}

.section-header p,
.chat-sheet-header p {
    margin: 0;
    font-size: 0.93rem;
    line-height: 1.7;
}

.mobile-list,
.chat-body {
    overflow: auto;
    min-height: 0;
    padding-left: 0.15rem;
}

.search-box {
    margin-bottom: 0.05rem;
    max-width: 22rem;
}

.search-box input {
    padding: 0.58rem 0.8rem;
    border-radius: 12px;
    min-height: 2.35rem;
    line-height: 1.35;
}

.conversation-list,
.search-results {
    display: grid;
    gap: 0.55rem;
    align-content: start;
}

.conversation-item,
.search-result {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.8rem;
    align-items: center;
    width: 100%;
    text-align: left;
    padding: 0.85rem 0.9rem;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(66, 111, 201, 0.08);
    transition: 0.18s ease;
}

.conversation-item.active,
.conversation-item:hover,
.search-result:hover,
.tab-btn.active {
    border-color: rgba(47, 128, 237, 0.18);
    background: rgba(227, 238, 255, 0.98);
    box-shadow: 0 10px 24px rgba(34, 77, 155, 0.08);
}

.avatar {
    width: 2.85rem;
    height: 2.85rem;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #8fc0fa 0%, #4d99f1 100%);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 10px 24px rgba(73, 132, 221, 0.2);
}

.conversation-meta,
.conversation-row,
.settings-card,
.search-box,
.search-box {
    display: grid;
    gap: 0.3rem;
}

.conversation-row {
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.45rem;
}

.preview {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-soft);
}

.badge {
    min-width: 1.5rem;
    height: 1.5rem;
    border-radius: 999px;
    display: inline-grid;
    place-items: center;
    padding: 0 0.35rem;
    background: var(--accent);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
}

.timestamp {
    font-size: 0.78rem;
    color: var(--text-faint);
}

.settings-card {
    padding: 1rem;
    background: rgba(245, 249, 255, 0.98);
    border-radius: 24px;
    border: 1px solid rgba(66, 111, 201, 0.12);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.settings-card {
    align-content: start;
}
.message-footer {
    display: flex;
    justify-content: space-between;
    gap: 0.6rem;
    color: #111;
    font-size: 0.78rem;
}

.news-form {
    display: grid;
    gap: 0.75rem;
}

.toggle-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 0.2rem 0;
}

.toggle-row input {
    width: 1.15rem;
    height: 1.15rem;
    border-radius: 999px;
    border: 1px solid rgba(66, 111, 201, 0.22);
    background: #fff;
    box-shadow: inset 0 1px 2px rgba(18, 44, 98, 0.04);
    transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.toggle-row input:checked {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.92);
}

.chat-sheet {
    background:
        linear-gradient(180deg, rgba(251, 253, 255, 0.98), rgba(241, 247, 255, 0.98));
    border-radius: 26px;
    border: 1px solid var(--panel-line);
    padding: 1rem;
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.82);
}

.chat-sheet-header {
    padding-bottom: 0.8rem;
    border-bottom: 1px solid rgba(66, 111, 201, 0.12);
}

.chat-sheet-heading {
    flex: 1;
}

.chat-sheet-title {
    display: grid;
    gap: 0.2rem;
    min-width: 0;
}

.chat-header-actions {
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.chat-body {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    min-height: 16rem;
    min-width: 0;
    padding: 0.8rem 0.15rem;
    background:
        radial-gradient(circle at top, rgba(90, 164, 243, 0.08), transparent 28%),
        linear-gradient(180deg, rgba(245, 250, 255, 0.7), rgba(241, 247, 255, 0.35));
    border-radius: 0 0 22px 22px;
}

.older-messages-wrap {
    display: flex;
    justify-content: center;
    padding-top: 0.1rem;
}

.message-day-divider {
    display: flex;
    justify-content: center;
    padding: 0.35rem 0 0.15rem;
}

.message-day-divider span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 1.9rem;
    padding: 0.2rem 0.8rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(66, 111, 201, 0.12);
    box-shadow: 0 8px 20px rgba(17, 43, 95, 0.08);
    color: var(--text-soft);
    font-size: 0.78rem;
    font-weight: 700;
    backdrop-filter: blur(12px);
}

#loadOlderMessagesBtn {
    min-width: 10.5rem;
}

.empty-state {
    margin: auto;
    text-align: center;
    color: var(--text-faint);
}

.chat-welcome {
    max-width: 26rem;
    gap: 0.8rem;
}

.chat-welcome strong {
    color: var(--text-main);
    font-size: 1.15rem;
}

.chat-welcome p {
    margin: 0;
    line-height: 1.9;
}

.empty-icon {
    font-size: 2.8rem;
}

.message-group {
    display: flex;
    width: 100%;
}

.message-group.is-highlighted .message-bubble {
    box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.18);
}

.message-group.mine {
    justify-content: flex-end;
}

.message-group.other {
    justify-content: flex-start;
}

.message-bubble {
    position: relative;
    max-width: min(78%, 33rem);
    padding: 0.82rem 0.95rem;
    border-radius: 22px;
    line-height: 1.8;
    background: var(--bubble-other);
    color: var(--text-main);
    box-shadow: 0 10px 26px rgba(22, 49, 102, 0.07);
    text-align: left;
    border: 1px solid rgba(66, 111, 201, 0.08);
}

.message-group.mine .message-bubble {
    background: var(--bubble-mine);
    color: #fff;
    border-bottom-right-radius: 8px;
    border-color: transparent;
}

.message-bubble,
.message-bubble * {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.message-group.other .message-bubble {
    border-bottom-left-radius: 8px;
}

.message-text {
    white-space: normal;
    word-break: break-word;
}

.text-rtl {
    direction: rtl;
    text-align: right;
}

.text-ltr {
    direction: ltr;
    text-align: left;
}

.reply-preview {
    display: grid;
    gap: 0.12rem;
    width: 100%;
    margin-bottom: 0.55rem;
    padding: 0.5rem 0.6rem;
    border-radius: 14px;
    border: 1px solid rgba(66, 111, 201, 0.12);
    background: rgba(255, 255, 255, 0.58);
    text-align: left;
}

.message-group.mine .reply-preview {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.reply-preview strong {
    font-size: 0.78rem;
}

.reply-preview span {
    font-size: 0.8rem;
    opacity: 0.88;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-audio {
    display: block;
    width: min(100%, 16rem);
    margin-bottom: 0.55rem;
}

.message-video {
    display: block;
    width: min(100%, 18rem);
    border-radius: 16px;
    margin-bottom: 0.55rem;
    background: rgba(8, 16, 34, 0.9);
}

.message-image {
    display: block;
    width: fit-content;
    max-width: min(100%, 18rem);
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 0.55rem;
}

.message-image img {
    display: block;
    width: auto;
    max-width: 100%;
    max-height: 22rem;
    object-fit: cover;
}

.message-image-wrap {
    display: grid;
    justify-items: start;
    gap: 0.45rem;
    margin-bottom: 0.55rem;
}

.message-status,
.message-status.read {
    color: #111;
}

.message-group.other .message-status {
    display: none;
}

.message-reaction-chip {
    position: absolute;
    bottom: -0.7rem;
    right: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.18rem 0.42rem;
    border-radius: 999px;
    background: #fff;
    color: var(--accent);
    border: 1px solid rgba(66, 111, 201, 0.14);
    box-shadow: 0 6px 14px rgba(22, 49, 102, 0.08);
    font-size: 0.72rem;
    line-height: 1;
}

.message-reaction-chip.is-active {
    background: rgba(47, 128, 237, 0.1);
}

.image-preview {
    display: grid;
    gap: 0.75rem;
    padding: 0.85rem;
    border-radius: 18px;
    background: rgba(226, 237, 255, 0.78);
    border: 1px solid rgba(66, 111, 201, 0.12);
}

.image-preview {
    grid-template-columns: 5.4rem 1fr;
    align-items: center;
}

.image-preview img {
    width: 5.4rem;
    height: 5.4rem;
    object-fit: cover;
    border-radius: 14px;
}

.image-preview-meta {
    display: grid;
    align-items: center;
    min-height: 5.4rem;
    padding: 0.8rem;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.55);
    color: var(--text-main);
    word-break: break-word;
}

.composer-context {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.7rem;
    align-items: center;
    padding: 0.7rem 0.85rem;
    border-radius: 18px;
    background: rgba(226, 237, 255, 0.78);
    border: 1px solid rgba(66, 111, 201, 0.12);
}

.composer-context-copy {
    display: grid;
    gap: 0.15rem;
    min-width: 0;
}

.composer-context-copy strong {
    font-size: 0.82rem;
}

.composer-context-copy p {
    margin: 0;
    color: var(--text-soft);
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-form {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 0.65rem;
    align-items: end;
    padding-top: 0.4rem;
}

.message-menu {
    position: fixed;
    z-index: 1200;
    display: grid;
    gap: 0.25rem;
    min-width: 9rem;
    padding: 0.35rem;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(66, 111, 201, 0.12);
    box-shadow: 0 16px 34px rgba(17, 43, 95, 0.18);
}

.message-menu-item,
.message-menu-reaction {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    padding: 0.58rem 0.72rem;
    border-radius: 10px;
    background: transparent;
    color: var(--text-main);
}

.message-menu-item:hover,
.message-menu-reaction:hover {
    background: rgba(227, 238, 255, 0.98);
}

.message-menu-item.danger {
    color: var(--danger);
}

.message-menu-reaction {
    justify-content: center;
    font-size: 1.2rem;
    color: var(--accent);
}

.icon-button {
    width: 2.6rem;
    height: 2.6rem;
    display: inline-grid;
    place-items: center;
    padding: 0;
    font-size: 1.15rem;
}

.upload-button,
.voice-toggle,
#sendBtn {
    display: inline-grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    padding: 0;
}

.voice-toggle {
    font-size: 1.2rem;
}

.voice-toggle.is-recording {
    background: rgba(180, 35, 24, 0.14);
    color: var(--danger);
}

#sendBtn {
    min-width: 4.8rem;
}

#messageInput {
    min-height: 3rem;
    max-height: 8rem;
}

#messageInput {
    background: rgba(255, 255, 255, 0.98);
}

.bottom-tabs {
    display: none;
}

.tab-btn {
    font-size: 0.82rem;
    min-width: 0;
}

.toast {
    position: fixed;
    left: max(1rem, var(--safe-left));
    right: max(1rem, var(--safe-right));
    bottom: max(1rem, var(--safe-bottom));
    padding: 0.9rem 1rem;
    border-radius: 16px;
    background: rgba(24, 42, 89, 0.96);
    color: #fff;
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
    transition: 0.2s ease;
    box-shadow: var(--shadow-md);
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.is-error {
    background: rgba(0, 0, 0, 0.92);
}

.toast.is-success {
    background: rgba(24, 42, 89, 0.96);
}

@media (max-width: 920px) {
    .phone-frame {
        grid-template-columns: 1fr;
    }

    .auth-card {
        width: min(100%, 480px);
    }

    .phone-frame {
        grid-template-rows: auto minmax(22rem, 1fr) minmax(28rem, 1fr) auto;
    }

    .mobile-sidebar,
    .mobile-content,
    .mobile-main {
        grid-column: 1;
    }

    .mobile-sidebar {
        grid-row: 1;
    }

    .mobile-content {
        grid-row: 2;
    }

    .mobile-main {
        grid-row: 3;
        min-height: 32rem;
    }
}

@media (max-width: 640px) {
    .app-shell {
        padding: max(0.18rem, var(--safe-top)) max(0.18rem, var(--safe-right)) max(0.12rem, var(--safe-bottom)) max(0.18rem, var(--safe-left));
    }

    .auth-page,
    .mobile-app,
    .phone-frame {
        min-height: calc(100svh - 0.36rem);
    }

    .auth-card,
    .phone-frame,
    .mobile-sidebar,
    .mobile-main,
    .chat-sheet,
    .settings-card {
        border-radius: 18px;
    }

    .auth-card,
    .phone-frame {
        padding: 0.28rem;
    }

    .auth-brand h1 {
        font-size: clamp(1.85rem, 8vw, 2.8rem);
    }

    .mobile-topbar,
    .chat-sheet-header {
        align-items: center;
        flex-wrap: nowrap;
    }

    .sidebar-profile,
    .chat-sheet-heading {
        align-items: center;
    }

    .message-form {
        grid-template-columns: auto 1fr auto;
        gap: 0.38rem;
        align-items: end;
        min-height: 0;
        padding-top: 0.1rem;
    }

    .image-preview {
        grid-template-columns: 1fr;
    }

    .conversation-row {
        grid-template-columns: 1fr;
        gap: 0.18rem;
    }

    .message-footer,
    .timestamp {
        font-size: 0.74rem;
    }

    .bottom-tabs {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 0.24rem;
        margin-top: 0.24rem;
        padding-bottom: max(0rem, var(--safe-bottom));
        justify-items: center;
    }

    .mobile-sidebar {
        display: none;
    }

    .mobile-content {
        grid-column: 1;
        grid-row: 1;
        min-height: calc(100svh - 8.6rem);
        border-radius: 18px;
        background: rgba(255, 255, 255, 0.82);
        border: 1px solid var(--panel-line);
        padding: 0.45rem;
    }

    .mobile-main {
        grid-column: 1;
        grid-row: 1;
        padding: 0;
        border: 0;
        background: transparent;
        display: none;
    }

    .mobile-app.chat-open .mobile-main {
        display: grid;
    }

    .mobile-app.chat-open .mobile-content,
    .mobile-app.chat-open .bottom-tabs {
        display: none;
    }

    .tab-view,
    .chat-sheet {
        position: absolute;
        inset: 0;
    }

    .chat-sheet {
        padding: 0.4rem 0.38rem 0.32rem;
        border-radius: 18px;
        grid-template-rows: auto minmax(0, 1fr) auto auto;
    }

    .bottom-tabs .tab-btn {
        width: 100%;
        max-width: 3.8rem;
        min-height: 3.8rem;
        aspect-ratio: 1;
        border-radius: 16px;
        padding: 0.3rem;
        font-size: 0.68rem;
        line-height: 1.15;
        display: grid;
        place-items: center;
        text-align: center;
    }

    .message-bubble {
        max-width: 88%;
        font-size: 0.88rem;
        padding: 0.68rem 0.78rem;
        border-radius: 18px;
    }

    .chat-body {
        padding: 0.26rem 0.02rem;
        gap: 0.46rem;
        min-height: 0;
        padding-bottom: 0.5rem;
        border-radius: 16px;
    }

    .settings-card {
        padding: 0.7rem;
    }

    .mobile-app.chat-open .phone-frame {
        grid-template-rows: minmax(0, 1fr);
    }

    .mobile-app.chat-open .mobile-main {
        grid-row: 1;
        min-height: 0;
    }

    .chat-sheet-header {
        padding: 0 0 0.38rem;
    }

    .chat-sheet-title h3 {
        font-size: 1.02rem;
    }

    .chat-sheet-title p {
        font-size: 0.78rem;
    }

    .icon-button {
        width: 2.15rem;
        height: 2.15rem;
        font-size: 0.92rem;
    }

    .upload-button,
    .voice-toggle,
    #sendBtn {
        position: static;
        width: 2.6rem;
        height: 2.6rem;
        min-width: 2.6rem;
        border-radius: 16px;
    }

    #messageInput {
        min-height: 2.7rem;
        width: 100%;
        padding: 0.72rem 0.85rem;
        border-radius: 18px;
    }

    .voice-toggle,
    #sendBtn {
        align-self: stretch;
        min-height: 2.7rem;
        width: 3rem;
        min-width: 3rem;
        padding: 0.4rem;
        border-radius: 18px;
    }

    #sendBtn {
        font-size: 0.9rem;
    }

    .voice-toggle {
        font-size: 1.2rem;
    }

    .chat-sheet-heading {
        gap: 0.55rem;
        min-width: 0;
    }

    .chat-sheet-title {
        gap: 0.1rem;
    }

    #backToTabsBtn {
        display: inline-grid;
    }

    .chat-header-actions {
        flex-shrink: 0;
    }

    .chat-header-actions .ghost-button {
        padding: 0.48rem 0.68rem;
        font-size: 0.82rem;
        border-radius: 14px;
    }

    .composer-context {
        padding: 0.58rem 0.72rem;
        border-radius: 16px;
    }

    .reply-preview {
        padding: 0.42rem 0.52rem;
        border-radius: 12px;
    }

    .message-menu {
        min-width: 8.4rem;
    }

    .message-audio {
        width: min(100%, 13rem);
    }

    .message-image {
        max-width: min(100%, 14.75rem);
    }

    .message-image img {
        max-height: 18.5rem;
    }

    .ghost-button,
    .tab-btn {
        padding: 0.62rem 0.82rem;
    }
}

@media (min-width: 641px) {
    .mobile-topbar > .ghost-button,
    .chat-sheet-header > .ghost-button,
    .chat-header-actions > .ghost-button {
        flex: 0 0 auto;
    }

    .current-user-username {
        display: none;
    }
}
