:root {
    --bg: #fff4d6;
    --bg-start: #f0e9ff;
    --accent-a: rgba(255, 212, 59, 0.46);
    --accent-b: rgba(32, 200, 255, 0.34);
    --accent-c: rgba(255, 79, 135, 0.16);
    --ink: #172126;
    --muted: #63727b;
    --line: #ded7ff;
    --panel: #ffffff;
    --surface: rgba(255, 255, 255, 0.91);
    --surface-strong: #ffffff;
    --soft: #fff2b8;
    --soft-text: #6a4300;
    --input-bg: #fbfdfc;
    --button-end: #2fb7ff;
    --shadow: rgba(36, 30, 79, 0.14);
    --brand: #7147ff;
    --brand-2: #ffd43b;
    --coral: #ff4f87;
    --sky: #20c8ff;
    --mint: #20df91;
    --bubble: #ffffff;
    --bubble-line: #e7dcff;
    --bubble-mine: #e9fff5;
    --bubble-mine-line: #a2f0ce;
    --avatar-text: #2b214a;
    --danger: #e54872;
    --ok: #18a96b;
}

body.theme-garcon {
    --bg: #ddf7ff;
    --bg-start: #e7fbff;
    --accent-a: rgba(84, 227, 164, 0.38);
    --accent-b: rgba(20, 121, 255, 0.28);
    --accent-c: rgba(36, 198, 220, 0.18);
    --line: #b9e7ff;
    --panel: #ffffff;
    --soft: #dff8ff;
    --soft-text: #075985;
    --button-end: #54e3a4;
    --brand: #1479ff;
    --brand-2: #54e3a4;
    --coral: #24c6dc;
    --sky: #36a3ff;
    --mint: #28d778;
    --bubble-mine: #e6fff4;
    --bubble-mine-line: #9df0cb;
}

body.theme-fille {
    --bg: #ffe7f1;
    --bg-start: #fff0f8;
    --accent-a: rgba(255, 209, 102, 0.38);
    --accent-b: rgba(181, 140, 255, 0.26);
    --accent-c: rgba(233, 68, 164, 0.18);
    --line: #ffc1dc;
    --panel: #fffafd;
    --soft: #fff0b9;
    --soft-text: #7c2d12;
    --button-end: #b58cff;
    --brand: #e944a4;
    --brand-2: #ffd166;
    --coral: #ff7aa8;
    --sky: #b58cff;
    --mint: #ffb3cf;
    --bubble-mine: #fff1f7;
    --bubble-mine-line: #ffb7d3;
}

body.theme-sombre {
    --bg: #17142c;
    --bg-start: #201b3f;
    --accent-a: rgba(255, 224, 102, 0.18);
    --accent-b: rgba(77, 214, 255, 0.16);
    --accent-c: rgba(255, 107, 157, 0.12);
    --ink: #f7f4ff;
    --muted: #c8c0e8;
    --line: #433a78;
    --panel: #241f42;
    --surface: rgba(36, 31, 66, 0.92);
    --surface-strong: #2e2855;
    --soft: #3b3367;
    --soft-text: #fff4ba;
    --input-bg: #1d1938;
    --button-end: #4dd6ff;
    --shadow: rgba(0, 0, 0, 0.32);
    --brand: #8f7cff;
    --brand-2: #ffe066;
    --coral: #ff6b9d;
    --sky: #4dd6ff;
    --mint: #5af0b0;
    --bubble: #2e2855;
    --bubble-line: #51468c;
    --bubble-mine: #203f44;
    --bubble-mine-line: #4dd6ff;
    --avatar-text: #17142c;
}

