/* Katarab Messenger — mobile-first UI */
:root {
    --bg: #f2f3f8;
    --surface: #ffffff;
    --surface-soft: #f8f9fc;
    --ink: #101828;
    --ink-soft: #344054;
    --muted: #667085;
    --muted-2: #98a2b3;
    --line: #e7e9f0;
    --accent: #4f46e5;
    --accent-dark: #4338ca;
    --accent-soft: #eef0ff;
    --danger: #d92d20;
    --danger-soft: #fef3f2;
    --success: #067647;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow-md: 0 12px 32px rgba(16, 24, 40, .08);
    --shadow-lg: 0 24px 64px rgba(16, 24, 40, .14);
    --radius: 16px;
    --radius-lg: 22px;
    --wa: #25d366;
    --tg: #2aabee;
    --max: #8b5cf6;
    --vk: #0077ff;
    --mail: #f59e0b;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
.icon { flex: 0 0 auto; }
[hidden] { display: none !important; }

/* ---------- auth ---------- */
.auth-body {
    background: radial-gradient(1200px 700px at 15% -10%, #e9e7ff 0%, transparent 55%),
                radial-gradient(900px 600px at 100% 100%, #e6f4ff 0%, transparent 50%),
                #f7f7fb;
}

.auth-page {
    min-height: 100dvh;
    display: grid;
    grid-template-columns: 1.05fr .95fr;
}

.auth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    background: linear-gradient(150deg, #4338ca 0%, #4f46e5 45%, #7c3aed 100%);
    color: #fff;
    position: relative;
    overflow: hidden;
}

.auth-brand::before,
.auth-brand::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, .16);
}
.auth-brand::before { width: 620px; height: 620px; right: -230px; top: -180px; }
.auth-brand::after { width: 420px; height: 420px; left: -160px; bottom: -160px; }

.auth-brand-inner { position: relative; max-width: 460px; }
.auth-brand h1 { font-size: clamp(38px, 4.2vw, 58px); line-height: 1.05; letter-spacing: -.03em; margin: 28px 0 18px; font-weight: 700; }
.auth-brand p { font-size: 17px; line-height: 1.55; color: rgba(255, 255, 255, .86); margin: 0 0 28px; }
.auth-features { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.auth-features li { display: flex; align-items: center; gap: 10px; color: rgba(255, 255, 255, .92); font-size: 14.5px; }
.auth-features .icon { color: #a7f3d0; }

.auth-form-side { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card {
    width: 100%;
    max-width: 420px;
    background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, .7);
    box-shadow: var(--shadow-lg);
    border-radius: 26px;
    padding: 32px;
}
.auth-card-head { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.auth-card-head h2 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.auth-card-head p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.auth-note { margin: 18px 0 0; color: var(--muted-2); font-size: 12.5px; line-height: 1.5; }
.btn-block { width: 100%; }
.btn-lg { height: 52px; font-size: 16px; }

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: linear-gradient(145deg, #4f46e5, #7c3aed);
    color: #fff;
    font-weight: 800;
    font-size: 18px;
    box-shadow: 0 6px 16px rgba(79, 70, 229, .35);
    flex: 0 0 auto;
}
.brand-mark-lg { width: 58px; height: 58px; border-radius: 18px; font-size: 28px; background: rgba(255,255,255,.16); box-shadow: none; border: 1px solid rgba(255,255,255,.35); }

/* ---------- buttons / fields ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
    padding: 0 18px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: var(--surface);
    color: var(--ink);
    font-weight: 600;
    font-size: 14.5px;
    white-space: nowrap;
    transition: transform .12s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 8px 18px rgba(79, 70, 229, .25); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { opacity: .5; box-shadow: none; cursor: not-allowed; }
.btn-ghost { background: var(--surface-soft); border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { background: #f1f3f9; }
.btn-danger-ghost { background: var(--danger-soft); color: var(--danger); border-color: #fecdca; }
.btn-sm { height: 36px; padding: 0 13px; border-radius: 10px; font-size: 13px; }

.field { display: grid; gap: 7px; margin-bottom: 16px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); letter-spacing: .01em; }
.field input,
.field select,
.field textarea,
.merge-search input {
    width: 100%;
    height: 46px;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 12px;
    padding: 0 14px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
    font-size: 15px;
}
.field input:focus,
.field select:focus,
.merge-search input:focus { border-color: #a5b4fc; box-shadow: 0 0 0 4px rgba(79, 70, 229, .1); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted-2); pointer-events: none; }
.input-icon input { padding-left: 42px; padding-right: 42px; }
.password-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; border-radius: 8px; }
.password-toggle:hover { background: var(--surface-soft); }

.switch { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-soft); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { width: 42px; height: 26px; border-radius: 999px; background: #dfe3ec; position: relative; transition: background .15s ease; flex: 0 0 auto; }
.switch-track::after { content: ""; position: absolute; width: 20px; height: 20px; border-radius: 50%; background: #fff; top: 3px; left: 3px; box-shadow: 0 1px 3px rgba(16,24,40,.2); transition: transform .16s ease; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch-row { display: flex; flex-wrap: wrap; gap: 18px; margin: 4px 0 20px; }
.switch-compact { margin: 4px 0 20px; font-size: 13px; }

/* ---------- messenger shell ---------- */
.messenger-body { height: 100dvh; overflow: hidden; background: var(--surface); }
.app-shell { display: grid; grid-template-columns: 380px minmax(0, 1fr); height: 100dvh; }

.sidebar {
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--surface);
    border-right: 1px solid var(--line);
    position: relative;
    z-index: 2;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(18px + var(--safe-top)) 18px 14px;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-text { display: grid; line-height: 1.15; }
.brand-text strong { font-size: 17px; letter-spacing: -.02em; }
.brand-text small { color: var(--muted-2); font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; margin-top: 2px; }

.user-menu { position: relative; }
.user-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    border: 0; background: linear-gradient(145deg, #eef0ff, #e0e7ff);
    color: var(--accent-dark); font-weight: 700; font-size: 13px;
    display: grid; place-items: center;
}
.dropdown {
    position: absolute; right: 0; top: 46px; width: 230px;
    background: #fff; border: 1px solid var(--line); border-radius: 14px;
    box-shadow: var(--shadow-lg); padding: 6px; z-index: 30;
}
.dropdown-head { padding: 10px 12px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; display: grid; gap: 2px; }
.dropdown-head strong { font-size: 13.5px; }
.dropdown-head span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.dropdown-item { width: 100%; display: flex; align-items: center; gap: 9px; border: 0; background: transparent; padding: 10px 12px; border-radius: 9px; font-size: 14px; color: var(--ink-soft); }
.dropdown-item:hover { background: var(--surface-soft); }

.search {
    position: relative;
    margin: 2px 18px 10px;
}
.search .search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted-2); }
.search input {
    width: 100%; height: 44px; border-radius: 12px; border: 1px solid transparent;
    background: var(--surface-soft); padding: 0 38px 0 40px; outline: none; font-size: 14.5px;
    transition: border-color .15s ease, background .15s ease;
}
.search input:focus { background: #fff; border-color: #c7d2fe; box-shadow: 0 0 0 4px rgba(79,70,229,.08); }
.search-clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; color: var(--muted); background: #e9ecf4; }

.chips {
    display: flex; flex-wrap: wrap; gap: 8px; padding: 0 18px 12px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
    display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 13px;
    border-radius: 999px; background: var(--surface-soft); border: 1px solid transparent;
    color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; flex: 0 0 auto;
}
.chip.is-active { background: #101828; color: #fff; }
.chip-dot { width: 7px; height: 7px; border-radius: 50%; }
.chip-count { background: #e5484d; color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; line-height: 17px; min-width: 17px; text-align: center; }

.conversation-list { flex: 1; overflow-y: auto; padding: 0 8px 10px; overscroll-behavior: contain; }
.conversation {
    overflow: hidden;
    min-width: 0;
    display: flex; gap: 12px; padding: 11px 10px; border-radius: 14px; position: relative;
    transition: background .12s ease;
}
.conversation:hover { background: var(--surface-soft); }
.conversation.is-active { background: var(--accent-soft); }
.conversation.is-active::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 3px; background: var(--accent); }

.avatar {
    position: relative; width: 50px; height: 50px; border-radius: 50%; flex: 0 0 auto;
    display: grid; place-items: center; font-weight: 700; font-size: 16px; color: #fff;
    letter-spacing: .01em;
}
.avatar-lg { width: 42px; height: 42px; font-size: 14px; }
.avatar-xl { width: 84px; height: 84px; font-size: 28px; border-radius: 26px; }
.avatar-channel { position: absolute; right: -1px; bottom: -1px; width: 15px; height: 15px; border-radius: 50%; border: 2.5px solid #fff; }
.tone-0 { background: linear-gradient(145deg, #667eea, #764ba2); }
.tone-1 { background: linear-gradient(145deg, #f0932b, #eb4d4b); }
.tone-2 { background: linear-gradient(145deg, #00b894, #0984e3); }
.tone-3 { background: linear-gradient(145deg, #e17055, #d63031); }
.tone-4 { background: linear-gradient(145deg, #6c5ce7, #a29bfe); }
.tone-5 { background: linear-gradient(145deg, #0097e6, #00a8ff); }
.tone-6 { background: linear-gradient(145deg, #44bd32, #4cd137); }
.tone-7 { background: linear-gradient(145deg, #c23616, #e84118); }

.conversation-body { min-width: 0; flex: 1; overflow: hidden; display: grid; align-content: center; gap: 3px; }
.conversation-top { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.conversation-name { min-width: 0; font-weight: 650; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; letter-spacing: -.01em; }
.conversation-time { font-size: 11.5px; color: var(--muted-2); flex: 0 0 auto; }
.conversation-bottom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.conversation-preview { min-width: 0; flex: 1; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-preview.has-error { color: var(--danger); }
.unread-badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; min-width: 19px; height: 19px; padding: 0 6px; display: grid; place-items: center; }
.conversation-channels { display: flex; gap: 4px; margin-top: 1px; }
.channel-pill {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 10.5px; font-weight: 700; letter-spacing: .02em;
    color: var(--channel-color, #64748b);
    background: color-mix(in srgb, var(--channel-color, #64748b) 11%, white);
    border-radius: 6px; padding: 1px 5px;
}
.channel-pill-lg { font-size: 12px; padding: 3px 8px; border-radius: 8px; }

.empty-list { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty-icon { width: 56px; height: 56px; border-radius: 18px; background: var(--surface-soft); display: grid; place-items: center; margin: 0 auto 14px; color: var(--muted-2); }
.empty-list strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.empty-list p { margin: 0; font-size: 13px; }

.list-pagination { display: flex; gap: 8px; justify-content: center; padding: 10px 18px calc(14px + var(--safe-bottom)); border-top: 1px solid var(--line); }

.main-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface-soft); }

/* ---------- welcome ---------- */
.welcome-pane { flex: 1; display: grid; place-items: center; padding: 32px; }
.welcome-card { max-width: 520px; text-align: center; }
.welcome-logo { width: 76px; height: 76px; border-radius: 24px; margin: 0 auto 22px; background: linear-gradient(145deg, #4f46e5, #7c3aed); display: grid; place-items: center; box-shadow: 0 20px 44px rgba(79,70,229,.28); }
.welcome-logo span { color: #fff; font-weight: 800; font-size: 36px; }
.welcome-card h1 { font-size: clamp(28px, 3vw, 38px); line-height: 1.1; letter-spacing: -.03em; margin: 0 0 14px; }
.welcome-card p { color: var(--muted); font-size: 15.5px; line-height: 1.6; margin: 0 auto 26px; max-width: 440px; }
.welcome-channels { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 26px; }
.welcome-channel { display: inline-flex; align-items: center; gap: 7px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.channel-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--channel-color); }
.welcome-tip { display: inline-flex; align-items: flex-start; gap: 9px; text-align: left; background: #fff; border: 1px dashed #d6dae6; border-radius: 14px; padding: 12px 14px; color: var(--muted); font-size: 12.5px; max-width: 400px; }

/* ---------- chat ---------- */
.chat-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; background: #f7f8fc; position: relative; }

.chat-head {
    display: flex; align-items: center; gap: 12px;
    padding: calc(10px + var(--safe-top)) 16px 10px;
    background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line); z-index: 5; flex: 0 0 auto;
}
.back-button { display: none; }
.chat-person { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 1; }
.chat-person-text { display: grid; line-height: 1.2; min-width: 0; }
.chat-person-text strong { font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }
.chat-person-text small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-actions { display: flex; align-items: center; gap: 8px; }
.chat-channel-badges { display: flex; gap: 4px; }

.icon-button {
    width: 42px; height: 42px; border-radius: 12px; border: 0; background: transparent;
    display: inline-grid; place-items: center; color: var(--ink-soft); flex: 0 0 auto;
    transition: background .14s ease;
}
.icon-button:hover { background: var(--surface-soft); }
.chat-head .back-button { display: none; margin-left: -6px; }

.messages { flex: 1; overflow-y: auto; padding: 18px clamp(12px, 4vw, 40px) 10px; display: flex; flex-direction: column; gap: 4px; overscroll-behavior: contain; scroll-behavior: smooth; }
.date-separator { display: flex; justify-content: center; margin: 14px 0 10px; }
.date-separator span { background: #e9ecf4; color: var(--muted); font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 4px 11px; }

.message-row { display: flex; margin-top: 4px; }
.message-row.is-out { justify-content: flex-end; }
.message-row.is-in { justify-content: flex-start; }
.bubble {
    max-width: min(78%, 560px); border-radius: 18px; padding: 9px 13px 7px;
    background: #fff; box-shadow: var(--shadow-sm); border: 1px solid #eceef4;
    position: relative; word-break: break-word;
}
.is-out .bubble { background: #eeedff; border-color: #e0defc; border-bottom-right-radius: 6px; }
.is-in .bubble { border-bottom-left-radius: 6px; }
.bubble-text { font-size: 14.5px; line-height: 1.45; white-space: pre-wrap; }
.bubble-meta { display: flex; align-items: center; justify-content: flex-end; gap: 5px; margin-top: 4px; color: var(--muted-2); font-size: 10.5px; }
.bubble-channel { color: var(--accent); font-weight: 600; margin-right: 2px; }
.bubble-check { color: var(--accent); display: inline-flex; }
.bubble-error { margin-top: 6px; border-top: 1px solid #fecdca; padding-top: 5px; color: var(--danger); font-size: 11.5px; }
.message-row.has-error .bubble { border-color: #fecdca; background: #fff7f7; }

.attachment-photo { display: block; margin: 6px 0 2px; border-radius: 12px; overflow: hidden; background: #f2f4f7; }
.attachment-photo img { max-height: 320px; width: auto; max-width: 100%; object-fit: cover; }
.attachment-video { width: 100%; max-height: 320px; border-radius: 12px; margin: 6px 0 2px; background: #000; }
.attachment-audio { display: flex; align-items: center; gap: 6px; margin: 6px 0 2px; }
.attachment-audio audio { width: 230px; max-width: 100%; height: 36px; }
.attachment-file { display: flex; align-items: center; gap: 10px; margin: 6px 0 2px; padding: 9px 10px; background: rgba(255,255,255,.7); border: 1px solid #e4e7ee; border-radius: 12px; }
.attachment-file-icon { width: 36px; height: 36px; border-radius: 10px; background: #eef0ff; color: var(--accent); display: grid; place-items: center; flex: 0 0 auto; }
.attachment-file-text { display: grid; min-width: 0; }
.attachment-file-text strong { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.attachment-file-text small { color: var(--muted); font-size: 10.5px; }

.chat-empty { margin: auto; text-align: center; color: var(--muted); padding: 30px; }
.chat-empty-icon { width: 64px; height: 64px; border-radius: 20px; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; margin: 0 auto 14px; color: var(--muted-2); }
.chat-empty strong { display: block; color: var(--ink); margin-bottom: 4px; }
.chat-empty p { margin: 0; font-size: 13px; }

.composer {
    flex: 0 0 auto; background: #fff; border-top: 1px solid var(--line);
    padding: 10px 14px calc(12px + var(--safe-bottom));
    display: grid; gap: 8px; z-index: 4;
}
.composer-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px; }
.composer-channel { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.composer-channel::-webkit-scrollbar { display: none; }
.channel-option { flex: 0 0 auto; }
.channel-option input { position: absolute; opacity: 0; pointer-events: none; }
.channel-option span {
    display: inline-flex; align-items: center; height: 30px; padding: 0 11px;
    border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--muted);
    background: var(--surface-soft); border: 1px solid transparent;
}
.channel-option input:checked + span {
    color: var(--channel-color); background: color-mix(in srgb, var(--channel-color) 12%, white);
    border-color: color-mix(in srgb, var(--channel-color) 35%, white);
}
.composer-subject { display: none; }
.composer-subject.is-visible { display: block; }
.composer-subject input { width: 100%; height: 38px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; font-size: 13px; outline: none; }

.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.attach-button { cursor: pointer; width: 42px; height: 42px; border-radius: 12px; color: var(--muted); }
.attach-button:hover { background: var(--surface-soft); }
#messageInput {
    flex: 1; min-height: 42px; max-height: 150px; resize: none;
    border: 1px solid var(--line); border-radius: 14px; padding: 10px 13px;
    outline: none; font-size: 15px; line-height: 1.4; background: var(--surface-soft);
    transition: border-color .15s ease, background .15s ease;
}
#messageInput:focus { background: #fff; border-color: #c7d2fe; box-shadow: 0 0 0 4px rgba(79,70,229,.08); }
.send-button {
    width: 44px; height: 44px; border-radius: 14px; border: 0; flex: 0 0 auto;
    background: var(--accent); color: #fff; display: grid; place-items: center;
    box-shadow: 0 8px 18px rgba(79,70,229,.28);
}
.send-button:disabled { opacity: .45; box-shadow: none; }
.send-button.is-loading .icon { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .4; } }

.file-preview { display: flex; flex-wrap: wrap; gap: 6px; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 9px; padding: 5px 8px; font-size: 11.5px; color: var(--ink-soft); }
.file-chip button { border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; padding: 0; }

.composer-error { background: var(--danger-soft); color: var(--danger); font-size: 12.5px; padding: 8px 16px; border-top: 1px solid #fecdca; }

/* ---------- contact ---------- */
.contact-body { background: var(--bg); overflow-y: auto; }
.contact-page { min-height: 100dvh; max-width: 760px; margin: 0 auto; background: var(--bg); }
.contact-topbar {
    position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
    padding: calc(10px + var(--safe-top)) 12px 10px; background: rgba(242,243,248,.92); backdrop-filter: blur(12px);
}
.contact-topbar-title { font-weight: 650; font-size: 15px; }
.contact-scroll { padding: 0 16px calc(28px + var(--safe-bottom)); display: grid; gap: 14px; }

.contact-hero { display: flex; align-items: center; gap: 18px; padding: 18px 4px 6px; }
.contact-hero-text h1 { margin: 0 0 4px; font-size: 26px; line-height: 1.15; letter-spacing: -.025em; }
.contact-hero-text p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.contact-channels { display: flex; flex-wrap: wrap; gap: 5px; }

.contact-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 11px 12px; display: grid; gap: 1px; }
.stat strong { font-size: 18px; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 11.5px; }

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

.card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.card-head h2 { margin: 0; font-size: 16px; letter-spacing: -.01em; }
.card-head span { color: var(--muted-2); font-size: 12px; text-align: right; }
.card-danger { border-color: #fecdca; background: #fffbfb; }
.form-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.channel-list { display: grid; gap: 8px; }
.channel-item { display: flex; align-items: center; gap: 11px; padding: 9px 10px; background: var(--surface-soft); border-radius: 12px; }
.channel-item-text { display: grid; min-width: 0; flex: 1; }
.channel-item-text strong { font-size: 13px; }
.channel-item-text span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.plain-list { display: grid; gap: 2px; }
.plain-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.plain-row:last-child { border-bottom: 0; }
.plain-row span { color: var(--muted); }
.muted { color: var(--muted); }
.text-danger { color: var(--danger); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(16,24,40,.45); display: grid; place-items: center; padding: 18px; }
.modal-card { width: 100%; max-width: 520px; background: #fff; border-radius: 22px; box-shadow: var(--shadow-lg); padding: 20px; max-height: 86dvh; overflow-y: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-head h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.modal-card .muted { font-size: 13px; margin: 0 0 16px; }
.merge-search { position: relative; margin-bottom: 10px; }
.merge-search .search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted-2); }
.merge-search input { padding-left: 40px; }
.merge-results { display: grid; gap: 6px; margin-bottom: 14px; max-height: 260px; overflow-y: auto; }
.merge-result { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 12px; background: #fff; text-align: left; width: 100%; }
.merge-result:hover { border-color: #c7d2fe; background: var(--accent-soft); }
.merge-result .avatar { width: 38px; height: 38px; font-size: 12px; }
.merge-result-text { display: grid; }
.merge-result-text strong { font-size: 13.5px; }
.merge-result-text span { color: var(--muted); font-size: 12px; }
.merge-selected { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 10px; }

/* ---------- toasts ---------- */
.toast-stack { position: fixed; top: calc(14px + var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; width: min(92vw, 460px); }
.toast { display: flex; align-items: flex-start; gap: 9px; background: #101828; color: #fff; border-radius: 12px; padding: 11px 14px; box-shadow: var(--shadow-lg); font-size: 13px; animation: toast-in .2s ease; }
.toast-success .icon { color: #6ce9a6; }
.toast-warning .icon { color: #fec84b; }
.toast-error .icon { color: #fda29b; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- responsive ---------- */
@media (max-width: 899px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { border-right: 0; height: 100dvh; }
    .screen-chat .sidebar { display: none; }
    .screen-chat .main-pane { display: flex; height: 100dvh; }
    .screen-inbox .main-pane { display: none; }
    .chat-head .back-button { display: inline-grid; }
    .welcome-pane { display: none; }
    .chat-head { padding-left: 8px; }
    .chips { flex-wrap: nowrap; overflow-x: auto; }
    .chat-person-text strong { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.15; }
    .chat-channel-badges { display: none; }
    .avatar { width: 46px; height: 46px; font-size: 15px; }
    .avatar-xl { width: 74px; height: 74px; font-size: 24px; }
    .bubble { max-width: 86%; }
    .contact-hero { align-items: flex-start; }
    .contact-hero-text h1 { font-size: 22px; }
}

@media (max-width: 560px) {
    .auth-page { grid-template-columns: 1fr; }
    .auth-brand { display: none; }
    .auth-form-side { min-height: 100dvh; padding: 22px 16px; }
    .auth-card { padding: 24px 20px; border-radius: 22px; }
    .field-row { grid-template-columns: 1fr; gap: 0; }
    .contact-hero { flex-direction: column; align-items: center; text-align: center; }
    .contact-channels { justify-content: center; }
    .contact-actions .btn { flex: 1; }
    .card { padding: 15px; }
    .card-head { flex-direction: column; gap: 2px; }
    .card-head span { text-align: left; }
}

@media (min-width: 1400px) {
    .app-shell { grid-template-columns: 420px minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
