:root {
    color-scheme: light;
    --bg: #f4f7fb;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --text: #101828;
    --muted: #667085;
    --line: #e4e9f1;
    --line-strong: #d4dde8;
    --brand: #087f7b;
    --brand-2: #16a6a1;
    --accent: #f2b544;
    --message-in: #ffffff;
    --message-out: #d9f6ef;
    --danger: #d92d20;
    --shadow: 0 16px 42px rgba(16, 24, 40, .10);
}

body[data-theme="night"] {
    color-scheme: dark;
    --bg: #0f1419;
    --panel: #161d24;
    --panel-soft: #1d2730;
    --text: #edf4f2;
    --muted: #9aaeb8;
    --line: #26343d;
    --line-strong: #34454f;
    --brand: #5ed3c6;
    --brand-2: #38bdb3;
    --accent: #f1bd55;
    --message-in: #1b2530;
    --message-out: #113c3a;
    --danger: #ff766f;
    --shadow: 0 16px 42px rgba(0, 0, 0, .32);
}

body[data-theme="forest"] {
    --bg: #eef6f1;
    --panel: #ffffff;
    --panel-soft: #f3faf5;
    --text: #12261f;
    --muted: #60756d;
    --line: #d8e8de;
    --line-strong: #bdd6c5;
    --brand: #166b4d;
    --brand-2: #269a71;
    --accent: #a87a18;
    --message-in: #ffffff;
    --message-out: #dff3e8;
}

body[data-theme="pearl"] {
    --bg: #f6f4f8;
    --panel: #ffffff;
    --panel-soft: #faf8fc;
    --text: #171923;
    --muted: #6b6478;
    --line: #e7e1ed;
    --line-strong: #d8ccdf;
    --brand: #236b72;
    --brand-2: #3e9aa2;
    --accent: #b18422;
    --message-in: #ffffff;
    --message-out: #e6f4f1;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, "Segoe UI", system-ui, sans-serif;
}
body.legal-page {
    min-height: 100%;
    overflow: auto;
}
button, input, textarea, select { font: inherit; }
button {
    cursor: pointer;
    user-select: none;
}
button:disabled { cursor: not-allowed; opacity: .55; }
.hidden { display: none !important; }

.legal-doc {
    width: min(880px, calc(100% - 28px));
    margin: 0 auto;
    padding: 34px 0 54px;
}
.legal-doc h1 {
    margin: 14px 0 8px;
    font-size: clamp(30px, 5vw, 48px);
    letter-spacing: 0;
}
.legal-doc h2 {
    margin: 28px 0 10px;
    font-size: 20px;
}
.legal-doc p {
    color: #344054;
    line-height: 1.65;
}
.legal-back {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 0 12px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--brand);
    text-decoration: none;
    font-weight: 900;
}