body.theme-pop {
    --bg: #e8fff4;
    --bg-start: #e9fbff;
    --accent-a: rgba(255, 183, 3, 0.36);
    --accent-b: rgba(58, 134, 255, 0.24);
    --accent-c: rgba(251, 86, 7, 0.14);
    --line: #b9f4dc;
    --panel: #ffffff;
    --soft: #fff0b7;
    --soft-text: #704214;
    --button-end: #fb5607;
    --brand: #00a5a8;
    --brand-2: #ffb703;
    --coral: #fb5607;
    --sky: #3a86ff;
    --mint: #06d6a0;
    --bubble-mine: #e6fff4;
    --bubble-mine-line: #8ce8c4;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        radial-gradient(circle at 12% 9%, var(--accent-a), transparent 26%),
        radial-gradient(circle at 88% 14%, var(--accent-b), transparent 25%),
        radial-gradient(circle at 50% 92%, var(--accent-c), transparent 30%),
        linear-gradient(180deg, var(--bg-start) 0, var(--bg) 360px);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.kid-loader {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    background: color-mix(in srgb, var(--bg) 72%, transparent);
    backdrop-filter: blur(6px);
}

.kid-loader[hidden] {
    display: none;
}

.loader-card {
    width: min(260px, calc(100% - 42px));
    border-radius: 8px;
    padding: 22px;
    background: var(--surface-strong);
    border: 3px solid var(--brand-2);
    box-shadow: 0 12px 0 color-mix(in srgb, var(--brand) 18%, transparent), 0 22px 44px var(--shadow);
    text-align: center;
}

.loader-hourglass {
    font-size: 3rem;
    animation: wobble 0.9s ease-in-out infinite alternate;
}

.loader-card strong,
.loader-card small {
    display: block;
}

.loader-card small {
    color: var(--muted);
    margin-top: 4px;
}

@keyframes wobble {
    from { transform: rotate(-8deg) scale(1); }
    to { transform: rotate(8deg) scale(1.08); }
}

a { color: inherit; text-decoration: none; }

button, .file-button {
    border: 0;
    min-height: 44px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--brand), var(--button-end));
    color: white;
    font-weight: 800;
    padding: 0 16px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.14s ease, box-shadow 0.14s ease;
}

button:active, .file-button:active {
    transform: translateY(2px) scale(0.98);
}

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

input, textarea, select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--ink);
    min-height: 44px;
    padding: 10px 12px;
    font: inherit;
}

textarea { min-height: 90px; resize: vertical; }

label { display: grid; gap: 6px; font-size: 0.92rem; font-weight: 750; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--surface);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
}

body.child-app .topbar {
    border-bottom: 0;
    box-shadow: none;
}

.topbar strong { display: block; font-size: 1.08rem; }
.topbar span { display: none; color: var(--muted); font-size: 0.9rem; }
.lang { display: flex; gap: 6px; }
.lang a {
    border: 1px solid var(--line);
    background: var(--surface-strong);
    border-radius: 8px;
    padding: 8px 9px;
    font-weight: 800;
    font-size: 0.8rem;
}

.flash {
    margin: 12px auto 0;
    width: min(960px, calc(100% - 24px));
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--soft);
    border: 1px solid var(--brand-2);
}

.login-shell, .app-shell, .admin-shell {
    width: min(980px, 100%);
    margin: 0 auto;
    padding: 14px;
}

.app-shell {
    padding-top: 0;
    padding-bottom: 96px;
}

.app-shell.chat-mode {
    padding-bottom: 0;
}

.login-shell {
    display: grid;
    gap: 14px;
}

.panel {
    background: var(--panel);
    border: 2px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    box-shadow: 0 12px 0 color-mix(in srgb, var(--brand) 11%, transparent), 0 18px 34px var(--shadow);
    animation: pop-in 0.22s ease both;
}

@keyframes pop-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-card {
    min-height: 380px;
    display: grid;
    align-content: center;
    gap: 16px;
}

.badge {
    width: max-content;
    border-radius: 999px;
    background: var(--soft);
    color: var(--soft-text);
    padding: 7px 10px;
    font-weight: 900;
    font-size: 0.8rem;
}

.badge-count {
    min-width: 22px;
    height: 22px;
    border-radius: 999px;
    background: var(--danger);
    color: white;
    display: inline-grid;
    place-items: center;
    padding: 0 7px;
    font-size: 0.76rem;
    font-weight: 950;
    line-height: 1;
}

.badge-count.empty {
    display: none;
}

h1, h2 { margin: 0 0 12px; letter-spacing: 0; }
h1 { font-size: 2rem; line-height: 1; }
h2 { font-size: 1.18rem; }
p { color: var(--muted); line-height: 1.5; }

