@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600;700&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

:root {
    --bg: #f6f8fb;
    --card: #ffffff;
    --ink: #12303a;
    --muted: #5d7282;
    --line: #d9e4ec;
    --accent: #0e9f8f;
    --accent-dark: #0b7669;
    --bubble-me: #d8f8ec;
    --bubble-other: #ffffff;
    --alert: #b3373e;
    --shadow: 0 20px 45px rgba(17, 54, 74, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'IBM Plex Sans', sans-serif;
    color: var(--ink);
    background: radial-gradient(circle at 10% 10%, #e9f5ff, transparent 42%),
    radial-gradient(circle at 88% 80%, #dff5ea, transparent 36%),
    var(--bg);
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

.shell {
    min-height: 100vh;
}

.muted {
    color: var(--muted);
}

.auth-view {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.auth-card {
    width: min(500px, 100%);
    background: var(--card);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 1.4rem;
    border: 1px solid var(--line);
}

.auth-card h1 {
    margin: 0;
    font-family: 'Space Grotesk', sans-serif;
    letter-spacing: 0.01em;
}

.auth-tabs {
    margin-top: 0.8rem;
    display: flex;
    gap: 0.4rem;
}

.tab-btn {
    flex: 1;
    border: 1px solid var(--line);
    background: #f1f5f8;
    color: var(--muted);
    border-radius: 10px;
    padding: 0.6rem;
    font-weight: 600;
    cursor: pointer;
}

.tab-btn.active {
    background: #d8fff7;
    color: var(--accent-dark);
    border-color: #99e7db;
}

.auth-form {
    display: none;
    margin-top: 0.8rem;
}

.auth-form.active {
    display: block;
}

.auth-form label {
    display: block;
    margin-bottom: 0.6rem;
    font-size: 0.93rem;
}

.auth-form input {
    width: 100%;
    margin-top: 0.25rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.6rem 0.7rem;
    font: inherit;
}

.auth-form button,
.send-btn,
.ghost-btn,
.icon-btn,
.file-btn {
    font: inherit;
}

.auth-form button,
.send-btn {
    border: 0;
    background: linear-gradient(145deg, var(--accent), #0ab6a2);
    color: #fff;
    border-radius: 11px;
    padding: 0.58rem 0.92rem;
    font-weight: 600;
    cursor: pointer;
}

.message {
    min-height: 1.4rem;
    margin: 0.5rem 0 0;
    color: var(--alert);
}

.chat-view {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    border-right: 1px solid var(--line);
    background: linear-gradient(180deg, #f8fcff, #f3f8fb);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sidebar-header {
    padding: 0.9rem;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
}

.profile {
    display: flex;
    gap: 0.6rem;
    align-items: center;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    background: #dfebf2;
}

.ghost-btn {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    padding: 0.45rem 0.7rem;
    cursor: pointer;
}

.sidebar-actions {
    padding: 0.8rem;
    border-bottom: 1px solid var(--line);
}

.sidebar-actions-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.42rem;
}

.sidebar-actions input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.58rem 0.67rem;
}

.search-results {
    max-height: 220px;
    overflow: auto;
    border-bottom: 1px solid var(--line);
}

.search-item {
    border: 0;
    background: transparent;
    width: 100%;
    text-align: left;
    padding: 0.62rem 0.8rem;
    cursor: pointer;
}

.search-item:hover {
    background: #ecf8f4;
}

.search-item-row {
    padding: 0.58rem 0.75rem;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.5rem;
    border-top: 1px solid rgba(217, 228, 236, 0.55);
}

.search-main {
    min-width: 0;
}

.search-title {
    font-weight: 600;
    font-size: 0.9rem;
}

.search-sub {
    color: var(--muted);
    font-size: 0.76rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-actions {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.mini-btn {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    padding: 0.25rem 0.5rem;
    font-size: 0.74rem;
    cursor: pointer;
}

.mini-btn.accept {
    border-color: #7ad2c3;
    background: #ebfffb;
    color: #0f6f62;
}

.mini-btn.reject,
.mini-btn.cancel {
    border-color: #e6c0c5;
    background: #fff6f7;
    color: #a63a45;
}

.mini-note {
    color: var(--muted);
    font-size: 0.76rem;
}

.friend-requests-panel {
    max-height: 180px;
    overflow: auto;
    border-bottom: 1px solid var(--line);
}

.request-heading {
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--muted);
    padding: 0.45rem 0.78rem 0.25rem;
}

.request-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.45rem;
    padding: 0.38rem 0.72rem 0.48rem;
    border-top: 1px solid rgba(217, 228, 236, 0.55);
}

.request-body {
    min-width: 0;
}

.request-name {
    font-size: 0.84rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.request-meta {
    color: var(--muted);
    font-size: 0.73rem;
}

.request-actions {
    display: flex;
    gap: 0.2rem;
}

.pane-title {
    margin: 0;
    padding: 0.7rem 0.85rem 0.55rem;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.96rem;
}

.conversation-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 1rem;
}

.conversation-item {
    border: 0;
    background: transparent;
    width: 100%;
    text-align: left;
    padding: 0.68rem 0.8rem;
    border-top: 1px solid rgba(217, 228, 236, 0.65);
    cursor: pointer;
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 0.58rem;
    align-items: center;
}

.conversation-item.active {
    background: #e9f9f4;
}

.conversation-item .title {
    font-weight: 600;
}

.conversation-item .preview {
    color: var(--muted);
    font-size: 0.84rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item .preview.minor {
    font-size: 0.72rem;
}

.badge {
    background: var(--accent);
    color: #fff;
    border-radius: 999px;
    padding: 0.12rem 0.42rem;
    font-size: 0.76rem;
    font-weight: 600;
}

.chat-pane {
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    min-width: 0;
    height: 100vh;
    min-height: 0;
    overflow: hidden;
}

.chat-header {
    border-bottom: 1px solid var(--line);
    background: #fff;
    padding: 0.85rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-actions {
    display: flex;
    gap: 0.42rem;
}

.chat-header h2 {
    margin: 0;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.05rem;
}

.message-list {
    overflow-y: auto;
    min-height: 0;
    padding: 1rem;
    background: linear-gradient(180deg, #fbfeff, #f4f9fc);
}

.msg {
    max-width: min(78%, 540px);
    margin-bottom: 0.7rem;
    border-radius: 14px;
    border: 1px solid var(--line);
    padding: 0.58rem 0.7rem;
    box-shadow: 0 8px 15px rgba(24, 65, 89, 0.04);
}

.msg.me {
    margin-left: auto;
    background: var(--bubble-me);
}

.msg.other {
    margin-right: auto;
    background: var(--bubble-other);
}

.msg .meta {
    margin-top: 0.4rem;
    display: flex;
    gap: 0.45rem;
    justify-content: flex-end;
    font-size: 0.73rem;
    color: var(--muted);
}

.msg-sender {
    font-size: 0.73rem;
    font-weight: 600;
    color: #215366;
    margin-bottom: 0.18rem;
}

.msg img.msg-image {
    display: block;
    width: min(270px, 100%);
    border-radius: 10px;
    margin-bottom: 0.45rem;
}

.msg-file {
    display: inline-flex;
    gap: 0.36rem;
    align-items: center;
    border: 1px dashed #a9c7d6;
    border-radius: 10px;
    padding: 0.45rem 0.5rem;
    background: #f9fdff;
    color: #154253;
    text-decoration: none;
}

.typing-indicator {
    min-height: 1.2rem;
    color: var(--muted);
    padding: 0 1rem 0.4rem;
    font-size: 0.86rem;
}

.composer {
    border-top: 1px solid var(--line);
    background: #fff;
    padding: 0.56rem 0.75rem 0.7rem;
}

.composer-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 0.5rem;
    align-items: end;
}

.composer-row textarea {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 0.56rem 0.88rem;
    font: inherit;
    min-height: 36px;
    max-height: 160px;
    overflow-y: hidden;
    resize: none;
    line-height: 1.35;
}

.icon-btn,
.file-btn {
    min-width: 44px;
    height: 36px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.6rem;
    cursor: pointer;
}

.emoji-panel {
    margin-top: 0;
    margin-bottom: 0.5rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fafeff;
    padding: 0.45rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    max-height: 200px;
    overflow-y: auto;
}

.emoji-btn {
    border: 0;
    background: transparent;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 7px;
}

.emoji-btn:hover {
    background: #ebf7ff;
}

.attachment-preview {
    margin-top: 0.45rem;
    font-size: 0.85rem;
    color: var(--muted);
}

.attachment-preview strong {
    color: var(--ink);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 24, 33, 0.45);
    display: grid;
    place-items: center;
    z-index: 40;
    padding: 1rem;
}

.modal-card {
    width: min(520px, 100%);
    background: #fff;
    border-radius: 16px;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    padding: 1rem;
}

.modal-card h3 {
    margin: 0 0 0.8rem;
    font-family: 'Space Grotesk', sans-serif;
}

.modal-card label {
    display: block;
    font-size: 0.9rem;
}

.modal-card input[type="text"] {
    width: 100%;
    margin-top: 0.3rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55rem 0.65rem;
    font: inherit;
}

.modal-subtitle {
    margin-top: 0.8rem;
    margin-bottom: 0.4rem;
    color: var(--muted);
    font-size: 0.83rem;
}

.group-friend-list {
    border: 1px solid var(--line);
    border-radius: 12px;
    max-height: 200px;
    overflow: auto;
    padding: 0.2rem 0;
}

.group-friend-item {
    display: grid;
    grid-template-columns: auto 34px minmax(0, 1fr);
    align-items: center;
    gap: 0.42rem;
    padding: 0.42rem 0.58rem;
    border-top: 1px solid rgba(217, 228, 236, 0.55);
    font-size: 0.88rem;
}

.group-friend-item:first-child {
    border-top: 0;
}

.modal-actions {
    margin-top: 0.9rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.42rem;
}

@media (max-width: 920px) {
    .chat-view {
        grid-template-columns: 280px minmax(0, 1fr);
    }
}

@media (max-width: 760px) {
    .chat-view {
        grid-template-columns: 1fr;
        position: relative;
    }

    .sidebar {
        min-height: 100vh;
    }

    .chat-pane {
        position: fixed;
        inset: 0;
        background: #fff;
        transform: translateX(100%);
        transition: transform 220ms ease;
        z-index: 20;
    }

    .chat-pane.open {
        transform: translateX(0);
    }

    .chat-header.empty-state {
        display: none;
    }
}
