/* ==========================================================================
   Webchat — styles
   ========================================================================== */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f1f3f5;
    --surface-3: #e9ecef;
    --border: #e3e6ea;
    --text: #15181d;
    --text-2: #5c6470;
    --text-3: #8a929d;
    --accent: #3b5bdb;
    --accent-hover: #3249c1;
    --accent-soft: #e8edff;
    --accent-text: #ffffff;
    --danger: #d6336c;
    --danger-soft: #fdecf2;
    --success: #2f9e44;
    --bubble-in: #ffffff;
    --bubble-in-text: #15181d;
    --bubble-out: #3b5bdb;
    --bubble-out-text: #ffffff;
    --chat-bg: #eef0f4;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 8px 24px rgba(16, 24, 40, .12);
    --shadow-lg: 0 24px 64px rgba(16, 24, 40, .22);
    --radius: 12px;
    --radius-lg: 18px;
    --sidebar-w: 360px;
    --header-h: 64px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
            "Noto Sans", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    color-scheme: light;
}

/* Dark theme: chosen in My profile, or "same as device" when the device is dark.
   Without a data-theme attribute the light theme above applies. */
:root[data-theme="dark"] {
    --bg: #0f1115;
    --surface: #16181d;
    --surface-2: #1d2027;
    --surface-3: #262a33;
    --border: #262a33;
    --text: #e8eaed;
    --text-2: #a3aab5;
    --text-3: #727a86;
    --accent: #5c7cfa;
    --accent-hover: #748ffc;
    --accent-soft: #1e2645;
    --danger: #f06595;
    --danger-soft: #3a1a26;
    --success: #51cf66;
    --bubble-in: #1f2229;
    --bubble-in-text: #e8eaed;
    --bubble-out: #4263eb;
    --bubble-out-text: #ffffff;
    --chat-bg: #0f1115;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .5);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, .6);
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    :root[data-theme="system"] {
        --bg: #0f1115;
        --surface: #16181d;
        --surface-2: #1d2027;
        --surface-3: #262a33;
        --border: #262a33;
        --text: #e8eaed;
        --text-2: #a3aab5;
        --text-3: #727a86;
        --accent: #5c7cfa;
        --accent-hover: #748ffc;
        --accent-soft: #1e2645;
        --danger: #f06595;
        --danger-soft: #3a1a26;
        --success: #51cf66;
        --bubble-in: #1f2229;
        --bubble-in-text: #e8eaed;
        --bubble-out: #4263eb;
        --bubble-out-text: #ffffff;
        --chat-bg: #0f1115;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow-md: 0 8px 24px rgba(0, 0, 0, .5);
        --shadow-lg: 0 24px 64px rgba(0, 0, 0, .6);
        color-scheme: dark;
    }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
}

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.45;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Buttons & form controls
   -------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    font-weight: 600;
    font-size: 14px;
    transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-text);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn-block { width: 100%; min-height: 46px; font-size: 15px; }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-2);
    transition: background-color .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.link-btn {
    border: 0;
    background: none;
    padding: 4px 0;
    color: var(--accent);
    font-weight: 600;
    font-size: 14px;
}

.form { display: grid; gap: 16px; }
.form-heading { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 600; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field small { color: var(--text-3); font-size: 12.5px; }

.check-field {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    justify-self: start;
    font-size: 15px;
    line-height: 22px;
    color: var(--text-2);
    cursor: pointer;
    user-select: none;
}
.check-field input {
    appearance: none;
    -webkit-appearance: none;
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    margin: 0;
    border: 2px solid var(--text-3);
    border-radius: 7px;
    background: var(--surface) center / 14px 14px no-repeat;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, box-shadow .15s;
}
.check-field:hover input { border-color: var(--accent); }
.check-field input:focus { box-shadow: none; }
.check-field input:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); border-color: var(--accent); }
.check-field input:checked {
    border-color: var(--accent);
    background-color: var(--accent);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 8.5l3 3 6-7'/%3E%3C/svg%3E");
}

