:root {
    --ink: #16171d;
    --muted: #6f7280;
    --muted-2: #979aa6;
    --line: #e5e6eb;
    --line-strong: #d6d8e0;
    --surface: #f5f6f8;
    --surface-2: #eef0f4;
    --paper: #ffffff;
    --paper-soft: #fbfbfc;
    --pink: #ed2a91;
    --pink-soft: #fff0f8;
    --cyan: #04b8df;
    --green: #0f9f6e;
    --green-soft: #e9f8f2;
    --danger: #d63f50;
    --danger-soft: #fff0f1;
    --shadow: 0 18px 50px rgba(25, 28, 40, .13);
    --message-bg: #f1f3f7;
    --mine-bg: #202127;
    --mine-ink: #ffffff;
    --focus: 0 0 0 3px rgba(237, 42, 145, .14);
}

body[data-theme="dark"] {
    --ink: #f2f3f7;
    --muted: #a8abb6;
    --muted-2: #777b89;
    --line: #30323a;
    --line-strong: #41434d;
    --surface: #111217;
    --surface-2: #1a1b22;
    --paper: #18191f;
    --paper-soft: #15161b;
    --pink-soft: #321528;
    --green-soft: #102a22;
    --danger-soft: #30171c;
    --message-bg: #111217;
    --mine-bg: #f0f1f4;
    --mine-ink: #17181d;
    --shadow: 0 18px 50px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; min-height: 100%; overflow: hidden; }
