:root {
    --bg: #0b1020;
    --bg-2: #111831;
    --surface: rgba(20, 28, 50, .92);
    --surface-2: rgba(25, 35, 61, .88);
    --surface-soft: rgba(30, 41, 70, .72);
    --surface-hover: rgba(39, 52, 86, .86);
    --line: rgba(148, 163, 184, .13);
    --line-strong: rgba(148, 163, 184, .23);
    --text: #eff4ff;
    --text-soft: #b8c3d7;
    --text-muted: #7b89a2;
    --primary: #69d7ff;
    --primary-strong: #8978ff;
    --primary-soft: rgba(105, 215, 255, .11);
    --cyan: #69d7ff;
    --violet: #8978ff;
    --pink: #f273b5;
    --success: #3bd29a;
    --warning: #f5c75d;
    --danger: #ff6d91;
    --admin: #4f7cff;
    --admin-deep: #6a50dc;
    --user: #263248;
    --user-deep: #1c2639;
    --chat-bg: #0c1324;
    --radius-sm: 10px;
    --radius-md: 15px;
    --radius-lg: 22px;
    --radius-xl: 28px;
    --radius-pill: 999px;
    --shadow-sm: 0 8px 18px rgba(0, 0, 0, .15);
    --shadow-md: 0 16px 36px rgba(0, 0, 0, .22);
    --shadow-lg: 0 28px 80px rgba(0, 0, 0, .38);
    --shadow-glow: 0 14px 34px rgba(105, 215, 255, .13);
    --ease: cubic-bezier(.2, .8, .2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    width: 100%;
    height: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    min-height: 100dvh;
    overflow: hidden;
    color: var(--text);
    background:
        radial-gradient(850px 560px at -5% -10%, rgba(105, 215, 255, .13), transparent 62%),
        radial-gradient(780px 560px at 104% 8%, rgba(137, 120, 255, .14), transparent 60%),
        radial-gradient(720px 500px at 72% 110%, rgba(242, 115, 181, .08), transparent 62%),
        linear-gradient(145deg, #090e1b 0%, #0e1427 48%, #0a1220 100%);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body::before,
body::after {
    content: "";
    position: fixed;
    z-index: -1;
    pointer-events: none;
    border-radius: 50%;
}

body::before {
    top: -170px;
    left: 12%;
    width: 430px;
    height: 430px;
    background: rgba(105, 215, 255, .08);
    filter: blur(90px);
}

body::after {
    right: -200px;
    bottom: -170px;
    width: 500px;
    height: 500px;
    background: rgba(137, 120, 255, .09);
    filter: blur(100px);
}

body.modal-open {
    overflow: hidden;
}

button,
input,
textarea {
    font: inherit;
}

button {
    border: 0;
    -webkit-tap-highlight-color: transparent;
}

button:disabled {
    cursor: not-allowed;
    opacity: .58;
}

.hidden {
    display: none !important;
}

.screen {
    width: 100%;
    height: 100dvh;
}

/* ---------- LOGIN ---------- */

.screen-login {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(560px 430px at 18% 16%, rgba(105, 215, 255, .10), transparent 66%),
        radial-gradient(580px 440px at 86% 82%, rgba(137, 120, 255, .10), transparent 68%);
    opacity: 0;
    pointer-events: none;
    transition: opacity .28s ease;
    z-index: 3000;
}

.screen-login.active {
    opacity: 1;
    pointer-events: auto;
}

.auth-shell {
    position: relative;
    width: min(100%, 448px);
    padding: 38px;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, .16);
    border-radius: var(--radius-xl);
    background:
        linear-gradient(145deg, rgba(24, 34, 59, .96), rgba(14, 21, 39, .98)),
        radial-gradient(circle at 15% 0%, rgba(105, 215, 255, .12), transparent 30%);
    box-shadow: var(--shadow-lg);
}

.auth-shell::before {
    content: "";
    position: absolute;
    top: -150px;
    right: -110px;
    width: 290px;
    height: 290px;
    border-radius: 50%;
    background: rgba(137, 120, 255, .12);
    filter: blur(65px);
    pointer-events: none;
}

.auth-shell > * {
    position: relative;
    z-index: 1;
}

.brand-mark {
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    margin-bottom: 24px;
    border: 1px solid rgba(255, 255, 255, .10);
    border-radius: 19px;
    color: #07121d;
    background: linear-gradient(145deg, var(--cyan), #8ecbff 42%, var(--violet));
    box-shadow: 0 16px 34px rgba(105, 215, 255, .16), 0 0 34px rgba(137, 120, 255, .10);
}

.eyebrow {
    color: var(--cyan);
    font-size: 11px;
    font-weight: 850;
    letter-spacing: .14em;
    text-transform: uppercase;
}

.auth-shell h1 {
    margin-top: 9px;
    font-size: clamp(30px, 5vw, 36px);
    line-height: 1.08;
    letter-spacing: -.045em;
}

.auth-subtitle,
.modal-description {
    margin-top: 11px;
    color: var(--text-soft);
    font-size: 14px;
    line-height: 1.6;
}

.auth-form {
    margin-top: 28px;
}

.field {
    display: block;
    margin-top: 17px;
}

.field > span {
    display: block;
    margin: 0 0 8px 2px;
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 750;
}

.field input,
.field textarea {
    width: 100%;
    min-height: 52px;
    padding: 0 16px;
    border: 1px solid var(--line-strong);
    border-radius: 15px;
    outline: none;
    color: var(--text);
    background: rgba(12, 19, 35, .76);
    box-shadow: inset 0 1px rgba(255, 255, 255, .025);
    transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}

.field input::placeholder,
textarea::placeholder {
    color: #5f6d84;
}

.field input:focus,
.field textarea:focus,
#search-input:focus,
#message-input:focus {
    border-color: rgba(105, 215, 255, .42);
    background: rgba(14, 23, 42, .94);
    box-shadow: 0 0 0 4px rgba(105, 215, 255, .07), 0 10px 24px rgba(0, 0, 0, .12);
}

#token2fa {
    text-align: center;
    font-size: 28px;
    font-weight: 850;
    letter-spacing: .34em;
    padding-left: .62em;
}

.field-hint {
    margin: 8px 2px 0;
    color: var(--text-muted);
    font-size: 12px;
}

.form-error {
    margin-top: 11px;
    color: #ff8ca6;
    font-size: 13px;
    line-height: 1.45;
}

.auth-actions {
    display: grid;
    grid-template-columns: 1fr 1.35fr;
    gap: 11px;
    margin-top: 23px;
}

.button {
    min-height: 49px;
    padding: 0 17px;
    border-radius: 14px;
    cursor: pointer;
    font-weight: 800;
    transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.button:hover {
    transform: translateY(-1px);
}

.button-primary {
    color: #061019;
    background: linear-gradient(135deg, var(--cyan), #8ecbff 40%, var(--violet));
    box-shadow: var(--shadow-glow);
}

.button-primary:hover {
    box-shadow: 0 18px 38px rgba(105, 215, 255, .19);
}

.button-secondary {
    color: var(--text);
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .045);
}

.button-wide {
    width: 100%;
    margin-top: 21px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* ---------- APP SHELL ---------- */

.app-shell {
    position: relative;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    isolation: isolate;
}

.view-panel {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, .12);
    background: linear-gradient(145deg, rgba(18, 27, 47, .96), rgba(9, 15, 28, .98));
    box-shadow: var(--shadow-lg);
    transition: transform .34s var(--ease);
}

.view-panel::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(255, 255, 255, .025), transparent 22%);
}