.stack { display: grid; gap: 12px; }
.admin-link { color: var(--brand); font-weight: 850; }

.profile-strip {
    position: sticky;
    top: 58px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0 -14px 12px;
    padding: 9px 14px 11px;
    background: var(--surface);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 8px 18px color-mix(in srgb, var(--shadow) 52%, transparent);
    transition: padding 0.18s ease, transform 0.18s ease;
}

.profile-strip > div {
    min-width: 0;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    column-gap: 10px;
    align-items: center;
}

.profile-strip strong, .profile-strip small { min-width: 0; overflow-wrap: anywhere; }
.profile-strip small { grid-column: 2; color: var(--muted); }

.profile-name {
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.profile-name strong {
    border-bottom: 3px solid color-mix(in srgb, var(--brand-2) 72%, transparent);
}

.avatar {
    grid-row: span 2;
    width: 44px;
    height: 44px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--brand-2), var(--coral));
    color: var(--avatar-text);
    display: grid;
    place-items: center;
    font-weight: 950;
    transition: width 0.18s ease, height 0.18s ease, border-radius 0.18s ease;
}

.avatar-img {
    overflow: hidden;
    background: var(--surface-strong);
    border: 3px solid var(--surface-strong);
    box-shadow: 0 5px 14px color-mix(in srgb, var(--brand) 24%, transparent);
}

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

.profile-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.logout-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--danger), var(--coral));
    color: white;
    font-size: 1.2rem;
    box-shadow: 0 5px 0 color-mix(in srgb, var(--danger) 22%, transparent);
}

.logout-button:active {
    transform: translateY(2px);
    box-shadow: 0 3px 0 color-mix(in srgb, var(--danger) 22%, transparent);
}

.avatar-form {
    grid-row: span 2;
    position: relative;
}

.avatar-picker {
    display: block;
    cursor: pointer;
    position: relative;
}

.avatar-picker::after {
    content: "+";
    position: absolute;
    right: -3px;
    bottom: -3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--coral);
    color: white;
    border: 2px solid var(--surface-strong);
    font-size: 0.86rem;
    font-weight: 950;
}

.avatar-choice {
    position: absolute;
    left: 0;
    top: calc(100% + 8px);
    z-index: 12;
    width: min(260px, calc(100vw - 28px));
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px;
    border: 2px solid var(--line);
    border-radius: 8px;
    background: var(--surface-strong);
    box-shadow: 0 14px 28px var(--shadow);
}

.avatar-choice[hidden] {
    display: none;
}

.avatar-choice button {
    min-height: 38px;
    padding: 0 10px;
    font-size: 0.82rem;
}

.avatar-choice button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.avatar-choice small {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 0.74rem;
}

.profile-strip.compact {
    padding-top: 5px;
    padding-bottom: 6px;
}

.profile-strip.compact .avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
}

.profile-strip.compact small {
    display: none;
}

.chat-mode .profile-strip {
    margin-bottom: 0;
    box-shadow: none;
}

.tabs {
    position: fixed;
    left: 50%;
    bottom: 10px;
    transform: translateX(-50%);
    z-index: 8;
    width: min(520px, calc(100% - 22px));
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 0;
    padding: 8px;
    border-radius: 8px;
    border: 2px solid var(--line);
    background: var(--surface);
    backdrop-filter: blur(12px);
    box-shadow: 0 10px 26px var(--shadow);
}

.chat-mode .tabs {
    display: none;
}

.tabs a {
    min-height: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-weight: 850;
    font-size: 0.78rem;
    box-shadow: none;
}

.tabs a.active {
    background: linear-gradient(135deg, var(--brand), var(--coral));
    color: white;
    animation: tab-bounce 0.28s ease;
}

.tab-icon {
    font-size: 1.2rem;
    line-height: 1;
}

.profile-panel {
    display: grid;
    gap: 14px;
}

.profile-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--surface-strong) 72%, transparent);
    border: 2px solid var(--line);
}

.profile-preview small {
    display: block;
    color: var(--muted);
}

.theme-grid {
    display: grid;
    gap: 10px;
}