.app { height: 100dvh; min-height: 0; overflow: hidden; }
.app[data-screen="auth"] {
    overflow-y: auto;
    overflow-x: hidden;
}
.auth-view {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 28px;
    background:
        linear-gradient(135deg, rgba(8,127,123,.16), transparent 42%),
        linear-gradient(315deg, rgba(22,166,161,.13), transparent 45%),
        var(--bg);
}
.auth-shell {
    width: min(960px, 100%);
    padding: 18px 0 28px;
}
.auth-brand, .compact-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}
.auth-brand { margin-bottom: 20px; }
.auth-brand h1 {
    margin: 0;
    font-size: 42px;
    line-height: 1;
    letter-spacing: 0;
}
.auth-brand p, .compact-brand span {
    margin: 5px 0 0;
    color: var(--muted);
}
.compact-brand strong {
    display: block;
    font-size: 20px;
    line-height: 1.1;
}
.brand-mark {
    width: 58px;
    height: 58px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: #fff;
    font-size: 29px;
    font-weight: 950;
    background: linear-gradient(135deg, var(--brand), var(--brand-2));
    box-shadow: 0 14px 26px rgba(8, 127, 123, .24);
}
.compact-brand .brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 15px;
    font-size: 24px;
}
.auth-grid {
    display: grid;
    grid-template-columns: minmax(280px, 420px) minmax(300px, 1fr);
    gap: 18px;
    align-items: stretch;
}
.auth-card, .profile-card, .panel-card {
    background: rgba(255,255,255,.94);
    border: 1px solid var(--line);
}
.auth-card {
    border-radius: 26px;
    padding: 24px;
    box-shadow: var(--shadow);
}
.card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}
.card-head.stacked { display: block; }
.auth-card h2, .panel-card h3, .profile-card h3, .dialog-card h2 {
    margin: 0;
    letter-spacing: 0;
}
.auth-card p, .card-head p {
    margin: 7px 0 0;
    color: var(--muted);
}
label {
    display: grid;
    gap: 7px;
    margin: 14px 0;
    color: #344054;
    font-weight: 800;
}
.check-row {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    font-weight: 700;
    color: var(--muted);
}
.check-row input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
}
.check-row a,
.legal-mini a,
.profile-links a {
    color: var(--brand);
    text-decoration: none;
}
.check-row a:hover,
.legal-mini a:hover,
.profile-links a:hover {
    text-decoration: underline;
}
.legal-mini {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
    color: var(--muted);
    font-size: 13px;
}
input, textarea, select {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 15px;
    padding: 12px 14px;
    background: var(--panel);
    color: var(--text);
    outline: none;
}
textarea {
    line-height: 1.38;
    resize: none;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px rgba(8,127,123,.12);
}
.primary-btn, .send-btn, .ghost-btn, .full-btn, .danger-btn, .link-btn {
    border-radius: 14px;
    min-height: 42px;
    padding: 0 16px;
    font-weight: 900;
}
.primary-btn, .send-btn {
    border: 0;
    background: var(--brand);
    color: #fff;
}
.primary-btn:hover, .send-btn:hover { background: #066b68; }
.ghost-btn, .full-btn {
    border: 1px solid var(--line-strong);
    background: #fff;
    color: var(--text);
}
.ghost-btn:hover, .full-btn:hover, .icon-btn:hover {
    border-color: rgba(8,127,123,.45);
    background: #f1fbf9;
}
.danger-btn {
    border: 0;
    background: var(--danger);
    color: #fff;
}
.link-btn {
    border: 0;
    min-height: 32px;
    padding: 0 8px;
    background: transparent;
    color: var(--brand);
}
.icon-btn {
    width: 44px;
    height: 44px;
    border: 1px solid var(--line-strong);
    border-radius: 15px;
    display: grid;
    place-items: center;
    background: #fff;
    color: var(--text);
    font-size: 19px;
    font-weight: 950;
}
.icon-btn.accent {
    background: var(--text);
    color: #fff;
    border-color: var(--text);
}
.status { color: var(--muted); min-height: 22px; }
.auth-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 14px;
}
.qr-box {
    aspect-ratio: 1;
    margin-top: 18px;
    border-radius: 24px;
    border: 1px solid var(--line);
    display: grid;
    place-items: center;
    overflow: hidden;
    background: #fff;
}
.qr-box img {
    width: min(82%, 320px);
    height: min(82%, 320px);
    object-fit: contain;
}
.qr-placeholder {
    width: 82%;
    height: 82%;
    border-radius: 22px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 12px;
    background:
        linear-gradient(135deg, rgba(8,127,123,.12), transparent 44%),
        linear-gradient(315deg, rgba(22,166,161,.12), transparent 48%),
        #f8fafc;
    color: var(--muted);
    text-align: center;
}
.qr-placeholder strong {
    width: 68px;
    height: 68px;
    border-radius: 21px;
    display: grid;
    place-items: center;
    background: #fff;
    color: var(--brand);
    font-size: 23px;
    box-shadow: 0 12px 24px rgba(16, 24, 40, .08);
}
.qr-placeholder span { max-width: 190px; font-size: 14px; }
.ticket-row {
    display: grid;
    gap: 8px;
    margin-top: 14px;
    color: var(--muted);
}
code {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 9px 10px;
    border-radius: 12px;
    background: #eef6f5;
    color: var(--brand);
}

