* {
    box-sizing: border-box;
}

html, body {
    width: 100%;
    min-height: 100%;
    margin: 0;
}

body {
    background: #e9ebee;
    color: #222;
    font-family: Arial, sans-serif;
}

.chat-container {
    width: min(540px, 100%);
    height: 90vh;
    height: 90dvh;
    margin: 5vh auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, .1);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    flex: 0 0 auto;
    color: #fff;
    /* background: #0078ff; */
    background: #3a3a3a;
}

.avatar {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    flex: 0 0 40px;
    border-radius: 50%;
    /* background: rgba(255, 255, 255, .2); */
    background: url("https://images.squarespace-cdn.com/content/v1/61480acb81244072fb6f9c86/1c32e203-9c35-4c13-91bb-3ca48984d0ca/favicon.ico?format=100w");
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;

    font-size: 20px;
    font-weight: bold;
}

.username {
    font-size: 17px;
    font-weight: bold;
}

.status {
    margin-top: 3px;
    color: rgba(255, 255, 255, .85);
    font-size: 12px;
}

.clear-form {
    margin-left: auto;
}

.clear-button {
    padding: 7px 11px;
    border: 1px solid rgba(255, 255, 255, .65);
    border-radius: 16px;
    color: white;
    background: transparent;
    cursor: pointer;
}

.chat-box {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px;
    background: #f2f2f2;
}

.message-row {
    display: flex;
    width: 100%;
    margin-bottom: 12px;
}

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

.message-row.incoming {
    justify-content: flex-start;
}

.message {
    width: fit-content;
    max-width: min(82%, 440px);
    padding: 10px 15px;
    border-radius: 15px;
    font-size: 15px;
    line-height: 1.45;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.received {
    color: #333;
    background: #fff;
    border-bottom-left-radius: 3px;
}

.sent {
    color: #fff;
    /* background: #0078ff; */
    background: #ef3043;
    border-bottom-right-radius: 3px;
}

.empty-state {
    margin: 20px auto;
    color: #777;
    text-align: center;
    font-size: 14px;
}

.chat-input {
    display: flex;
    gap: 10px;
    flex: 0 0 auto;
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid #ddd;
}

.chat-input input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 22px;
    outline: none;
    font: inherit;
    font-size: 16px;
}

.chat-input input:focus {
    /* border-color: #0078ff; */
    border-color: #ef3043;
}

.chat-input button {
    flex: 0 0 auto;
    padding: 10px 19px;
    border: 0;
    border-radius: 22px;
    color: white;
    /* background: #0078ff; */
    background: #ef3043;
    font-size: 15px;
    cursor: pointer;
}

.chat-input button:hover {
    /* background: #005fcc; */
    background: #DB1125;
}

.chat-input button:disabled {
    opacity: .65;
    cursor: wait;
}

@media (max-width: 600px) {
    body {
        background: white;
    }

    .chat-container {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        margin: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .chat-box {
        padding: 12px;
    }

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