input[type="text"], input[type="password"], input[type="search"], textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    padding: 11px 13px;
    font-size: 16px; /* ≥16px prevents iOS zoom on focus */
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
select.select {
    width: 100%;
    min-height: 44px;
    padding: 10px 40px 10px 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a929d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center / 18px;
    font: inherit;
    font-size: 16px;
    color: var(--text);
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}
select.select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

input:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }

.alert, .notice {
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 14px;
    margin-bottom: 18px;
}
.alert { background: var(--danger-soft); color: var(--danger); }
.alert p + p { margin-top: 4px; }
.notice { background: var(--accent-soft); color: var(--accent); }

.form-error { color: var(--danger); font-size: 14px; margin-top: 12px; }
.form-msg { font-size: 14px; color: var(--success); }
.form-msg.is-error { color: var(--danger); }

/* --------------------------------------------------------------------------
   Avatars
   -------------------------------------------------------------------------- */

.avatar {
    --size: 44px;
    position: relative;
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
    width: var(--size);
    height: var(--size);
    border-radius: 50%;
    font-size: calc(var(--size) * .38);
    font-weight: 600;
    color: #fff;
    letter-spacing: .02em;
    user-select: none;
    background: #868e96;
}
.avatar-sm { --size: 36px; }
.avatar-xs { --size: 28px; }
.avatar-xl { --size: 80px; }
.avatar-xxl { --size: 112px; }
.avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    object-fit: cover;
    background: var(--surface-2);
}
.avatar.has-img { color: transparent; }
.avatar.c0 { background: #4c6ef5; }
.avatar.c1 { background: #12b886; }
.avatar.c2 { background: #f76707; }
.avatar.c3 { background: #ae3ec9; }
.avatar.c4 { background: #e64980; }
.avatar.c5 { background: #1098ad; }
.avatar.c6 { background: #7048e8; }
.avatar.c7 { background: #2b8a3e; }
.avatar.is-group { border-radius: 30%; }
.avatar svg { width: 50%; height: 50%; }
.avatar.is-online::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: 0;
    width: 28%;
    height: 28%;
    min-width: 10px;
    min-height: 10px;
    border-radius: 50%;
    background: var(--success);
    border: 2px solid var(--surface);
    z-index: 1;
}

.badge {
    display: inline-grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}

/* --------------------------------------------------------------------------
   Auth pages
   -------------------------------------------------------------------------- */

.auth-body {
    min-height: 100%;
    background:
        radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%),
        var(--bg);
}

.auth {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: calc(32px + var(--safe-top)) 16px calc(32px + var(--safe-bottom));
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
}
.brand-mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 11px;
    background: var(--accent);
    color: #fff;
}
.brand-mark svg { fill: currentColor; stroke: none; }
.brand-name { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }

.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 32px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}
.auth-card h1 { font-size: 24px; letter-spacing: -.015em; }
.auth-sub { color: var(--text-2); margin: 6px 0 24px; }
.auth-card .btn-block { margin-top: 6px; }
.auth-switch { margin-top: 22px; text-align: center; color: var(--text-2); font-size: 14px; }
.auth-foot { margin-top: 20px; color: var(--text-3); font-size: 13px; text-align: center; }
.lang-switch {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px 10px;
    margin-top: 14px;
    font-size: 14px;
    color: var(--text-3);
}
.lang-switch a, .lang-switch .lang-current {
    padding: 6px 10px;
    border-radius: 999px;
}
.lang-switch a { color: var(--text-2); }
.lang-switch a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.lang-switch .lang-current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

@media (max-width: 480px) {
    .auth { justify-content: flex-start; padding-top: calc(40px + var(--safe-top)); }
    .auth-card { padding: 24px 20px; border-radius: var(--radius); box-shadow: var(--shadow-sm); }
}

/* --------------------------------------------------------------------------
   App layout
   -------------------------------------------------------------------------- */

.app-body {
    overflow: hidden;
    overscroll-behavior: none;
}

.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: 100vh;
    height: 100dvh;
    background: var(--surface);
}

/* Sidebar ------------------------------------------------------------------ */

.sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-right: 1px solid var(--border);
    background: var(--surface);
    padding-left: var(--safe-left);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    height: calc(var(--header-h) + var(--safe-top));
    padding: var(--safe-top) 12px 0 16px;
    flex-shrink: 0;
}
.sidebar-title { flex: 1; font-size: 20px; font-weight: 700; letter-spacing: -.015em; }

.me-button {
    border: 0;
    padding: 0;
    background: none;
    border-radius: 50%;
}

.search {
    position: relative;
    margin: 0 16px 8px;
    flex-shrink: 0;
}
.search svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-3);
    pointer-events: none;
}
.search input {
    padding: 9px 12px 9px 38px;
    background: var(--surface-2);
    border-color: transparent;
    border-radius: 10px;
}
.search input:focus { background: var(--surface); }
.search-inline { margin: 0 0 8px; }

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px calc(12px + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
}