.messenger-view {
    display: none;
    height: 100dvh;
    min-height: 0;
    width: 100vw;
    overflow: hidden;
    grid-template-columns: minmax(286px, 362px) minmax(430px, 1fr);
    background: var(--bg);
}
.app[data-screen="messenger"] .auth-view { display: none; }
.app[data-screen="messenger"] .messenger-view { display: grid; }
.sidebar, .details {
    min-width: 0;
    min-height: 0;
    background: rgba(255,255,255,.96);
}
.sidebar {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--line);
}
.details {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 8;
    width: min(360px, 100vw);
    height: 100dvh;
    display: grid;
    align-content: start;
    gap: 14px;
    overflow: auto;
    padding: 16px;
    border-left: 1px solid var(--line);
    box-shadow: -18px 0 40px rgba(16,24,40,.12);
    transform: translateX(100%);
    transition: transform .2s ease;
}
.app.details-open .details {
    transform: translateX(0);
}
.details-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.details-top strong {
    font-size: 18px;
}
.sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px;
}
.search {
    position: relative;
    margin: 0 18px 12px;
}
.search span {
    position: absolute;
    left: 14px;
    top: 13px;
    color: var(--muted);
    font-weight: 900;
}
.search input { padding-left: 38px; }
.tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 0 18px 14px;
}
.tab {
    min-width: 0;
    min-height: 38px;
    border: 0;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: transparent;
    color: var(--muted);
    font-weight: 950;
}
.tab:hover { background: var(--panel-soft); color: var(--text); }
.tab.active {
    background: #d9f6ef;
    color: var(--brand);
}
.tab-badge {
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    padding: 0 5px;
    background: var(--brand);
    color: #fff;
    font-size: 11px;
    line-height: 1;
}
.list {
    display: grid;
    gap: 7px;
    align-content: start;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    padding: 0 10px 18px;
}
.chat-item {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr) auto;
    gap: 11px;
    align-items: center;
    border: 1px solid transparent;
    border-radius: 18px;
    padding: 10px;
    background: transparent;
    text-align: left;
}
.chat-item:hover {
    background: #f4f8fb;
    border-color: var(--line);
}
.chat-item.active {
    background: #eef7f5;
    border-color: rgba(8,127,123,.22);
    box-shadow: 0 10px 24px rgba(8,127,123,.08);
}
.chat-item.unread .chat-main > span {
    color: var(--text);
    font-weight: 850;
}
.chat-item.unread .time-mini {
    color: var(--brand);
    font-weight: 950;
}
.chat-main {
    min-width: 0;
    display: grid;
    gap: 4px;
}
.chat-title-row {
    display: flex;
    min-width: 0;
    gap: 8px;
    align-items: center;
}
.chat-title-row strong, .chat-item span {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.chat-title-row strong { font-size: 15px; }
.chat-item span {
    color: var(--muted);
    font-size: 13px;
}
.time-mini {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}
.avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    background:
        linear-gradient(135deg, rgba(8,127,123,.18), transparent 52%),
        linear-gradient(315deg, rgba(22,166,161,.16), transparent 48%),
        #f5f7fb;
    color: var(--brand);
    font-weight: 950;
}
.avatar.large {
    width: 86px;
    height: 86px;
    margin: 0 auto 12px;
    font-size: 32px;
}
.avatar.tiny {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 12px;
}
.badge {
    min-width: 24px;
    height: 24px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    padding: 0 7px;
    background: var(--brand-2);
    color: #fff;
    font-size: 12px;
    font-weight: 950;
}
.empty-list {
    margin: 12px;
    padding: 16px;
    border: 1px dashed var(--line-strong);
    border-radius: 18px;
    color: var(--muted);
    text-align: center;
}
.empty-state {
    display: grid;
    gap: 7px;
    justify-items: center;
    color: var(--muted);
    text-align: center;
}
.empty-state strong {
    color: var(--text);
    font-size: 15px;
}
.empty-state.compact {
    margin: 12px;
    padding: 18px;
    border: 1px dashed var(--line-strong);
    border-radius: 20px;
    background: rgba(255,255,255,.72);
}
.empty-state.conversation {
    align-self: center;
    justify-self: center;
    max-width: 360px;
    margin: auto;
    padding: 28px;
}
.empty-state.conversation .brand-mark {
    width: 64px;
    height: 64px;
    border-radius: 20px;
}