.view-panel > * {
    position: relative;
    z-index: 1;
}

.view-panel.right {
    transform: translateX(100%);
}

.view-panel.left {
    transform: translateX(-9%);
}

.view-panel.active {
    transform: translateX(0);
    z-index: 2;
}

.view-room {
    z-index: 1;
}

/* ---------- HEADER ---------- */

.header-bar {
    flex: 0 0 auto;
    border-bottom: 1px solid var(--line);
    background: rgba(12, 19, 35, .92);
}

.list-header {
    padding: 15px 18px 14px;
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand-button {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: var(--text);
    background: transparent;
    cursor: pointer;
    text-align: left;
}

.brand-button strong {
    display: block;
    font-size: 17px;
    letter-spacing: -.025em;
}

.brand-button small {
    display: block;
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.brand-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--cyan), var(--violet), var(--pink));
    box-shadow: 0 0 0 5px rgba(105, 215, 255, .06), 0 0 22px rgba(105, 215, 255, .22);
}

.connection-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 11px;
    border: 1px solid rgba(59, 210, 154, .16);
    border-radius: var(--radius-pill);
    color: #58e2b3;
    background: rgba(59, 210, 154, .08);
    font-size: 11px;
    font-weight: 800;
}

.connection-chip.offline {
    border-color: rgba(245, 199, 93, .15);
    color: #f5ce71;
    background: rgba(245, 199, 93, .07);
}

