/* Externalized from chat/index.html for CSP. */
:root {
            --panel: rgba(17, 24, 39, .95);
            --text: #e5e7eb;
            --muted: #9ca3af;
            --accent: #2563eb;
            --accentHover: #1d4ed8;

            --top-nav-h: calc(56px + env(safe-area-inset-top));
            --bottom-nav-h: 92px;
            --kb: 0px;
            --composer-h: 64px;
            --seen-chat-vh: 100vh;
        }

        @supports (height: 100svh) {
            :root {
                --seen-chat-vh: 100svh;
            }
        }

        @supports (height: 100dvh) {
            :root {
                --seen-chat-vh: 100dvh;
            }
        }

        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            background: #020617;
            color: var(--text);
            font-family: var(--seen-font);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        .img-loading {
            background: linear-gradient(90deg,
                    rgba(30, 41, 59, 0.45),
                    rgba(59, 130, 246, 0.28),
                    rgba(30, 41, 59, 0.45));
            background-size: 200% 100%;
            animation: shimmer 1.15s ease-in-out infinite;
        }

        @keyframes shimmer {
            0% {
                background-position: -200% 0;
            }

            100% {
                background-position: 200% 0;
            }
        }

        @media (prefers-reduced-motion: reduce) {
            .img-loading {
                animation: none;
            }
        }

        .msg-media.img-failed::after,
        .msg-photo-grid-item.img-failed::after,
        .profile-pop-main.img-failed::after,
        .profile-pop-thumb.img-failed::after {
            content: "Tap to retry";
            position: absolute;
            inset: 0;
            display: grid;
            place-items: center;
            font-size: 11px;
            font-weight: 800;
            letter-spacing: 0.08em;
            text-transform: uppercase;
            color: #fecaca;
            background: rgba(2, 6, 23, 0.78);
            pointer-events: none;
        }

        .msg-media.img-failed img,
        .msg-photo-grid-item.img-failed img,
        .profile-pop-main.img-failed img,
        .profile-pop-thumb.img-failed img,
        .thumbs img.img-failed {
            opacity: 0.4;
            filter: grayscale(1);
        }

        /* Chat layout */
        .chat-shell {
            display: grid;
            grid-template-columns: 320px 1fr;
            gap: 12px;

            height: calc(var(--seen-chat-vh) - 84px);
            min-height: 0;
        }

        .thread-list {
            border-right: 1px solid rgba(30, 64, 175, 0.4);
            background: radial-gradient(circle at top, #020617, #020617 60%, #000);
            padding: 10px;
            overflow-y: auto;
        }

        .chat-thread-status {
            border: 1px solid rgba(248, 113, 113, 0.45);
            background: rgba(30, 41, 59, 0.72);
            border-radius: 12px;
            padding: 12px;
            margin-bottom: 10px;
            display: grid;
            gap: 8px;
            color: #e2e8f0;
        }

        .chat-thread-status-title {
            font-size: 13px;
            font-weight: 800;
            letter-spacing: 0.01em;
        }

        .chat-thread-status-message {
            font-size: 12px;
            color: #cbd5e1;
            line-height: 1.45;
        }

        .chat-thread-status-actions {
            display: flex;
            gap: 8px;
            flex-wrap: wrap;
        }

        .chat-thread-status-btn {
            border: 1px solid rgba(148, 163, 184, 0.38);
            background: rgba(15, 23, 42, 0.9);
            color: #e5e7eb;
            font-size: 12px;
            font-weight: 800;
            border-radius: 10px;
            padding: 8px 11px;
            cursor: pointer;
        }

        .chat-thread-status-btn.is-primary {
            background: rgba(37, 99, 235, 0.28);
            border-color: rgba(59, 130, 246, 0.55);
        }

        .thread-item {
            border-radius: 10px;
            padding: 10px;
            margin-bottom: 8px;
            background: rgba(15, 23, 42, 0.9);
            border: 1px solid rgba(148, 163, 184, 0.35);
            cursor: pointer;
            font-size: 13px;
        }

        .thread-item:hover {
            background: rgba(30, 64, 175, 0.6);
        }

        .thread-item.is-support-thread {
            border-color: rgba(56, 189, 248, 0.52);
            background: linear-gradient(140deg, rgba(30, 64, 175, 0.24), rgba(15, 23, 42, 0.94));
            box-shadow: inset 0 0 0 1px rgba(125, 211, 252, 0.14);
        }

        .thread-item.is-support-thread:hover {
            background: linear-gradient(140deg, rgba(37, 99, 235, 0.34), rgba(15, 23, 42, 0.96));
            border-color: rgba(125, 211, 252, 0.62);
        }

        /* Unread badge */
        .thread-right {
            display: flex;
            align-items: center;
            gap: 8px;
            flex: 0 0 auto;
        }

        .thread-badge {
            min-width: 18px;
            height: 18px;
            padding: 0 6px;
            border-radius: 999px;
            display: none;
            /* shown when unread > 0 */
            align-items: center;
            justify-content: center;

            font-size: 11px;
            font-weight: 800;
            line-height: 18px;

            background: rgba(34, 197, 94, 0.95);
            color: #fff;
            border: 1px solid rgba(255, 255, 255, 0.18);
        }

        .thread-badge.is-zero {
            background: rgba(148, 163, 184, 0.22);
            color: #cbd5f5;
            border-color: rgba(148, 163, 184, 0.3);
            font-weight: 700;
        }

        .thread-item.has-unread .thread-label {
            font-weight: 800;
        }

        .thread-label-row {
            display: flex;
            align-items: center;
            gap: 6px;
            min-width: 0;
        }

        .thread-label-text {
            min-width: 0;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .thread-label-text.is-support-thread-label {
            font-size: 15px;
            font-weight: 900;
            letter-spacing: 0.01em;
            color: #e0f2fe;
        }

        .thread-trust-badge {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border-radius: 999px;
            border: 1px solid rgba(251, 191, 36, 0.45);
            background: rgba(161, 98, 7, 0.18);
            color: #fde68a;
            font-size: 9px;
            font-weight: 800;
            letter-spacing: 0.05em;
            text-transform: uppercase;
            padding: 2px 6px;
            line-height: 1;
            white-space: nowrap;
            flex: 0 0 auto;
        }

        .chat-panel {
            display: flex;
            flex-direction: column;
            position: relative;
            background: radial-gradient(circle at top, #020617, #020617 50%, #000);
            padding: 10px;
            overflow: hidden;
        }

        .chat-panel.is-empty {
            background: rgba(2, 6, 23, 0.6);
        }

        .chat-empty-state {
            height: 100%;
            display: grid;
            place-items: center;
            text-align: center;
            color: rgba(156, 163, 175, 0.95);
            font-weight: 700;
            font-size: 14px;
            padding: 24px;
        }

        .messages {
            flex: 1;
            min-height: 0;
            overflow-y: auto;
            overflow-x: hidden;
            -webkit-overflow-scrolling: touch;
            overscroll-behavior: contain;
            border-radius: 10px;
            border: 1px solid rgba(15, 23, 42, 0.9);
            background: rgba(15, 23, 42, 0.95);
            padding: 10px;
            font-size: 13px;
            transition: opacity 0.12s ease;
        }

        .messages.loading {
            opacity: 0;
        }

        .chat-center-toast {
            position: fixed;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%) scale(0.98);
            z-index: 1400;
            padding: 12px 16px;
            border-radius: 14px;
            border: 1px solid rgba(148, 163, 184, 0.35);
            background: rgba(2, 6, 23, 0.88);
            color: #e2e8f0;
            font-size: 13px;
            font-weight: 800;
            letter-spacing: 0.01em;
            text-align: center;
            min-width: 180px;
            max-width: min(86vw, 340px);
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.2s ease, transform 0.2s ease;
            box-shadow: 0 14px 34px rgba(2, 6, 23, 0.45);
        }

        .chat-center-toast.show {
            opacity: 1;
            transform: translate(-50%, -50%) scale(1);
        }

        .chat-upload-progress {
            position: fixed;
            right: 14px;
            top: calc(74px + env(safe-area-inset-top));
            z-index: 1405;
            width: min(88vw, 340px);
            padding: 12px;
            border: 1px solid rgba(59, 130, 246, 0.42);
            border-radius: 14px;
            background: rgba(2, 6, 23, 0.96);
            box-shadow: 0 16px 36px rgba(2, 6, 23, 0.5);
            color: #e2e8f0;
        }

        .chat-upload-progress-title {
            font-size: 12px;
            font-weight: 900;
            margin-bottom: 8px;
        }
        .chat-upload-progress-cancel {
            border: 1px solid rgba(248, 113, 113, .7);
            border-radius: 999px;
            background: rgba(127, 29, 29, .28);
            color: #fecaca;
            padding: 6px 12px;
            font: inherit;
            font-weight: 800;
            cursor: pointer;
            margin: 2px 0 8px;
        }

        .chat-upload-progress-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
            padding: 5px 0;
            border-top: 1px solid rgba(148, 163, 184, 0.14);
            font-size: 11px;
        }

        .chat-upload-progress-name {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .chat-upload-progress-state { color: #93c5fd; font-weight: 800; white-space: nowrap; }
        .chat-upload-progress-state.is-complete { color: #86efac; }
        .chat-upload-progress-state.is-failed { color: #fca5a5; }

        .chat-action-toast {
            position: fixed;
            left: 50%;
            bottom: calc(18px + env(safe-area-inset-bottom));
            transform: translate(-50%, 14px);
            z-index: 1400;
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 10px 12px;
            border-radius: 14px;
            border: 1px solid rgba(148, 163, 184, 0.35);
            background: rgba(2, 6, 23, 0.92);
            color: #e2e8f0;
            min-width: min(88vw, 360px);
            max-width: min(92vw, 420px);
            box-shadow: 0 14px 34px rgba(2, 6, 23, 0.45);
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.2s ease, transform 0.2s ease;
        }

        .chat-action-toast.show {
            opacity: 1;
            transform: translate(-50%, 0);
            pointer-events: auto;
        }

        .chat-action-toast-text {
            flex: 1;
            font-size: 12px;
            font-weight: 700;
            line-height: 1.3;
            color: #e2e8f0;
        }

        .chat-action-toast-btn {
            border: 1px solid rgba(59, 130, 246, 0.75);
            background: rgba(30, 64, 175, 0.28);
            color: #dbeafe;
            border-radius: 999px;
            padding: 6px 10px;
            font-size: 11px;
            font-weight: 800;
            cursor: pointer;
            white-space: nowrap;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            min-height: 30px;
        }

        .chat-action-toast-btn:hover {
            background: rgba(30, 64, 175, 0.46);
        }

        .jump-latest {
            position: absolute;
            right: 18px;
            bottom: calc(var(--composer-h) + 14px);
            border: 1px solid rgba(148, 163, 184, 0.28);
            background: rgba(2, 6, 23, 0.88);
            color: #e5e7eb;
            padding: 8px 12px;
            border-radius: 999px;
            font-size: 12px;
            font-weight: 700;
            cursor: pointer;
            display: none;
            z-index: 18;
            backdrop-filter: blur(8px);
            box-shadow: 0 14px 32px rgba(2, 6, 23, 0.34);
        }

        .jump-latest:hover {
            border-color: rgba(37, 99, 235, 0.8);
            background: rgba(15, 23, 42, 0.92);
        }

        .chat-history-top {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 8px;
            margin-bottom: 8px;
        }

        .chat-history-top.is-hidden {
            display: none;
        }

        .chat-history-top-btn {
            border: 1px solid rgba(148, 163, 184, 0.3);
            background: rgba(30, 41, 59, 0.82);
            color: #e2e8f0;
            border-radius: 999px;
            padding: 7px 12px;
            font-size: 11px;
            font-weight: 800;
            letter-spacing: 0.03em;
            cursor: pointer;
        }

        .chat-history-top-btn:hover {
            border-color: rgba(96, 165, 250, 0.55);
            background: rgba(30, 64, 175, 0.25);
        }

        .chat-history-top-btn:disabled {
            opacity: 0.6;
            cursor: wait;
        }

        .chat-history-top-status {
            color: #94a3b8;
            font-size: 11px;
            font-weight: 700;
        }

        .chat-history-sentinel {
            width: 100%;
            height: 1px;
            margin-bottom: 2px;
        }

        .msg-date-divider {
            display: flex;
            align-items: center;
            gap: 10px;
            margin: 14px 0 10px;
            color: #94a3b8;
            font-size: 10px;
            font-weight: 800;
            letter-spacing: 0.12em;
            text-transform: uppercase;
        }

        .msg-date-divider::before,
        .msg-date-divider::after {
            content: "";
            flex: 1 1 auto;
            height: 1px;
            background: rgba(148, 163, 184, 0.16);
        }

        .msg-day-media-toggle {
            width: min(280px, 88%);
            margin: 0 auto 10px;
            display: grid;
            gap: 4px;
            border: 1px solid rgba(96, 165, 250, 0.24);
            background: rgba(15, 23, 42, 0.76);
            color: #dbeafe;
            border-radius: 16px;
            padding: 10px 12px;
            text-align: left;
            cursor: pointer;
        }

        .msg-day-media-toggle strong {
            font-size: 12px;
            font-weight: 800;
        }

        .msg-day-media-toggle span {
            font-size: 11px;
            color: #93c5fd;
            line-height: 1.4;
        }

        .msg-day-media-toggle:hover {
            border-color: rgba(96, 165, 250, 0.42);
            background: rgba(30, 41, 59, 0.9);
        }

        .msg {
            margin-bottom: 6px;
            max-width: 80%;
            min-width: 0;
            padding: 8px 10px;
            border-radius: 12px;
            line-height: 1.35;
            position: relative;
            overflow-wrap: anywhere;
            word-break: break-word;
        }

        .msg-text,
        .msg-text a {
            overflow-wrap: anywhere;
            word-break: break-word;
        }

        .msg-link {
            text-decoration: underline;
            text-decoration-thickness: 1.5px;
            text-underline-offset: 2px;
        }

        .msg.me .msg-link {
            color: #dbeafe;
        }

        .msg.them .msg-link {
            color: #93c5fd;
        }

        .msg.me {
            margin-left: auto;
            /* push to right */
            margin-right: 0;
            background: #1d4ed8;
            color: white;
            text-align: right;
        }

        .msg.them {
            margin-right: auto;
            /* push to left */
            margin-left: 0;
            background: #020617;
            border: 1px solid rgba(30, 64, 175, 0.7);
            text-align: left;
        }

        .msg-sender {
            display: flex;
            align-items: center;
            gap: 6px;
            margin-bottom: 6px;
            min-width: 0;
            font-size: 10px;
            font-weight: 900;
            letter-spacing: 0.08em;
            text-transform: uppercase;
            opacity: 0.92;
        }

        .msg.me .msg-sender {
            justify-content: flex-end;
            color: rgba(219, 234, 254, 0.96);
        }

        .msg.them .msg-sender {
            justify-content: flex-start;
            color: #bfdbfe;
        }

        .msg-sender-avatar {
            width: 18px;
            height: 18px;
            border-radius: 999px;
            object-fit: cover;
            flex: 0 0 18px;
            border: 1px solid rgba(148, 163, 184, 0.44);
            background: rgba(15, 23, 42, 0.86);
        }

        .msg-sender-avatar.is-default {
            object-fit: contain;
            padding: 2px;
        }

        .msg-sender-name {
            min-width: 0;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .msg-photo-group .msg-sender {
            padding: 0 2px;
        }

        .msg.system {
            margin: 8px auto;
            max-width: min(320px, 92%);
            background: rgba(15, 23, 42, 0.78);
            border: 1px solid rgba(56, 189, 248, 0.24);
            color: #cbd5e1;
            text-align: center;
            font-size: 13px;
            padding: 8px 12px;
        }

        .composer {
            display: flex;
            gap: 8px;
            margin-top: 10px;

            position: sticky;
            bottom: 0;
            background: rgba(2, 6, 23, 0.92);
            padding: 10px 0;
            border-top: 1px solid rgba(148, 163, 184, 0.18);
            z-index: 5;
            flex-shrink: 0;
        }

        .composer input {
            flex: 1;
            min-width: 0;
            padding: 10px;
            border-radius: 999px;
            border: 1px solid #334155;
            background: #020617;
            color: var(--text);
        }

        .composer button {
            flex: 0 0 auto;
            border-radius: 999px;
            padding: 0 16px;
            border: 0;
            background: var(--accent);
            color: #fff;
            font-weight: 600;
            cursor: pointer;
        }

        .composer button:hover {
            background: var(--accentHover);
        }

        .attach-btn {
            width: 42px;
            min-width: 42px;
            padding: 0;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-size: 18px;
        }

        .attach-btn svg {
            width: 27px;
            height: 27px;
            display: block;
        }

        .msg-media {
            width: 240px;
            max-width: 72vw;
            border-radius: 12px;
            overflow: hidden;
            border: 1px solid rgba(148, 163, 184, 0.22);
            background: rgba(2, 6, 23, 0.6);
            position: relative;
        }

        .msg-media.is-clickable {
            cursor: pointer;
        }

        .msg-media img,
        .msg-media video {
            width: 100%;
            height: auto;
            display: block;
        }

        .msg-audio-card {
            width: 240px;
            max-width: 72vw;
            padding: 12px;
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .msg-audio-meta {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
            font-size: 12px;
            color: rgba(226, 232, 240, 0.84);
            font-weight: 800;
        }

        .msg-audio-kind {
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }

        .msg-audio-duration {
            color: rgba(191, 219, 254, 0.92);
        }

        .msg-audio-card audio {
            width: 100%;
            display: block;
        }

        .msg-location-card {
            width: 240px;
            max-width: 72vw;
            display: flex;
            flex-direction: column;
            gap: 8px;
            padding: 2px 0;
        }

        .msg-location-pill {
            align-self: flex-start;
            padding: 4px 8px;
            border-radius: 999px;
            background: rgba(15, 23, 42, 0.28);
            border: 1px solid rgba(191, 219, 254, 0.24);
            font-size: 10px;
            font-weight: 900;
            letter-spacing: 0.08em;
            text-transform: uppercase;
        }

        .msg-location-title {
            font-size: 15px;
            font-weight: 800;
            line-height: 1.3;
        }

        .msg-location-subtitle {
            font-size: 13px;
            line-height: 1.45;
            opacity: 0.92;
            word-break: break-word;
        }

        .msg-location-link {
            align-self: flex-start;
            margin-top: 2px;
            padding: 8px 12px;
            border-radius: 10px;
            border: 1px solid rgba(191, 219, 254, 0.24);
            background: rgba(15, 23, 42, 0.18);
            color: inherit;
            text-decoration: none;
            font-size: 12px;
            font-weight: 800;
        }

        .msg-location-link[aria-disabled="true"] {
            opacity: 0.58;
            cursor: default;
        }

        .msg.them .msg-location-pill,
        .msg.them .msg-location-link {
            background: rgba(30, 41, 59, 0.86);
        }

        .msg-photo-group {
            padding: 6px;
            border-radius: 16px;
        }

        .msg.me.msg-photo-group {
            background: linear-gradient(145deg, #2563eb 0%, #1d4ed8 100%);
        }

        .msg.them.msg-photo-group {
            background: linear-gradient(145deg, rgba(2, 6, 23, 0.98) 0%, rgba(15, 23, 42, 0.95) 100%);
            border: 1px solid rgba(59, 130, 246, 0.32);
        }

        .msg-photo-grid {
            width: 240px;
            max-width: 72vw;
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 4px;
        }

        .msg-photo-grid-item {
            position: relative;
            display: block;
            width: 100%;
            aspect-ratio: 1 / 1;
            border: 0;
            margin: 0;
            padding: 0;
            border-radius: 10px;
            overflow: hidden;
            cursor: pointer;
            background: rgba(2, 6, 23, 0.58);
            box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.22);
        }

        .msg-photo-grid-item:disabled {
            cursor: default;
        }

        .msg-photo-grid-item:focus-visible {
            outline: 2px solid rgba(191, 219, 254, 0.95);
            outline-offset: 2px;
        }

        .msg-photo-grid-item img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            display: block;
        }

        .msg-photo-grid-more {
            position: absolute;
            inset: 0;
            display: grid;
            place-items: center;
            color: #fff;
            font-size: 20px;
            font-weight: 900;
            letter-spacing: 0.02em;
            background: rgba(2, 6, 23, 0.58);
            backdrop-filter: blur(2px);
        }

        .msg-photo-grid-count {
            margin-top: 6px;
            display: inline-block;
            padding: 2px 8px;
            border-radius: 999px;
            font-size: 10px;
            font-weight: 800;
            letter-spacing: 0.08em;
            text-transform: uppercase;
        }

        .msg.me .msg-photo-grid-count {
            color: rgba(219, 234, 254, 0.95);
            background: rgba(15, 23, 42, 0.28);
        }

        .msg.them .msg-photo-grid-count {
            color: #bfdbfe;
            background: rgba(30, 64, 175, 0.22);
        }

        .msg.is-highlighted,
        .msg-photo-group.is-highlighted {
            box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.75), 0 0 22px rgba(250, 204, 21, 0.22);
            animation: chatHighlightPulse 2.8s ease;
        }

        @keyframes chatHighlightPulse {
            0% {
                box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.85), 0 0 24px rgba(250, 204, 21, 0.28);
            }

            100% {
                box-shadow: 0 0 0 2px rgba(250, 204, 21, 0), 0 0 0 rgba(250, 204, 21, 0);
            }
        }

        .thread-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
        }

        .thread-main {
            display: flex;
            flex-direction: column;
            min-width: 0;
            flex: 1;
        }

        .thread-item.is-support-thread .thread-main {
            justify-content: center;
        }

        .thread-label {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .thread-meta {
            font-size: 11px;
            color: #94a3b8;
            margin-top: 2px;
            min-height: 14px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .thread-meta.is-empty {
            visibility: hidden;
        }

        .thread-item.is-support-thread .thread-meta {
            display: none;
        }

        .thread-inline-actions {
            display: flex;
            gap: 6px;
            margin-top: 8px;
        }

        .thread-inline-btn {
            border: 1px solid rgba(148, 163, 184, 0.35);
            border-radius: 999px;
            background: rgba(148, 163, 184, 0.14);
            color: #e2e8f0;
            font-size: 11px;
            font-weight: 800;
            padding: 6px 9px;
            cursor: pointer;
        }

        .thread-inline-btn.is-primary {
            background: rgba(37, 99, 235, 0.24);
            border-color: rgba(59, 130, 246, 0.45);
        }

        .thread-toolbar {
            display: flex;
            flex-direction: column;
            gap: 8px;
            margin: 2px 0 10px;
        }

        .thread-toolbar-row {
            display: grid;
            grid-template-columns: repeat(3, minmax(0, 1fr));
            gap: 8px;
        }

        .thread-toolbar-pill {
            appearance: none;
            min-height: 44px;
            border-radius: 999px;
            border: 1px solid rgba(96, 165, 250, 0.22);
            background: rgba(15, 23, 42, 0.92);
            color: #e2e8f0;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            padding: 0 14px;
            font-size: 12px;
            font-weight: 800;
            letter-spacing: 0.02em;
            cursor: pointer;
            box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
        }

        .thread-toolbar-pill:hover {
            border-color: rgba(96, 165, 250, 0.42);
            background: rgba(30, 41, 59, 0.96);
        }

        .thread-toolbar-pill:disabled {
            opacity: 0.58;
            cursor: not-allowed;
        }

        .thread-toolbar-pill[aria-pressed="true"] {
            border-color: rgba(56, 189, 248, 0.48);
            background: rgba(30, 64, 175, 0.26);
            color: #eff6ff;
        }

        .thread-toolbar-pill svg {
            width: 18px;
            height: 18px;
            flex: 0 0 18px;
        }

        .thread-toolbar-pill-logo svg {
            width: 22px;
            height: 22px;
            flex-basis: 22px;
        }

        .thread-toolbar-search {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 8px 10px;
            border-radius: 18px;
            border: 1px solid rgba(96, 165, 250, 0.18);
            background: rgba(10, 16, 34, 0.86);
        }

        .thread-toolbar-search-input {
            width: 100%;
            min-width: 0;
            border: none;
            background: transparent;
            color: #eff6ff;
            font: inherit;
            font-size: 13px;
        }

        .thread-toolbar-search-input::placeholder {
            color: #64748b;
        }

        .thread-toolbar-search-input:focus {
            outline: none;
        }

        .thread-toolbar-search-clear {
            appearance: none;
            border: 1px solid rgba(148, 163, 184, 0.22);
            background: rgba(30, 41, 59, 0.9);
            color: #cbd5e1;
            border-radius: 999px;
            padding: 6px 10px;
            font-size: 11px;
            font-weight: 800;
            cursor: pointer;
            flex: 0 0 auto;
        }

        .thread-toolbar-bulkbar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
            flex-wrap: wrap;
            padding: 10px 12px;
            border-radius: 18px;
            border: 1px solid rgba(248, 113, 113, 0.18);
            background: rgba(38, 12, 18, 0.7);
        }

        .thread-toolbar-bulkcopy {
            color: #fecaca;
            font-size: 12px;
            font-weight: 800;
        }

        .thread-toolbar-bulkactions {
            display: flex;
            align-items: center;
            gap: 8px;
            flex-wrap: wrap;
        }

        .thread-toolbar-mini {
            appearance: none;
            border-radius: 999px;
            border: 1px solid rgba(148, 163, 184, 0.22);
            background: rgba(15, 23, 42, 0.94);
            color: #eff6ff;
            padding: 7px 11px;
            font-size: 11px;
            font-weight: 800;
            cursor: pointer;
        }

        .thread-toolbar-mini.danger {
            border-color: rgba(248, 113, 113, 0.3);
            background: rgba(153, 27, 27, 0.26);
            color: #fecaca;
        }

        .thread-toolbar-mini:disabled {
            opacity: 0.55;
            cursor: not-allowed;
        }

        .thread-avatar {
            width: 34px;
            height: 34px;
            border-radius: 10px;
            object-fit: cover;
            flex: 0 0 34px;
            border: 2px solid rgba(148, 163, 184, 0.45);
            background: rgba(2, 6, 23, 0.6);
        }

        .thread-avatar.is-active,
        .chat-avatar.is-active {
            border-color: #22c55e;
            box-shadow:
                0 0 0 3px rgba(34, 197, 94, 0.22),
                0 0 12px rgba(34, 197, 94, 0.55);
        }

        .thread-avatar.is-recent,
        .chat-avatar.is-recent {
            border-color: #f59e0b;
            box-shadow:
                0 0 0 3px rgba(245, 158, 11, 0.2),
                0 0 12px rgba(245, 158, 11, 0.55);
        }

        .thread-avatar.is-offline,
        .chat-avatar.is-offline {
            border-color: rgba(148, 163, 184, 0.55);
            box-shadow: none;
        }

        .thread-avatar.is-default,
        .chat-avatar.is-default,
        .profile-card-avatar.is-default {
            border: none;
            box-shadow: none;
            background: transparent;
            object-fit: contain;
            padding: 3px;
        }

        .thread-avatar.is-support {
            padding: 4px;
            object-fit: contain;
            background: rgba(2, 6, 23, 0.96);
        }

        .thread-avatar.is-seen-invite {
            border: none;
            box-shadow: none;
            background: transparent;
            object-fit: contain;
            padding: 0;
        }

        .thread-select-indicator {
            width: 24px;
            height: 24px;
            border-radius: 999px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            color: #94a3b8;
            background: rgba(15, 23, 42, 0.96);
            border: 1px solid rgba(148, 163, 184, 0.24);
            flex: 0 0 24px;
        }

        .thread-select-indicator svg {
            width: 14px;
            height: 14px;
        }

        .thread-select-indicator.is-selected {
            color: #dcfce7;
            background: rgba(21, 128, 61, 0.32);
            border-color: rgba(34, 197, 94, 0.46);
        }

        .thread-select-indicator.is-locked {
            color: #64748b;
            background: rgba(15, 23, 42, 0.72);
        }

        .thread-item.is-bulk-mode {
            cursor: pointer;
        }

        .thread-item.is-bulk-mode:hover {
            background: rgba(22, 32, 58, 0.96);
        }

        .thread-item.is-selected {
            border-color: rgba(56, 189, 248, 0.5);
            background: rgba(29, 78, 216, 0.24);
            box-shadow: inset 0 0 0 1px rgba(125, 211, 252, 0.16);
        }

        .thread-item.is-bulk-protected {
            opacity: 0.7;
            cursor: default;
        }

        .eye-btn {
            width: 40px;
            height: 40px;
            padding: 0;
            border-radius: 50%;
            background: transparent;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .eye-btn img {
            width: 22px;
            height: 22px;
            opacity: 0.9;
        }

        .eye-btn:active img {
            transform: scale(0.95);
        }

        .media-icon {
            width: 22px;
            height: 22px;
            opacity: 0.95;
        }

        .media-menu {
            position: absolute;
            left: 14px;
            bottom: 78px;
            /* sits above composer */
            width: 280px;
            border-radius: 14px;
            border: 1px solid rgba(148, 163, 184, 0.22);
            background: rgba(2, 6, 23, 0.96);
            box-shadow: 0 16px 60px rgba(0, 0, 0, 0.55);
            backdrop-filter: blur(10px);
            z-index: 80;
            padding: 10px;
        }

        .media-action-menu {
            position: absolute;
            left: 14px;
            bottom: 78px;
            width: min(230px, calc(100% - 28px));
            border-radius: 14px;
            border: 1px solid rgba(148, 163, 184, 0.22);
            background: rgba(2, 6, 23, 0.96);
            box-shadow: 0 16px 48px rgba(0, 0, 0, 0.42);
            backdrop-filter: blur(10px);
            z-index: 82;
            padding: 8px;
        }

        .voice-note-sheet {
            position: absolute;
            left: 14px;
            bottom: 78px;
            width: min(300px, calc(100% - 28px));
            border-radius: 16px;
            border: 1px solid rgba(148, 163, 184, 0.22);
            background: rgba(2, 6, 23, 0.97);
            box-shadow: 0 18px 56px rgba(0, 0, 0, 0.52);
            backdrop-filter: blur(10px);
            z-index: 83;
            padding: 12px;
        }

        .location-share-sheet {
            position: absolute;
            left: 14px;
            bottom: 78px;
            width: min(320px, calc(100% - 28px));
            border-radius: 16px;
            border: 1px solid rgba(148, 163, 184, 0.22);
            background: rgba(2, 6, 23, 0.97);
            box-shadow: 0 18px 56px rgba(0, 0, 0, 0.52);
            backdrop-filter: blur(10px);
            z-index: 84;
            padding: 12px;
        }

        .voice-note-sheet-head {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
            margin-bottom: 10px;
        }

        .voice-note-sheet-title {
            display: flex;
            flex-direction: column;
            gap: 3px;
        }

        .voice-note-sheet-title strong {
            font-size: 14px;
            letter-spacing: 0.01em;
        }

        .voice-note-sheet-title span {
            color: rgba(203, 213, 225, 0.72);
            font-size: 12px;
        }

        .location-share-status {
            margin: 0 0 12px;
            color: rgba(226, 232, 240, 0.92);
            font-size: 12px;
            line-height: 1.45;
        }

        .location-share-status.is-error {
            color: #fecaca;
        }

        .location-share-status.is-info {
            color: #bfdbfe;
        }

        .location-share-status.is-success {
            color: #bbf7d0;
        }

        .location-share-actions {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .location-share-editor-backdrop {
            position: fixed;
            inset: 0;
            z-index: 91;
            display: none;
            align-items: center;
            justify-content: center;
            padding: 18px;
            background: rgba(2, 6, 23, 0.54);
            backdrop-filter: blur(10px);
        }

        .location-share-editor-modal {
            width: min(360px, calc(100vw - 36px));
            border-radius: 22px;
            border: 1px solid rgba(148, 163, 184, 0.18);
            background: rgba(2, 6, 23, 0.98);
            box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4);
            padding: 16px;
        }

        .location-share-editor-body {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .location-share-input {
            width: 100%;
            padding: 13px 14px;
            border-radius: 14px;
            border: 1px solid rgba(148, 163, 184, 0.22);
            background: rgba(15, 23, 42, 0.9);
            color: #f8fafc;
            font-size: 14px;
        }

        .location-share-input::placeholder {
            color: rgba(148, 163, 184, 0.9);
        }

        .location-share-action {
            width: 100%;
            border: 1px solid rgba(148, 163, 184, 0.18);
            background: rgba(148, 163, 184, 0.10);
            color: rgba(229, 231, 235, 0.96);
            padding: 13px 14px;
            border-radius: 14px;
            font-weight: 700;
            font-size: 14px;
            cursor: pointer;
        }

        .location-share-action:hover {
            background: rgba(148, 163, 184, 0.16);
        }

        .location-share-action.primary {
            background: rgba(248, 250, 252, 0.98);
            border-color: rgba(226, 232, 240, 0.96);
            color: #0f172a;
        }

        .location-share-action:disabled {
            opacity: 0.58;
            cursor: default;
        }

        .voice-note-close {
            width: 34px;
            height: 34px;
            border-radius: 999px;
            border: 1px solid rgba(148, 163, 184, 0.22);
            background: rgba(15, 23, 42, 0.96);
            color: rgba(226, 232, 240, 0.94);
            font-size: 18px;
            font-weight: 700;
            cursor: pointer;
        }

        .voice-note-status {
            min-height: 36px;
            margin-bottom: 10px;
            color: rgba(226, 232, 240, 0.92);
            font-size: 13px;
            line-height: 1.45;
        }

        .voice-note-status.is-error {
            color: #fecaca;
        }

        .voice-note-status.is-info {
            color: #bfdbfe;
        }

        .voice-note-timer-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
            padding: 10px 12px;
            border-radius: 12px;
            border: 1px solid rgba(148, 163, 184, 0.18);
            background: rgba(15, 23, 42, 0.86);
            margin-bottom: 10px;
        }

        .voice-note-indicator {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            font-size: 12px;
            font-weight: 800;
            letter-spacing: 0.04em;
            text-transform: uppercase;
            color: rgba(226, 232, 240, 0.86);
        }

        .voice-note-indicator-dot {
            width: 10px;
            height: 10px;
            border-radius: 999px;
            background: rgba(239, 68, 68, 0.95);
            box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6);
        }

        .voice-note-indicator.is-recording .voice-note-indicator-dot {
            animation: voice-note-pulse 1.2s ease-in-out infinite;
        }

        @keyframes voice-note-pulse {
            0% {
                box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.52);
            }

            70% {
                box-shadow: 0 0 0 9px rgba(239, 68, 68, 0);
            }

            100% {
                box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
            }
        }

        .voice-note-timer {
            font-size: 18px;
            font-weight: 900;
            letter-spacing: 0.03em;
            color: #f8fafc;
        }

        .voice-note-preview {
            display: none;
            margin-bottom: 10px;
            padding: 10px 12px;
            border-radius: 12px;
            border: 1px solid rgba(148, 163, 184, 0.18);
            background: rgba(15, 23, 42, 0.86);
        }

        .voice-note-preview.open {
            display: block;
        }

        .voice-note-preview-meta {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
            margin-bottom: 8px;
            font-size: 12px;
            color: rgba(203, 213, 225, 0.82);
            font-weight: 700;
        }

        .voice-note-preview audio {
            width: 100%;
            display: block;
        }

        .voice-note-actions {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 8px;
        }

        .voice-note-action {
            border: 1px solid rgba(148, 163, 184, 0.18);
            background: rgba(148, 163, 184, 0.10);
            color: rgba(229, 231, 235, 0.96);
            padding: 10px 12px;
            border-radius: 12px;
            font-weight: 800;
            font-size: 13px;
            cursor: pointer;
        }

        .voice-note-action:hover {
            background: rgba(148, 163, 184, 0.16);
        }

        .voice-note-action.primary {
            background: linear-gradient(135deg, rgba(37, 99, 235, 0.98), rgba(29, 78, 216, 0.98));
            border-color: rgba(96, 165, 250, 0.42);
            color: #fff;
        }

        .voice-note-action.record {
            background: linear-gradient(135deg, rgba(15, 118, 110, 0.98), rgba(6, 95, 70, 0.98));
            border-color: rgba(45, 212, 191, 0.36);
            color: #fff;
        }

        .voice-note-action.danger {
            background: rgba(127, 29, 29, 0.9);
            border-color: rgba(248, 113, 113, 0.3);
            color: #fff;
        }

        .voice-note-action:disabled,
        .voice-note-close:disabled {
            opacity: 0.58;
            cursor: default;
        }

        .media-action-item {
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: flex-start;
            gap: 10px;
            border: 1px solid rgba(148, 163, 184, 0.18);
            background: rgba(148, 163, 184, 0.1);
            color: rgba(229, 231, 235, 0.96);
            padding: 11px 12px;
            border-radius: 12px;
            font-weight: 800;
            font-size: 13px;
            cursor: pointer;
        }

        .media-action-item:hover {
            background: rgba(148, 163, 184, 0.16);
        }

        .media-action-divider {
            height: 1px;
            margin: 8px 6px 10px;
            background: linear-gradient(90deg, rgba(148, 163, 184, 0), rgba(148, 163, 184, 0.32), rgba(148, 163, 184, 0));
        }

        .media-action-divider[hidden] {
            display: none !important;
        }

        .media-action-item.danger {
            border-color: rgba(239, 68, 68, 0.32);
            background: rgba(127, 29, 29, 0.28);
            color: #fecaca;
        }

        .media-action-item.danger:hover {
            background: rgba(153, 27, 27, 0.34);
        }

        .media-action-item svg {
            width: 16px;
            height: 16px;
            flex: 0 0 auto;
            opacity: 0.92;
        }

        .media-menu-tabs {
            display: flex;
            gap: 8px;
            margin-bottom: 10px;
        }

        .media-menu-actions {
            display: flex;
            gap: 8px;
            margin-bottom: 10px;
        }

        .media-menu-action-btn {
            flex: 1;
            border: 1px solid rgba(148, 163, 184, 0.18);
            background: rgba(148, 163, 184, 0.10);
            color: rgba(229, 231, 235, 0.95);
            padding: 9px 10px;
            border-radius: 12px;
            font-weight: 800;
            font-size: 12px;
            cursor: pointer;
        }

        .media-menu-action-btn:hover {
            background: rgba(148, 163, 184, 0.16);
        }

        .media-menu-tab {
            flex: 1;
            border: 1px solid rgba(148, 163, 184, 0.18);
            background: rgba(148, 163, 184, 0.10);
            color: rgba(229, 231, 235, 0.95);
            padding: 8px 10px;
            border-radius: 999px;
            font-weight: 800;
            font-size: 12px;
            cursor: pointer;
        }

        .media-menu-tab.is-active {
            background: rgba(37, 99, 235, 0.28);
            border-color: rgba(37, 99, 235, 0.38);
        }

        .media-menu-seen-plus-tab-wrap {
            display: flex;
            flex: 1;
            gap: 4px;
            min-width: 0;
        }

        .media-menu-seen-plus-tab-wrap .media-menu-tab {
            min-width: 0;
        }

        .media-menu-seen-plus-lock {
            align-self: center;
            flex: 0 0 44px;
            width: 44px;
            height: 44px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border: 0;
            border-radius: 999px;
            background: transparent;
            cursor: pointer;
            padding: 0;
        }

        .media-menu-seen-plus-lock::before {
            content: '🔒';
            width: 27px;
            height: 27px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border: 1px solid rgba(250, 204, 21, 0.62);
            border-radius: 999px;
            background: rgba(15, 23, 42, 0.92);
            color: #fde68a;
            font-size: 12px;
            line-height: 1;
        }

        .media-menu-seen-plus-lock:hover::before,
        .media-menu-seen-plus-lock:focus-visible::before {
            border-color: #fde68a;
            color: #fff7c2;
        }

        .media-menu-body {
            margin-bottom: 10px;
        }

        .media-menu-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 6px;
            height: 220px;
            max-height: 220px;
            align-content: start;
            align-items: start;
            grid-auto-rows: min-content;
            overflow: auto;
            padding-right: 2px;
        }

        .media-menu-item {
            position: relative;
            width: 100%;
            aspect-ratio: 1 / 1;
            border-radius: 12px;
            overflow: hidden;
            border: 1px solid rgba(148, 163, 184, 0.20);
            background: rgba(15, 23, 42, 0.75);
            cursor: pointer;
        }

        .media-menu-item img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            display: block;
        }

        .media-menu-item.is-selected {
            border-color: rgba(34, 197, 94, 0.65);
            box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
        }

        .media-menu-check {
            position: absolute;
            bottom: 6px;
            right: 6px;
            width: 22px;
            height: 22px;
            border-radius: 999px;
            border: 1px solid rgba(34, 197, 94, 0.8);
            background: rgba(6, 95, 70, 0.9);
            color: #ecfdf3;
            font-size: 12px;
            font-weight: 900;
            display: flex;
            align-items: center;
            justify-content: center;
            opacity: 0;
            transform: scale(0.92);
            transition: opacity 0.15s ease, transform 0.15s ease;
        }

        .media-menu-item.is-selected .media-menu-check {
            opacity: 1;
            transform: scale(1);
        }

        .media-menu-empty {
            grid-column: 1 / -1;
            color: rgba(156, 163, 175, 0.95);
            font-size: 12px;
            font-weight: 700;
            padding: 8px 4px;
        }

        .media-menu-status {
            color: rgba(156, 163, 175, 0.95);
            font-size: 12px;
            font-weight: 700;
        }

        .media-menu-status.is-warn {
            color: #fbbf24;
        }

        .media-menu-status.is-info {
            color: #93c5fd;
        }

        .media-menu-footer {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .private-queue-actions {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
        }

        .private-queue-action {
            min-height: 40px;
            border: 1px solid rgba(96, 165, 250, 0.52);
            border-radius: 999px;
            background: rgba(30, 64, 175, 0.22);
            color: #bfdbfe;
            cursor: pointer;
            font-size: 12px;
            font-weight: 800;
            padding: 8px 13px;
        }

        .private-queue-action.is-remove {
            border-color: rgba(248, 113, 113, 0.5);
            background: rgba(127, 29, 29, 0.2);
            color: #fecaca;
        }

        .private-queue-action:disabled {
            cursor: wait;
            opacity: 0.55;
        }

        .media-menu-upgrade-btn {
            align-self: flex-start;
            border: 1px solid rgba(250, 204, 21, 0.55);
            border-radius: 999px;
            background: linear-gradient(135deg, rgba(250, 204, 21, 0.2), rgba(249, 115, 22, 0.18));
            color: #fde68a;
            cursor: pointer;
            font-size: 12px;
            font-weight: 800;
            padding: 7px 12px;
        }

        .media-menu-upgrade-btn:hover,
        .media-menu-upgrade-btn:focus-visible {
            border-color: rgba(250, 204, 21, 0.9);
            color: #fff7c2;
        }

        .media-menu-move-btn {
            align-self: flex-start;
            border: 1px solid rgba(148, 163, 184, 0.3);
            border-radius: 999px;
            background: rgba(15, 23, 42, 0.72);
            color: #cbd5e1;
            font-size: 12px;
            font-weight: 800;
            padding: 7px 12px;
        }

        .media-menu-move-btn:not(:disabled) {
            cursor: pointer;
        }

        .media-menu-move-btn:not(:disabled):hover,
        .media-menu-move-btn:not(:disabled):focus-visible {
            border-color: rgba(96, 165, 250, 0.7);
            color: #dbeafe;
        }

        .media-menu-action-btn:disabled {
            opacity: 0.55;
            cursor: not-allowed;
        }

        .media-menu-remove {
            position: absolute;
            top: 6px;
            right: 6px;
            width: 22px;
            height: 22px;
            border-radius: 999px;
            border: 1px solid rgba(148, 163, 184, 0.22);
            background: rgba(2, 6, 23, 0.75);
            color: rgba(229, 231, 235, 0.95);
            font-weight: 900;
            line-height: 20px;
            cursor: pointer;
        }

        /* Mobile: single-pane chat UX (threads OR chat, not both stacked) */
        @media (max-width: 720px) {
            .chat-shell {
                display: block;
            }

            /* Default (mobile): show thread list only */
            .thread-list {
                display: block;
                height: 100%;
                max-height: none;
                padding: 10px;
                overflow-y: auto;
                overflow-x: hidden;
                border-right: 0;
                border-bottom: 0;
            }

            .chat-panel {
                height: 100%;
                padding: 10px;
                min-height: 0;
                display: none;
                /* hidden until a thread is opened */
            }

            /* When a thread is opened: show chat only */
            body.mobile-chat-open .thread-list {
                display: none;
            }

            body.mobile-chat-open .chat-panel {
                display: flex;
                padding-top: calc(env(safe-area-inset-top) + 10px);
            }

            /* Header layout when back button exists */
            .chat-header {
                justify-content: center;
            }

            .chat-back {
                display: none;
            }

            body.mobile-chat-open .chat-back {
                display: inline-flex;
            }

            .chat-details-btn-mobile {
                font-size: 11px;
                padding: 5px 10px;
            }

            .chat-handle {
                flex: 1;
                text-align: center;
            }

            .composer input {
                font-size: 16px;
                min-height: 44px;
            }

            .composer button {
                min-height: 44px;
                padding: 0 16px;
                font-size: 16px;
            }

            .messages {
                font-size: 14px;
            }

            .msg-photo-grid {
                width: min(240px, 68vw);
                gap: 3px;
            }

            .msg-photo-grid-item {
                border-radius: 9px;
            }
        }

        .msg-time {
            font-size: 11px;
            opacity: 0.6;
            margin-top: 4px;
        }

        .msg-time-line {
            display: block;
        }

        .msg.me .msg-time {
            text-align: right;
        }

        .msg.them .msg-time {
            text-align: left;
        }

        .msg.system .msg-time {
            text-align: center;
        }

        .msg.is-optimistic .msg-media,
        .msg.is-optimistic .msg-photo-grid {
            opacity: 0.72;
        }

        .msg-send-status {
            margin-top: 5px;
            font-size: 11px;
            font-weight: 800;
            letter-spacing: 0.02em;
            text-align: right;
            color: #bfdbfe;
        }

        .msg.is-failed .msg-send-status {
            color: #fecaca;
        }

        .chat-header {
            --chat-header-aside-size: 92px;
            padding: 14px 16px 14px 104px;
            margin-bottom: 12px;
            border-radius: 12px;
            border: 1px solid rgba(148, 163, 184, 0.25);
            background: rgba(15, 23, 42, 0.55);
            display: grid;
            grid-template-columns: minmax(0, 1fr) auto;
            align-items: center;
            gap: 16px;
            position: relative;
        }

        .chat-video-banner {
            margin: -4px 0 12px;
            padding: 12px 14px;
            border-radius: 14px;
            border: 1px solid rgba(34, 211, 238, 0.28);
            background: linear-gradient(135deg, rgba(8, 47, 73, 0.9), rgba(15, 23, 42, 0.96));
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
        }

        .chat-video-banner[hidden] {
            display: none !important;
        }

        .chat-video-banner-copy {
            min-width: 0;
            display: flex;
            flex-direction: column;
            gap: 4px;
        }

        .chat-video-banner-title {
            font-size: 14px;
            font-weight: 800;
            color: #f8fafc;
        }

        .chat-video-banner-body {
            font-size: 12px;
            line-height: 1.45;
            color: rgba(226, 232, 240, 0.82);
        }

        .chat-video-banner-actions {
            display: flex;
            flex-wrap: wrap;
            justify-content: flex-end;
            gap: 8px;
        }

        .chat-video-banner-btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            min-height: 38px;
            padding: 0 14px;
            border-radius: 999px;
            border: 1px solid rgba(148, 163, 184, 0.22);
            background: rgba(15, 23, 42, 0.7);
            color: #e2e8f0;
            font-size: 12px;
            font-weight: 800;
            cursor: pointer;
        }

        .chat-video-banner-btn:hover {
            background: rgba(30, 41, 59, 0.92);
        }

        .chat-video-banner-btn.is-primary {
            border-color: rgba(34, 211, 238, 0.55);
            background: linear-gradient(135deg, rgba(37, 99, 235, 0.34), rgba(8, 145, 178, 0.34));
            color: #ecfeff;
        }

        .chat-video-banner-btn.is-danger {
            border-color: rgba(239, 68, 68, 0.45);
            color: #fecaca;
        }

        .chat-video-banner-btn:disabled {
            opacity: 0.55;
            cursor: not-allowed;
        }

        .chat-title {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 4px;
            min-width: 0;
            padding-top: 4px;
        }

        .chat-title-row {
            display: flex;
            align-items: center;
            justify-content: center;
            min-width: 0;
            width: 100%;
            max-width: 100%;
        }

        .chat-badge-row {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            min-height: 0;
            width: 100%;
        }

        .chat-back {
            display: none;
            align-items: center;
            justify-content: center;
            padding: 6px 10px;
            border-radius: 999px;
            border: 1px solid rgba(148, 163, 184, 0.28);
            background: rgba(2, 6, 23, 0.35);
            color: #e5e7eb;
            font-weight: 800;
            font-size: 13px;
            cursor: pointer;
        }

        .chat-back:hover {
            background: rgba(148, 163, 184, 0.18);
        }

        .chat-header-leading {
            position: absolute;
            left: 12px;
            top: 50%;
            transform: translateY(-50%);
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            gap: 8px;
        }

        .chat-header-aside {
            width: var(--chat-header-aside-size);
            min-width: var(--chat-header-aside-size);
            display: flex;
            align-items: stretch;
            justify-content: flex-end;
            position: relative;
            align-self: stretch;
        }

        .chat-header:not(.has-avatar) {
            grid-template-columns: minmax(0, 1fr);
        }

        .chat-header:not(.has-avatar) .chat-header-aside {
            display: none;
            width: 0;
            min-width: 0;
        }

        .chat-find-backdrop {
            position: absolute;
            inset: 0;
            background: rgba(2, 6, 23, 0.48);
            backdrop-filter: blur(4px);
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.18s ease;
            z-index: 16;
        }

        .chat-find-backdrop.open {
            opacity: 1;
            pointer-events: auto;
        }

        .chat-find-drawer {
            position: absolute;
            top: 10px;
            right: 10px;
            bottom: 10px;
            width: min(360px, calc(100% - 20px));
            display: grid;
            grid-template-rows: auto auto auto 1fr;
            gap: 12px;
            padding: 14px;
            border-radius: 22px;
            border: 1px solid rgba(96, 165, 250, 0.24);
            background: rgba(2, 6, 23, 0.96);
            box-shadow: 0 24px 54px rgba(2, 6, 23, 0.46);
            transform: translateX(calc(100% + 18px));
            transition: transform 0.2s ease;
            z-index: 17;
        }

        .chat-find-drawer.open {
            transform: translateX(0);
        }

        .chat-find-drawer.open~.composer {
            display: none !important;
        }

        .chat-find-head {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
        }

        .chat-find-title {
            display: grid;
            gap: 3px;
        }

        .chat-find-title strong {
            font-size: 16px;
            font-weight: 800;
            color: #e2e8f0;
        }

        .chat-find-title span {
            font-size: 11px;
            color: #94a3b8;
        }

        .chat-find-close {
            border: 1px solid rgba(148, 163, 184, 0.24);
            background: rgba(30, 41, 59, 0.8);
            color: #e2e8f0;
            border-radius: 999px;
            padding: 8px 12px;
            font-size: 12px;
            font-weight: 800;
            cursor: pointer;
        }

        .chat-find-close:hover {
            background: rgba(51, 65, 85, 0.92);
        }

        .chat-find-tabs {
            display: flex;
            gap: 8px;
        }

        .chat-find-tab {
            flex: 1 1 0;
            border: 1px solid rgba(148, 163, 184, 0.24);
            background: rgba(15, 23, 42, 0.9);
            color: #cbd5e1;
            border-radius: 999px;
            padding: 8px 12px;
            font-size: 12px;
            font-weight: 800;
            cursor: pointer;
        }

        .chat-find-tab.is-active {
            border-color: rgba(96, 165, 250, 0.48);
            background: rgba(30, 64, 175, 0.28);
            color: #eff6ff;
        }

        .chat-find-search-bar {
            display: flex;
            gap: 8px;
        }

        .chat-find-search-bar input {
            flex: 1 1 auto;
            border-radius: 14px;
            border: 1px solid rgba(51, 65, 85, 0.92);
            background: rgba(15, 23, 42, 0.94);
            color: #e2e8f0;
            padding: 10px 12px;
            font-size: 13px;
        }

        .chat-find-search-clear {
            border: 1px solid rgba(148, 163, 184, 0.24);
            background: rgba(15, 23, 42, 0.92);
            color: #cbd5e1;
            border-radius: 14px;
            padding: 0 12px;
            font-size: 11px;
            font-weight: 800;
            cursor: pointer;
        }

        .chat-find-search-clear:hover {
            background: rgba(30, 41, 59, 0.92);
        }

        .chat-find-status {
            font-size: 11px;
            font-weight: 700;
            color: #94a3b8;
        }

        .chat-find-status.is-warn {
            color: #fca5a5;
        }

        .chat-find-panel {
            min-height: 0;
            overflow-y: auto;
            display: none;
            gap: 10px;
            padding-right: 2px;
        }

        .chat-find-panel.open {
            display: grid;
        }

        .chat-find-result {
            border: 1px solid rgba(148, 163, 184, 0.18);
            background: rgba(15, 23, 42, 0.86);
            border-radius: 16px;
            padding: 10px 12px;
            display: grid;
            gap: 6px;
            text-align: left;
            color: #e2e8f0;
            cursor: pointer;
        }

        .chat-find-result:hover {
            border-color: rgba(96, 165, 250, 0.4);
            background: rgba(30, 41, 59, 0.96);
        }

        .chat-find-result-meta {
            font-size: 10px;
            font-weight: 800;
            letter-spacing: 0.08em;
            text-transform: uppercase;
            color: #93c5fd;
        }

        .chat-find-result-snippet {
            font-size: 13px;
            line-height: 1.45;
            color: #e2e8f0;
        }

        .chat-find-media-group {
            display: grid;
            gap: 8px;
        }

        .chat-find-media-date {
            font-size: 10px;
            font-weight: 800;
            letter-spacing: 0.12em;
            text-transform: uppercase;
            color: #94a3b8;
            padding-top: 4px;
        }

        .chat-find-media-grid {
            display: grid;
            grid-template-columns: repeat(3, minmax(0, 1fr));
            gap: 8px;
        }

        .chat-find-media-item {
            border: 1px solid rgba(148, 163, 184, 0.18);
            background: rgba(15, 23, 42, 0.92);
            border-radius: 14px;
            overflow: hidden;
            cursor: pointer;
            display: grid;
            gap: 0;
            padding: 0;
        }

        .chat-find-media-item img,
        .chat-find-media-item video {
            width: 100%;
            aspect-ratio: 1 / 1;
            object-fit: cover;
            display: block;
            background: rgba(2, 6, 23, 0.7);
        }

        .chat-find-media-caption {
            padding: 8px;
            font-size: 10px;
            font-weight: 700;
            color: #cbd5e1;
            background: rgba(15, 23, 42, 0.94);
        }

        .chat-find-load-more {
            justify-self: center;
            border: 1px solid rgba(148, 163, 184, 0.24);
            background: rgba(15, 23, 42, 0.92);
            color: #e2e8f0;
            border-radius: 999px;
            padding: 8px 14px;
            font-size: 11px;
            font-weight: 800;
            cursor: pointer;
        }

        .chat-find-load-more:hover {
            border-color: rgba(96, 165, 250, 0.42);
            background: rgba(30, 64, 175, 0.26);
        }

        .chat-handle {
            background: transparent;
            border: 0;
            color: #e5e7eb;
            font-weight: 700;
            font-size: 16px;
            cursor: pointer;
            padding: 6px 10px;
            border-radius: 999px;
            max-width: 100%;
            min-width: 0;
            flex: 1 1 auto;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .chat-handle:hover {
            background: rgba(148, 163, 184, 0.18);
        }

        .chat-seen-plus-badge {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border-radius: 999px;
            border: 1px solid rgba(56, 189, 248, 0.5);
            background: rgba(30, 64, 175, 0.22);
            color: #dbeafe;
            font-size: 10px;
            font-weight: 800;
            letter-spacing: 0.05em;
            text-transform: uppercase;
            padding: 3px 8px;
            white-space: nowrap;
            line-height: 1;
        }

        .chat-seen-plus-badge[hidden] {
            display: none !important;
        }

        .chat-new-badge {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border-radius: 999px;
            border: 1px solid rgba(251, 191, 36, 0.45);
            background: rgba(161, 98, 7, 0.18);
            color: #fde68a;
            font-size: 10px;
            font-weight: 800;
            letter-spacing: 0.05em;
            text-transform: uppercase;
            padding: 3px 8px;
            white-space: nowrap;
            line-height: 1;
        }

        .chat-new-badge[hidden] {
            display: none !important;
        }

        .chat-avatar-btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border: 0;
            background: rgba(2, 6, 23, 0.48);
            padding: 0;
            cursor: pointer;
            border-radius: 18px;
            width: 100%;
            aspect-ratio: 1 / 1;
            overflow: hidden;
            box-shadow: 0 18px 36px rgba(2, 6, 23, 0.28);
        }

        .chat-avatar {
            width: 100%;
            height: 100%;
            border-radius: 18px;
            object-fit: cover;
            border: 2px solid rgba(148, 163, 184, 0.45);
            background: rgba(2, 6, 23, 0.6);
        }

        .chat-last-seen {
            font-size: 11px;
            color: #94a3b8;
            min-height: 14px;
        }

        .chat-last-seen.is-empty {
            visibility: hidden;
        }

        .chat-last-seen.is-typing {
            visibility: visible;
            color: #86efac;
            font-weight: 800;
        }

        .composer .unsend-btn {
            background: rgba(148, 163, 184, 0.18);
            border: 1px solid rgba(148, 163, 184, 0.35);
            color: #e5e7eb;
            font-size: 12px;
            font-weight: 700;
            padding: 0 12px;
        }

        .composer .unsend-btn:hover {
            background: rgba(148, 163, 184, 0.3);
        }

        .composer .unsend-btn:disabled {
            opacity: 0.55;
            cursor: not-allowed;
        }

        @media (max-width: 420px) {
            .composer {
                gap: 6px;
            }

            .attach-btn {
                width: 40px;
                min-width: 40px;
            }

            .composer button {
                padding: 0 14px;
            }

            .composer .unsend-btn {
                padding: 0 10px;
                font-size: 11px;
            }
        }

        @media (max-width: 720px) {
            .chat-header {
                --chat-header-aside-size: 68px;
                padding: 10px 12px 10px 84px;
                margin-bottom: 6px;
                align-items: center;
                gap: 12px;
            }

            .chat-video-banner {
                margin-top: 0;
                padding: 10px 12px;
                flex-direction: column;
                align-items: stretch;
            }

            .chat-video-banner-actions {
                justify-content: stretch;
            }

            .chat-video-banner-btn {
                flex: 1 1 120px;
            }

            .chat-title {
                align-items: center;
                gap: 3px;
                padding-top: 5px;
            }

            .chat-title-row {
                width: 100%;
            }

            .chat-badge-row {
                gap: 6px;
                min-height: 0;
            }

            .chat-seen-plus-badge {
                font-size: 9px;
                padding: 2px 6px;
            }

            .chat-new-badge {
                font-size: 9px;
                padding: 2px 6px;
            }

            .chat-header-leading {
                left: 10px;
                top: 8px;
                transform: none;
                gap: 6px;
            }

            .chat-avatar-btn,
            .chat-avatar {
                border-radius: 14px;
            }

            .chat-handle {
                font-size: 15px;
                padding: 2px 8px;
            }

            .chat-last-seen {
                font-size: 10px;
            }

            .thread-toolbar-row {
                gap: 6px;
            }

            .thread-toolbar-pill {
                min-height: 42px;
                padding: 0 12px;
                font-size: 11px;
            }

            .thread-toolbar-pill-logo svg {
                width: 22px;
                height: 22px;
                flex-basis: 22px;
            }

            .thread-toolbar-search {
                padding: 8px 9px;
            }

            .thread-toolbar-bulkbar {
                padding: 9px 10px;
            }

            .chat-find-drawer {
                top: auto;
                left: 0;
                right: 0;
                bottom: 0;
                width: 100%;
                height: min(82vh, 720px);
                border-radius: 24px 24px 0 0;
                transform: translateY(calc(100% + 20px));
                padding-bottom: calc(14px + env(safe-area-inset-bottom));
            }

            .chat-find-drawer.open {
                transform: translateY(0);
            }

            body.keyboard-open .chat-find-drawer {
                bottom: var(--kb);
                height: min(82vh, calc(var(--seen-chat-vh) - var(--kb) - env(safe-area-inset-top) - 8px));
            }

            .chat-find-search-bar input {
                font-size: 16px;
            }

            .chat-find-media-grid {
                grid-template-columns: repeat(2, minmax(0, 1fr));
            }

            .media-action-menu {
                position: fixed;
                left: 10px;
                bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + var(--composer-h) + 34px);
                width: min(250px, calc(100vw - 20px));
                max-width: calc(100vw - 20px);
            }

            .media-menu {
                position: fixed;
                left: 10px;
                bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + var(--composer-h) + 34px);
                width: min(320px, calc(100vw - 20px));
                max-width: calc(100vw - 20px);
            }

            .voice-note-sheet {
                position: fixed;
                left: 10px;
                bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + var(--composer-h) + 56px);
                width: min(340px, calc(100vw - 20px));
                max-width: calc(100vw - 20px);
                max-height: min(68vh, calc(var(--seen-chat-vh) - env(safe-area-inset-top) - 16px));
                overflow-y: auto;
            }

            .location-share-sheet {
                position: fixed;
                left: 10px;
                bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + var(--composer-h) + 56px);
                width: min(340px, calc(100vw - 20px));
                max-width: calc(100vw - 20px);
                max-height: min(72vh, calc(var(--seen-chat-vh) - env(safe-area-inset-top) - 16px));
                overflow-y: auto;
            }

            body.keyboard-open .media-action-menu,
            body.keyboard-open .media-menu {
                bottom: calc(env(safe-area-inset-bottom) + var(--kb) + var(--composer-h) + 20px);
            }

            body.keyboard-open .voice-note-sheet,
            body.keyboard-open .location-share-sheet {
                bottom: calc(env(safe-area-inset-bottom) + var(--kb) + var(--composer-h) + 32px);
                max-height: min(68vh, calc(var(--seen-chat-vh) - var(--kb) - env(safe-area-inset-top) - 14px));
            }

            body.keyboard-open .location-share-editor-backdrop {
                align-items: flex-start;
                padding-top: max(18px, env(safe-area-inset-top) + 18px);
            }
        }

        /* Modal */
        .modal {
            position: fixed;
            inset: 0;
            z-index: 999;
            display: none;
            align-items: center;
            justify-content: center;
            padding: 16px;
            background: rgba(0, 0, 0, 0.65);
            backdrop-filter: blur(6px);
        }

        .modal.open {
            display: flex;
        }

        .modal-card {
            width: min(720px, 96vw);
            max-height: 88vh;
            overflow: auto;
            border-radius: 14px;
            border: 1px solid rgba(148, 163, 184, 0.25);
            background: rgba(15, 23, 42, 0.98);
            padding: 14px;
        }

        .modal-card.profile-pop-wrap {
            width: min(560px, 96vw);
            max-height: calc(100dvh - 32px);
            overflow-y: auto;
            overflow-x: visible;
            overscroll-behavior: contain;
            -webkit-overflow-scrolling: touch;
            border: none;
            background: transparent;
            padding: 0;
        }

        @media (max-width: 900px) {
            html.is-browser-mode #profileModal.modal,
            #profileModal.profile-menu-open {
                align-items: flex-start;
                overflow-y: auto;
                -webkit-overflow-scrolling: touch;
                overscroll-behavior: contain;
                touch-action: pan-y;
                min-height: 100vh;
                min-height: 100dvh;
                height: 100vh;
                height: 100dvh;
                padding-top: calc(env(safe-area-inset-top) + 8px);
                padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
                padding-left: max(10px, env(safe-area-inset-left));
                padding-right: max(10px, env(safe-area-inset-right));
                scroll-padding-top: calc(env(safe-area-inset-top) + 12px);
                scroll-padding-bottom: calc(env(safe-area-inset-bottom) + 18px);
            }

            html.is-browser-mode #profileModal .modal-card.profile-pop-wrap,
            #profileModal.profile-menu-open .modal-card.profile-pop-wrap {
                width: min(560px, 100%);
                margin: 0 auto;
                margin-bottom: calc(env(safe-area-inset-bottom) + 4px);
                max-height: none;
                overflow: visible;
                touch-action: pan-y;
            }
        }

        @media (min-width: 721px) and (max-width: 1180px) and (hover: none) and (pointer: coarse) {
            html.is-browser-mode #profileModal.modal,
            #profileModal.profile-menu-open {
                align-items: flex-start;
                overflow-y: auto;
                -webkit-overflow-scrolling: touch;
                overscroll-behavior: contain;
                touch-action: pan-y;
                min-height: 100vh;
                min-height: 100dvh;
                height: 100vh;
                height: 100dvh;
                padding-top: calc(env(safe-area-inset-top) + 16px);
                padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
                padding-left: max(14px, env(safe-area-inset-left));
                padding-right: max(14px, env(safe-area-inset-right));
                scroll-padding-top: calc(env(safe-area-inset-top) + 20px);
                scroll-padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
            }

            html.is-browser-mode #profileModal .modal-card.profile-pop-wrap,
            #profileModal.profile-menu-open .modal-card.profile-pop-wrap {
                width: min(620px, 100%);
                margin: 0 auto;
                margin-bottom: calc(env(safe-area-inset-bottom) + 6px);
                max-height: none;
                overflow: visible;
                touch-action: pan-y;
            }
        }

        .modal-top {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
            margin-bottom: 10px;
        }

        .modal-title {
            font-weight: 700;
            font-size: 14px;
        }

        .modal-close {
            border: 0;
            background: rgba(148, 163, 184, 0.18);
            color: #e5e7eb;
            padding: 6px 10px;
            border-radius: 10px;
            cursor: pointer;
        }

        .modal-close:hover {
            background: rgba(148, 163, 184, 0.28);
        }

        /* Gallery */
        .gallery-main {
            width: 100%;
            border-radius: 12px;
            border: 1px solid rgba(148, 163, 184, 0.25);
            background: rgba(2, 6, 23, 0.6);
            object-fit: contain;
            max-height: 60vh;
            touch-action: pan-y pinch-zoom;
            -webkit-user-drag: none;
            user-select: none;
        }

        .gallery-controls {
            display: flex;
            gap: 8px;
            margin-top: 10px;
        }

        .gallery-btn {
            border: 0;
            background: rgba(37, 99, 235, 0.2);
            color: #e5e7eb;
            padding: 8px 12px;
            border-radius: 10px;
            cursor: pointer;
            font-weight: 600;
        }

        .gallery-btn:hover {
            background: rgba(37, 99, 235, 0.3);
        }

        .thumbs {
            display: flex;
            gap: 8px;
            overflow-x: auto;
            padding: 10px 2px 2px;
            margin-top: 8px;
        }

        .thumbs img {
            width: 56px;
            height: 56px;
            border-radius: 10px;
            object-fit: cover;
            border: 1px solid rgba(148, 163, 184, 0.25);
            cursor: pointer;
            opacity: 0.85;
        }

        .thumbs img.active {
            border-color: rgba(37, 99, 235, 0.9);
            opacity: 1;
        }

        /* Profile popup (chat header -> profile modal) */
        .profile-pop {
            background: linear-gradient(145deg, #0b3b9f, #0a2a78);
            border-radius: 26px;
            border: 1px solid rgba(37, 99, 235, 0.35);
            padding: 16px;
            display: grid;
            gap: 12px;
            box-shadow: 0 28px 60px rgba(3, 7, 18, 0.6);
            max-height: none;
            overflow: visible;
            touch-action: pan-y;
            --profile-pop-icon-like: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 10v12'/%3E%3Cpath d='M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z'/%3E%3C/svg%3E");
            --profile-pop-icon-user: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 21a8 8 0 0 0-16 0'/%3E%3Ccircle cx='12' cy='7' r='4'/%3E%3C/svg%3E");
            --profile-pop-icon-menu: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 12h16'/%3E%3Cpath d='M4 6h16'/%3E%3Cpath d='M4 18h16'/%3E%3C/svg%3E");
            --profile-pop-icon-chat: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15a4 4 0 0 1-4 4H7l-4 4V7a4 4 0 0 1 4-4h10a4 4 0 0 1 4 4z'/%3E%3C/svg%3E");
        }

        .profile-pop-media {
            display: grid;
            grid-template-columns: 1.2fr 1fr;
            gap: 12px;
        }

        .profile-pop-main {
            position: relative;
            border-radius: 18px;
            overflow: hidden;
            background: rgba(2, 6, 23, 0.35);
            border: 1px solid rgba(255, 255, 255, 0.12);
            min-height: 150px;
            display: grid;
            place-items: center;
        }

        .profile-pop-main.is-active {
            border-color: #22c55e;
            box-shadow:
                0 0 0 3px rgba(34, 197, 94, 0.22),
                0 0 18px rgba(34, 197, 94, 0.5);
        }

        .profile-pop-main.is-recent {
            border-color: #f59e0b;
            box-shadow:
                0 0 0 3px rgba(245, 158, 11, 0.2),
                0 0 18px rgba(245, 158, 11, 0.5);
        }

        .profile-pop-main.is-offline {
            border-color: rgba(255, 255, 255, 0.12);
            box-shadow: none;
        }

        .profile-pop-main img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            display: block;
        }

        .profile-pop-main img.is-default {
            object-fit: contain;
            padding: 16px;
            opacity: 0.9;
        }

        .profile-pop-thumbs {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 10px;
        }

        .profile-pop-thumb {
            border-radius: 14px;
            background: rgba(2, 6, 23, 0.35);
            border: 1px solid rgba(255, 255, 255, 0.12);
            min-height: 64px;
            display: grid;
            place-items: center;
            overflow: hidden;
            position: relative;
        }

        .profile-pop-thumb img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            display: block;
        }

        .profile-pop-thumb.is-empty img {
            display: none;
        }

        .profile-pop-info {
            display: grid;
            gap: 6px;
        }

        .profile-pop-name {
            display: flex;
            align-items: baseline;
            gap: 6px;
            flex-wrap: wrap;
            font-weight: 800;
            font-size: 18px;
        }

        .profile-pop-age {
            color: var(--muted);
            font-size: 14px;
            font-weight: 700;
        }

        .profile-pop-meta {
            color: var(--muted);
            font-size: 12px;
            font-weight: 700;
        }

        .profile-pop-bio {
            color: rgba(226, 232, 240, 0.88);
            font-size: 13px;
            line-height: 1.35;
            white-space: pre-wrap;
        }

        .profile-pop-actions {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 10px;
            align-items: center;
        }

        .profile-pop-gear {
            width: 100%;
            min-height: 40px;
            border-radius: 8px;
            border: 1px solid rgba(125, 169, 242, 0.28);
            background:
                linear-gradient(180deg, rgba(45, 84, 158, 0.88), rgba(31, 65, 132, 0.9));
            color: rgba(219, 234, 254, 0.96);
            font-size: 13px;
            font-weight: 800;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            cursor: pointer;
            box-shadow:
                inset 0 1px 0 rgba(255, 255, 255, 0.09),
                0 8px 18px rgba(2, 6, 23, 0.2);
            transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease, color 0.16s ease;
        }

        .profile-pop-btn {
            border: 1px solid rgba(125, 169, 242, 0.28);
            border-radius: 8px;
            padding: 11px 14px;
            font-weight: 800;
            font-size: 14px;
            cursor: pointer;
            width: 100%;
            min-height: 40px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            text-align: center;
            color: rgba(219, 234, 254, 0.96);
            background:
                linear-gradient(180deg, rgba(45, 84, 158, 0.88), rgba(31, 65, 132, 0.9));
            box-shadow:
                inset 0 1px 0 rgba(255, 255, 255, 0.09),
                0 8px 18px rgba(2, 6, 23, 0.2);
            transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease, color 0.16s ease;
        }

        .profile-pop-btn::before,
        .profile-pop-gear::before {
            content: '';
            width: 14px;
            height: 14px;
            flex: 0 0 auto;
            background: currentColor;
            opacity: 0.72;
            -webkit-mask: var(--profile-pop-action-icon) center / contain no-repeat;
            mask: var(--profile-pop-action-icon) center / contain no-repeat;
        }

        .profile-pop-btn:hover,
        .profile-pop-gear:hover {
            transform: translateY(-1px);
            border-color: rgba(147, 197, 253, 0.5);
            background:
                linear-gradient(180deg, rgba(55, 98, 180, 0.94), rgba(35, 74, 148, 0.94));
            box-shadow:
                inset 0 1px 0 rgba(255, 255, 255, 0.12),
                0 10px 22px rgba(2, 6, 23, 0.25);
        }

        .profile-pop-btn:focus,
        .profile-pop-gear:focus {
            outline: none;
        }

        .profile-pop-btn:focus-visible,
        .profile-pop-gear:focus-visible {
            border-color: rgba(191, 219, 254, 0.78);
            box-shadow:
                0 0 0 2px rgba(96, 165, 250, 0.28),
                inset 0 1px 0 rgba(255, 255, 255, 0.12),
                0 10px 22px rgba(2, 6, 23, 0.25);
        }

        .profile-pop-btn.profile {
            --profile-pop-action-icon: var(--profile-pop-icon-user);
        }

        .profile-pop-btn.chat {
            --profile-pop-action-icon: var(--profile-pop-icon-chat);
        }

        .profile-pop-btn.seen {
            --profile-pop-action-icon: var(--profile-pop-icon-like);
        }

        .profile-pop-btn.seen.is-added {
            background:
                linear-gradient(180deg, rgba(23, 126, 72, 0.86), rgba(16, 105, 67, 0.9));
            border-color: rgba(74, 222, 128, 0.42);
            color: #dcfce7;
        }

        .profile-pop-btn.seen.is-pending {
            background:
                linear-gradient(180deg, rgba(161, 98, 7, 0.88), rgba(120, 73, 15, 0.92));
            border-color: rgba(251, 191, 36, 0.48);
            color: #fff7d6;
        }

        .profile-pop-gear {
            --profile-pop-action-icon: var(--profile-pop-icon-menu);
        }

        .profile-pop-menu-btn.is-added {
            background:
                linear-gradient(180deg, rgba(23, 126, 72, 0.86), rgba(16, 105, 67, 0.9));
            color: #dcfce7;
            border-color: rgba(74, 222, 128, 0.42);
            box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.09);
        }

        .profile-pop-menu-btn.is-pending {
            background:
                linear-gradient(180deg, rgba(161, 98, 7, 0.88), rgba(120, 73, 15, 0.92));
            color: #fff7d6;
            border-color: rgba(251, 191, 36, 0.48);
            box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.09);
        }

        .profile-pop-btn[disabled] {
            opacity: 0.55;
            cursor: not-allowed;
        }

        .profile-pop-menu {
            display: none;
            background: rgba(15, 23, 42, 0.75);
            border-radius: 20px;
            padding: 12px;
            border: 1px solid rgba(148, 163, 184, 0.25);
            gap: 10px;
        }

        .profile-pop-menu.open {
            display: grid;
        }

        .profile-pop-menu-title {
            font-size: 12px;
            font-weight: 800;
            letter-spacing: 0.1em;
            text-transform: uppercase;
            text-align: center;
        }

        .profile-pop-menu-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 10px;
        }

        .profile-pop-menu-btn {
            border-radius: 8px;
            border: 1px solid rgba(125, 169, 242, 0.2);
            padding: 10px 8px;
            font-weight: 800;
            font-size: 13px;
            background:
                linear-gradient(180deg, rgba(30, 58, 120, 0.82), rgba(17, 36, 82, 0.88));
            color: rgba(219, 234, 254, 0.96);
            cursor: pointer;
            box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
        }

        .profile-pop-menu-btn:hover {
            border-color: rgba(147, 197, 253, 0.42);
            background:
                linear-gradient(180deg, rgba(44, 83, 158, 0.9), rgba(29, 64, 132, 0.92));
        }

        .profile-pop-menu-btn:focus {
            outline: none;
        }

        .profile-pop-menu-btn:focus-visible {
            border-color: rgba(191, 219, 254, 0.72);
            box-shadow:
                0 0 0 2px rgba(96, 165, 250, 0.24),
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
        }

        .profile-pop-menu-btn[disabled] {
            opacity: 0.55;
            cursor: not-allowed;
        }

        .profile-pop-menu-btn.danger {
            color: #fca5a5;
        }

        @media (max-width: 640px) {
            .profile-pop-media {
                grid-template-columns: 1fr;
            }

            .profile-pop-thumbs {
                grid-template-columns: repeat(4, 1fr);
            }
        }

        @media (max-width: 720px) {
            #profileModal .profile-pop {
                padding: 14px;
                gap: 10px;
                border-radius: 22px;
            }

            #profileModal .profile-pop-main {
                min-height: clamp(128px, 26vh, 220px);
            }

            #profileModal .profile-pop-thumbs {
                gap: 8px;
            }

            #profileModal .profile-pop-thumb {
                min-height: 56px;
            }

            #profileModal .profile-pop-name {
                font-size: clamp(16px, 4.8vw, 19px);
            }

            #profileModal .profile-pop-actions {
                gap: 8px;
            }

            #profileModal .profile-pop-btn,
            #profileModal .profile-pop-gear {
                min-height: 38px;
                padding: 10px 12px;
                font-size: 13px;
            }

            #profileModal .profile-pop-menu {
                padding: 10px;
                gap: 8px;
                border-radius: 16px;
            }

            #profileModal .profile-pop-menu-grid {
                gap: 8px;
            }

            #profileModal .profile-pop-menu-btn {
                padding: 9px 8px;
                font-size: 12px;
            }
        }

        @media (max-width: 720px) and (max-height: 780px) {
            #profileModal .profile-pop {
                padding: 12px;
                gap: 8px;
            }

            #profileModal .profile-pop-main {
                min-height: clamp(112px, 22vh, 180px);
            }

            #profileModal .profile-pop-thumb {
                min-height: 50px;
            }
        }

        .group-members-pop {
            background: linear-gradient(145deg, #152345, #111a34);
            border-radius: 24px;
            border: 1px solid rgba(96, 165, 250, 0.24);
            padding: 16px;
            display: grid;
            gap: 12px;
            box-shadow: 0 28px 60px rgba(3, 7, 18, 0.56);
        }

        .group-members-head {
            display: flex;
            align-items: flex-start;
            justify-content: space-between;
            gap: 12px;
        }

        .group-members-title {
            display: grid;
            gap: 4px;
            min-width: 0;
        }

        .group-members-title strong {
            font-size: 20px;
            font-weight: 800;
            color: #f8fafc;
            line-height: 1.1;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .group-members-title span {
            font-size: 12px;
            font-weight: 700;
            color: #94a3b8;
        }

        .group-members-status {
            display: none;
            border-radius: 14px;
            padding: 10px 12px;
            font-size: 12px;
            font-weight: 700;
            line-height: 1.45;
            border: 1px solid rgba(148, 163, 184, 0.2);
            background: rgba(15, 23, 42, 0.72);
            color: #cbd5e1;
        }

        .group-members-status.show {
            display: block;
        }

        .group-members-status.is-error {
            border-color: rgba(248, 113, 113, 0.32);
            background: rgba(127, 29, 29, 0.22);
            color: #fecaca;
        }

        .group-members-status.is-success {
            border-color: rgba(34, 197, 94, 0.32);
            background: rgba(20, 83, 45, 0.22);
            color: #dcfce7;
        }

        .group-members-rename {
            display: grid;
            gap: 8px;
            border: 1px solid rgba(148, 163, 184, 0.2);
            border-radius: 16px;
            background: rgba(2, 6, 23, 0.34);
            padding: 10px;
        }

        .group-members-rename-label {
            font-size: 11px;
            font-weight: 800;
            color: #93c5fd;
            letter-spacing: 0.08em;
            text-transform: uppercase;
        }

        .group-members-rename-row {
            display: grid;
            grid-template-columns: minmax(0, 1fr) auto auto;
            gap: 8px;
            align-items: center;
        }

        .group-members-rename-input {
            width: 100%;
            min-height: 38px;
            border-radius: 12px;
            border: 1px solid rgba(96, 165, 250, 0.32);
            background: rgba(15, 23, 42, 0.84);
            color: #eff6ff;
            font-size: 16px;
            font-weight: 700;
            padding: 0 12px;
            outline: none;
        }

        .group-members-rename-input:focus-visible {
            border-color: rgba(96, 165, 250, 0.7);
            box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.24);
        }

        .group-members-rename-btn {
            min-height: 38px;
            border-radius: 12px;
            border: 1px solid rgba(96, 165, 250, 0.28);
            background: rgba(30, 64, 175, 0.22);
            color: #dbeafe;
            font-size: 12px;
            font-weight: 800;
            padding: 0 12px;
            cursor: pointer;
        }

        .group-members-rename-btn.alt {
            border-color: rgba(148, 163, 184, 0.24);
            background: rgba(15, 23, 42, 0.76);
            color: #cbd5e1;
        }

        .group-members-rename-btn[disabled] {
            opacity: 0.55;
            cursor: not-allowed;
        }

        .group-members-list {
            display: grid;
            gap: 10px;
            max-height: min(52vh, 420px);
            overflow-y: auto;
            padding-right: 2px;
        }

        .group-members-empty {
            border: 1px dashed rgba(148, 163, 184, 0.22);
            border-radius: 18px;
            padding: 18px 14px;
            text-align: center;
            font-size: 13px;
            font-weight: 700;
            color: #94a3b8;
            background: rgba(2, 6, 23, 0.28);
        }

        .group-members-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            border-radius: 18px;
            padding: 12px 14px;
            background: rgba(2, 6, 23, 0.46);
            border: 1px solid rgba(148, 163, 184, 0.18);
        }

        .group-members-item.is-openable {
            cursor: pointer;
            transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
        }

        .group-members-item.is-openable:hover,
        .group-members-item.is-openable:focus-visible {
            border-color: rgba(96, 165, 250, 0.38);
            background: rgba(15, 23, 42, 0.72);
            transform: translateY(-1px);
            outline: none;
        }

        .group-members-main {
            min-width: 0;
            display: grid;
            gap: 4px;
        }

        .group-members-avatar {
            width: 42px;
            height: 42px;
            border-radius: 999px;
            object-fit: cover;
            flex: 0 0 42px;
            border: 1px solid rgba(148, 163, 184, 0.44);
            background: rgba(15, 23, 42, 0.86);
        }

        .group-members-avatar.is-default {
            object-fit: contain;
            padding: 5px;
        }

        .group-members-name {
            font-size: 15px;
            font-weight: 800;
            color: #f8fafc;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .group-members-meta {
            display: flex;
            align-items: center;
            gap: 6px;
            flex-wrap: wrap;
            font-size: 11px;
            font-weight: 800;
            color: #94a3b8;
            text-transform: uppercase;
            letter-spacing: 0.06em;
        }

        .group-members-pill {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            min-height: 24px;
            padding: 0 10px;
            border-radius: 999px;
            border: 1px solid rgba(148, 163, 184, 0.2);
            background: rgba(15, 23, 42, 0.84);
            color: #dbeafe;
            font-size: 11px;
            font-weight: 800;
        }

        .group-members-pill.you {
            border-color: rgba(56, 189, 248, 0.28);
            background: rgba(37, 99, 235, 0.22);
        }

        .group-members-pill.creator {
            border-color: rgba(96, 165, 250, 0.28);
            background: rgba(30, 41, 59, 0.92);
        }

        .group-members-remove {
            flex: 0 0 auto;
            border: 1px solid rgba(248, 113, 113, 0.28);
            background: rgba(153, 27, 27, 0.2);
            color: #fecaca;
            min-height: 36px;
            padding: 0 12px;
            border-radius: 999px;
            font-size: 12px;
            font-weight: 800;
            cursor: pointer;
        }

        .group-members-remove[disabled] {
            opacity: 0.55;
            cursor: not-allowed;
        }

        @media (max-width: 720px) {
            #groupMembersModal .group-members-pop {
                padding: 14px;
                gap: 10px;
                border-radius: 22px;
            }

            #groupMembersModal .group-members-title strong {
                font-size: 18px;
            }

            #groupMembersModal .group-members-item {
                padding: 11px 12px;
            }

            #groupMembersModal .group-members-rename-row {
                grid-template-columns: minmax(0, 1fr) auto;
            }

            #groupMembersModal .group-members-rename-input {
                grid-column: 1 / -1;
            }

            #groupMembersModal .group-members-avatar {
                width: 38px;
                height: 38px;
                flex-basis: 38px;
            }

            #groupMembersModal .group-members-remove {
                min-height: 34px;
                padding: 0 11px;
                font-size: 11px;
            }
        }

        /* -----------------------------
   SEEN MOBILE NAV v1 (LOCKED)
   - Same CSS on map/grid/chat
   - No per-page offsets
------------------------------*/

        .bottom-nav {
            display: none;
            position: fixed;
            left: 0;
            right: 0;
            bottom: 0;

            height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
            padding: 8px 12px calc(env(safe-area-inset-bottom) + 10px);

            background: linear-gradient(to top,
                    rgba(15, 23, 42, 1),
                    rgba(15, 23, 42, 0.95),
                    rgba(15, 23, 42, 0.80));

            border-top: 1px solid rgba(148, 163, 184, 0.25);
            backdrop-filter: blur(10px);
            z-index: 60;

            flex-direction: column;
            justify-content: center;
            gap: 6px;
        }

        .bottom-nav-row {
            display: flex;
            gap: 10px;
            align-items: center;
            justify-content: space-around;
        }

        .bn-link {
            flex: 1 1 0;
            text-align: center;
            padding: 10px 12px;
            border-radius: 999px;
            text-decoration: none;
            color: rgba(229, 231, 235, 0.92);
            font-weight: 800;
            font-size: 13px;
            border: 1px solid transparent;
            background: rgba(148, 163, 184, 0.10);
        }

        .bn-link:hover {
            background: rgba(148, 163, 184, 0.18);
        }

        .bn-link.active {
            background: rgba(37, 99, 235, 0.28);
            border-color: rgba(37, 99, 235, 0.38);
        }

        /* Optional status line (map uses it, others can omit it) */
        .bottom-nav-status {
            text-align: center;
            color: rgba(156, 163, 175, 0.95);
            font-size: 12px;
            font-weight: 750;
            text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
            line-height: 1.1;
            /* keeps layout stable even when empty */
            min-height: 14px;
        }

        @media (max-width: 720px) {
            :root {
                --bottom-nav-h: 64px;
            }

            html,
            body {
                padding-bottom: 0;
                height: var(--seen-chat-vh);
                min-height: var(--seen-chat-vh);
                overflow: hidden;
            }

            html.is-browser-mode body {
                overflow-y: auto;
                overscroll-behavior-y: none;
            }

            html.is-browser-mode body.mobile-chat-open.keyboard-open {
                overflow-y: hidden;
                overscroll-behavior-y: none;
            }

            body:not(.is-admin) .top-nav {
                height: auto;
                padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
                gap: 8px;
                flex-wrap: nowrap;
            }

            body:not(.is-admin) .nav-links {
                flex: 1 1 auto;
                min-width: 0;
                margin-left: auto;
                justify-content: flex-end;
                flex-wrap: nowrap;
                overflow: hidden;
                gap: 6px;
                padding-bottom: 0;
            }

            body:not(.is-admin) .nav-link {
                flex: 0 0 auto;
                padding: 8px 8px;
                font-size: 13px;
                white-space: nowrap;
            }

            .nav-mobile-hide {
                display: none !important;
            }

            body.mobile-chat-open .top-nav {
                display: none;
            }

            .bottom-nav {
                display: flex;
                padding: 6px 10px calc(env(safe-area-inset-bottom) + 6px);
                gap: 4px;
            }

            .bn-link {
                padding: 8px 10px;
                font-size: 12px;
            }

            .bottom-nav-status {
                font-size: 11px;
                min-height: 11px;
            }

            .thread-list {
                padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 10px);
            }

            .chat-panel {
                padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 10px);
            }

            /* Map page: keep bottom bar from covering map */
            #map {
                bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
            }

            /* Chat page: keep bottom bar from covering layout */
            .chat-shell {
                height: calc(var(--seen-chat-vh) - var(--top-nav-h));
            }

            .jump-latest {
                right: 14px;
                bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + var(--composer-h) + 18px);
            }

            body.mobile-chat-open .chat-shell {
                height: var(--seen-chat-vh);
            }

            html.is-browser-mode body .chat-shell {
                min-height: calc(var(--seen-chat-vh) - var(--top-nav-h));
            }

            html.is-browser-mode body.mobile-chat-open .chat-shell {
                min-height: var(--seen-chat-vh);
            }

            body.keyboard-open .bottom-nav {
                display: none;
            }

            body.keyboard-open .thread-list,
            body.keyboard-open .chat-panel {
                padding-bottom: calc(var(--composer-h) + 10px);
            }

            body.keyboard-open .composer {
                position: fixed;
                left: 10px;
                right: 10px;
                bottom: calc(env(safe-area-inset-bottom) + var(--kb));
                margin: 0;
                z-index: 70;
            }

            body.keyboard-open .jump-latest {
                bottom: calc(env(safe-area-inset-bottom) + var(--kb) + var(--composer-h) + 14px);
            }

        }
