* {
    box-sizing: border-box;
}

:root {
    --bg: #eef3f8;
    --panel: #ffffff;
    --text: #17212b;
    --muted: #758392;
    --line: #dfe7ef;
    --primary: #3390ec;
    --primary-dark: #277dcc;
    --bubble: #e8f5ff;
    --sidebar: #ffffff;
    --danger-bg: #fff0f0;
    --danger: #b42318;
}

html, body {
    margin: 0;
    min-height: 100%;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

a {
    color: var(--primary);
    text-decoration: none;
}

button, input {
    font: inherit;
}

.hidden {
    display: none !important;
}

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

.small {
    font-size: 13px;
}

.brand {
    color: var(--primary);
    font-size: 30px;
    font-weight: 800;
    letter-spacing: -1px;
}

.brand-small {
    font-size: 22px;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(100%, 430px);
    background: var(--panel);
    border-radius: 18px;
    padding: 32px;
    box-shadow: 0 16px 50px rgba(23, 33, 43, 0.12);
}

.auth-card h1 {
    margin: 14px 0 6px;
}

.auth-card form {
    display: grid;
    gap: 16px;
    margin-top: 24px;
}

.auth-card label {
    display: grid;
    gap: 7px;
    font-weight: 600;
    font-size: 14px;
}

.auth-card input,
.search-box input,
.message-form input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    outline: none;
    background: #fff;
}

.auth-card input:focus,
.search-box input:focus,
.message-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(51, 144, 236, 0.13);
}

.primary-button {
    border: 0;
    border-radius: 12px;
    padding: 13px 16px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.primary-button:hover {
    background: var(--primary-dark);
}

.auth-link {
    text-align: center;
    margin: 22px 0 0;
}

.alert {
    margin-top: 18px;
    border-radius: 10px;
    padding: 12px 14px;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
}

.app-shell {
    height: 100vh;
    display: grid;
    grid-template-columns: 360px 1fr;
    max-width: 1500px;
    margin: 0 auto;
    background: var(--panel);
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.08);
}

.sidebar {
    min-width: 0;
    border-right: 1px solid var(--line);
    background: var(--sidebar);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    min-height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
}

.logout-link {
    font-size: 14px;
}

.search-box {
    position: relative;
    padding: 14px;
}

.search-results {
    position: absolute;
    z-index: 20;
    left: 14px;
    right: 14px;
    top: 62px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(23, 33, 43, 0.14);
}

.search-user {
    width: 100%;
    border: 0;
    background: #fff;
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 11px 12px;
    cursor: pointer;
    text-align: left;
}

.search-user:hover {
    background: #f4f8fb;
}

.search-user span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 3px;
}

.search-empty,
.sidebar-empty {
    color: var(--muted);
    padding: 14px;
    font-size: 14px;
}

.section-title {
    padding: 2px 18px 10px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.chat-list {
    overflow-y: auto;
    flex: 1;
}

.chat-item {
    width: 100%;
    border: 0;
    background: transparent;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    text-align: left;
    cursor: pointer;
}

.chat-item:hover,
.chat-item.active {
    background: #edf6fd;
}

.avatar {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: linear-gradient(145deg, #58aef3, #2f8ad5);
    color: #fff;
    font-size: 18px;
    font-weight: 800;
}

.chat-item-body {
    min-width: 0;
    flex: 1;
}

.chat-item-top {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.chat-item-top span {
    color: var(--muted);
    font-size: 12px;
}

.chat-preview {
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 4px;
}

.conversation {
    min-width: 0;
    background:
        linear-gradient(rgba(240, 246, 251, .92), rgba(240, 246, 251, .92)),
        radial-gradient(circle at 20% 20%, #d9ecfa 0 2px, transparent 3px);
    background-size: auto, 34px 34px;
}

.empty-state {
    height: 100%;
    display: grid;
    place-content: center;
    text-align: center;
    color: var(--muted);
}

.empty-state h2 {
    color: var(--text);
    margin: 10px 0 4px;
}

.empty-state p {
    margin: 0;
}

.empty-icon {
    font-size: 52px;
}

.chat-panel {
    height: 100%;
    display: grid;
    grid-template-rows: 76px 1fr 76px;
}

.chat-header {
    background: rgba(255, 255, 255, .97);
    display: flex;
    align-items: center;
    padding: 12px 22px;
    border-bottom: 1px solid var(--line);
}

.chat-header h2 {
    margin: 0 0 3px;
    font-size: 18px;
}

.messages {
    overflow-y: auto;
    padding: 22px clamp(14px, 5vw, 70px);
}

.message-row {
    display: flex;
    margin: 7px 0;
}

.message-row.mine {
    justify-content: flex-end;
}

.message-bubble {
    max-width: min(72%, 680px);
    padding: 9px 12px 6px;
    border-radius: 15px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(23, 33, 43, .08);
}

.message-row.mine .message-bubble {
    background: var(--bubble);
    border-bottom-right-radius: 5px;
}

.message-row.theirs .message-bubble {
    border-bottom-left-radius: 5px;
}

.message-text {
    word-break: break-word;
    line-height: 1.4;
}

.message-time {
    text-align: right;
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}

.message-form {
    display: grid;
    grid-template-columns: 1fr 52px;
    gap: 10px;
    padding: 12px 18px;
    background: rgba(255, 255, 255, .97);
    border-top: 1px solid var(--line);
}

.message-form button {
    border: 0;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 21px;
    cursor: pointer;
}

.message-form button:hover {
    background: var(--primary-dark);
}

@media (max-width: 800px) {
    .app-shell {
        grid-template-columns: 130px 1fr;
    }

    .sidebar-header .small,
    .logout-link,
    .section-title,
    .chat-item-body,
    .search-box {
        display: none;
    }

    .sidebar-header {
        justify-content: center;
        padding: 10px;
    }

    .brand-small {
        font-size: 16px;
    }

    .chat-item {
        justify-content: center;
    }

    .message-bubble {
        max-width: 88%;
    }
}