.theme-choice {
    position: relative;
    min-height: 78px;
    border-radius: 8px;
    border: 3px solid var(--line);
    padding: 10px 10px 10px 74px;
    background: var(--surface-strong);
    cursor: pointer;
    box-shadow: 0 6px 0 color-mix(in srgb, var(--brand) 11%, transparent);
}

.theme-choice input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.theme-choice.selected {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent);
}

.theme-choice strong,
.theme-choice small {
    display: block;
}

.theme-choice small {
    color: var(--muted);
}

.theme-swatch {
    position: absolute;
    left: 12px;
    top: 12px;
    width: 46px;
    height: 46px;
    border-radius: 14px;
    border: 3px solid var(--surface-strong);
    box-shadow: 0 5px 12px var(--shadow);
}

.theme-choice-general .theme-swatch { background: linear-gradient(135deg, #7147ff, #ffd43b, #20c8ff); }
.theme-choice-garcon .theme-swatch { background: linear-gradient(135deg, #1479ff, #54e3a4, #24c6dc); }
.theme-choice-fille .theme-swatch { background: linear-gradient(135deg, #e944a4, #ffd166, #b58cff); }
.theme-choice-sombre .theme-swatch { background: linear-gradient(135deg, #17142c, #8f7cff, #ffe066); }
.theme-choice-pop .theme-swatch { background: linear-gradient(135deg, #00a5a8, #ffb703, #fb5607); }

.chat-list-panel {
    display: grid;
    gap: 0;
    overflow: hidden;
    border: 2px solid var(--line);
    border-radius: 8px;
    background: var(--surface-strong);
    box-shadow: 0 12px 28px var(--shadow);
}

.chat-list-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-bottom: 2px solid var(--line);
    background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 12%, var(--surface-strong)), color-mix(in srgb, var(--brand-2) 22%, var(--surface-strong)));
}

.chat-list-title h2 {
    margin: 0;
}

.mini-action {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: white;
    background: linear-gradient(135deg, var(--brand), var(--coral));
    font-size: 1.6rem;
    font-weight: 950;
}

.list-section-label {
    padding: 11px 13px 7px;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 950;
    text-transform: uppercase;
    letter-spacing: 0;
    background: color-mix(in srgb, var(--bg) 38%, var(--surface-strong));
    border-bottom: 1px solid var(--line);
}

.empty-list {
    padding: 18px 13px;
    color: var(--muted);
    background: var(--surface-strong);
}

.conversation-row {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) minmax(52px, auto);
    gap: 11px;
    align-items: center;
    min-height: 76px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-strong);
    box-shadow: none;
    transition: background 0.14s ease, transform 0.14s ease;
}

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

.conversation-row:active {
    transform: scale(0.992);
}

.conversation-row.has-unread {
    background: color-mix(in srgb, var(--brand-2) 16%, var(--surface-strong));
}

.conversation-row.has-unread .conversation-main strong {
    color: var(--brand);
}

.conversation-avatar {
    width: 50px;
    height: 50px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: linear-gradient(135deg, var(--sky), var(--brand-2));
    font-weight: 950;
    color: var(--avatar-text);
    border: 2px solid color-mix(in srgb, var(--surface-strong) 76%, var(--line));
}

.conversation-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.group-avatar {
    color: white;
    background: linear-gradient(135deg, var(--brand), var(--coral));
    font-size: 1.4rem;
}

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

.conversation-main strong {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1rem;
    line-height: 1.2;
}

.conversation-main small,
.conversation-meta small {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-main small,
.conversation-meta small {
    color: var(--muted);
}

.conversation-meta {
    display: grid;
    justify-items: end;
    align-content: center;
    gap: 7px;
    min-width: 52px;
}

.conversation-meta small {
    max-width: 72px;
    font-size: 0.72rem;
}

@keyframes tab-bounce {
    0% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
    100% { transform: translateY(0); }
}

.grid, .admin-grid {
    display: grid;
    gap: 12px;
}

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

.item {
    border: 2px solid var(--line);
    border-radius: 8px;
    min-height: 58px;
    padding: 10px;
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    background: var(--surface-strong);
    transition: transform 0.14s ease, border-color 0.14s ease;
}

.item:hover {
    transform: translateY(-2px);
    border-color: var(--brand);
}

.item span { min-width: 0; }
.item small { display: block; color: var(--muted); overflow-wrap: anywhere; }
.item.vertical { display: grid; align-items: stretch; }
.item.compact {
    gap: 4px;
    min-height: auto;
    padding: 9px;
}

.usage-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 8px 0 10px;
}

.usage-metrics span {
    border: 2px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(135deg, color-mix(in srgb, var(--brand-2) 28%, var(--surface-strong)), color-mix(in srgb, var(--mint) 18%, var(--surface-strong)));
    padding: 10px 8px;
    min-width: 0;
}

.usage-metrics b {
    display: block;
    font-size: 0.96rem;
    overflow-wrap: anywhere;
}

.usage-metrics small {
    display: block;
    color: var(--muted);
    font-size: 0.76rem;
}

.muted {
    color: var(--muted);
}

.danger-text {
    color: var(--danger) !important;
}

.group-chat-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.invite-toggle {
    width: 100%;
    margin-top: 8px;
}

.group-invite-panel {
    display: grid;
    gap: 10px;
    margin-top: 8px;
    padding: 10px;
    border: 2px solid var(--line);
    border-radius: 8px;
    background: color-mix(in srgb, var(--bg) 26%, var(--surface-strong));
}

.group-invite-panel[hidden] {
    display: none;
}

.friend-checks {
    display: grid;
    gap: 8px;
}

.friend-check {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 7px 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-strong);
}

.friend-check input {
    width: 20px;
    min-height: 20px;
}

.friend-card {
    display: grid;
    align-items: stretch;
}

.friend-card.blocked {
    background: color-mix(in srgb, var(--danger) 8%, var(--surface-strong));
    border-color: color-mix(in srgb, var(--danger) 42%, var(--line));
}

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

.block-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    margin-top: 8px;
}

.block-reason {
    margin: 8px 0 0;
    color: var(--danger);
    font-size: 0.9rem;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.actions button { min-height: 36px; padding: 0 10px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: color-mix(in srgb, var(--muted) 48%, var(--surface-strong)); flex: 0 0 auto; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 5px color-mix(in srgb, var(--ok) 18%, transparent); }

.chat {
    min-height: calc(100vh - 154px);
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 10px;
}

.chat-mode .chat {
    gap: 0;
}

.chat-header {
    position: sticky;
    top: 116px;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 50px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--surface);
    border: 2px solid var(--line);
    backdrop-filter: blur(12px);
}

.chat-mode .chat-header {
    margin: 0 -14px;
    top: 107px;
    border-top: 0;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    background: var(--surface);
}

.back-button {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--soft);
    color: var(--soft-text);
    font-size: 2rem;
    line-height: 1;
    font-weight: 950;
}

.chat-feed {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: auto;
    padding: 6px 0 150px;
}

.chat-feed::after {
    content: "";
    display: block;
    height: 42px;
    flex: 0 0 auto;
}

.bubble {
    width: min(86%, 560px);
    border-radius: 8px;
    background: var(--bubble);
    border: 2px solid var(--bubble-line);
    padding: 10px;
    display: block;
    box-shadow: 0 5px 0 color-mix(in srgb, var(--brand) 11%, transparent);
}

.bubble.mine {
    align-self: flex-end;
    background: var(--bubble-mine);
    border-color: var(--bubble-mine-line);
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--sky), var(--brand-2));
    display: grid;
    place-items: center;
    font-weight: 950;
    overflow: hidden;
    flex: 0 0 auto;
}