.chat-panel {
    position: relative;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #e5ddd5;
    background-image: url('https://www.transparenttextures.com/patterns/cubes.png');
}
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    background: #ffffff;
    z-index: 5;
}
.mobile-back { display: none; }
.chat-heading { min-width: 0; }
.chat-heading, #chatAvatar { cursor: pointer; }
.chat-heading h2 {
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 22px;
}
.chat-heading p {
    margin: 4px 0 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
}
.header-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}
.drop-hint {
    display: none;
    margin: 12px 18px 0;
    padding: 14px 16px;
    border: 1px dashed var(--brand);
    border-radius: 18px;
    background: #ecfdf5;
    color: var(--brand);
}
.chat-panel.dragging .drop-hint {
    display: grid;
    gap: 4px;
}
.messages {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 18px;
    scrollbar-color: var(--line-strong) transparent;
}
.date-chip {
    align-self: center;
    padding: 6px 11px;
    border-radius: 999px;
    background: #e9eef5;
    color: #536176;
    font-size: 12px;
    font-weight: 900;
}
.message {
    position: relative;
    align-self: flex-start;
    max-width: 85%;
    min-width: 60px;
    border: none;
    border-radius: 0 12px 12px 12px;
    padding: 8px 12px 24px;
    background: #ffffff;
    box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
    margin-bottom: 4px;
}
.message.out {
    align-self: flex-end;
    background: #dcf8c6;
    border-radius: 12px 0 12px 12px;
}
.message .meta {
    position: absolute;
    right: 8px;
    bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    color: rgba(0,0,0,0.45);
    font-size: 11px;
}
.message .receipt {
    letter-spacing: -3px;
    padding-right: 3px;
    font-weight: 950;
    color: #8a98aa;
}
.message .receipt.read {
    color: #178bff;
}
.message-menu {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    font-weight: 950;
}
.message-menu:hover { background: rgba(16,24,40,.06); }
.select-mark {
    position: absolute;
    left: -14px;
    top: 12px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: var(--brand);
    color: #fff;
    font-weight: 950;
    box-shadow: var(--shadow);
}
.reply-quote {
    display: grid;
    gap: 2px;
    width: 100%;
    margin: 0 0 8px;
    padding: 8px 10px;
    border: 0;
    border-left: 3px solid var(--brand);
    border-radius: 12px;
    background: rgba(255,255,255,.66);
    color: var(--text);
    text-align: left;
}
.reply-quote span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 12px;
}
.message-files {
    display: grid;
    gap: 6px;
    margin-top: 9px;
}
.message-file {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
    width: 100%;
    border: 0;
    padding: 8px;
    border-radius: 14px;
    background: rgba(255,255,255,.82);
    color: var(--text);
    text-align: left;
    text-decoration: none;
}
.message-file:hover { background: #fff; }
.message-file.disabled {
    opacity: .6;
    pointer-events: none;
}
.message-file strong, .message-file span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.message-file span { color: var(--muted); font-size: 12px; }
.file-preview {
    display: grid;
    gap: 6px;
    margin: 0;
    max-width: min(360px, 100%);
}
.file-preview button {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    border-radius: 14px;
    overflow: hidden;
    background: transparent;
    cursor: pointer;
}
.file-preview img,
.file-preview video {
    display: block;
    width: 100%;
    max-height: 280px;
    border-radius: 14px;
    object-fit: cover;
    background: #0b1220;
}
.file-preview figcaption {
    color: var(--muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.play-badge {
    position: absolute;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(16,24,40,.72);
    color: #fff;
    font-weight: 950;
}
.attachments {
    display: flex;
    gap: 8px;
    min-height: 0;
    max-height: 112px;
    overflow: auto;
    padding: 0 12px 8px;
}
.selection-bar,
.reply-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 14px 8px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255,255,255,.96);
    box-shadow: 0 12px 28px rgba(16,24,40,.08);
}
.selection-bar > div {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.selection-bar button {
    min-height: 34px;
    border-radius: 12px;
    border: 1px solid var(--line-strong);
    background: #fff;
    padding: 0 10px;
    font-weight: 900;
}
.reply-bar {
    border-left: 4px solid var(--brand);
}
.reply-bar > div {
    display: grid;
    min-width: 0;
}
.reply-bar span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
}
.attachment-pill {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    gap: 9px;
    align-items: center;
    min-width: 238px;
    max-width: 340px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
}
.file-icon {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: #eaf8f5;
    color: var(--brand);
    font-weight: 950;
}
.attachment-pill strong, .attachment-pill span {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.attachment-pill span {
    color: var(--muted);
    font-size: 12px;
}
.remove-attachment {
    width: 32px;
    height: 32px;
    border-radius: 11px;
    font-size: 16px;
}
.composer {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 10px;
    align-items: end;
    padding: 12px 14px;
    border-top: 1px solid var(--line);
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(16px);
}
.composer textarea {
    min-height: 50px;
    max-height: 138px;
    border-radius: 26px;
    padding: 13px 16px;
}
.composer :disabled {
    opacity: .55;
}
.attach-btn { font-size: 18px; }
.composer .icon-btn {
    width: 48px;
    height: 48px;
    border-color: transparent;
    border-radius: 50%;
    background: var(--panel-soft);
    color: var(--brand);
}
.send-btn {
    width: 52px;
    min-width: 52px;
    min-height: 52px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    padding: 0;
    font-size: 20px;
    line-height: 1;
}

.profile-card, .panel-card {
    border-radius: 22px;
    padding: 16px;
    text-align: center;
    box-shadow: 0 10px 28px rgba(16,24,40,.055);
}
.profile-card h3 { margin-top: 0; }
.profile-card p {
    margin: 7px 0 0;
    color: var(--muted);
    overflow-wrap: anywhere;
}
.profile-card .details-bio {
    margin-top: 10px;
    padding: 10px;
    border-radius: 14px;
    background: var(--panel-soft);
    color: var(--text);
    text-align: left;
    font-size: 13px;
}
.profile-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-top: 12px;
}
.profile-meta span {
    max-width: 100%;
    border-radius: 999px;
    padding: 5px 9px;
    background: var(--panel-soft);
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}
.quota {
    display: grid;
    gap: 4px;
    margin-top: 15px;
    padding: 13px;
    border-radius: 17px;
    background: var(--panel-soft);
    text-align: left;
}
.quota span { color: var(--muted); }
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.panel-head h3 { margin: 0; }
.members-list {
    display: grid;
    gap: 7px;
}
.member-row {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    align-items: center;
    gap: 9px;
    width: 100%;
    min-width: 0;
    padding: 8px;
    border: 1px solid transparent;
    border-radius: 14px;
    background: var(--panel-soft);
    color: var(--text);
    text-align: left;
}
.member-row:hover,
.member-row.active {
    border-color: rgba(8,127,123,.28);
    background: #eef7f5;
}
.member-row strong,
.member-row small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.member-row small {
    color: var(--muted);
    font-size: 12px;
}
.media-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
}
.media-tile {
    aspect-ratio: 1;
    border: 0;
    border-radius: 15px;
    display: grid;
    place-items: center;
    gap: 4px;
    min-width: 0;
    overflow: hidden;
    background:
        linear-gradient(135deg, rgba(8,127,123,.12), transparent 52%),
        linear-gradient(315deg, rgba(22,166,161,.14), transparent 52%),
        #f5f7fb;
    color: var(--brand);
    font-weight: 950;
}
.media-tile img,
.media-tile video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.media-tile small {
    max-width: 100%;
    padding: 0 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 10px;
}
.media-tile:hover { outline: 2px solid rgba(8,127,123,.22); }
.empty-attachments {
    grid-column: 1 / -1;
    padding: 14px;
    border: 1px dashed var(--line-strong);
    border-radius: 14px;
    color: var(--muted);
    text-align: center;
    font-size: 13px;
}
.full-btn {
    width: 100%;
    margin-top: 8px;
}