.conv {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    text-align: left;
    transition: background-color .12s;
}
.conv { color: var(--text); text-decoration: none; }
.conv:hover { background: var(--surface-2); text-decoration: none; }
.conv.is-active { background: var(--accent-soft); }
.conv-main { flex: 1; min-width: 0; }
.conv-row { display: flex; align-items: baseline; gap: 8px; }
.conv-title {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conv-time { font-size: 12px; color: var(--text-3); flex-shrink: 0; }
.conv-preview {
    flex: 1;
    min-width: 0;
    margin-top: 2px;
    font-size: 14px;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conv.is-unread .conv-title { color: var(--text); }
.conv.is-unread .conv-preview { color: var(--text); font-weight: 500; }
.conv.is-unread .conv-time { color: var(--accent); font-weight: 600; }
.conv .badge { margin-top: 2px; }

.conv-preview.is-deleted { font-style: italic; }
.list-heading {
    margin: 12px 10px 4px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-3);
}
.muted { color: var(--text-3); font-size: 14px; }

.list-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-3);
    font-size: 14px;
}

.sidebar-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    padding: 48px 24px;
    color: var(--text-2);
    text-align: center;
}

/* Chat pane --------------------------------------------------------------- */

.chat {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--chat-bg);
    padding-right: var(--safe-right);
}

