:root {
    --blue: #1668ff;
    --blue-2: #00a3ff;
    --bg: #f3f8ff;
    --panel: #ffffff;
    --panel-2: #eef6ff;
    --text: #152238;
    --muted: #6d7b91;
    --line: #dce8f7;
    --success: #16a34a;
    --danger: #ef4444;
    --shadow: 0 20px 50px rgba(25, 90, 180, .12);
    --radius: 24px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: radial-gradient(circle at top left, #dff0ff 0, transparent 34%), linear-gradient(135deg, #f7fbff 0%, #eef7ff 100%);
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }

.app-shell {
    display: grid;
    grid-template-columns: 290px minmax(0, 1fr);
    min-height: 100vh;
    padding: 18px;
    gap: 18px;
}

.sidebar {
    background: rgba(255,255,255,.9);
    backdrop-filter: blur(18px);
    border: 1px solid rgba(220,232,247,.9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    position: sticky;
    top: 18px;
    height: calc(100vh - 36px);
    overflow-y: auto;
}

.main-content {
    min-width: 0;
    background: rgba(255,255,255,.78);
    border: 1px solid rgba(220,232,247,.9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}
.brand-mark {
    width: 48px; height: 48px;
    display: grid; place-items: center;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--blue), var(--blue-2));
    color: white;
    font-weight: 900;
    box-shadow: 0 12px 28px rgba(22,104,255,.28);
}
.brand small, .me-info small { display: block; color: var(--muted); margin-top: 2px; }
.me-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: linear-gradient(135deg, #eef7ff, #fff);
    border: 1px solid var(--line);
    border-radius: 22px;
    margin-bottom: 16px;
}
.me-info { min-width: 0; }
.me-info strong, .me-info small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 170px; }

.nav-menu { display: grid; gap: 8px; }
.nav-menu a {
    padding: 13px 14px;
    border-radius: 16px;
    color: #263a58;
    font-weight: 700;
    transition: .18s ease;
}
.nav-menu a:hover, .nav-menu a.active {
    background: #eaf4ff;
    color: var(--blue);
}
.nav-menu .logout-link { color: var(--danger); }

.page { padding: 26px; }
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}
.page-title h1 { margin: 0; font-size: clamp(24px, 3vw, 34px); letter-spacing: -.03em; }
.page-title p { margin: 7px 0 0; color: var(--muted); }