body {
    margin: 0;
    color: var(--ink);
    background: var(--surface);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, textarea { color: inherit; font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: none; box-shadow: var(--focus); }
svg { width: 20px; height: 20px; stroke-width: 1.9; }
[hidden] { display: none !important; }

.icon-button {
    width: 40px;
    height: 40px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 12px;
    transition: color .15s ease, background .15s ease, transform .15s ease;
}
.icon-button:hover { color: var(--ink); background: var(--surface-2); }
.icon-button:active { transform: scale(.95); }
.primary-button, .secondary-button, .danger-button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 18px;
    border-radius: 13px;
    font-weight: 750;
}
.primary-button { color: #fff; background: linear-gradient(135deg, var(--pink), #8554ff 55%, var(--cyan)); border: 0; }
.secondary-button { color: var(--ink); background: var(--surface-2); border: 1px solid var(--line); }
.danger-button { color: #fff; background: var(--danger); border: 0; }

.toast-stack {
    position: fixed;
    z-index: 200;
    top: max(18px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    min-width: 280px;
    max-width: min(440px, calc(100vw - 32px));
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 13px 16px;
    color: #fff;
    background: #202127;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .24);
    font-size: 13px;
    font-weight: 700;
    animation: toastIn .2s ease;
}
.toast.success { background: #087a55; }
.toast.error { background: #a52b3a; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } }

/* Device pairing */
.pairing-view { height: 100dvh; overflow: auto; background: var(--surface); }
.pairing-header {
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 clamp(20px, 5vw, 72px);
    background: var(--paper);
    border-bottom: 1px solid var(--line);
}
.messages-brand { width: 106px; height: 58px; display: flex; align-items: center; overflow: hidden; }
.messages-brand img, .compact-brand img { width: 106px; height: 78px; object-fit: contain; }
.icon-text-link { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; font-weight: 750; }
.pairing-layout {
    width: min(1120px, calc(100% - 40px));
    min-height: calc(100dvh - 152px);
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    gap: 9vw;
    align-items: center;
    padding: 64px 0;
}
.section-label { color: var(--pink); font-size: 12px; font-weight: 850; text-transform: uppercase; letter-spacing: .08em; }
.pairing-copy h1 { max-width: 690px; margin: 17px 0 24px; font-size: clamp(48px, 6.6vw, 82px); line-height: .99; letter-spacing: -.055em; }
.pairing-copy > p { max-width: 620px; margin: 0; color: var(--muted); font-size: 18px; line-height: 1.65; }
.pairing-copy ol { list-style: none; margin: 42px 0 0; padding: 0; border-top: 1px solid var(--line-strong); }
.pairing-copy li { min-height: 78px; display: grid; grid-template-columns: 38px 1fr; gap: 16px; align-items: center; border-bottom: 1px solid var(--line-strong); }
.pairing-copy li > span { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; color: #fff; background: var(--ink); border-radius: 50%; font-size: 12px; font-weight: 850; }
.pairing-copy li div { display: flex; flex-direction: column; gap: 4px; }
.pairing-copy li small { color: var(--muted); font-size: 13px; }
.pairing-panel { padding: 20px; background: var(--paper); border: 1px solid var(--line-strong); border-radius: 22px; box-shadow: var(--shadow); }
.pairing-panel-head { min-height: 42px; display: flex; align-items: center; justify-content: space-between; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.pairing-panel-head > span { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 800; }
.pairing-panel-head > span svg { color: var(--green); }
.pairing-qr { width: 280px; height: 280px; margin: 30px auto 20px; display: flex; align-items: center; justify-content: center; background: #fff; border: 1px solid var(--line); border-radius: 16px; }
.pairing-qr > svg { width: 76px; height: 76px; color: var(--muted-2); }
.pairing-qr img, .pairing-qr canvas { width: 260px !important; height: 260px !important; }
.pair-code { display: block; text-align: center; font-size: 15px; letter-spacing: .08em; }
.pair-status { min-height: 38px; margin: 8px 0 16px; color: var(--muted); text-align: center; font-size: 13px; line-height: 1.45; }
.pair-progress { height: 4px; overflow: hidden; background: var(--surface-2); border-radius: 4px; }
.pair-progress span { display: block; width: 100%; height: 100%; background: linear-gradient(90deg, var(--pink), var(--cyan)); transform-origin: left; transition: transform 1s linear; }
.pairing-footer { min-height: 80px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 20px clamp(20px, 5vw, 72px); color: var(--muted); background: var(--paper); border-top: 1px solid var(--line); font-size: 12px; }
.pairing-footer > span { display: flex; align-items: center; gap: 7px; }
.pairing-footer nav { display: flex; gap: 20px; font-weight: 650; }

/* Main shell */
.messages-app {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-columns: clamp(320px, 26vw, 370px) minmax(0, 1fr);
    overflow: hidden;
    background: var(--paper);
}
.messages-app.with-details { grid-template-columns: 340px minmax(0, 1fr) 330px; }
.conversation-pane {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: 72px 60px 46px minmax(0, 1fr) 68px;
    overflow: hidden;
    background: var(--paper-soft);
    border-right: 1px solid var(--line);
}
.pane-header { display: grid; grid-template-columns: 74px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 0 12px 0 14px; border-bottom: 1px solid var(--line); }
.compact-brand { width: 70px; height: 58px; display: flex; align-items: center; overflow: hidden; }
.compact-brand img { width: 76px; height: 58px; }
.pane-title { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.pane-title b { font-size: 16px; letter-spacing: -.02em; }
.pane-title span { display: flex; align-items: center; gap: 5px; color: var(--green); font-size: 10px; font-weight: 700; }
.pane-title span i, .presence-pill i { width: 7px; height: 7px; display: inline-block; background: currentColor; border-radius: 50%; box-shadow: 0 0 0 3px var(--green-soft); }
.pane-tools { display: flex; align-items: center; gap: 2px; }
.search-wrap { position: relative; display: flex; align-items: center; padding: 10px 14px; }
.search-wrap > svg { position: absolute; left: 27px; width: 17px; color: var(--muted-2); pointer-events: none; }
.search-wrap input {
    width: 100%;
    height: 40px;
    padding: 0 56px 0 40px;
    color: var(--ink);
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: 12px;
    outline: none;
    font-size: 13px;
}
.search-wrap input:focus { background: var(--paper); border-color: var(--line-strong); box-shadow: var(--focus); }
.search-wrap kbd { position: absolute; right: 24px; padding: 3px 5px; color: var(--muted-2); background: var(--paper); border: 1px solid var(--line); border-radius: 5px; font: 9px/1 ui-monospace, monospace; }
.conversation-tabs { display: flex; align-items: end; gap: 22px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.conversation-tabs button { height: 46px; display: flex; align-items: center; gap: 6px; padding: 0; color: var(--muted); background: none; border: 0; border-bottom: 2px solid transparent; font-size: 12px; font-weight: 800; }
.conversation-tabs button.active { color: var(--ink); border-color: var(--pink); }
.conversation-tabs span { min-width: 18px; height: 18px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center; color: #fff; background: var(--pink); border-radius: 10px; font-size: 9px; }
.conversation-list { min-height: 0; overflow: hidden auto; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.conversation-item {
    width: 100%;
    min-height: 76px;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 10px 14px;
    color: inherit;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--line);
    text-align: left;
    transition: background .15s ease;
}
.conversation-item:hover { background: var(--surface); }
.conversation-item.active { background: var(--pink-soft); box-shadow: inset 3px 0 var(--pink); }
.conversation-item .avatar { width: 46px; height: 46px; }
.conversation-main { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.conversation-name { min-width: 0; display: flex; align-items: center; gap: 6px; }
.conversation-name b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.conversation-name svg { width: 13px; height: 13px; flex: none; color: var(--muted-2); }
.conversation-main > span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-meta { align-self: stretch; display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: 8px; }
.conversation-meta time { color: var(--muted-2); font-size: 10px; }
.unread-count { min-width: 20px; height: 20px; padding: 0 6px; display: flex; align-items: center; justify-content: center; color: #fff; background: linear-gradient(135deg, var(--pink), #a94cff); border-radius: 10px; font-size: 10px; font-weight: 850; }
.avatar { position: relative; flex: none; width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center; color: #fff; background: linear-gradient(145deg, #7b8294, #4c5364); border-radius: 50%; overflow: visible; font-size: 13px; font-weight: 850; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.avatar.online::after { content: ""; position: absolute; right: 0; bottom: 1px; width: 9px; height: 9px; background: #20b77b; border: 2px solid var(--paper); border-radius: 50%; }
.account-strip { display: grid; grid-template-columns: 42px minmax(0, 1fr) 40px; gap: 10px; align-items: center; padding: 0 14px; background: var(--paper); border-top: 1px solid var(--line); }
.account-strip > div { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.account-strip b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.account-strip small { color: var(--muted); font-size: 10px; }

/* Conversation */
.chat-pane { min-width: 0; min-height: 0; height: 100%; overflow: hidden; background: var(--message-bg); }
.empty-chat { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px; text-align: center; }
.empty-mark { width: 92px; height: 92px; display: flex; align-items: center; justify-content: center; color: #fff; background: linear-gradient(145deg, var(--pink), #8c50f5 55%, var(--cyan)); border-radius: 30px; box-shadow: 0 18px 42px rgba(218, 40, 143, .25); transform: rotate(-4deg); }
.empty-mark svg { width: 42px; height: 42px; transform: rotate(4deg); }
.empty-chat h1 { margin: 26px 0 10px; font-size: 31px; letter-spacing: -.04em; }
.empty-chat p { max-width: 430px; margin: 0; color: var(--muted); line-height: 1.6; }
.empty-chat .primary-button { margin-top: 24px; }
.empty-chat > span { display: flex; align-items: center; gap: 7px; margin-top: 24px; color: var(--muted-2); font-size: 11px; }
.empty-chat > span svg { width: 15px; }
.active-chat {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-header { min-width: 0; min-height: 72px; flex: none; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 0 16px; background: var(--paper); border-bottom: 1px solid var(--line); }
.mobile-back { display: none; }
.person-button { min-width: 0; width: fit-content; max-width: 100%; display: flex; align-items: center; gap: 11px; padding: 5px; color: inherit; background: transparent; border: 0; border-radius: 13px; text-align: left; }
.person-button:hover { background: var(--surface); }
.chat-person { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.chat-person b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chat-person small { color: var(--green); font-size: 11px; }
.chat-tools { display: flex; align-items: center; gap: 2px; }
.message-search { min-height: 54px; display: grid; grid-template-columns: 20px minmax(0, 1fr) auto 40px; gap: 10px; align-items: center; padding: 0 14px 0 20px; background: var(--paper); border-bottom: 1px solid var(--line); }
.message-search input { width: 100%; color: var(--ink); background: transparent; border: 0; outline: 0; font-size: 13px; }
.message-search > span { color: var(--muted); font-size: 11px; }
.conversation-notice { min-height: 48px; display: flex; align-items: center; justify-content: center; gap: 9px; padding: 8px 16px; color: #8c4c13; background: #fff5df; border-bottom: 1px solid #f1d6a5; font-size: 12px; }
body[data-theme="dark"] .conversation-notice { color: #ffc987; background: #302317; border-color: #513921; }
.conversation-notice svg { width: 17px; }
.conversation-notice button { padding: 5px 9px; color: inherit; background: transparent; border: 1px solid currentColor; border-radius: 8px; font-size: 11px; font-weight: 800; }
.message-stage { position: relative; min-height: 0; flex: 1 1 auto; overflow: hidden; }
.message-list {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden auto;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 22px clamp(18px, 4vw, 72px) 26px;
    scroll-behavior: smooth;
    background-color: var(--message-bg);
    background-image: radial-gradient(circle at 20% 20%, rgba(237, 42, 145, .035), transparent 32%), radial-gradient(circle at 80% 78%, rgba(4, 184, 223, .04), transparent 35%);
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
}
.day-label { position: sticky; z-index: 2; top: 4px; align-self: center; margin: 8px 0 14px; padding: 6px 11px; color: var(--muted); background: color-mix(in srgb, var(--paper) 90%, transparent); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 3px 12px rgba(20, 22, 30, .06); backdrop-filter: blur(8px); font-size: 10px; font-weight: 800; }
.thread-empty { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px; color: var(--muted); text-align: center; }
.thread-empty span { width: 58px; height: 58px; display: flex; align-items: center; justify-content: center; margin-bottom: 15px; color: var(--pink); background: var(--pink-soft); border-radius: 20px; }
.thread-empty b { color: var(--ink); font-size: 16px; }
.thread-empty p { max-width: 330px; margin: 7px 0 0; font-size: 12px; line-height: 1.55; }
.message-row { position: relative; max-width: min(74%, 680px); display: flex; flex-direction: column; gap: 4px; }
.message-row.mine { align-self: flex-end; align-items: flex-end; }
.message-row.theirs { align-self: flex-start; align-items: flex-start; }
/* Sadece yeni gelen/gonderilen mesaja uygulanir (bkz. messages.js
   isPureAppend) — tum listeyi degil, sadece o an eklenen satiri hafifce
   belirginlestirir. */
.message-row.message-enter { animation: messageEnter .28s ease both; }
@keyframes messageEnter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.message-bubble { position: relative; min-width: 92px; padding: 10px 12px 7px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 18px 18px 18px 5px; box-shadow: 0 2px 5px rgba(22, 22, 28, .05); }
.message-row.mine .message-bubble { color: var(--mine-ink); background: var(--mine-bg); border-color: var(--mine-bg); border-radius: 18px 18px 5px 18px; }
.message-bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.48; }
.message-bubble p a { color: var(--pink); text-decoration: underline; text-underline-offset: 2px; }
.message-row.mine .message-bubble p a { color: #79dcf4; }
.message-reply { min-width: 180px; margin: -2px -3px 8px; padding: 8px 10px; background: color-mix(in srgb, var(--surface-2) 88%, transparent); border-left: 3px solid var(--pink); border-radius: 9px; }
.message-row.mine .message-reply { background: rgba(255, 255, 255, .1); }
.message-reply b, .message-reply span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-reply b { color: var(--pink); font-size: 10px; }
.message-row.mine .message-reply b { color: #ff81c5; }
.message-reply span { margin-top: 3px; opacity: .8; font-size: 11px; }
.deleted-message { display: flex; align-items: center; gap: 7px; opacity: .68; font-style: italic; font-size: 13px; }
.deleted-message svg { width: 15px; }
.message-time { display: flex; justify-content: flex-end; align-items: center; gap: 4px; margin-top: 5px; color: var(--muted-2); font-size: 9px; }
.message-row.mine .message-time { color: color-mix(in srgb, var(--mine-ink) 65%, transparent); }
.message-time svg { width: 13px; height: 13px; }
.message-time em { font-style: normal; }
.message-media { display: block; max-width: min(380px, 58vw); max-height: 390px; margin: -4px -6px 8px; border-radius: 13px; object-fit: cover; cursor: zoom-in; }
video.message-media { width: min(380px, 58vw); background: #000; cursor: default; }
.video-note { display: block; max-width: 300px; padding: 8px 2px; color: var(--muted); font-size: 11px; line-height: 1.45; }
audio.message-audio { width: 300px; max-width: min(68vw, 100%); }
.location-message { min-width: 250px; display: grid; grid-template-columns: 44px minmax(0, 1fr) 20px; gap: 11px; align-items: center; color: inherit; }
.location-message > span:first-child { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; color: #fff; background: var(--green); border-radius: 13px; }
.location-message div { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.location-message b, .location-message small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.location-message small { color: var(--muted); }
.message-row.mine .location-message small { color: color-mix(in srgb, var(--mine-ink) 70%, transparent); }
.message-tools { position: absolute; top: 50%; display: flex; opacity: 0; transform: translateY(-50%); transition: opacity .15s ease; }
.message-row.mine .message-tools { right: calc(100% + 7px); }
.message-row.theirs .message-tools { left: calc(100% + 7px); }
.message-row:hover .message-tools, .message-row:focus-within .message-tools { opacity: 1; }
.message-tools button { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; color: var(--muted); background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 5px 16px rgba(20, 22, 30, .08); }
.message-tools svg { width: 15px; height: 15px; }
.reaction-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: -1px; }
.message-row.mine .reaction-row { justify-content: flex-end; }
.reaction-pill { height: 24px; display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 12px; font-size: 11px; }
.reaction-pill.mine { border-color: var(--pink); background: var(--pink-soft); }
.jump-bottom { position: absolute; z-index: 4; right: 22px; bottom: 16px; width: 42px; height: 42px; display: flex; align-items: center; justify-content: center; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 50%; box-shadow: var(--shadow); }
.jump-bottom span { position: absolute; top: -6px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; display: flex; align-items: center; justify-content: center; color: #fff; background: var(--pink); border-radius: 10px; font-size: 9px; font-weight: 800; }
.drop-zone { position: absolute; z-index: 12; inset: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; color: var(--pink); background: color-mix(in srgb, var(--paper) 92%, transparent); border: 2px dashed var(--pink); border-radius: 20px; backdrop-filter: blur(7px); }
.drop-zone svg { width: 34px; height: 34px; }
.drop-zone b { color: var(--ink); }
.drop-zone span { color: var(--muted); font-size: 12px; }

/* Composer */
.composer-context { min-height: 52px; flex: none; display: grid; grid-template-columns: 24px minmax(0, 1fr) 40px; gap: 9px; align-items: center; padding: 7px 14px 7px 18px; background: var(--paper); border-top: 1px solid var(--line); box-shadow: inset 3px 0 var(--pink); }
.composer-context > svg { color: var(--pink); }
.composer-context div { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.composer-context b { color: var(--pink); font-size: 11px; }
.composer-context span { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.upload-preview { min-height: 62px; flex: none; display: grid; grid-template-columns: 46px minmax(0, 1fr) 40px; gap: 10px; align-items: center; padding: 7px 14px 7px 18px; background: var(--paper); border-top: 1px solid var(--line); }
.upload-thumb { width: 46px; height: 46px; display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--pink); background: var(--pink-soft); border-radius: 12px; }
.upload-thumb img, .upload-thumb video { width: 100%; height: 100%; object-fit: cover; }
.upload-preview > div:nth-child(2) { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.upload-preview b, .upload-preview span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-preview b { font-size: 12px; }
.upload-preview span { color: var(--muted); font-size: 10px; }
.composer { position: relative; min-height: 72px; flex: none; display: grid; grid-template-columns: auto minmax(0, 1fr) auto 48px; gap: 8px; align-items: end; padding: 10px 14px max(10px, env(safe-area-inset-bottom)); background: var(--paper); border-top: 1px solid var(--line); }
.composer-actions { display: flex; gap: 4px; }
.composer-button { background: var(--surface-2); }
.composer-input { min-height: 46px; display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px; background: var(--surface-2); border: 1px solid transparent; border-radius: 16px; }
.composer-input:focus-within { background: var(--paper); border-color: var(--line-strong); box-shadow: var(--focus); }
.composer textarea { width: 100%; min-height: 26px; max-height: 120px; resize: none; overflow-y: auto; color: var(--ink); background: transparent; border: 0; outline: 0; line-height: 1.45; }
.composer textarea::placeholder { color: var(--muted-2); }
.character-count { display: none; flex: none; padding-bottom: 3px; color: var(--muted-2); font-size: 9px; }
.composer-input:focus-within .character-count { display: inline; }
.send-button { width: 48px; height: 46px; display: flex; align-items: center; justify-content: center; color: #fff; background: linear-gradient(135deg, var(--pink), #9751ed 55%, var(--cyan)); border: 0; border-radius: 15px; box-shadow: 0 8px 20px rgba(230, 43, 146, .22); transition: opacity .15s ease, transform .15s ease; }
.send-button:not(:disabled):hover { transform: translateY(-1px); }
.send-button:disabled { opacity: .38; cursor: not-allowed; box-shadow: none; }
.attach-wrap, .emoji-wrap { position: relative; }
.attach-menu, .emoji-picker {
    position: absolute;
    z-index: 30;
    left: 0;
    bottom: 54px;
    background: var(--paper);
    border: 1px solid var(--line-strong);
    border-radius: 16px;
    box-shadow: var(--shadow);
}
.attach-menu { width: 270px; padding: 8px; }
.attach-menu button { width: 100%; display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 10px; align-items: center; padding: 9px; color: inherit; background: transparent; border: 0; border-radius: 11px; text-align: left; }
.attach-menu button:hover { background: var(--surface); }
.attach-icon { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; color: #fff; border-radius: 12px; }
.attach-icon.media { background: linear-gradient(135deg, var(--pink), #a84ee6); }
.attach-icon.location { background: var(--green); }
.attach-menu button > span:last-child { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.attach-menu b { font-size: 12px; }
.attach-menu small { color: var(--muted); font-size: 10px; }
.emoji-picker { width: 304px; padding: 12px; }
.emoji-picker header { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 10px; }
.emoji-picker header b { font-size: 13px; }
.emoji-picker header span { color: var(--muted); font-size: 10px; }
.emoji-picker > div { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; }
.emoji-picker button { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; background: transparent; border: 0; border-radius: 8px; font-size: 20px; }
.emoji-picker button:hover { background: var(--pink-soft); transform: scale(1.08); }
.record-button { position: relative; width: 42px; }
.record-button span { margin-left: 5px; font-size: 10px; font-weight: 800; }
.record-button.recording { width: 72px; color: #fff; background: var(--danger); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .68; } }

/* Details */
.details-pane { min-width: 0; min-height: 0; overflow: hidden; background: var(--paper); border-left: 1px solid var(--line); }
.details-pane > header { height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px 0 20px; border-bottom: 1px solid var(--line); }
.details-scroll { height: calc(100% - 72px); overflow: hidden auto; }
.details-profile { display: flex; flex-direction: column; align-items: center; padding: 30px 20px 26px; border-bottom: 1px solid var(--line); }
.avatar.large { width: 84px; height: 84px; font-size: 25px; }
.details-profile h2 { margin: 16px 0 3px; font-size: 20px; letter-spacing: -.03em; }
.details-profile p { margin: 0; color: var(--muted); font-size: 12px; }
.presence-pill { display: flex; align-items: center; gap: 6px; margin-top: 12px; padding: 5px 9px; color: var(--green); background: var(--green-soft); border-radius: 12px; font-size: 10px; font-weight: 800; }
.details-section { padding: 18px 14px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 11px; }
.section-heading b { font-size: 12px; }
.section-heading span { color: var(--muted); font-size: 10px; }
.media-gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.media-gallery button { aspect-ratio: 1; overflow: hidden; padding: 0; color: var(--muted); background: var(--surface-2); border: 0; border-radius: 9px; }
.media-gallery img, .media-gallery video { width: 100%; height: 100%; object-fit: cover; }
.media-gallery .gallery-empty { grid-column: 1 / -1; aspect-ratio: auto; padding: 20px 8px; color: var(--muted); background: var(--surface); font-size: 10px; cursor: default; }
.details-actions { padding: 8px; }
.details-actions button { width: 100%; display: grid; grid-template-columns: 36px minmax(0, 1fr) 18px; gap: 8px; align-items: center; padding: 12px; color: inherit; background: transparent; border: 0; border-radius: 12px; text-align: left; }
.details-actions button:hover { background: var(--surface); }
.details-actions button > svg:first-child { color: var(--muted); }
.details-actions button > svg:last-child { width: 16px; color: var(--muted-2); }
.details-actions button > span { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.details-actions b { font-size: 12px; }
.details-actions small { color: var(--muted); font-size: 10px; }
.details-actions .danger, .details-actions .danger > svg:first-child { color: var(--danger); }

/* Popovers and modals */
.popover, .message-action-menu { position: fixed; z-index: 80; padding: 7px; background: var(--paper); border: 1px solid var(--line-strong); border-radius: 15px; box-shadow: var(--shadow); }
.menu-popover { top: 62px; left: min(calc(26vw - 288px), 70px); width: 286px; }
.popover button { width: 100%; display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 8px; align-items: center; padding: 10px; color: inherit; background: transparent; border: 0; border-radius: 10px; text-align: left; }
.popover button:hover { background: var(--surface); }
.popover button > span { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.popover b { font-size: 12px; }
.popover small { color: var(--muted); font-size: 10px; }
.popover .danger, .message-action-menu .danger { color: var(--danger); }
.message-action-menu { width: 220px; }
.quick-reactions { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; padding-bottom: 7px; border-bottom: 1px solid var(--line); }
.quick-reactions button { height: 34px; padding: 0; background: transparent; border: 0; border-radius: 8px; font-size: 18px; }
.quick-reactions button:hover { background: var(--pink-soft); transform: scale(1.08); }
.action-menu-buttons { padding-top: 5px; }
.action-menu-buttons button { width: 100%; display: flex; align-items: center; gap: 9px; padding: 9px; color: inherit; background: transparent; border: 0; border-radius: 9px; text-align: left; font-size: 12px; }
.action-menu-buttons button:hover { background: var(--surface); }
.action-menu-buttons svg { width: 16px; }
.modal-backdrop { position: fixed; z-index: 100; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(15, 16, 22, .55); backdrop-filter: blur(5px); }
.modal-card { width: min(480px, 100%); max-height: min(650px, calc(100dvh - 40px)); overflow: hidden; background: var(--paper); border: 1px solid var(--line-strong); border-radius: 22px; box-shadow: 0 28px 90px rgba(0, 0, 0, .28); }
.new-chat-card { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.new-chat-card > header { display: flex; align-items: flex-start; justify-content: space-between; padding: 20px 20px 13px; }
.new-chat-card > header span { color: var(--pink); font-size: 10px; font-weight: 850; text-transform: uppercase; letter-spacing: .07em; }
.new-chat-card h2 { margin: 5px 0 0; font-size: 22px; letter-spacing: -.04em; }
.modal-search { position: relative; display: flex; align-items: center; padding: 0 20px 14px; }
.modal-search svg { position: absolute; left: 34px; width: 17px; color: var(--muted); }
.modal-search input { width: 100%; height: 42px; padding: 0 13px 0 40px; color: var(--ink); background: var(--surface-2); border: 1px solid transparent; border-radius: 12px; outline: none; }
.new-chat-list { min-height: 220px; max-height: 440px; overflow: hidden auto; padding: 0 10px 12px; }
.new-chat-item { width: 100%; display: grid; grid-template-columns: 44px minmax(0, 1fr) 34px; gap: 11px; align-items: center; padding: 10px; color: inherit; background: transparent; border: 0; border-radius: 13px; text-align: left; }
.new-chat-item:hover { background: var(--surface); }
.new-chat-item > span:nth-child(2) { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.new-chat-item b, .new-chat-item small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.new-chat-item small { color: var(--muted); }
.new-chat-item > svg { width: 17px; color: var(--muted); }
.confirm-card { padding: 26px; text-align: center; }
.confirm-icon { width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; margin: 0 auto; color: var(--danger); background: var(--danger-soft); border-radius: 18px; }
.confirm-icon svg { width: 26px; height: 26px; }
.confirm-card h2 { margin: 17px 0 8px; font-size: 21px; }
.confirm-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 22px; }
.confirm-actions.has-secondary { grid-template-columns: repeat(3, 1fr); }
.lightbox { z-index: 120; background: rgba(7, 8, 12, .88); }
.lightbox-close { position: absolute; top: 18px; right: 18px; color: #fff; background: rgba(255, 255, 255, .12); }
.lightbox > div { max-width: min(1100px, 92vw); max-height: 88dvh; }
.lightbox img, .lightbox video { display: block; max-width: 100%; max-height: 88dvh; border-radius: 14px; box-shadow: 0 24px 80px rgba(0, 0, 0, .4); }
.list-empty { padding: 44px 24px; color: var(--muted); text-align: center; font-size: 13px; line-height: 1.6; }

@media (max-width: 1180px) {
    .messages-app, .messages-app.with-details { grid-template-columns: 330px minmax(0, 1fr); }
    .details-pane { position: fixed; z-index: 60; top: 0; right: 0; bottom: 0; width: min(350px, 92vw); box-shadow: -18px 0 45px rgba(0, 0, 0, .15); }
    .menu-popover { left: 34px; }
}

@media (max-width: 760px) {
    .pairing-header { height: 64px; padding: 0 16px; }
    .pairing-layout { width: calc(100% - 32px); min-height: auto; grid-template-columns: 1fr; gap: 40px; padding: 42px 0; }
    .pairing-copy h1 { font-size: 48px; }
    .pairing-copy > p { font-size: 16px; }
    .pairing-panel { width: 100%; }
    .pairing-qr { width: min(280px, 100%); height: auto; aspect-ratio: 1; }
    .pairing-footer { align-items: flex-start; flex-direction: column; }
    .messages-app, .messages-app.with-details { display: block; }
    .conversation-pane { width: 100%; height: 100dvh; grid-template-rows: 66px 56px 44px minmax(0, 1fr) 66px; }
    .pane-header { grid-template-columns: 66px minmax(0, 1fr) auto; }
    .search-wrap { padding-top: 8px; padding-bottom: 8px; }
    .search-wrap kbd { display: none; }
    .chat-pane { position: fixed; z-index: 30; inset: 0; width: 100%; height: 100dvh; transform: translateX(100%); transition: transform .22s ease; }
    .messages-app.chat-open .chat-pane { transform: translateX(0); }
    .chat-header { min-height: 64px; grid-template-columns: 40px minmax(0, 1fr) auto; padding: 0 8px; }
    .mobile-back { display: inline-flex; }
    .message-row { max-width: 86%; }
    .message-list { padding: 18px 12px 24px; }
    .message-tools { position: static; margin-top: 1px; opacity: 1; transform: none; }
    .message-row.mine .message-tools, .message-row.theirs .message-tools { align-self: inherit; }
    .message-tools button { width: 28px; height: 26px; box-shadow: none; }
    .composer { grid-template-columns: auto minmax(0, 1fr) auto 44px; gap: 5px; padding: 8px 7px max(8px, env(safe-area-inset-bottom)); }
    .composer-actions { gap: 1px; }
    .composer .icon-button { width: 36px; }
    .composer-input { min-height: 44px; padding: 7px 10px; }
    .send-button { width: 44px; height: 44px; }
    .record-button.recording { width: 66px; }
    .emoji-picker { position: fixed; right: 8px; bottom: 72px; left: 8px; width: auto; }
    .attach-menu { position: fixed; right: 8px; bottom: 72px; left: 8px; width: auto; }
    .details-pane { z-index: 70; width: min(360px, 94vw); }
    .menu-popover { top: 58px; right: 10px; left: auto; width: min(286px, calc(100vw - 20px)); }
    .message-action-menu { width: 210px; }
    .new-chat-card { height: min(650px, calc(100dvh - 24px)); }
}

@media (max-width: 410px) {
    .pane-title { display: none; }
    .pane-header { grid-template-columns: 1fr auto; }
    .composer .emoji-wrap { display: none; }
    .composer { grid-template-columns: 38px minmax(0, 1fr) auto 44px; }
    .message-media, video.message-media { max-width: 72vw; width: auto; }
}