dialog {
    border: 0;
    border-radius: 22px;
    padding: 0;
    overflow: hidden;
    box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(16,24,40,.42); }
#mediaPreviewDialog {
    max-width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
}
.dialog-card {
    width: min(480px, calc(100vw - 32px));
    padding: 22px;
}
.dialog-card.compact { width: min(420px, calc(100vw - 32px)); }
.dialog-card.friend-request-card { width: min(520px, calc(100vw - 32px)); }
.dialog-card.attachments-dialog { width: min(760px, calc(100vw - 32px)); }
.dialog-card p { color: var(--muted); }
.media-dialog {
    width: min(1120px, calc(100vw - 24px));
    height: min(820px, calc(100dvh - 24px));
    min-width: min(340px, calc(100vw - 24px));
    min-height: min(360px, calc(100dvh - 24px));
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    background: #050816;
    color: #fff;
}
.media-dialog-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
}
.media-dialog-top > div {
    display: flex;
    gap: 8px;
}
.media-dialog .icon-btn {
    color: #fff;
    border-color: rgba(255,255,255,.18);
    background: rgba(255,255,255,.08);
    text-decoration: none;
}
.media-preview-body {
    min-width: 0;
    min-height: 0;
    display: grid;
    place-items: center;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 14px;
}
.media-preview-body img,
.media-preview-body video {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    border-radius: 14px;
    object-fit: contain;
    background: #050816;
}
.media-preview-body .media-full-image {
    object-position: center center;
}
.media-preview-body.is-actual-size {
    place-items: start center;
}
.media-preview-body.is-actual-size img,
.media-preview-body.is-actual-size video {
    max-width: none;
    max-height: none;
}
.friend-request-card textarea {
    min-height: 112px;
    resize: vertical;
    line-height: 1.45;
}
.dialog-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.attachment-sections {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-top: 16px;
}
.attachment-section {
    display: grid;
    align-content: start;
    gap: 8px;
    min-width: 0;
}
.attachment-section h3 {
    margin: 0 0 4px;
    font-size: 14px;
}
.attachment-section p {
    margin: 0;
    padding: 12px;
    border: 1px dashed var(--line-strong);
    border-radius: 14px;
}
.attachment-row {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    color: var(--text);
    text-align: left;
}
.attachment-row strong,
.attachment-row small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.attachment-row small {
    color: var(--muted);
}
.dialog-actions {
    display: flex;
    gap: 9px;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-top: 16px;
}
.dialog-actions button {
    min-height: 40px;
    border-radius: 13px;
    border: 1px solid var(--line-strong);
    background: #fff;
    padding: 0 13px;
    font-weight: 900;
}
.dialog-actions .primary-btn, .dialog-actions .danger-btn { border: 0; }
.toast {
    position: fixed;
    left: 50%;
    bottom: 22px;
    transform: translate(-50%, 18px);
    max-width: min(520px, calc(100vw - 32px));
    padding: 12px 16px;
    border-radius: 15px;
    background: #101828;
    color: #fff;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
    box-shadow: var(--shadow);
    z-index: 30;
}
.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