.chat-placeholder {
    margin: auto;
    padding: 24px;
    text-align: center;
    color: var(--text-2);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.placeholder-icon {
    display: grid;
    place-items: center;
    width: 72px;
    height: 72px;
    margin-bottom: 8px;
    border-radius: 50%;
    background: var(--surface);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}
.placeholder-icon svg { width: 32px; height: 32px; }
.chat-placeholder h2 { color: var(--text); font-size: 20px; }
.chat-placeholder .btn { margin-top: 12px; }

.chat-view {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 4px;
    height: calc(var(--header-h) + var(--safe-top));
    padding: var(--safe-top) 8px 0 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 2;
}
.back-btn { display: none; }
.chat-heading {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    padding: 6px;
    border: 0;
    border-radius: var(--radius);
    background: none;
    text-align: left;
}
.chat-heading:hover { background: var(--surface-2); }
.chat-heading .avatar { --size: 40px; }
.chat-heading-text { display: flex; flex-direction: column; min-width: 0; }
.chat-title {
    font-weight: 650;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-status {
    font-size: 13px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-status.is-online, .chat-status.is-typing { color: var(--accent); }

/* Messages ---------------------------------------------------------------- */

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
.messages-inner {
    display: flex;
    flex-direction: column;
    max-width: 860px;
    min-height: 100%;
    margin: 0 auto;
    padding: 16px 20px 8px;
}
.messages-inner::before { content: ""; flex: 1; } /* push messages to the bottom */

.history-loader {
    align-self: center;
    margin: 4px 0 12px;
    font-size: 13px;
    color: var(--text-3);
}

.day-sep {
    align-self: center;
    margin: 16px 0 10px;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-2);
    font-size: 12px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 8px;
    z-index: 1;
}

.system-msg {
    align-self: center;
    max-width: 85%;
    margin: 8px 0;
    color: var(--text-3);
    font-size: 13px;
    text-align: center;
}

.msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: min(78%, 620px);
    margin-top: 2px;
}
.msg.is-first { margin-top: 10px; }
.msg.is-out { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar { --size: 30px; visibility: hidden; }
.msg.is-last .avatar { visibility: visible; }
.msg-col { display: flex; flex-direction: column; min-width: 0; }
.msg.is-out .msg-col { align-items: flex-end; }

.msg-sender {
    margin: 0 12px 3px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--accent);
}

.msg-line {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    max-width: 100%;
}
.msg.is-out .msg-line { flex-direction: row-reverse; }
@media (hover: none) {
    .msg:not(.is-pending) .bubble { cursor: pointer; transition: filter .12s; }
    .msg:not(.is-pending) .bubble:active { filter: brightness(.94); }
    .bubble { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
}

.bubble {
    position: relative;
    padding: 8px 12px 6px;
    border-radius: 18px;
    background: var(--bubble-in);
    color: var(--bubble-in-text);
    box-shadow: var(--shadow-sm);
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
.msg.is-out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); }
.msg:not(.is-out):not(.is-last) .bubble { border-bottom-left-radius: 6px; }
.msg:not(.is-out):not(.is-first) .bubble { border-top-left-radius: 6px; }
.msg.is-out:not(.is-last) .bubble { border-bottom-right-radius: 6px; }
.msg.is-out:not(.is-first) .bubble { border-top-right-radius: 6px; }
.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.bubble.is-emoji { background: transparent; box-shadow: none; font-size: 40px; line-height: 1.15; padding: 0 2px; }
.msg.is-out .bubble.is-emoji { background: transparent; }
.msg.is-out .bubble.is-emoji .meta { color: var(--text-3); }

.meta {
    float: right;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin: 6px 0 -2px 10px;
    font-size: 11px;
    line-height: 1;
    white-space: nowrap;
    opacity: .7;
    user-select: none;
}
.bubble.is-emoji .meta { float: none; display: flex; justify-content: flex-end; margin: 2px 0 0; font-size: 11px; }
.meta svg { width: 15px; height: 15px; stroke-width: 2.2; }
.msg.is-pending .meta { opacity: .5; }
.meta .edited { margin-right: 2px; font-style: italic; }
.bubble.is-deleted {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-style: italic;
    background: transparent !important;
    color: var(--text-3) !important;
    box-shadow: inset 0 0 0 1px var(--border);
}
.bubble.is-deleted > svg { width: 16px; height: 16px; }
.bubble.is-deleted .meta { margin-left: 4px; }
.bubble.is-editing { box-shadow: 0 0 0 2px var(--accent), var(--shadow-sm); }
.msg.is-out .bubble.is-editing { box-shadow: 0 0 0 2px var(--chat-bg), 0 0 0 4px var(--accent); }
.msg.is-failed .bubble { opacity: .6; }
.msg-failed {
    margin: 3px 4px 0;
    font-size: 12px;
    color: var(--danger);
    border: 0;
    background: none;
    padding: 0;
}

.typing-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 0 2px;
    color: var(--text-3);
    font-size: 13px;
}
.typing-dots {
    display: inline-flex;
    gap: 3px;
    padding: 10px 12px;
    border-radius: 18px;
    background: var(--bubble-in);
    box-shadow: var(--shadow-sm);
}
.typing-dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-3);
    animation: typing 1.2s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30% { transform: translateY(-3px); opacity: 1; }
}

.jump-btn {
    position: absolute;
    right: 20px;
    bottom: calc(84px + var(--safe-bottom));
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-2);
    box-shadow: var(--shadow-md);
    z-index: 3;
}
.jump-btn .badge { position: absolute; top: -6px; right: -4px; }

/* Composer ---------------------------------------------------------------- */

.composer-wrap {
    position: relative;
    flex-shrink: 0;
}