.connection-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 10px currentColor;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-top: 14px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: rgba(19, 28, 48, .74);
    box-shadow: inset 0 1px rgba(255, 255, 255, .025);
}

#search-input {
    width: 100%;
    min-height: 44px;
    border: 0;
    outline: 0;
    color: var(--text);
    background: transparent;
    font-size: 14px;
}

.search-clear {
    color: var(--text-muted);
    background: transparent;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
}

.list-meta {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 14px;
    padding: 20px 18px 11px;
}

.list-meta h2 {
    margin-top: 4px;
    font-size: 24px;
    letter-spacing: -.04em;
}

.list-count {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 750;
}

/* ---------- SCROLL ---------- */

.scroll-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #34445f transparent;
}

.scroll-container::-webkit-scrollbar {
    width: 7px;
}

.scroll-container::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: #34445f;
}

/* ---------- CHAT LIST ---------- */

.chat-list {
    padding: 3px 11px 112px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 78px;
    margin: 6px 0;
    padding: 11px 12px;
    border: 1px solid rgba(148, 163, 184, .10);
    border-radius: 18px;
    background: linear-gradient(145deg, rgba(24, 35, 59, .93), rgba(15, 23, 40, .96));
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    outline: none;
    transition: background .18s ease, border-color .18s ease, transform .18s ease, box-shadow .18s ease;
}

.chat-item:hover,
.chat-item:focus-visible {
    border-color: rgba(105, 215, 255, .22);
    background: linear-gradient(145deg, rgba(30, 44, 72, .96), rgba(16, 26, 45, .98));
    box-shadow: var(--shadow-md), inset 0 1px rgba(255, 255, 255, .025);
    transform: translateY(-1px);
}

.chat-item:active {
    transform: scale(.992);
}

.chat-item.focused-chat {
    border-color: rgba(137, 120, 255, .30);
    background: linear-gradient(145deg, rgba(43, 39, 76, .92), rgba(18, 26, 45, .98));
}

.avatar-wrapper {
    position: relative;
    width: 49px;
    height: 49px;
    flex: 0 0 49px;
}

.avatar {
    width: 49px;
    height: 49px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 50%;
    color: #fff;
    font-size: 15px;
    font-weight: 850;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .10), 0 8px 20px rgba(0, 0, 0, .20);
}

.avatar-lg {
    width: 41px;
    height: 41px;
    font-size: 13px;
}

.status-indicator {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 14px;
    height: 14px;
    border: 2px solid #111a2e;
    border-radius: 50%;
    background: #77849c;
}

.status-indicator.online {
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(59, 210, 154, .08), 0 0 10px rgba(59, 210, 154, .34);
}

.status-indicator.offline {
    background: #77849c;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-header {
    display: flex;
    min-width: 0;
    align-items: center;
}