.bubble-content {
    min-width: 0;
}

.message-head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.message-head small {
    min-width: 0;
    overflow-wrap: anywhere;
}

.bubble small {
    color: var(--muted);
    font-weight: 800;
}

.bubble p { margin: 6px 0 0; color: var(--ink); overflow-wrap: anywhere; font-size: 1.04rem; }
.bubble em { display: block; color: var(--danger); font-size: 0.8rem; margin-top: 5px; }
.attachment { display: inline-flex; margin-top: 7px; font-weight: 850; color: var(--brand); overflow-wrap: anywhere; }

.image-attachment {
    display: block;
    margin-top: 8px;
    width: min(100%, 310px);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--line);
    background: var(--input-bg);
}

.image-attachment img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 360px;
    object-fit: contain;
}

.voice-player {
    display: block;
    width: min(100%, 300px);
    margin-top: 8px;
}

.video-player {
    display: block;
    width: min(100%, 320px);
    max-height: 360px;
    margin-top: 8px;
    border-radius: 8px;
    background: var(--input-bg);
}

.composer {
    position: fixed;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: min(760px, 100%);
    z-index: 9;
    background: color-mix(in srgb, var(--bg) 82%, var(--surface-strong));
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding: 10px 14px;
    display: grid;
    gap: 8px;
}

