/* iMessage Style Live Chat CSS */
.chat-page-fullwidth {
    width: 100%;
    min-height: calc(100vh - 200px);
    display: flex;
    justify-content: center;
    padding: 20px 16px;
    background: var(--background);
    box-sizing: border-box;
}

.chat-shell {
    width: 100%;
    max-width: 720px;
    background: var(--surface-container-lowest);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 300px);
    min-height: 480px;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    position: relative;
    border: 1px solid var(--border-light);
}

.chat-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    background: linear-gradient(160deg, #eef1f5 0%, #f7f9fc 100%);
}

.chat-container {
    width: 100%;
    max-width: 500px;
    background: #fff;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 32px);
    max-height: 840px;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    position: relative;
    border: 1px solid rgba(0,0,0,0.06);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: #fff;
    border-bottom: 1px solid #eef0f3;
    position: relative;
    z-index: 5;
}

.chat-back-btn {
    background: #f1f3f5;
    border: none;
    font-size: 18px;
    color: #111;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-back-btn:hover {
    background: #e2e5e8;
}

.chat-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    flex-shrink: 0;
    border: 1px solid var(--border-light);
}

.chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-header-info {
    flex: 1;
}

.chat-header-name {
    font-weight: 700;
    font-size: 16px;
    color: #111;
}

.chat-header-sub {
    font-size: 12px;
    color: #34c759;
    font-weight: 500;
}

/* Watermark logo in chat body */
.chat-watermark {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.12;
    pointer-events: none;
    z-index: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    max-width: 70%;
}

.chat-watermark img {
    max-height: 100px;
    max-width: 240px;
    object-fit: contain;
    filter: grayscale(100%);
}

.chat-watermark-text {
    font-weight: 700;
    font-size: 16px;
    color: #163328;
    text-align: center;
    letter-spacing: 1px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    z-index: 1;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 10px; }

.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 85%;
}

.msg-row.sent { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.received { align-self: flex-start; }

.msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.msg-avatar.admin {
    background: #fff;
    border: 1px solid var(--border-light);
}
.msg-avatar.admin img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.msg-avatar.user {
    background: #8e8e93;
}
.msg-avatar.user svg {
    width: 15px;
    height: 15px;
}

.msg-bubble-wrap {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.msg-row.sent .msg-bubble-wrap { align-items: flex-end; }
.msg-row.received .msg-bubble-wrap { align-items: flex-start; }

.message {
    padding: 10px 15px;
    font-size: 15px;
    line-height: 1.45;
    word-wrap: break-word;
}

/* Sent: solid blue, right, tail bottom-right */
.msg-row.sent .message {
    background: #007aff;
    color: #fff;
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 1px 2px rgba(0,122,255,0.3);
}

/* Received: white/light, left, tail bottom-left, visible border */
.msg-row.received .message {
    background: #e9eaec;
    color: #111;
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.msg-time {
    font-size: 10px;
    color: rgba(0,0,0,0.4);
    margin-top: 3px;
    padding: 0 4px;
}
.msg-row.sent .msg-time { align-self: flex-end; }

.chat-input-area {
    padding: 12px 14px;
    border-top: 1px solid #eef0f3;
    background: #fff;
    display: flex;
    gap: 10px;
    align-items: center;
    position: relative;
    z-index: 5;
}

.chat-input {
    flex: 1;
    padding: 12px 18px;
    border: none;
    border-radius: 24px;
    outline: none;
    font-size: 15px;
    background: #f1f3f5;
    transition: background 0.2s;
}
.chat-input:focus { background: #e8eaed; }

.chat-send-btn {
    background: #007aff;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s, background 0.2s;
    flex-shrink: 0;
}
.chat-send-btn:hover { background: #0056b3; transform: scale(1.05); }
.chat-send-btn:active { transform: scale(0.95); }

/* Mobile */
@media (max-width: 768px) {
    .chat-page-fullwidth { padding: 0; }
    .chat-shell { height: calc(100vh - 130px); border-radius: 14px; }
}
@media (max-width: 520px) {
    .chat-page { padding: 0; }
    .chat-shell { max-width: 100%; border-radius: 0; border: none; box-shadow: none; height: calc(100vh - 110px); }
    .chat-container { max-width: 100%; height: 100vh; max-height: 100vh; border-radius: 0; box-shadow: none; border: none; }
}
