:root {
    --bg: #030712;
    --panel: rgba(9, 18, 35, .92);
    --panel-2: rgba(15, 27, 48, .84);
    --soft: rgba(255, 255, 255, .06);
    --line: rgba(148, 163, 184, .16);
    --text: #f8fafc;
    --muted: #94a3b8;
    --primary: #22d3ee;
    --primary-2: #2563eb;
    --danger: #fb7185;
    --success: #34d399;
    --shadow: 0 24px 80px rgba(0, 0, 0, .42);
    --radius: 20px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at 10% 0%, rgba(14, 165, 233, .16), transparent 34%),
        radial-gradient(circle at 90% 100%, rgba(124, 58, 237, .14), transparent 36%),
        var(--bg);
}
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { color: inherit; }
.hidden { display: none !important; }
.small { font-size: 12px; }
.center { text-align: center; }
.muted { color: var(--muted); }

/* Auth */
.auth-body { min-height: 100%; display: grid; place-items: center; padding: 28px; }
.auth-shell {
    width: min(1100px, 100%);
    display: grid;
    grid-template-columns: 1.08fr .92fr;
    border: 1px solid var(--line);
    border-radius: 32px;
    overflow: hidden;
    background: rgba(4, 11, 24, .78);
    box-shadow: var(--shadow);
    backdrop-filter: blur(22px);
}
.auth-brand {
    min-height: 650px;
    padding: 58px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background:
        linear-gradient(135deg, rgba(14, 165, 233, .16), rgba(37, 99, 235, .04)),
        radial-gradient(circle at 25% 20%, rgba(34, 211, 238, .18), transparent 34%);
    border-right: 1px solid var(--line);
}
.brand-mark {
    width: 64px; height: 64px; display: grid; place-items: center;
    border-radius: 19px; font-weight: 900; letter-spacing: -.05em; font-size: 22px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    box-shadow: 0 16px 40px rgba(34, 211, 238, .2);
    margin-bottom: 34px;
}
.eyebrow { color: var(--primary); font-size: 12px; letter-spacing: .24em; font-weight: 800; }
.auth-brand h1 { font-size: clamp(36px, 5vw, 58px); line-height: 1.04; letter-spacing: -.055em; margin: 15px 0 20px; max-width: 640px; }
.auth-brand > p { color: #b6c2d2; line-height: 1.75; max-width: 560px; font-size: 16px; margin-bottom: 28px; }
.feature-row { display: flex; gap: 12px; color: #dbeafe; margin: 7px 0; }
.feature-row span { color: var(--primary); }
.auth-card { padding: 48px; align-self: center; }
.tabs { display: flex; gap: 6px; padding: 5px; border-radius: 14px; background: var(--soft); }
.tab-btn { border: 0; background: transparent; color: var(--muted); padding: 10px 16px; border-radius: 10px; cursor: pointer; font-weight: 750; }
.tab-btn.active { color: #fff; background: rgba(37, 99, 235, .52); box-shadow: 0 8px 24px rgba(37, 99, 235, .18); }
.auth-tabs { margin-bottom: 24px; }
.auth-tabs .tab-btn { flex: 1; }
.auth-form { display: none; }
.auth-form.active { display: grid; gap: 15px; }
label { display: grid; gap: 8px; font-weight: 700; color: #dbeafe; font-size: 14px; }
label small { color: var(--muted); font-weight: 500; }
input, textarea, select {
    width: 100%; border: 1px solid var(--line); border-radius: 13px; outline: none;
    color: var(--text); background: rgba(2, 8, 23, .62); padding: 13px 14px;
    transition: border .2s, box-shadow .2s, background .2s;
}
input:focus, textarea:focus, select:focus { border-color: rgba(34, 211, 238, .65); box-shadow: 0 0 0 4px rgba(34, 211, 238, .1); background: rgba(3, 12, 29, .9); }
input[readonly] { color: #94a3b8; cursor: not-allowed; }
.primary-btn, .secondary-btn, .tiny-btn, .send-btn, .icon-btn {
    border: 0; cursor: pointer; transition: transform .18s, filter .18s, background .18s;
}
.primary-btn {
    padding: 13px 18px; border-radius: 13px; font-weight: 850;
    background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
    box-shadow: 0 12px 28px rgba(37, 99, 235, .2);
}
.primary-btn:hover, .secondary-btn:hover, .tiny-btn:hover, .send-btn:hover, .icon-btn:hover { filter: brightness(1.1); }
.primary-btn:active, .secondary-btn:active, .tiny-btn:active, .send-btn:active, .icon-btn:active { transform: scale(.97); }
.secondary-btn { padding: 12px 17px; border-radius: 13px; background: var(--soft); border: 1px solid var(--line); font-weight: 750; }
.wide { width: 100%; }
.compact { padding: 10px 14px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 21px 0; font-size: 12px; }
.divider::before, .divider::after { content: ''; height: 1px; flex: 1; background: var(--line); }
.alert { padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; line-height: 1.5; }
.alert.error { color: #fecdd3; background: rgba(244, 63, 94, .12); border: 1px solid rgba(244, 63, 94, .22); }
.alert.success { color: #a7f3d0; background: rgba(16, 185, 129, .12); border: 1px solid rgba(16, 185, 129, .22); }

/* Main chat */
.app-body { overflow: hidden; }
.chat-app { height: 100vh; display: grid; grid-template-columns: 340px minmax(390px, 1fr) 300px; }
.sidebar, .details-panel, .chat-main { min-width: 0; }
.sidebar {
    display: flex; flex-direction: column; background: rgba(5, 13, 27, .94);
    border-right: 1px solid var(--line); backdrop-filter: blur(20px); z-index: 20;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 18px 14px; }
.mini-profile { display: flex; align-items: center; gap: 11px; min-width: 0; }
.mini-profile img, .chat-target img { width: 44px; height: 44px; object-fit: cover; border-radius: 14px; border: 1px solid var(--line); }
.mini-profile div, .chat-target div { min-width: 0; }
.mini-profile strong, .chat-target strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-profile small, .chat-target small { display: block; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; background: var(--soft); border: 1px solid var(--line); }
.search-box { margin: 2px 18px 12px; position: relative; }
.search-box span { position: absolute; top: 50%; left: 13px; transform: translateY(-50%); color: var(--muted); font-size: 22px; }
.search-box input { padding-left: 40px; }
.search-results {
    display: none; position: absolute; left: 18px; top: 132px; width: calc(340px - 36px); max-height: 390px;
    overflow: auto; z-index: 50; padding: 8px; border: 1px solid var(--line); border-radius: 16px;
    background: rgba(8, 18, 35, .99); box-shadow: var(--shadow);
}
.search-results.show { display: block; }
.search-user { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 10px; padding: 9px; border-radius: 12px; }
.search-user:hover { background: var(--soft); }
.search-user img { width: 42px; height: 42px; object-fit: cover; border-radius: 13px; }
.search-user span { min-width: 0; }
.search-user strong, .search-user small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.search-user small { color: var(--muted); margin-top: 3px; }
.search-user > div { display: flex; flex-direction: column; gap: 5px; align-items: flex-end; }
.status-text { font-size: 11px; color: var(--muted); }
.sidebar-tabs { margin: 0 18px 10px; }
.sidebar-tabs .tab-btn { flex: 1; padding: 9px 7px; font-size: 13px; }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 20px; background: var(--danger); color: #fff; font-size: 10px; }
.side-panel { display: none; flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 16px; }
.side-panel.active { display: block; }
.section-label { color: var(--muted); font-size: 11px; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; padding: 13px 8px 8px; }
.contact-list { display: grid; gap: 3px; }
.contact-item {
    width: 100%; display: flex; align-items: center; gap: 11px; border: 0; text-align: left;
    padding: 10px; border-radius: 14px; background: transparent; cursor: pointer; min-width: 0;
}
.contact-item:hover, .contact-item.active { background: rgba(37, 99, 235, .14); }
.contact-item.active { box-shadow: inset 0 0 0 1px rgba(34, 211, 238, .17); }
.contact-item.static { cursor: default; }
.avatar-wrap { position: relative; flex: 0 0 auto; }
.avatar-wrap img { width: 46px; height: 46px; object-fit: cover; border-radius: 15px; border: 1px solid var(--line); display: block; }
.online-dot { width: 9px; height: 9px; display: inline-block; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px rgba(52, 211, 153, .12); }
.avatar-dot { position: absolute; right: -1px; bottom: 0; border: 2px solid #081223; width: 12px; height: 12px; }
.contact-copy { flex: 1; min-width: 0; }
.contact-copy strong, .contact-copy small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-copy small { color: var(--muted); margin-top: 4px; }
.contact-meta { display: grid; justify-items: end; gap: 6px; color: var(--muted); font-size: 11px; }
.unread-badge { min-width: 20px; height: 20px; display: grid; place-items: center; padding: 0 5px; border-radius: 20px; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: white; font-size: 10px; }
.inline-actions { display: flex; gap: 5px; }
.tiny-btn { padding: 7px 10px; border-radius: 9px; background: rgba(37, 99, 235, .28); color: #dbeafe; font-size: 11px; font-weight: 800; white-space: nowrap; }
.tiny-btn.danger { background: rgba(244, 63, 94, .13); color: #fecdd3; }
.empty-list { padding: 18px 12px; color: var(--muted); font-size: 13px; text-align: center; line-height: 1.6; }
.sidebar-footer { display: flex; align-items: center; justify-content: space-between; padding: 13px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.sidebar-footer span { display: flex; align-items: center; gap: 8px; }
.sidebar-footer a { color: #fda4af; }

.chat-main { display: grid; grid-template-rows: 72px 1fr auto; background: rgba(3, 9, 21, .58); position: relative; }
.chat-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: rgba(4, 12, 27, .75); backdrop-filter: blur(16px); }
.chat-target { display: flex; align-items: center; gap: 11px; min-width: 0; }
.empty-avatar { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; background: var(--soft); }
.welcome-screen { align-self: center; justify-self: center; width: min(760px, calc(100% - 42px)); text-align: center; }
.welcome-icon { width: 76px; height: 76px; display: grid; place-items: center; margin: 0 auto 20px; border-radius: 24px; font-size: 32px; background: linear-gradient(135deg, rgba(34, 211, 238, .22), rgba(37, 99, 235, .25)); border: 1px solid rgba(34, 211, 238, .2); }
.welcome-screen h2 { font-size: clamp(27px, 4vw, 42px); letter-spacing: -.04em; margin: 0 0 12px; }
.welcome-screen > p { color: var(--muted); line-height: 1.7; margin: 0 auto 30px; max-width: 620px; }
.welcome-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; text-align: left; }
.welcome-grid article { padding: 19px; border: 1px solid var(--line); border-radius: 17px; background: var(--soft); }
.welcome-grid span { display: block; color: var(--primary); font-size: 11px; font-weight: 900; letter-spacing: .12em; }
.welcome-grid strong { display: block; margin: 12px 0 7px; }
.welcome-grid small { color: var(--muted); line-height: 1.55; }
.messages { min-height: 0; overflow-y: auto; padding: 24px clamp(16px, 4vw, 48px); scroll-behavior: smooth; }
.message-row { display: flex; align-items: flex-end; gap: 9px; margin: 9px 0; }
.message-row.own { justify-content: flex-end; }
.message-avatar { width: 30px; height: 30px; border-radius: 10px; object-fit: cover; }
.message-wrap { max-width: min(72%, 680px); }
.message-sender { display: flex; align-items: center; gap: 5px; color: var(--primary); font-size: 11px; font-weight: 800; margin: 0 0 4px 5px; }
.message-admin-badge,
.chat-admin-badge { display: inline-flex; align-items: center; justify-content: center; padding: 2px 5px; border: 1px solid rgba(255, 193, 7, .55); border-radius: 5px; background: rgba(255, 193, 7, .16); color: #ffd54a; font-size: 8px; font-weight: 900; line-height: 1; letter-spacing: .5px; vertical-align: middle; }
.chat-admin-badge { margin-left: 4px; padding: 3px 6px; font-size: 9px; }
.message-bubble { padding: 11px 14px; border-radius: 7px 18px 18px 18px; background: rgba(30, 41, 59, .92); border: 1px solid rgba(148, 163, 184, .13); white-space: pre-wrap; word-break: break-word; line-height: 1.48; }
.message-row.own .message-bubble { border-radius: 18px 7px 18px 18px; background: linear-gradient(135deg, #0891b2, #2563eb); border-color: transparent; }
.message-meta { margin: 4px 6px 0; color: var(--muted); font-size: 10px; }
.message-row.own .message-meta { text-align: right; }
.conversation-empty { height: 100%; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.conversation-empty span { font-size: 36px; }
.conversation-empty strong { color: var(--text); margin: 10px 0 4px; }
.composer { display: flex; align-items: flex-end; gap: 10px; padding: 13px clamp(14px, 3vw, 28px) 18px; background: linear-gradient(180deg, transparent, rgba(3, 9, 21, .92) 25%); }
.composer textarea { resize: none; min-height: 47px; max-height: 140px; line-height: 1.45; padding: 13px 15px; }
.send-btn { flex: 0 0 auto; width: 48px; height: 48px; display: grid; place-items: center; border-radius: 15px; background: linear-gradient(135deg, var(--primary), var(--primary-2)); font-size: 18px; }

.details-panel { padding: 22px 17px; background: rgba(5, 13, 27, .9); border-left: 1px solid var(--line); overflow-y: auto; }
.details-placeholder { min-height: 100%; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); padding: 20px; }
.details-placeholder span { font-size: 34px; }
.detail-profile { text-align: center; padding: 14px 4px 22px; }
.detail-profile > img { width: 92px; height: 92px; object-fit: cover; border-radius: 28px; border: 1px solid var(--line); box-shadow: 0 18px 42px rgba(0, 0, 0, .25); }
.detail-profile h3 { margin: 13px 0 3px; }
.detail-profile p { color: var(--muted); margin: 0 0 10px; }
.account-chip { display: inline-flex; padding: 6px 10px; border-radius: 30px; background: rgba(34, 211, 238, .1); color: #a5f3fc; border: 1px solid rgba(34, 211, 238, .16); font-size: 11px; font-weight: 800; }
.detail-list { display: grid; gap: 7px; margin: 0 0 16px; }
.detail-list div { display: flex; justify-content: space-between; gap: 10px; padding: 11px; border-radius: 12px; background: var(--soft); font-size: 12px; }
.detail-list span { color: var(--muted); }
.member-list { display: grid; gap: 5px; }
.member-row { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 9px; padding: 8px; border-radius: 12px; }
.member-row:hover { background: var(--soft); }
.member-row .avatar-wrap img { width: 40px; height: 40px; border-radius: 12px; }
.member-row strong, .member-row small { display: block; }
.member-row small { color: var(--muted); margin-top: 2px; }
.member-row em { color: var(--primary); font-size: 10px; font-style: normal; }
.add-member-box { display: flex; gap: 7px; margin: 0 0 8px; }
.add-member-box select { padding: 9px; font-size: 12px; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(0, 0, 0, .68); backdrop-filter: blur(8px); }
.modal-card { width: min(520px, 100%); max-height: 86vh; overflow: auto; padding: 22px; border-radius: 22px; background: #081225; border: 1px solid var(--line); box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { margin: 0; }
.member-picker { display: grid; gap: 6px; max-height: 310px; overflow: auto; margin-bottom: 18px; }
.picker-item { display: grid; grid-template-columns: 20px 42px 1fr; align-items: center; gap: 9px; padding: 9px; border-radius: 12px; cursor: pointer; }
.picker-item:hover { background: var(--soft); }
.picker-item input { width: 17px; height: 17px; }
.picker-item img { width: 42px; height: 42px; border-radius: 13px; object-fit: cover; }
.picker-item strong, .picker-item small { display: block; }
.picker-item small { color: var(--muted); }

.toast-stack { position: fixed; right: 18px; top: 18px; z-index: 200; display: grid; gap: 9px; }
.toast { transform: translateY(-8px); opacity: 0; min-width: 240px; max-width: 360px; padding: 12px 14px; border-radius: 13px; background: #0f1d32; border: 1px solid var(--line); box-shadow: var(--shadow); transition: .2s; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { border-color: rgba(244, 63, 94, .3); color: #fecdd3; }

/* Profile */
.profile-body { min-height: 100%; padding: 24px; }
.profile-shell { width: min(920px, 100%); margin: auto; }
.profile-nav { display: flex; justify-content: space-between; color: #bae6fd; margin-bottom: 14px; font-weight: 700; }
.profile-card { overflow: hidden; border: 1px solid var(--line); border-radius: 27px; background: rgba(8, 18, 35, .9); box-shadow: var(--shadow); }
.profile-cover { height: 170px; background: radial-gradient(circle at 30% 20%, rgba(34, 211, 238, .7), transparent 30%), linear-gradient(135deg, #075985, #1d4ed8 55%, #6d28d9); }
.profile-form { padding: 0 42px 42px; }
.avatar-editor { width: 130px; margin-top: -68px; position: relative; cursor: pointer; }
.avatar-editor img { width: 130px; height: 130px; object-fit: cover; border-radius: 35px; border: 6px solid #081225; box-shadow: 0 16px 36px rgba(0, 0, 0, .28); }
.avatar-editor span { position: absolute; left: 11px; right: 11px; bottom: 7px; text-align: center; padding: 6px; border-radius: 10px; background: rgba(0, 0, 0, .7); font-size: 10px; }
.avatar-editor input { display: none; }
.profile-title { margin: -56px 0 28px 160px; min-height: 80px; }
.profile-title h1 { margin: 9px 0 1px; font-size: 30px; letter-spacing: -.03em; }
.profile-title p { color: var(--muted); margin: 0; }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 22px; }
.profile-grid .full { grid-column: 1 / -1; }
.mobile-only { display: none; }
.mobile-backdrop { display: none; }

@media (max-width: 1150px) {
    .chat-app { grid-template-columns: 320px minmax(370px, 1fr); }
    .details-panel { display: none; }
    .search-results { width: calc(320px - 36px); }
}

@media (max-width: 780px) {
    .auth-body { padding: 14px; }
    .auth-shell { grid-template-columns: 1fr; border-radius: 23px; }
    .auth-brand { display: none; }
    .auth-card { padding: 28px 20px; }
    .chat-app { display: block; }
    .sidebar {
        position: fixed; inset: 0 auto 0 0; width: min(345px, 88vw); transform: translateX(-104%);
        transition: transform .22s ease; box-shadow: var(--shadow);
    }
    .sidebar.mobile-open { transform: translateX(0); }
    .mobile-backdrop { position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, .58); }
    .mobile-backdrop.show { display: block; }
    .search-results { position: fixed; left: 12px; top: 132px; width: min(321px, calc(88vw - 24px)); }
    .chat-main { height: 100vh; grid-template-rows: 66px 1fr auto; }
    .mobile-only { display: grid; }
    .chat-header { padding: 9px 12px; }
    .chat-target { flex: 1; }
    .welcome-grid { grid-template-columns: 1fr; }
    .welcome-screen { align-self: start; margin-top: 12vh; }
    .welcome-grid article:nth-child(n+3) { display: none; }
    .messages { padding: 18px 12px; }
    .message-wrap { max-width: 84%; }
    .composer { padding: 9px 10px 12px; }
    .profile-body { padding: 12px; }
    .profile-cover { height: 130px; }
    .profile-form { padding: 0 18px 28px; }
    .avatar-editor { width: 104px; margin-top: -54px; }
    .avatar-editor img { width: 104px; height: 104px; border-radius: 28px; }
    .profile-title { margin: 14px 0 24px; }
    .profile-grid { grid-template-columns: 1fr; }
    .profile-grid .full { grid-column: auto; }
}

@media (max-width: 430px) {
    .inline-actions { flex-direction: column; }
    .contact-item { padding: 9px 7px; }
    .avatar-wrap img { width: 43px; height: 43px; }
    .toast-stack { left: 12px; right: 12px; }
    .toast { min-width: 0; max-width: none; }
}