@media (max-width: 1180px) {
    .messenger-view { grid-template-columns: minmax(286px, 350px) minmax(430px, 1fr); }
}
@media (max-width: 820px) {
    .app { min-height: 0; }
    .auth-view { overflow: auto; place-items: start center; }
    .auth-grid { grid-template-columns: 1fr; }
    .messenger-view { grid-template-columns: 1fr; }
    .sidebar {
        display: flex;
        position: absolute;
        inset: 0;
        z-index: 6;
        width: 100%;
        min-height: 100dvh;
        background: #fff;
        transform: translateX(0);
        transition: transform .2s ease;
    }
    .app.chat-open .sidebar { transform: translateX(-100%); }
    .mobile-back { display: grid; }
    .message { max-width: 88%; }
    .send-btn { min-width: 52px; }
}
@media (max-width: 540px) {
    .auth-view { padding: 16px; }
    .auth-brand h1 { font-size: 34px; }
    .auth-card { padding: 18px; border-radius: 22px; }
    .composer {
        grid-template-columns: auto minmax(0, 1fr) auto auto;
    }
    .send-btn {
        grid-column: auto;
        width: 52px;
    }
}

/* Senta 0.1.1 UI fixes */
html, body { overflow: hidden; }
.app { height: 100dvh; min-height: 0; }
.auth-view { min-height: 100dvh; overflow: auto; padding: clamp(12px, 2.4vh, 24px); }
.auth-shell { width: min(920px, 100%); }
.auth-grid { align-items: start; }
.auth-card { padding: clamp(16px, 2.2vh, 22px); }
.qr-box { max-height: min(44vh, 330px); min-height: 210px; }
.qr-box img { width: min(78%, 260px); height: min(78%, 260px); }
.ticket-row code { font-size: 12px; }

