/*
 * style.css
 * 用途：移动端优先的聊天界面，视觉参考 WhatsApp：
 * 顶部绿色栏、底部固定输入栏、左右消息气泡、浅色聊天背景。
 */

:root {
    --green: #008069;
    --green-dark: #075e54;
    --bubble-mine: #d9fdd3;
    --bubble-theirs: #ffffff;
    --page-bg: #d1d7db;
    --chat-bg: #efeae2;
    --text: #111b21;
    --muted: #667781;
    --line: rgba(17, 27, 33, 0.12);
    --danger: #b42318;
}

* {
    box-sizing: border-box;
}

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

body {
    color: var(--text);
    background: var(--page-bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.chat-body {
    overflow: hidden;
}

.chat-shell {
    width: 100%;
    max-width: 820px;
    height: 100dvh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
}

.chat-header {
    min-height: 58px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    color: #ffffff;
    background: var(--green);
    box-shadow: 0 1px 2px rgba(17, 27, 33, 0.16);
    z-index: 2;
}

.chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: var(--green-dark);
    background: #dfeee9;
    font-weight: 700;
}

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

.chat-heading h1,
.chat-heading p {
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-heading h1 {
    font-size: 17px;
    line-height: 1.2;
    font-weight: 650;
}

.chat-heading p {
    margin-top: 2px;
    font-size: 12px;
    opacity: 0.86;
}

.logout-link {
    min-height: 34px;
    padding: 7px 10px;
    border-radius: 6px;
    color: #ffffff;
    text-decoration: none;
    font-size: 14px;
}

.logout-link:active,
.logout-link:hover {
    background: rgba(255, 255, 255, 0.14);
}

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 10px 14px;
    background-color: var(--chat-bg);
}

.message {
    width: 100%;
    display: flex;
}

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

.message.theirs {
    justify-content: flex-start;
}

.bubble {
    max-width: min(78%, 560px);
    padding: 6px 8px 5px;
    border-radius: 8px;
    box-shadow: 0 1px 0.5px rgba(17, 27, 33, 0.18);
    overflow: hidden;
}

.mine .bubble {
    background: var(--bubble-mine);
    border-top-right-radius: 2px;
}

.theirs .bubble {
    background: var(--bubble-theirs);
    border-top-left-radius: 2px;
}

.sender-name {
    margin: 0 0 3px;
    color: var(--green);
    font-size: 12px;
    font-weight: 700;
}

.message-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    font-size: 15px;
    line-height: 1.38;
}

.message-image {
    display: block;
    width: min(62vw, 260px);
    max-height: 360px;
    object-fit: cover;
    border-radius: 6px;
    background: #d8dbd4;
}

.message-meta {
    min-height: 18px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    margin-top: 2px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1;
}

.delete-message {
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 50%;
    display: inline-grid;
    place-items: center;
    color: var(--muted);
    background: transparent;
    padding: 0;
}

.delete-message svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.delete-message:hover,
.delete-message:active {
    color: var(--danger);
    background: rgba(180, 35, 24, 0.08);
}

.composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: #f0f2f5;
    border-top: 1px solid var(--line);
}

.file-input {
    display: none;
}

.icon-button {
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    padding: 0;
}

.icon-button svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.attach-button {
    color: #54656f;
    background: transparent;
}

.send-button {
    color: #ffffff;
    background: var(--green);
}

.icon-button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

#messageInput {
    width: 100%;
    min-height: 42px;
    max-height: 132px;
    resize: none;
    border: 0;
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    background: #ffffff;
    outline: none;
    line-height: 1.35;
}

#messageInput:focus {
    box-shadow: inset 0 0 0 1px rgba(0, 128, 105, 0.35);
}

.login-page {
    min-height: 100%;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #f7f8fa;
}

.login-panel {
    width: min(100%, 360px);
    padding: 24px 22px;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 8px 24px rgba(17, 27, 33, 0.08);
}

.login-title {
    margin: 0 0 20px;
    color: #202124;
    font-size: 20px;
    line-height: 1.2;
    font-weight: 500;
}

.login-error {
    margin: 0 0 14px;
    padding: 9px 10px;
    border-radius: 6px;
    color: var(--danger);
    background: rgba(180, 35, 24, 0.08);
    font-size: 14px;
}

.login-form {
    display: grid;
    gap: 14px;
}

.login-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}

.login-form input {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 9px 10px;
    color: var(--text);
    outline: none;
}

.login-form input:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(0, 128, 105, 0.12);
}

.login-form button {
    min-height: 42px;
    border: 0;
    border-radius: 6px;
    color: #ffffff;
    background: var(--green);
    font-weight: 700;
}

@media (min-width: 821px) {
    .chat-shell {
        border-left: 1px solid rgba(17, 27, 33, 0.12);
        border-right: 1px solid rgba(17, 27, 33, 0.12);
    }
}