.edit-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 8px 8px 18px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    color: var(--accent);
}
.edit-bar-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding-left: 10px;
    border-left: 2px solid var(--accent);
    font-size: 13px;
    line-height: 1.35;
}
.edit-bar-text span {
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.edit-bar:not([hidden]) + .emoji-panel + .composer { border-top: 0; }

.emoji-btn.is-active { color: var(--accent); background: var(--accent-soft); }
.emoji-panel {
    position: absolute;
    left: 12px;
    bottom: calc(100% + 8px);
    display: flex;
    flex-direction: column;
    width: 360px;
    height: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: 5;
    animation: modal-in .15s ease-out;
}
.emoji-tabs {
    display: flex;
    gap: 2px;
    padding: 6px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
}
.emoji-tabs::-webkit-scrollbar { display: none; }
.emoji-tab {
    display: grid;
    place-items: center;
    flex: 1 0 36px;
    height: 36px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 20px;
    color: var(--text-2);
    filter: grayscale(.6);
    opacity: .75;
}
.emoji-tab svg { width: 20px; height: 20px; }
.emoji-tab:hover { background: var(--surface-2); opacity: 1; }
.emoji-tab.is-active { background: var(--accent-soft); filter: none; opacity: 1; color: var(--accent); }
.emoji-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    align-content: start;
    gap: 2px;
    padding: 4px 8px 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.emoji-label {
    grid-column: 1 / -1;
    padding: 6px 4px 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
}
.emoji {
    display: grid;
    place-items: center;
    height: 40px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 26px;
    line-height: 1;
    transition: transform .08s, background-color .12s;
}
.emoji:hover { background: var(--surface-2); transform: scale(1.12); }
.emoji:active { transform: scale(.95); }

.composer {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 16px calc(10px + var(--safe-bottom)) 10px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.composer .emoji-btn { width: 44px; height: 44px; flex-shrink: 0; }
.composer textarea {
    flex: 1;
    max-height: 160px;
    min-height: 44px;
    resize: none;
    padding: 11px 16px;
    border-radius: 22px;
    background: var(--surface-2);
    border-color: transparent;
    line-height: 1.4;
}
.composer textarea:focus { background: var(--surface); box-shadow: none; }
.send-btn {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    transition: background-color .15s, opacity .15s, transform .1s;
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:active:not(:disabled) { transform: scale(.94); }
.send-btn:disabled { opacity: .4; cursor: default; }
.send-btn svg { stroke-width: 2.4; }

/* --------------------------------------------------------------------------
   Modals
   -------------------------------------------------------------------------- */

.modal {
    width: min(480px, calc(100vw - 32px));
    max-height: min(720px, calc(100dvh - 48px));
    padding: 0;
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.modal[open] { display: flex; animation: modal-in .18s ease-out; }
.modal::backdrop { background: rgba(10, 12, 16, .5); animation: fade-in .18s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes fade-in { from { opacity: 0; } }

.modal-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 0;
    max-height: inherit;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 12px 10px 20px;
    flex-shrink: 0;
}
.modal-header h2 { font-size: 18px; }
.modal-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 20px 20px;
}
.modal-body > .form { padding-top: 20px; margin-top: 20px; border-top: 1px solid var(--border); }
.modal-body > .form:first-of-type { border-top: 0; margin-top: 4px; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px calc(16px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.modal-footer form { margin: 0; }

.segmented {
    display: flex;
    gap: 4px;
    margin: 0 20px 12px;
    padding: 4px;
    border-radius: 10px;
    background: var(--surface-2);
    flex-shrink: 0;
}
.seg-btn {
    flex: 1;
    min-height: 34px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text-2);
    font-size: 14px;
    font-weight: 600;
}
.seg-btn.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

#group-name-field { margin-bottom: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px 4px 4px;
    border: 0;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
}
.chip .avatar { --size: 22px; }
.chip svg { width: 14px; height: 14px; }

.user-results { display: grid; gap: 2px; margin: 0 -8px; }
.user-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    text-align: left;
}
.user-row:hover { background: var(--surface-2); text-decoration: none; }
a.user-row { color: var(--text); }
.user-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.user-row-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row-sub { font-size: 13px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border: 2px solid var(--border);
    border-radius: 50%;
    color: transparent;
    flex-shrink: 0;
}
.check svg { width: 14px; height: 14px; stroke-width: 3; }
.user-row.is-selected .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.results-hint { padding: 20px 8px; text-align: center; color: var(--text-3); font-size: 14px; }

.info-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px 0 20px;
    text-align: center;
}
.info-hero .avatar { margin-bottom: 6px; }
.info-hero h3 { font-size: 20px; overflow-wrap: anywhere; }
.info-hero p { color: var(--text-3); font-size: 14px; }

.inline-form { display: flex; gap: 8px; margin-bottom: 16px; }
.inline-form input { flex: 1; min-width: 0; }

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-3);
}
.section-title .link-btn { text-transform: none; letter-spacing: 0; }