.composer textarea { min-height: 54px; max-height: 120px; }

.composer.sending textarea {
    border-color: var(--brand);
    background:
        linear-gradient(90deg, color-mix(in srgb, var(--brand-2) 18%, transparent), transparent, color-mix(in srgb, var(--sky) 18%, transparent)),
        var(--input-bg);
    background-size: 220% 100%;
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 14%, transparent);
    animation: send-field-glow 0.9s ease-in-out infinite;
}

.composer.sending .composer-actions button:not([type]),
.composer.sending .composer-actions button[type="submit"] {
    opacity: 0.72;
    animation: send-button-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes send-field-glow {
    from { background-position: 0 0; }
    to { background-position: 220% 0; }
}

@keyframes send-button-pulse {
    from { transform: scale(1); }
    to { transform: scale(0.97); }
}

.fun-toggle {
    min-height: 40px;
    width: 100%;
    background: var(--soft);
    color: var(--soft-text);
    border: 2px solid var(--brand-2);
}

.fun-panel {
    display: grid;
    gap: 7px;
    max-height: 164px;
    overflow: auto;
    padding: 8px;
    border: 2px solid var(--brand-2);
    border-radius: 8px;
    background: var(--surface);
}

.fun-panel[hidden] {
    display: none;
}

.fun-tray,
.sticker-tray {
    display: grid;
    gap: 6px;
}

.fun-tray {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.sticker-tray {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.fun-object {
    min-height: 40px;
    padding: 0;
    background: var(--surface-strong);
    color: var(--ink);
    border: 2px solid var(--brand-2);
    font-size: 1.24rem;
    box-shadow: 0 4px 0 color-mix(in srgb, var(--brand-2) 30%, transparent);
}

.sticker-object {
    min-height: 38px;
    padding: 0 8px;
    background: var(--surface-strong);
    color: var(--brand);
    border: 2px solid var(--line);
    font-size: 0.86rem;
    box-shadow: 0 4px 0 color-mix(in srgb, var(--brand) 16%, transparent);
}

.fun-object:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 color-mix(in srgb, var(--brand-2) 30%, transparent);
}

.composer-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
}

.composer-actions button, .composer-actions .file-button {
    padding: 0 8px;
    font-size: 0.82rem;
}

.record.recording {
    background: var(--danger);
    color: white;
    animation: voice-record-pulse 0.72s ease-in-out infinite alternate;
}

.hold-record {
    touch-action: none;
    user-select: none;
}

@keyframes voice-record-pulse {
    from { transform: scale(1); box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 30%, transparent); }
    to { transform: scale(1.04); box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger) 8%, transparent); }
}

.admin-grid { padding-bottom: 22px; }
.alert {
    border-left: 5px solid var(--danger);
    background: color-mix(in srgb, var(--danger) 7%, var(--surface-strong));
    border-radius: 8px;
    padding: 10px;
    margin-top: 8px;
}

.alert.reviewed { border-left-color: var(--brand-2); }
.alert.closed { border-left-color: var(--ok); }

@media (min-width: 720px) {
    .topbar { padding: 14px 24px; }
    .topbar span { display: block; }
    .login-shell {
        min-height: calc(100vh - 72px);
        grid-template-columns: 1fr 1fr;
        align-items: center;
    }
    .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid .panel:last-child { grid-column: 1 / -1; }
    .admin-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    h1 { font-size: 2.7rem; }
}
