/* ================== RESET & BASE ================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* ================== THEME VARIABLES ================== */
:root {
    --bg-primary: #eef1f7;
    --bg-glass: rgba(255, 255, 255, 0.25);
    --glass-border: rgba(255, 255, 255, 0.4);
    --text-primary: #1a1a1a;
    --text-secondary: #555;
    --message-own: rgba(0, 122, 255, 0.7);      /* آبی شفاف برای پیام خودی */
    --message-other: rgba(255, 255, 255, 0.6);  /* سفید شفاف برای دیگران */
    --highlight-bg: rgba(255, 255, 0, 0.25);
    --swipe-color: rgba(0, 122, 255, 0.15);
    --reply-bg: rgba(0, 122, 255, 0.1);
    --shadow-sm: 0 8px 20px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] {
    --bg-primary: #0f1115;
    --bg-glass: rgba(30, 30, 30, 0.35);
    --glass-border: rgba(255, 255, 255, 0.15);
    --text-primary: #f2f2f2;
    --text-secondary: #aaa;
    --message-own: rgba(0, 122, 255, 0.6);      /* آبی تیره‌تر */
    --message-other: rgba(255, 255, 255, 0.2);  /* تیره برای دیگران */
    --highlight-bg: rgba(255, 255, 0, 0.15);
    --swipe-color: rgba(255, 255, 255, 0.1);
    --reply-bg: rgba(0, 122, 255, 0.2);
}

/* ================== CONTAINERS ================== */
.container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    background: var(--bg-primary);
}

.container.active {
    display: block;
}

/* ================== LOGIN PAGE ================== */
#login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, var(--bg-primary) 0%, #d9e0eb 100%);
    padding: 1.5rem;
}

[data-theme="dark"] #login-container {
    background: linear-gradient(145deg, #1a1d24 0%, #0f1115 100%);
}

.login-box {
    width: 100%;
    max-width: 400px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 40px;
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.login-box h1 {
    font-size: 2.4rem;
    margin-bottom: 2rem;
    font-weight: 600;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

.login-box input {
    width: 100%;
    padding: 1.4rem 1.8rem;
    margin-bottom: 1.6rem;
    border: 1px solid var(--glass-border);
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 30px;
    font-size: 1.6rem;
    color: var(--text-primary);
    outline: none;
    transition: border 0.2s;
}

.login-box input:focus {
    border-color: #007aff;
}

.login-box button {
    width: 100%;
    padding: 1.4rem;
    background: #007aff;
    border: none;
    border-radius: 30px;
    font-size: 1.8rem;
    font-weight: 600;
    color: white;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(0, 122, 255, 0.3);
    transition: transform 0.1s, box-shadow 0.2s;
}

.login-box button:active {
    transform: scale(0.97);
    box-shadow: 0 5px 10px rgba(0, 122, 255, 0.4);
}

.hint {
    margin-top: 2rem;
    font-size: 1.4rem;
    color: var(--text-secondary);
}

/* ================== CHAT CARD ================== */
.chat-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    background: var(--bg-primary);
}

/* ================== HEADER ================== */
.chat-header {
    flex-shrink: 0;
    height: 90px;
    padding: 1.2rem 1.8rem;
    background: var(--bg-glass);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.7rem;
    font-weight: 600;
    border-radius: 0 0 28px 28px;
    box-shadow: var(--shadow-sm);
}

.room-info {
    background: var(--bg-glass);
    padding: 0.6rem 1.4rem;
    border-radius: 30px;
    border: 1px solid var(--glass-border);
    font-size: 1.5rem;
}

.chat-header button {
    padding: 0.7rem 1.3rem;
    margin-left: 0.8rem;
    border-radius: 30px;
    border: 1px solid var(--glass-border);
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-header button:active {
    background: rgba(255, 255, 255, 0.3);
}

/* ================== MESSAGES AREA ================== */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.6rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    -webkit-overflow-scrolling: touch;
}

.message {
    max-width: 80%;
    padding: 1.2rem 1.6rem;
    border-radius: 28px;
    background: var(--message-other);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    font-size: 1.6rem;        /* دو برابر اندازه قبلی (قبلاً 1.45rem) */
    line-height: 1.6;
    word-break: break-word;
    transition: transform 0.2s ease, background-color 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

.message.own {
    background: var(--message-own);
    color: #fff;
    align-self: flex-end;
    border-color: rgba(255, 255, 255, 0.1);
}

.message-header {
    display: flex;
    justify-content: space-between;
    font-size: 1.3rem;
    margin-bottom: 0.6rem;
    opacity: 0.8;
}

.message.own .message-header {
    color: rgba(255, 255, 255, 0.9);
}

.sender {
    font-weight: 600;
}

.time {
    font-size: 1.2rem;
}

.message-content {
    line-height: 1.5;
}

.message-content img,
.message-content video,
.message-content audio {
    max-width: 100%;
    border-radius: 16px;
    margin-top: 0.4rem;
}

/* swipe animation */
.message.swiping {
    background-color: var(--swipe-color);
    transition: none;
}

.message.highlight {
    background-color: var(--highlight-bg);
    transition: background-color 0.3s;
}

/* ================== REPLY QUOTE ================== */
.reply-quote {
    background: var(--reply-bg);
    border-right: 4px solid #007aff;
    padding: 0.8rem 1.2rem;
    border-radius: 18px;
    margin-bottom: 0.8rem;
    font-size: 1.3rem;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    cursor: pointer;
    transition: background 0.2s;
}

.reply-quote:active {
    background: rgba(0, 122, 255, 0.2);
}

.reply-quote .sender {
    font-weight: 600;
    color: #007aff;
}

/* ================== REPLY PREVIEW ================== */
.reply-preview {
    flex-shrink: 0;
    background: var(--bg-glass);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border-top: 1px solid var(--glass-border);
    border-bottom: 1px solid var(--glass-border);
    padding: 1rem 1.8rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 1.4rem;
    color: var(--text-primary);
    direction: rtl;
}

.reply-preview span {
    font-weight: 600;
    color: #007aff;
}

.reply-preview div:first-child {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#cancel-reply {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0 0.8rem;
}

/* ================== STICKER PANEL ================== */
.sticker-panel {
    flex-shrink: 0;
    padding: 1rem;
    background: var(--bg-glass);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.sticker {
    width: 65px;
    height: 65px;
    font-size: 3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-glass);
    border-radius: 30px;
    border: 1px solid var(--glass-border);
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
    flex-shrink: 0;
}

.sticker:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.3);
}