.member-list { list-style: none; margin: 0 -8px; padding: 0; display: grid; gap: 2px; }
.role-tag { font-size: 12px; color: var(--text-3); font-weight: 600; }

.toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: var(--text-2);
    cursor: pointer;
}
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

/* Message menu ------------------------------------------------------------ */

.msg-menu {
    position: fixed;
    z-index: 60;
    min-width: 180px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    animation: modal-in .12s ease-out;
}
.msg-menu button {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
}
.msg-menu button:hover, .msg-menu button:focus-visible { background: var(--surface-2); outline: none; }
.msg-menu svg { width: 18px; height: 18px; color: var(--text-2); }
.msg-menu .is-danger, .msg-menu .is-danger svg { color: var(--danger); }
.menu-scrim { position: fixed; inset: 0; z-index: 59; }

/* Confirm dialog ---------------------------------------------------------- */

.modal-sm { width: min(400px, calc(100vw - 32px)); }
.confirm-body { padding: 24px 24px 8px; }
.confirm-body h2 { font-size: 18px; margin-bottom: 8px; }
.confirm-body p { color: var(--text-2); }
.modal-sm .modal-footer { border-top: 0; }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: var(--danger); filter: brightness(.92); }

/* Profile ----------------------------------------------------------------- */

.profile-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}
.profile-heading {
    flex: 1;
    padding-left: 8px;
    font-size: 17px;
    font-weight: 650;
}
.profile-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
.profile-inner {
    display: grid;
    gap: 16px;
    max-width: 560px;
    margin: 0 auto;
    padding: 24px 20px calc(32px + var(--safe-bottom));
}
.profile-card {
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.profile-card.form { gap: 14px; }
.profile-card-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding-top: 28px;
}
.profile-hero { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.profile-avatar-wrap { position: relative; margin-bottom: 10px; }
.profile-avatar-wrap .avatar.is-online::after { border-width: 3px; }
.avatar-edit {
    position: absolute;
    right: 0;
    bottom: 0;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: 3px solid var(--surface);
    cursor: pointer;
    z-index: 2;
}
.avatar-edit svg { width: 16px; height: 16px; }
.avatar-edit:hover { background: var(--accent-hover); }
.profile-name { font-size: 22px; letter-spacing: -.01em; overflow-wrap: anywhere; }
.profile-username { color: var(--text-2); font-size: 15px; }
.profile-status { margin-top: 6px; color: var(--text-3); font-size: 14px; }
.profile-status.is-online { color: var(--accent); }
.profile-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 18px;
}
.profile-actions .btn svg { width: 18px; height: 18px; }
.profile-card-hero .form-msg { margin-top: 12px; }
.info-row {
    display: grid;
    gap: 2px;
    padding: 12px 0;
    border-top: 1px solid var(--border);
}
.info-row:first-child { border-top: 0; padding-top: 0; }
.info-row:last-child { padding-bottom: 0; }
.info-label { font-size: 12.5px; font-weight: 600; color: var(--text-3); }
.info-value { font-size: 15px; overflow-wrap: anywhere; }
.profile-bio { white-space: pre-wrap; }
.input-prefix { position: relative; }
.input-prefix > span {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-3);
    font-size: 16px;
    pointer-events: none;
}
.input-prefix input { padding-left: 30px; }
.field textarea { resize: vertical; min-height: 80px; }
.counter { justify-self: end; }
.form-actions { display: flex; justify-content: flex-start; }
.signout { padding: 12px; }