.messenger-view {
    height: 100dvh;
    grid-template-columns: minmax(260px, 330px) minmax(360px, 1fr);
}
.sidebar-top { padding: 14px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.compact-brand { min-width: 0; }
.compact-brand > div:last-child { min-width: 0; }
.compact-brand span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.chat-header { padding: 10px 14px; }
.messages { padding: 14px; }
.details { padding: 12px; gap: 10px; }
.profile-card, .panel-card { padding: 13px; border-radius: 18px; }
.avatar { background-size: cover; background-position: center; overflow: hidden; }
.avatar.large { width: 74px; height: 74px; font-size: 28px; }
.composer { grid-template-columns: auto minmax(0, 1fr) auto auto; padding: 10px 12px; }
.voice-btn.recording { background: #fff1f0; color: var(--danger); border-color: rgba(217,45,32,.28); }
.voice-message { display: grid; gap: 6px; min-width: min(280px, 100%); }
.voice-message audio { width: 100%; max-width: 340px; }
.voice-message span { color: var(--muted); font-size: 12px; }
.user-result {
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr) auto auto;
    gap: 10px;
    align-items: center;
    margin: 0 8px 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
}
.user-result .primary-btn, .user-result .ghost-btn { min-height: 36px; padding: 0 12px; }
.user-result.muted {
    background: #f8fafc;
}
.user-result button:disabled {
    cursor: default;
    opacity: .72;
}
.request-note {
    display: block;
    max-height: 42px;
    overflow: hidden;
    color: var(--text);
    opacity: .78;
    line-height: 1.35;
}
.list-section { padding: 10px 16px 8px; color: var(--muted); font-weight: 950; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.danger-soft { color: var(--danger); border-color: rgba(217,45,32,.25); }
.profile-editor { display: grid; gap: 10px; place-items: center; }
.profile-editor label:not(.avatar-picker),
.profile-section label:not(.check-row) {
    width: 100%;
}
.profile-section {
    display: grid;
    gap: 10px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}
.profile-section h3 {
    margin: 0;
}
.profile-links {
    display: grid;
    gap: 9px;
    padding: 12px;
    border-radius: 16px;
    background: var(--panel-soft);
}
.avatar-picker { margin: 4px 0; cursor: pointer; text-align: center; color: var(--brand); }
.muted-line { color: var(--muted); margin: 0; overflow-wrap: anywhere; }
.dialog-actions.spread { justify-content: space-between; }
.dialog-actions button.primary-btn { background: var(--brand); color: #fff; }
.dialog-actions button.danger-btn { background: var(--danger); color: #fff; border: 0; }
dialog { max-width: calc(100vw - 24px); }
.dialog-card { max-height: calc(100dvh - 36px); overflow-y: auto; overflow-x: hidden; }
#profileDialog .dialog-card { max-height: calc(100dvh - 36px); }
.profile-editor textarea {
    min-height: 82px;
    resize: vertical;
    line-height: 1.45;
}
#newGroupDialog .primary-btn, #renameDialog .primary-btn { background: var(--brand) !important; color: #fff !important; border: 0 !important; }
#newGroupDialog .dialog-actions button, #renameDialog .dialog-actions button { color: var(--text); }

body[data-theme="night"] .legal-back,
body[data-theme="night"] .auth-card,
body[data-theme="night"] .panel-card,
body[data-theme="night"] .profile-card,
body[data-theme="night"] .dialog-card,
body[data-theme="night"] .sidebar,
body[data-theme="night"] .details,
body[data-theme="night"] .chat-header,
body[data-theme="night"] .composer,
body[data-theme="night"] .attachment-pill,
body[data-theme="night"] .message-file:hover,
body[data-theme="night"] .attachment-row,
body[data-theme="night"] .media-tile,
body[data-theme="night"] .user-result {
    background: var(--panel) !important;
    color: var(--text);
}

body[data-theme="night"] input,
body[data-theme="night"] textarea,
body[data-theme="night"] select,
body[data-theme="night"] .chat-item:hover,
body[data-theme="night"] .file-preview button,
body[data-theme="night"] .voice-message,
body[data-theme="night"] .selection-bar,
body[data-theme="night"] .reply-bar,
body[data-theme="night"] .drop-hint {
    background: var(--panel-soft);
    color: var(--text);
}

body[data-theme="night"] .chat-item.active,
body[data-theme="night"] .tab.active {
    background: rgba(94, 211, 198, .16);
}

body[data-theme="night"] .chat-panel {
    background: linear-gradient(180deg, rgba(15,20,25,.82), rgba(15,20,25,.98)), var(--bg);
}

body[data-theme="night"] .message:not(.out) { background: var(--message-in); }
body[data-theme="night"] .message.out { background: var(--message-out); }

@media (max-width: 1260px) {
    .messenger-view { grid-template-columns: minmax(250px, 320px) minmax(360px, 1fr); }
}
@media (max-width: 900px) {
    .auth-grid { grid-template-columns: 1fr; }
    .qr-box { max-height: 290px; }
}
@media (max-width: 820px) {
    .messenger-view { grid-template-columns: 1fr; }
    .sidebar { position: absolute; inset: 0; z-index: 6; width: 100%; min-height: 100dvh; background: #fff; transition: transform .2s ease; }
    .app.chat-open .sidebar { transform: translateX(-100%); }
    .mobile-back { display: grid; }
    .message { max-width: 90%; }
}
@media (max-width: 560px) {
    .composer { grid-template-columns: auto minmax(0, 1fr) auto auto; }
    .composer textarea { min-width: 0; }
    .send-btn { grid-column: auto; width: 52px; }
    .user-result { grid-template-columns: 42px minmax(0,1fr); }
    .user-result button { grid-column: span 1; }
    .file-preview img,
    .file-preview video { max-height: 220px; }
    .attachment-sections { grid-template-columns: 1fr; }
}