.grid-2 {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    gap: 18px;
    min-height: calc(100vh - 88px);
}
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: 0 10px 28px rgba(25, 90, 180, .06);
}
.panel-pad { padding: 18px; }
.list { display: grid; gap: 10px; }
.user-row, .group-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid transparent;
    border-radius: 18px;
    transition: .18s ease;
}
.user-row:hover, .group-row:hover, .user-row.active, .group-row.active {
    background: #f0f7ff;
    border-color: #d7eaff;
}
.row-main { min-width: 0; flex: 1; }
.row-main strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main small { color: var(--muted); display: block; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { color: var(--muted); font-size: 12px; }

.avatar {
    flex: none;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: white;
    background: linear-gradient(135deg, #1f7cff, #38bdf8);
    font-weight: 900;
    object-fit: cover;
    border: 3px solid white;
    box-shadow: 0 6px 16px rgba(22,104,255,.20);
}
.avatar-sm { width: 36px; height: 36px; font-size: 13px; }
.avatar-md { width: 48px; height: 48px; font-size: 15px; }
.avatar-lg { width: 74px; height: 74px; font-size: 25px; }
.group-avatar {
    width: 48px; height: 48px;
    flex: none;
    border-radius: 18px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #2dd4bf, #2563eb);
    color: #fff;
    font-weight: 900;
    border: 3px solid #fff;
}

.form-card {
    max-width: 460px;
    margin: 8vh auto;
    padding: 28px;
    background: rgba(255,255,255,.92);
    border: 1px solid var(--line);
    border-radius: 28px;
    box-shadow: var(--shadow);
}
.form-card h1 { margin: 0 0 8px; font-size: 30px; }
.form-card p { color: var(--muted); margin-top: 0; }
.form-grid { display: grid; gap: 13px; }
.field label { display: block; margin-bottom: 7px; font-weight: 800; font-size: 14px; }
.input, .textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 13px 14px;
    background: #fbfdff;
    color: var(--text);
    outline: none;
    transition: .18s ease;
}
.textarea { min-height: 96px; resize: vertical; }
.input:focus, .textarea:focus {
    border-color: #7db7ff;
    box-shadow: 0 0 0 4px rgba(22,104,255,.10);
}
.btn {
    border: 0;
    border-radius: 16px;
    padding: 13px 16px;
    background: linear-gradient(135deg, var(--blue), var(--blue-2));
    color: white;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 12px 26px rgba(22,104,255,.22);
    transition: .18s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn:hover { transform: translateY(-1px); }
.btn.secondary { background: #eaf4ff; color: var(--blue); box-shadow: none; }
.btn.danger { background: var(--danger); }
.btn.full { width: 100%; }
.alert {
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid;
    margin-bottom: 14px;
}
.alert.error { background: #fff1f2; border-color: #fecdd3; color: #be123c; }
.alert.success { background: #ecfdf5; border-color: #bbf7d0; color: #047857; }

.chat-wrap {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: calc(100vh - 36px);
}
.chat-top {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,.86);
}
.chat-top .title { min-width: 0; flex: 1; }
.chat-top .title strong { display: block; font-size: 18px; }
.chat-top .title small { color: var(--muted); }
.messages {
    padding: 20px;
    overflow-y: auto;
    background:
        radial-gradient(circle at top right, rgba(0,163,255,.10), transparent 28%),
        linear-gradient(180deg, #f7fbff, #eef7ff);
}
.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 60px 20px;
}
.msg {
    display: flex;
    gap: 9px;
    margin-bottom: 12px;
    align-items: flex-end;
}
.msg.me { justify-content: flex-end; }
.bubble {
    max-width: min(68%, 680px);
    padding: 11px 13px;
    border-radius: 20px;
    background: white;
    border: 1px solid #e7eef8;
    box-shadow: 0 6px 16px rgba(25,90,180,.06);
    line-height: 1.45;
    word-break: break-word;
}
.msg.me .bubble {
    background: linear-gradient(135deg, var(--blue), var(--blue-2));
    color: white;
    border: 0;
}
.bubble small { display: block; margin-top: 6px; font-size: 11px; opacity: .72; }
.sender-name { display: block; color: var(--blue); font-weight: 900; font-size: 12px; margin-bottom: 4px; }
.chat-form {
    display: flex;
    gap: 10px;
    padding: 14px;
    background: white;
    border-top: 1px solid var(--line);
}
.chat-form textarea {
    flex: 1;
    min-height: 48px;
    max-height: 130px;
    resize: none;
}

.searchbar { display: flex; gap: 10px; margin-bottom: 14px; }
.searchbar .input { flex: 1; }
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border-radius: 999px;
    background: #edf7ff;
    color: var(--blue);
    font-size: 12px;
    font-weight: 900;
}
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 14px;
}
.person-card {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: white;
    box-shadow: 0 10px 24px rgba(25,90,180,.06);
}
.person-card .top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.person-card p { color: var(--muted); min-height: 38px; }
.person-card .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.profile-head {
    display: flex;
    gap: 18px;
    align-items: center;
    padding: 22px;
    background: linear-gradient(135deg, #eef7ff, #fff);
    border-radius: 24px;
    border: 1px solid var(--line);
    margin-bottom: 18px;
}
.muted { color: var(--muted); }
.mt { margin-top: 14px; }

@media (max-width: 960px) {
    .app-shell { grid-template-columns: 1fr; padding: 10px; }
    .sidebar { position: static; height: auto; border-radius: 22px; }
    .main-content { border-radius: 22px; }
    .grid-2 { grid-template-columns: 1fr; min-height: auto; }
    .chat-wrap { height: 76vh; }
}
@media (max-width: 640px) {
    .page { padding: 18px; }
    .page-header { align-items: flex-start; flex-direction: column; }
    .bubble { max-width: 86%; }
    .chat-form { align-items: end; }
    .chat-form .btn { padding-inline: 12px; }
    .searchbar { flex-direction: column; }
}