/* Calls ------------------------------------------------------------------- */

.call-actions { display: flex; align-items: center; gap: 2px; }

.call-screen {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: calc(24px + var(--safe-top)) 16px calc(32px + var(--safe-bottom));
    background: radial-gradient(120% 80% at 50% 0%, #2a3350 0%, #12151d 60%, #0b0d12 100%);
    color: #fff;
    overflow: hidden;
    animation: fade-in .2s ease-out;
}

.call-remote-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
    display: none;
}
.call-screen.has-remote-video .call-remote-video { display: block; }
.call-screen.remote-contain .call-remote-video { object-fit: contain; }

.call-info {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-top: 10vh;
    text-align: center;
    max-width: 100%;
}
.call-info .avatar { margin-bottom: 14px; box-shadow: 0 0 0 8px rgba(255, 255, 255, .06), 0 0 0 16px rgba(255, 255, 255, .03); }
.call-screen[data-state="incoming"] .call-info .avatar,
.call-screen[data-state="ringing"] .call-info .avatar { animation: call-pulse 2s ease-in-out infinite; }
@keyframes call-pulse {
    0%, 100% { box-shadow: 0 0 0 8px rgba(255, 255, 255, .06), 0 0 0 16px rgba(255, 255, 255, .03); }
    50% { box-shadow: 0 0 0 14px rgba(255, 255, 255, .09), 0 0 0 28px rgba(255, 255, 255, .04); }
}
.call-name { font-size: 26px; font-weight: 650; letter-spacing: -.01em; overflow-wrap: anywhere; }
.call-status { font-size: 15px; color: rgba(255, 255, 255, .75); font-variant-numeric: tabular-nums; }

/* With the other person's video showing, shrink the caption to the top. */
.call-screen.has-remote-video .call-info { margin-top: 0; align-self: flex-start; align-items: flex-start; text-align: left; }
.call-screen.has-remote-video .call-info .avatar { display: none; }
.call-screen.has-remote-video .call-name { font-size: 18px; }
.call-screen.has-remote-video .call-name,
.call-screen.has-remote-video .call-status { text-shadow: 0 1px 4px rgba(0, 0, 0, .6); }

.call-local-video {
    position: absolute;
    top: calc(16px + var(--safe-top));
    right: 16px;
    z-index: 2;
    width: clamp(96px, 26vw, 220px);
    aspect-ratio: 3 / 4;
    object-fit: cover;
    border-radius: 14px;
    background: #222;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
    transform: scaleX(-1); /* mirror the selfie view */
    display: none;
}
.call-screen[data-kind="video"]:not([data-state="incoming"]) .call-local-video { display: block; }
.call-screen.camera-off .call-local-video { display: none !important; }
.call-screen.local-rear .call-local-video { transform: none; }
@media (min-width: 768px) {
    .call-local-video { aspect-ratio: 16 / 9; width: 240px; }
}

.call-controls {
    position: relative;
    z-index: 2;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 14px 22px;
    max-width: 480px;
}
.call-screen[data-state="incoming"] #call-controls { display: none; }
.call-screen:not([data-state="incoming"]) #call-incoming { display: none; }
.call-incoming { gap: 72px; }