.chat-name {
    overflow: hidden;
    color: var(--text);
    font-size: 15px;
    font-weight: 820;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chat-last-msg {
    max-width: 100%;
    margin-top: 6px;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.38;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chat-right {
    align-self: stretch;
    display: flex;
    min-width: 63px;
    align-items: flex-end;
    flex-direction: column;
    justify-content: center;
    gap: 7px;
}

.chat-time {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 750;
    white-space: nowrap;
}

.unread-badge {
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-pill);
    color: #061019;
    background: linear-gradient(135deg, var(--cyan), #8ecbff 46%, var(--violet));
    font-size: 10px;
    font-weight: 900;
    box-shadow: 0 7px 16px rgba(105, 215, 255, .14);
}

mark {
    padding: 0 3px;
    border-radius: 5px;
    background: rgba(105, 215, 255, .14);
    color: #8ce4ff;
}

.fab {
    position: absolute;
    right: 21px;
    bottom: calc(23px + env(safe-area-inset-bottom));
    width: 57px;
    height: 57px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .10);
    border-radius: 18px;
    color: #061019;
    background: linear-gradient(145deg, var(--cyan), #8ecbff 45%, var(--violet));
    box-shadow: 0 18px 36px rgba(0, 0, 0, .30), 0 0 32px rgba(105, 215, 255, .10);
    cursor: pointer;
    z-index: 5;
    transition: transform .18s ease, box-shadow .18s ease;
}

.fab:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 22px 42px rgba(0, 0, 0, .34), 0 0 38px rgba(105, 215, 255, .14);
}

/* ---------- LOADING / EMPTY ---------- */

.chat-skeleton {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 10px;
}

.skeleton-avatar,
.skeleton-lines span {
    background: linear-gradient(90deg, #18243c, #253754, #18243c);
    background-size: 200% 100%;
    animation: shimmer 1.3s infinite;
}

.skeleton-avatar {
    width: 49px;
    height: 49px;
    border-radius: 50%;
}

.skeleton-lines {
    flex: 1;
}

.skeleton-lines span {
    display: block;
    height: 11px;
    margin: 7px 0;
    border-radius: 999px;
}

.skeleton-lines span:first-child {
    width: 43%;
}

.skeleton-lines span:last-child {
    width: 72%;
}

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

.empty-state {
    position: absolute;
    inset: 155px 28px 90px;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 8px;
    text-align: center;
    color: var(--text-soft);
    pointer-events: none;
}

.empty-icon {
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    margin-bottom: 6px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(24, 35, 59, .82);
    color: #8290aa;
    font-size: 28px;
    box-shadow: var(--shadow-sm);
}

.empty-state strong {
    color: var(--text);
    font-size: 15px;
}

.empty-state span {
    max-width: 290px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.5;
}

/* ---------- ROOM HEADER ---------- */

.room-header {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 70px;
    padding: 10px 13px;
    border-bottom: 1px solid var(--line);
    background: rgba(12, 19, 35, .90);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
}

.icon-btn {
    width: 41px;
    height: 41px;
    flex: 0 0 41px;
    display: grid;
    place-items: center;
    border: 1px solid transparent;
    border-radius: 13px;
    color: #9eacc2;
    background: rgba(255, 255, 255, .025);
    cursor: pointer;
    transition: background .18s ease, color .18s ease, transform .18s ease, border-color .18s ease;
}

.icon-btn:hover {
    border-color: var(--line);
    color: var(--text);
    background: rgba(255, 255, 255, .05);
}

.icon-btn:active {
    transform: scale(.95);
}

.composer-btn {
    color: #91a0b7;
}

.composer-btn:hover {
    color: var(--cyan);
    background: rgba(105, 215, 255, .06);
}

.send-btn {
    color: #061019;
    background: linear-gradient(145deg, var(--cyan), #8ecbff 46%, var(--violet));
    box-shadow: 0 10px 22px rgba(105, 215, 255, .12);
}

.send-btn:hover {
    color: #061019;
    box-shadow: 0 14px 28px rgba(105, 215, 255, .16);
}

.header-avatar-wrapper {
    width: 41px;
    height: 41px;
    flex-basis: 41px;
}

.room-title-container {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.room-user-name {
    overflow: hidden;
    color: var(--text);
    font-size: 16px;
    font-weight: 850;
    line-height: 1.2;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.room-subtitle {
    position: relative;
    margin-top: 4px;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 11.5px;
    font-weight: 550;
    white-space: nowrap;
}

.room-user-name.scrolling {
    overflow: visible;
    width: max-content;
    padding-right: 35px;
    animation: title-marquee 8s linear infinite;
}

.room-subtitle.scrolling {
    width: max-content;
    padding-right: 45px;
    animation: subtitle-marquee 9s linear infinite;
}

@keyframes title-marquee {
    0%, 14% { transform: translateX(0); }
    52%, 68% { transform: translateX(-38%); }
    100% { transform: translateX(0); }
}

@keyframes subtitle-marquee {
    0%, 13% { transform: translateX(0); opacity: 1; }
    55%, 70% { transform: translateX(-42%); opacity: 1; }
    96%, 100% { transform: translateX(0); opacity: .9; }
}

/* ---------- CHAT AREA ---------- */

.chat-bg {
    position: relative;
    padding: 19px 12px 21px;
    background:
        radial-gradient(620px 360px at 8% 8%, rgba(105, 215, 255, .065), transparent 64%),
        radial-gradient(660px 400px at 92% 76%, rgba(137, 120, 255, .075), transparent 67%),
        linear-gradient(180deg, #0b1322 0%, #0a1220 100%);
    scroll-behavior: smooth;
}

.date-separator {
    align-self: center;
    width: fit-content;
    margin: 9px auto 15px;
    padding: 6px 11px;
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
    color: #8090aa;
    background: rgba(17, 27, 46, .90);
    box-shadow: var(--shadow-sm);
    font-size: 11px;
    font-weight: 800;
}

.message-wrapper {
    width: 100%;
    display: flex;
    margin-bottom: 9px;
    transition: transform .18s ease;
    touch-action: pan-y;
}

.message-wrapper.admin {
    justify-content: flex-end;
    padding-right: 10px;
}

.message-wrapper.user {
    justify-content: flex-start;
    padding-left: 10px;
}

.message-wrapper.swiping {
    transition: none;
}

.bubble {
    position: relative;
    max-width: min(83%, 650px);
    min-width: 82px;
    padding: 11px 13px 9px;
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: 18px;
    color: #fff;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .20), inset 0 1px rgba(255, 255, 255, .07);
}

.message-wrapper.admin .bubble {
    border-bottom-right-radius: 7px;
    background:
        radial-gradient(circle at 20% 10%, rgba(255, 255, 255, .12), transparent 28%),
        linear-gradient(145deg, #4d82ff, #5965e8 54%, #6b4fd4);
}

.message-wrapper.user .bubble {
    border-bottom-left-radius: 7px;
    background:
        radial-gradient(circle at 82% 8%, rgba(255, 255, 255, .065), transparent 28%),
        linear-gradient(145deg, #27354b, #202d42 58%, #1b2638);
}

.bubble::after {
    content: "";
    position: absolute;
    bottom: -1px;
    width: 11px;
    height: 13px;
    background: inherit;
}

.message-wrapper.admin .bubble::after {
    right: -5px;
    clip-path: polygon(0 0, 100% 100%, 0 100%);
}

.message-wrapper.user .bubble::after {
    left: -5px;
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

.bubble .text {
    color: #f6f8ff;
    font-size: 15px;
    line-height: 1.52;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.bubble .text a {
    color: #c7f1ff;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.msg-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    color: rgba(255, 255, 255, .64);
}

.msg-time {
    font-size: 10px;
    font-weight: 750;
}

.message-status {
    display: inline-flex;
    width: 12px;
    height: 12px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 8px;
    font-weight: 900;
}

.message-status.failed {
    color: #ffc1ce;
}

/* ---------- REPLY ---------- */

.reply-box {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-bottom: 8px;
    padding: 7px 9px;
    border-left: 3px solid rgba(255, 255, 255, .82);
    border-radius: 9px;
    color: #fff;
    background: rgba(0, 0, 0, .14);
    text-align: left;
    cursor: pointer;
    transition: background .18s ease, opacity .18s ease;
}

.reply-box:hover {
    background: rgba(0, 0, 0, .21);
}

.reply-box:active {
    opacity: .78;
}

.reply-box strong,
.reply-box span {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.reply-box strong {
    font-size: 11px;
    font-weight: 850;
}

.reply-box span {
    color: rgba(255, 255, 255, .73);
    font-size: 11px;
}

/* ---------- MEDIA ---------- */

.media-box {
    position: relative;
    overflow: hidden;
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 96px;
    max-height: 330px;
    margin-bottom: 8px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 13px;
    background: rgba(255, 255, 255, .055);
    cursor: pointer;
}

.photo-attachment img {
    display: block;
    width: 100%;
    max-height: 330px;
    object-fit: cover;
}

.video-attachment video {
    display: block;
    width: 100%;
    max-height: 330px;
    object-fit: cover;
}

.play-overlay {
    position: absolute;
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .24);
    border-radius: 50%;
    color: #fff;
    background: rgba(8, 13, 25, .60);
    box-shadow: 0 9px 24px rgba(0, 0, 0, .24);
    pointer-events: none;
}

.audio-attachment {
    min-width: 240px;
    margin-bottom: 6px;
}

.audio-title {
    margin-bottom: 7px;
    color: rgba(255, 255, 255, .92);
    font-size: 12px;
    font-weight: 800;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.audio-attachment audio {
    display: block;
    width: 100%;
    height: 38px;
}

.file-attachment {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 230px;
    width: 100%;
    margin-bottom: 8px;
    padding: 11px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 13px;
    color: inherit;
    background: rgba(255, 255, 255, .065);
    text-decoration: none;
    transition: background .18s ease, transform .18s ease;
}

.file-attachment:hover {
    background: rgba(255, 255, 255, .11);
    transform: translateY(-1px);
}

.file-icon {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    color: #72e0ff;
    background: rgba(105, 215, 255, .11);
    font-size: 16px;
    font-weight: 900;
}

.file-details {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.file-name,
.file-size {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.file-name {
    color: #fff;
    font-size: 12px;
    font-weight: 750;
}

.file-size {
    margin-top: 2px;
    color: rgba(255, 255, 255, .64);
    font-size: 10px;
}

.file-placeholder {
    min-height: 72px;
    width: 100%;
    padding: 13px;
    border-radius: 12px;
    color: rgba(255, 255, 255, .80);
    background: rgba(255, 255, 255, .065);
    font-size: 12px;
    cursor: default !important;
}

/* ---------- MESSAGE STATES ---------- */

.highlight-msg .bubble {
    animation: message-pulse 1.5s ease;
}

@keyframes message-pulse {
    0%, 100% {
        box-shadow: 0 10px 24px rgba(0, 0, 0, .20), inset 0 1px rgba(255, 255, 255, .07);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(105, 215, 255, .14), 0 16px 34px rgba(105, 215, 255, .16);
    }
}

.messages-loading,
.conversation-error {
    min-height: 100%;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 9px;
    color: var(--text-muted);
    text-align: center;
}

.messages-loading {
    display: flex;
    align-items: center;
    gap: 5px;
}

.messages-loading span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #687792;
    animation: dot 1s infinite ease-in-out;
}

.messages-loading span:nth-child(2) {
    animation-delay: .14s;
}

.messages-loading span:nth-child(3) {
    animation-delay: .28s;
}

@keyframes dot {
    0%, 80%, 100% { transform: scale(.65); opacity: .45; }
    40% { transform: scale(1); opacity: 1; }
}

.conversation-error strong {
    color: var(--text);
    font-size: 14px;
}

.conversation-error span {
    font-size: 12px;
}

.new-messages {
    position: absolute;
    right: 18px;
    bottom: 101px;
    z-index: 4;
    padding: 9px 13px;
    border: 1px solid rgba(105, 215, 255, .18);
    border-radius: var(--radius-pill);
    color: #8ee7ff;
    background: rgba(12, 20, 35, .94);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    font-size: 12px;
    font-weight: 850;
}

/* ---------- COMPOSER ---------- */

.footer-bar {
    flex: 0 0 auto;
    padding: 11px 11px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(12, 19, 35, .94);
}

.composer-context {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 49px;
    margin-bottom: 9px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(22, 32, 54, .78);
    box-shadow: var(--shadow-sm);
}

.context-accent {
    width: 3px;
    align-self: stretch;
    border-radius: var(--radius-pill);
    background: linear-gradient(180deg, var(--cyan), var(--violet));
}

.file-preview-icon {
    width: 31px;
    height: 31px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    color: #72e0ff;
    background: rgba(105, 215, 255, .10);
    font-weight: 900;
}

.context-copy {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.context-label,
.context-text,
.context-meta {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.context-label {
    color: var(--text);
    font-size: 11px;
    font-weight: 820;
}

.context-label strong {
    color: var(--cyan);
}

.context-text {
    margin-top: 2px;
    color: var(--text-soft);
    font-size: 11px;
}

.context-meta {
    margin-top: 1px;
    color: var(--text-muted);
    font-size: 9px;
}

.context-close {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    border-radius: 10px;
    color: var(--text-muted);
    background: transparent;
    cursor: pointer;
    font-size: 19px;
}

.context-close:hover {
    color: var(--text);
    background: rgba(148, 163, 184, .08);
}

.composer-form {
    display: flex;
    align-items: flex-end;
    gap: 7px;
}

#message-input {
    flex: 1;
    min-width: 0;
    max-height: 120px;
    min-height: 46px;
    padding: 12px 15px;
    border: 1px solid var(--line-strong);
    border-radius: 17px;
    resize: none;
    outline: none;
    overflow-y: auto;
    color: var(--text);
    background: rgba(14, 22, 40, .90);
    line-height: 1.48;
}

#message-input::-webkit-scrollbar {
    width: 0;
}

/* ---------- OVERLAYS / CONTEXT MENU ---------- */

.overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    background: rgba(1, 6, 15, .28);
}

.context-menu {
    position: fixed;
    z-index: 1000;
    width: 204px;
    padding: 7px;
    border: 1px solid var(--line-strong);
    border-radius: 16px;
    background: #111a2c;
    box-shadow: var(--shadow-lg);
}

.context-menu button {
    width: 100%;
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
    border-radius: 11px;
    color: var(--text-soft);
    background: transparent;
    text-align: left;
    cursor: pointer;
    font-size: 12px;
    font-weight: 760;
}

.context-menu button:hover {
    color: var(--text);
    background: rgba(255, 255, 255, .05);
}

.context-menu button.danger {
    color: #ff8ca6;
}

.menu-icon {
    width: 27px;
    height: 27px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    font-size: 10px;
    font-weight: 900;
}

.menu-icon.success {
    color: #61e8ba;
    background: rgba(59, 210, 154, .10);
}

.menu-icon.warning {
    color: #f5ce71;
    background: rgba(245, 199, 93, .09);
}

.menu-icon.danger {
    color: #ff8ca6;
    background: rgba(255, 109, 145, .09);
}

/* ---------- MODALS ---------- */

.modal,
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(2, 6, 15, .72);
}

.modal-card {
    position: relative;
    width: min(100%, 410px);
    padding: 29px;
    border: 1px solid var(--line-strong);
    border-radius: 24px;
    background: linear-gradient(150deg, #18233c, #10192d);
    box-shadow: var(--shadow-lg);
}

.modal-close {
    position: absolute;
    top: 11px;
    right: 11px;
    width: 35px;
    height: 35px;
    border-radius: 11px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, .045);
    cursor: pointer;
    font-size: 21px;
}

.modal-close:hover {
    color: var(--text);
    background: rgba(255, 255, 255, .08);
}

.modal-icon {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    margin-bottom: 15px;
    border-radius: 15px;
    color: var(--cyan);
    background: rgba(105, 215, 255, .10);
    font-size: 25px;
}

.modal-card h3 {
    margin-top: 5px;
    font-size: 24px;
    letter-spacing: -.035em;
}

.modal-actions {
    display: grid;
    grid-template-columns: 1fr 1.25fr;
    gap: 10px;
    margin-top: 23px;
}

.profile-card {
    text-align: left;
}

.profile-avatar {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    margin-bottom: 16px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 19px;
    color: #fff;
    font-size: 19px;
    font-weight: 900;
    box-shadow: 0 12px 28px rgba(0, 0, 0, .20);
}

.profile-row {
    margin-top: 21px;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(22, 32, 54, .72);
}

.profile-row span,
.profile-id span {
    display: block;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.profile-row strong {
    display: block;
    margin-top: 4px;
    color: var(--text);
    font-size: 15px;
}

.profile-id {
    width: 100%;
    margin-top: 10px;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(22, 32, 54, .72);
    text-align: left;
    cursor: pointer;
}

.profile-id:hover {
    border-color: rgba(105, 215, 255, .25);
    background: rgba(105, 215, 255, .06);
}

.profile-id strong {
    display: block;
    margin-top: 4px;
    color: var(--cyan);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
}

.profile-id small {
    display: block;
    margin-top: 5px;
    color: var(--text-muted);
    font-size: 10px;
}

/* ---------- LIGHTBOX ---------- */

.lightbox {
    grid-template-rows: 1fr auto;
    gap: 15px;
    background: rgba(2, 5, 12, .96);
}

.lightbox-close {
    position: absolute;
    top: max(16px, env(safe-area-inset-top));
    right: 16px;
    width: 43px;
    height: 43px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 13px;
    color: #fff;
    background: rgba(255, 255, 255, .07);
    cursor: pointer;
    font-size: 23px;
}

.lightbox-content {
    width: 100%;
    height: min(78dvh, 720px);
    display: grid;
    place-items: center;
}

.lightbox-media {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 15px;
    box-shadow: 0 26px 64px rgba(0, 0, 0, .38);
}

.download-btn {
    align-self: end;
    margin-bottom: max(6px, env(safe-area-inset-bottom));
    padding: 11px 18px;
    border-radius: var(--radius-pill);
    color: #061019;
    background: linear-gradient(135deg, var(--cyan), #8ecbff 48%, var(--violet));
    text-decoration: none;
    font-size: 12px;
    font-weight: 820;
    box-shadow: 0 12px 26px rgba(105, 215, 255, .12);
}

/* ---------- TOAST ---------- */

.toast-region {
    position: fixed;
    left: 50%;
    bottom: max(19px, env(safe-area-inset-bottom));
    z-index: 5000;
    display: flex;
    width: min(92vw, 420px);
    transform: translateX(-50%);
    pointer-events: none;
}

.toast {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid rgba(255, 255, 255, .10);
    border-radius: 14px;
    background: rgba(16, 23, 40, .96);
    color: #fff;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(13px);
    transition: opacity .18s ease, transform .18s ease;
    font-size: 12.5px;
    font-weight: 720;
}

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

.toast-success {
    background: rgba(8, 95, 74, .96);
}

.toast-error {
    background: rgba(127, 29, 55, .96);
}

/* ---------- DESKTOP ---------- */

@media (min-width: 860px) {
    .app-shell {
        padding: 14px;
    }

    .view-panel {
        inset: 14px;
        height: calc(100dvh - 28px);
        border-radius: 25px;
    }

    .view-list {
        width: 400px;
        border-right: 1px solid var(--line);
    }

    .view-room {
        left: 400px;
    }

    .view-list.left {
        transform: translateX(0);
    }

    .view-room.right {
        transform: translateX(110%);
    }

    .view-room.active {
        transform: translateX(0);
    }

    .list-meta {
        padding-top: 18px;
    }

    .chat-list {
        padding-bottom: 91px;
    }

    .bubble {
        max-width: min(70%, 650px);
    }

    .new-messages {
        bottom: 88px;
    }
}

/* ---------- MOBILE ---------- */

@media (max-width: 520px) {
    .auth-shell {
        padding: 30px 23px;
        border-radius: 24px;
    }

    .auth-actions {
        grid-template-columns: 1fr;
    }

    .button-secondary {
        order: 2;
    }

    .button-primary {
        order: 1;
    }

    .message-wrapper.admin {
        padding-right: 4px;
    }

    .message-wrapper.user {
        padding-left: 4px;
    }

    .bubble {
        max-width: 91%;
        padding: 10px 12px 8px;
    }

    .bubble .text {
        font-size: 14.5px;
    }

    .chat-list {
        padding-left: 7px;
        padding-right: 7px;
    }

    .list-meta {
        padding-left: 14px;
        padding-right: 14px;
    }

    .room-header {
        min-height: 66px;
    }
}

/* ---------- REDUCED MOTION ---------- */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: .001ms !important;
    }
}