/* ================== INPUT AREA (نصف ارتفاع قبلی) ================== */
.input-area {
    flex-shrink: 0;
    height: 20vh;               /* نصف 33vh قبلی ≈ 16.5vh، ولی 20vh انتخاب شد */
    min-height: 150px;          /* حداقل ارتفاع مناسب */
    padding: 1rem 1.5rem;
    background: var(--bg-glass);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border-top: 1px solid var(--glass-border);
    border-radius: 28px 28px 0 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.02);
}

.input-top {
    display: flex;
    align-items: center;
    gap: 1.8rem;
    padding: 0 0.2rem;
}

#sticker-btn,
.attach-btn,
.camera-btn {
    font-size: 2.8rem;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    line-height: 1;
    transition: transform 0.1s;
}

#sticker-btn:active,
.attach-btn:active,
.camera-btn:active {
    transform: scale(0.9);
}

.input-bottom {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
}

#message-input {
    flex: 1;
    padding: 1rem 1.6rem;       /* کمی کمتر از قبل */
    border-radius: 40px;
    border: 1px solid var(--glass-border);
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    font-size: 1.6rem;
    color: var(--text-primary);
    outline: none;
    transition: border 0.2s;
}

#message-input:focus {
    border-color: #007aff;
}

#send-btn {
    padding: 1rem 2rem;
    background: #007aff;
    color: #fff;
    border: none;
    border-radius: 40px;
    font-size: 1.6rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 16px rgba(0, 122, 255, 0.3);
    transition: transform 0.1s, box-shadow 0.2s;
    white-space: nowrap;
}

#send-btn:active {
    transform: scale(0.96);
    box-shadow: 0 4px 8px rgba(0, 122, 255, 0.4);
}

/* ================== MOBILE OPTIMIZATIONS ================== */
@media (max-width: 480px) {
    .chat-header {
        height: 85px;
        padding: 0.8rem 1.2rem;
        font-size: 1.6rem;
    }

    .room-info {
        font-size: 1.4rem;
        padding: 0.4rem 1rem;
    }

    .message {
        font-size: 1.8rem;        /* دو برابر بیشتر در موبایل */
        max-width: 90%;
        padding: 1rem 1.4rem;
    }

    #message-input {
        font-size: 1.6rem;
        padding: 0.8rem 1.4rem;
    }

    #send-btn {
        font-size: 1.6rem;
        padding: 0.8rem 1.6rem;
    }

    .sticker {
        width: 55px;
        height: 55px;
        font-size: 2.8rem;
    }

    .reply-preview {
        font-size: 1.3rem;
        padding: 0.8rem 1.4rem;
    }

    .input-area {
        min-height: 130px;         /* کاهش بیشتر برای صفحه‌های خیلی کوچک */
    }
}

@media (max-height: 600px) {
    .input-area {
        min-height: 120px;
    }
}

/* ================== HIDE ELEMENTS INITIALLY ================== */
#sticker-panel {
    display: none;
}

/* ================== SCROLLBAR ================== */
.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border-radius: 20px;
}