.call-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 78px;
    padding: 0;
    border: 0;
    background: none;
    color: #fff;
    font-size: 12.5px;
    line-height: 1.25;
    text-align: center;
}
.call-btn > svg {
    box-sizing: content-box;
    width: 26px;
    height: 26px;
    padding: 19px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .16);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: background-color .15s, transform .1s;
}
.call-btn:hover > svg { background: rgba(255, 255, 255, .26); }
.call-btn:active > svg { transform: scale(.94); }
.call-btn .when-off { display: none; }
.call-btn.is-off .when-on { display: none; }
.call-btn.is-off .when-off { display: block; }
.call-btn.is-off > svg { background: #fff; color: #15181d; }
.call-btn-end > svg, .call-btn-end:hover > svg { background: #e03131; }
.call-btn-accept > svg, .call-btn-accept:hover > svg { background: #2f9e44; animation: call-accept 1.4s ease-in-out infinite; }
.call-btn-label { text-shadow: 0 1px 3px rgba(0, 0, 0, .5); }
.hangup-icon { transform: rotate(135deg); }
.call-btn:active > .hangup-icon { transform: rotate(135deg) scale(.94); }
@keyframes call-accept {
    0%, 100% { box-shadow: 0 0 0 0 rgba(47, 158, 68, .55); }
    50% { box-shadow: 0 0 0 14px rgba(47, 158, 68, 0); }
}

/* Toast ------------------------------------------------------------------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(96px + var(--safe-bottom));
    transform: translateX(-50%);
    max-width: calc(100vw - 32px);
    padding: 10px 16px;
    border-radius: 10px;
    background: #1f2329;
    color: #fff;
    font-size: 14px;
    box-shadow: var(--shadow-md);
    z-index: 100;
    animation: fade-in .2s ease-out;
}
body.in-call { overflow: hidden; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 1100px) {
    :root { --sidebar-w: 320px; }
}

@media (max-width: 767px) {
    :root { --header-h: 56px; }

    .app {
        display: block;
        position: relative;
        overflow: hidden;
    }
    .sidebar, .chat {
        position: absolute;
        inset: 0;
        border-right: 0;
        transition: transform .25s cubic-bezier(.2, .8, .2, 1);
    }
    .sidebar { padding-right: var(--safe-right); }
    .chat { padding-left: var(--safe-left); transform: translateX(100%); }
    .app.show-chat .chat { transform: translateX(0); }
    .app.show-chat .sidebar { transform: translateX(-25%); }

    .chat-placeholder { display: none; }
    .back-btn { display: inline-grid; margin-left: -4px; }
    .chat-header { padding-left: 4px; padding-right: 4px; }
    .chat-heading { padding: 4px; gap: 10px; }
    #btn-info-icon { display: none; }

    .messages-inner { padding: 12px 10px 6px; }
    .msg { max-width: 86%; }
    .composer { padding: 8px 10px calc(8px + var(--safe-bottom)); }
    .jump-btn { right: 12px; bottom: calc(72px + var(--safe-bottom)); }
    .composer { padding-left: 4px; }

    .emoji-panel {
        position: static;
        width: 100%;
        height: min(300px, 42dvh);
        border: 0;
        border-top: 1px solid var(--border);
        border-radius: 0;
        box-shadow: none;
        animation: none;
        order: 2;
    }
    .composer-wrap { display: flex; flex-direction: column; }
    .composer-wrap .composer { order: 1; }
    .composer-wrap .edit-bar { order: 0; }
    .emoji-panel:not([hidden]) ~ .composer { padding-bottom: 8px; }

    .msg-menu {
        top: auto !important;
        left: 8px !important;
        right: 8px;
        bottom: calc(8px + var(--safe-bottom));
        padding: 8px;
        border-radius: var(--radius-lg);
        animation: sheet-in .2s cubic-bezier(.2, .8, .2, 1);
    }
    .msg-menu button { padding: 14px 12px; font-size: 16px; }
    .menu-scrim { background: rgba(10, 12, 16, .4); }

    .modal.modal-sm {
        width: calc(100vw - 32px);
        height: auto;
        max-height: calc(100dvh - 32px);
        margin: auto;
        border-radius: var(--radius-lg);
    }
    .modal.modal-sm[open] { animation: modal-in .18s ease-out; }
    .modal-sm .modal-card { height: auto; }
    .modal-sm .modal-footer { padding-bottom: 16px; }

    .profile-inner { padding: 16px 12px calc(24px + var(--safe-bottom)); gap: 12px; }
    .profile-card { padding: 16px; }

    /* Full-screen sheets on phones */
    .modal {
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        margin: 0;
        border-radius: 0;
    }
    .modal[open] { animation: sheet-in .22s cubic-bezier(.2, .8, .2, 1); }
    .modal-header { padding-top: calc(10px + var(--safe-top)); }
    .modal-card { height: 100%; }
    @keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
}

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