@import url('https://fonts.googleapis.com/css2?family=M+PLUS+1p:wght@400;700&display=swap');

html, body {
    height: 100%;
}

body {
    font-family: 'M PLUS 1p', sans-serif;
    background-color: #1a1a1a;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100%;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
}

.smartphone {
    position: relative;
    width: 390px;
    height: 844px;
    background-color: #111;
    border-radius: 50px;
    border: 10px solid #000;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.notch {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 30px;
    background-color: #000;
    border-radius: 20px;
    z-index: 2;
}

.screen {
    width: 100%;
    height: 100%;
    background-color: #8ab6c9;
    display: flex;
    flex-direction: column;
    position: relative; /* Context for the absolute footer */
}

.chat-header {
    background-color: #333a42;
    color: white;
    padding: 20px 15px 10px 15px;
    text-align: center;
    flex-shrink: 0;
    padding-top: 50px;
    z-index: 1;
}

.contact-name {
    font-weight: bold;
    font-size: 1.1em;
}

.chat-log {
    flex-grow: 1;
    min-height: 0;
    padding: 20px 10px 80px 10px; /* Increased bottom padding for footer */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.chat-log::-webkit-scrollbar {
    width: 3px;
}
.chat-log::-webkit-scrollbar-track {
    background: transparent;
}
.chat-log::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.message-container {
    display: flex;
    align-items: flex-end; /* Align avatar with bottom of content */
    gap: 10px;
    animation: fadeIn 0.5s forwards;
    opacity: 0;
    transform: translateY(20px);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
}

.message-content {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: calc(100% - 50px); 
}

.message-bubble {
    background-color: white;
    color: #333;
    padding: 10px 15px;
    border-radius: 20px;
    line-height: 1.5;
    word-wrap: break-word;
    flex-shrink: 1;
}

.meta-info {
    display: flex;
    flex-direction: column; /* Stack Read and Time */
    align-items: flex-end; /* Align text to the right */
    flex-shrink: 0;
    margin-bottom: 5px;
}

.read-status {
    font-size: 0.75em;
    color: #888;
}

.timestamp {
    font-size: 0.75em;
    color: #888;
    white-space: nowrap;
}

@keyframes fadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #f7f7f7;
    padding: 10px;
    border-top: 1px solid #e0e0e0;
    z-index: 2;
}

#scrollToBottomButton {
    position: absolute;
    bottom: 80px;
    right: 20px;
    width: 40px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.4);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 3;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

#scrollToBottomButton.visible {
    opacity: 1;
    visibility: visible;
}


.home-indicator {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 140px;
    height: 5px;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 5px;
}

@media (max-width: 1300px) {
    body {
        padding: 0;
    }
    .smartphone {
        width: 100%;
        height: var(--app-height, 100%);
        border-radius: 0;
        border: none;
    }
    .notch {
        display: none;
    }
    .chat-header {
        padding-top: calc(10px + env(safe-area-inset-top));
    }
    #status-time,
    .status-icons {
        display: none;
    }
}

/* Visitor message styles */
.message-container.visitor {
    justify-content: flex-end;
}
.message-container.visitor .message-content {
    flex-direction: row-reverse; /* Puts meta on the left of bubble */
}
.message-container.visitor .avatar {
    display: none;
}
.message-bubble.visitor {
    background-color: #c9eec9;
}

/* Input Form Styles */
.input-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

#message-input {
    flex-grow: 1;
    min-width: 0;
    border: 1px solid #ccc;
    border-radius: 20px;
    padding: 8px 15px;
    font-size: 1em;
    font-family: 'M PLUS 1p', sans-serif;
}

#message-input:focus {
    outline: none;
    border-color: #8ab6c9;
}

/* Status Bar Styles */
.status-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 44px;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    z-index: 3;
}

#status-time {
    font-weight: bold;
    font-size: 0.9em;
    padding-left: 10px;
}

.status-icons {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-icons svg {
    width: 18px;
    height: 18px;
    fill: white;
}

/* Final Send Button Styles */
.input-form button {
    background-color: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.icon-send {
    width: 28px;
    height: 28px;
    fill: #007bff;
    transition: fill 0.2s;
}

.input-form button:hover .icon-send {
    fill: #0056b3;
}
