/* =========================================================
   CHATBOX THEME - WhatsApp-style look (loads after chat.css)
   Light by default, follows the device's dark mode.
   Only transform/opacity animations, so it stays smooth.
   ========================================================= */

:root {
    --green: #008069;
    --green-2: #00a884;
    --app-bg: #d1d7db;
    --wall: #efeae2;
    --bubble-me: #d9fdd3;
    --bubble-other: #ffffff;
    --text: #111b21;
    --text-2: #667781;
    --bar: #f0f2f5;
    --pill: #ffffff;
    --header: #008069;
    --tick: #53bdeb;
    --line: rgba(11, 20, 26, 0.08);
    --bubble-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
    --wall-ink: 0.07;
}

@media (prefers-color-scheme: dark) {
    :root {
        --app-bg: #0b141a;
        --wall: #0b141a;
        --bubble-me: #005c4b;
        --bubble-other: #202c33;
        --text: #e9edef;
        --text-2: #8696a0;
        --bar: #202c33;
        --pill: #2a3942;
        --header: #202c33;
        --line: rgba(255, 255, 255, 0.08);
        --wall-ink: 0.05;
    }
}

html,
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--app-bg);
    color: var(--text);
}

button {
    font-family: inherit;
}


/* =========================================================
   LOGIN  (cat photo above the login box)
   ========================================================= */

#loginScreen {
    height: 100vh;
    height: 100dvh;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    gap: 16px;
    padding: 18px 16px;
    overflow-y: auto;
    background: linear-gradient(180deg, var(--green-2) 0, var(--green) 230px, var(--app-bg) 230px);
}

.login-hero {
    flex: none;
    margin-top: clamp(8px, 7dvh, 56px);
    width: auto;
    height: auto;
    max-width: min(92vw, 460px);
    max-height: 42dvh;
    border-radius: 22px;
    border: 4px solid #fff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    animation: rise 0.45s ease-out both;
}

.login-box {
    flex: none;
    margin-bottom: auto;
    width: 100%;
    max-width: 380px;
    background: var(--pill);
    color: var(--text);
    padding: 22px 26px 26px;
    border-radius: 20px;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.14);
    animation: rise 0.5s 0.05s ease-out both;
}

.login-box h1 {
    margin: 0;
    font-size: 26px;
    color: var(--green);
}

.login-sub {
    margin: 4px 0 16px;
    color: var(--text-2);
    font-size: 14px;
}

.login-box input {
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--bar);
    color: var(--text);
}

.login-box input:focus {
    border-color: var(--green-2);
    outline: none;
}

.login-box button {
    background: var(--green-2);
    border-radius: 12px;
    font-weight: 600;
    transition: background 0.15s, transform 0.1s;
}

.login-box button:hover {
    background: var(--green);
}

.login-box button:active {
    transform: scale(0.98);
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}


/* =========================================================
   CHAT SCREEN + HEADER
   ========================================================= */

#chatScreen {
    background: var(--wall);
    box-shadow: 0 0 0 1px var(--line), 0 8px 30px rgba(0, 0, 0, 0.12);
}

.chat-header {
    min-height: 62px;
    padding: 8px 12px;
    background: var(--header);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

.avatar {
    flex: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    background: #cfd8dc;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
    cursor: pointer;
    transition: transform 0.15s;
}

.avatar:active {
    transform: scale(0.94);
}

.header-title {
    min-width: 0;
}

.chat-header h2 {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.2;
}

#otherStatus {
    margin-top: 1px;
    font-size: 12.5px;
    opacity: 0.9;
}

#otherStatus.online {
    color: #c8ffe9;
}

#otherStatus.offline {
    color: rgba(255, 255, 255, 0.75);
}

#connectionStatus {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.18);
    transition: opacity 0.4s;
}

#connectionStatus.hide {
    opacity: 0;
    pointer-events: none;
    width: 0;
    padding: 0;
    overflow: hidden;
}

.call-button {
    background: rgba(255, 255, 255, 0.14);
    transition: background 0.15s, transform 0.1s;
}

.call-button:hover {
    background: rgba(255, 255, 255, 0.28);
}

.call-button:active {
    transform: scale(0.92);
}

.selection-toolbar {
    background: var(--header);
    color: #fff;
}


/* =========================================================
   MESSAGES  (chat wallpaper + bubbles)
   ========================================================= */

#messages {
    padding: 12px 10px 8px;
    background-color: var(--wall);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='%23808c93' fill-opacity='0.07'%3E%3Ccircle cx='20' cy='22' r='4'/%3E%3Ccircle cx='31' cy='15' r='3'/%3E%3Ccircle cx='42' cy='22' r='4'/%3E%3Cellipse cx='31' cy='30' rx='7' ry='5.5'/%3E%3Cpath d='M86 82c-6-7-15-1-9 6l9 9 9-9c6-7-3-13-9-6z'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 120px 120px;
}

.message-row {
    margin-bottom: 3px;
}

.message-row:last-child {
    animation: pop 0.16s ease-out;
}

@keyframes pop {
    from {
        opacity: 0;
        transform: translateY(6px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.message {
    max-width: min(78%, 520px);
    min-width: 64px;
    padding: 6px 8px 4px 9px;
    border-radius: 10px;
    color: var(--text);
    box-shadow: var(--bubble-shadow);
}

.message.me {
    background: var(--bubble-me);
    border-bottom-right-radius: 10px;
    border-top-right-radius: 2px;
}

.message.other {
    background: var(--bubble-other);
    border-bottom-left-radius: 10px;
    border-top-left-radius: 2px;
}

/* 1-to-1 chat: names inside bubbles are not needed */
.message > .message-sender {
    display: none;
}

.message-text {
    font-size: 14.5px;
    line-height: 1.35;
}

.message-row.selected {
    background: rgba(0, 168, 132, 0.22);
}

.message-row.selected .message {
    box-shadow: var(--bubble-shadow);
}

.message img {
    border-radius: 8px;
}

.message-reply {
    border-left-color: var(--green-2);
    background: rgba(11, 20, 26, 0.07);
}

.message-reply strong {
    color: var(--green);
}

.message-reply-text {
    color: var(--text-2);
}

.message-meta {
    margin-top: 2px;
}

.message-time,
.message-edited {
    color: var(--text-2);
    font-size: 11px;
}

.message-status {
    color: var(--text-2);
}

.message-status.seen {
    color: var(--tick);
}

.reaction-chip {
    background: var(--pill);
    border-color: var(--line);
    color: var(--text);
}

.reaction-chip.mine {
    border-color: var(--green-2);
    background: rgba(0, 168, 132, 0.15);
}

.reaction-picker {
    background: var(--pill);
    border-radius: 30px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.22);
}


/* =========================================================
   COMPOSER  (emoji | text | gallery | camera) + send
   ========================================================= */

.composer-preview {
    background: var(--bar);
    color: var(--text);
    border-left: 4px solid var(--green-2);
}

.chat-input-area {
    gap: 8px;
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom, 0px));
    border-top: none;
    background: var(--bar);
}

.composer-pill {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 4px;
    border-radius: 24px;
    background: var(--pill);
    box-shadow: 0 1px 1px rgba(11, 20, 26, 0.08);
}

.chat-input-area .composer-pill input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: 12px 4px;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--text);
    font-size: 16px;
}

.chat-input-area .composer-pill input[type="text"]::placeholder {
    color: var(--text-2);
}

.chat-input-area .pill-btn {
    width: 38px;
    height: 38px;
    background: transparent;
    color: var(--text-2);
    font-size: 21px;
    line-height: 1;
    transition: transform 0.12s, background 0.15s;
}

.chat-input-area .pill-btn:hover {
    background: rgba(128, 140, 147, 0.16);
}

.chat-input-area .pill-btn:active {
    transform: scale(0.88);
}

.chat-input-area .send-btn {
    width: 46px;
    height: 46px;
    background: var(--green-2);
    font-size: 19px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.12s, background 0.15s;
}

.chat-input-area .send-btn:hover {
    background: var(--green);
}

.chat-input-area .send-btn:active {
    transform: scale(0.92);
}


/* =========================================================
   EMOJI PANEL
   ========================================================= */

.emoji-panel {
    flex: 0 0 auto;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    background: var(--bar);
    border-top: 1px solid transparent;
    transition: max-height 0.22s ease, opacity 0.18s ease;
}

.emoji-panel.open {
    max-height: 290px;
    opacity: 1;
    border-top-color: var(--line);
}

.emoji-tabs {
    display: flex;
    justify-content: space-around;
    padding: 4px 6px 0;
    border-bottom: 1px solid var(--line);
}

.emoji-tabs button {
    flex: 1;
    padding: 8px 0 6px;
    border: none;
    border-bottom: 3px solid transparent;
    background: none;
    font-size: 21px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.emoji-tabs button.active {
    opacity: 1;
    border-bottom-color: var(--green-2);
}

.emoji-grid {
    height: 236px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    align-content: start;
    padding: 6px 8px;
    -webkit-overflow-scrolling: touch;
}

.emoji-grid button {
    height: 44px;
    border: none;
    border-radius: 10px;
    background: none;
    font-size: 26px;
    cursor: pointer;
    transition: background 0.1s, transform 0.1s;
}

.emoji-grid button:hover {
    background: rgba(128, 140, 147, 0.2);
}

.emoji-grid button:active {
    transform: scale(1.25);
}


/* =========================================================
   CAMERA / PHOTO PREVIEW
   ========================================================= */

.media-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    background: #000;
    color: #fff;
    animation: fade 0.18s ease-out;
}

.media-top,
.media-bottom {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
}

.media-top {
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
}

.media-bottom {
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
}

.media-top button,
.media-side {
    min-width: 44px;
    height: 44px;
    padding: 0 12px;
    border: none;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
}

#mediaTitle {
    font-weight: 600;
}

.media-stage {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.media-stage video,
.media-stage img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
}

.media-stage video.mirror {
    transform: scaleX(-1);
}

.shutter {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 5px solid #fff;
    background: rgba(255, 255, 255, 0.35);
    cursor: pointer;
    transition: transform 0.1s, background 0.15s;
}

.shutter:active {
    transform: scale(0.9);
    background: #fff;
}

.media-send {
    width: 58px;
    height: 58px;
    border: none;
    border-radius: 50%;
    background: var(--green-2);
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.1s;
}

.media-send:active {
    transform: scale(0.92);
}

.media-send:disabled {
    opacity: 0.55;
}

/* modes: camera = live video + shutter, preview = photo + retake + send */
.mode-camera #mediaPreview,
.mode-camera .media-send,
.mode-camera .media-side {
    display: none;
}

.mode-camera .media-bottom {
    justify-content: center;
}

.mode-preview #mediaVideo,
.mode-preview .shutter,
.mode-preview #mediaSwitchBtn {
    display: none;
}

.mode-preview.no-retake .media-side {
    visibility: hidden;
}

.mode-preview #mediaSwitchBtn {
    display: block;
    visibility: hidden;
}

@keyframes fade {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}


/* =========================================================
   DP VIEWER + CALL AVATARS
   ========================================================= */

.avatar-viewer {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.78);
    animation: fade 0.18s ease-out;
}

.avatar-viewer img {
    width: min(82vw, 360px);
    height: min(82vw, 360px);
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.call-avatar {
    display: block;
    width: 96px;
    height: 96px;
    margin: 0 auto 10px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 0 0 4px rgba(0, 168, 132, 0.35);
}

.call-avatar.small {
    width: 44px;
    height: 44px;
    margin: 0 10px 0 0;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.call-popup-box {
    background: var(--pill);
    color: var(--text);
    border-radius: 22px;
}

.accept-call {
    background: var(--green-2);
}

.active-call-header {
    display: flex;
    align-items: center;
}

.active-call-header > span {
    margin-right: 10px;
}


/* =========================================================
   WIDE SCREENS + REDUCED MOTION
   ========================================================= */

@media (min-width: 960px) {
    #chatScreen {
        height: calc(100dvh - 32px);
        margin-top: 16px;
        border-radius: 12px;
    }
}

@media (max-width: 600px) {
    .message {
        max-width: 84%;
    }

    .emoji-panel.open {
        max-height: 270px;
    }

    .emoji-grid {
        height: 216px;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}


/* =========================================================
   REACTION PILLS (the small emoji under a bubble)
   ========================================================= */

.reaction-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 7px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--pill);
    color: var(--text);
    font-size: 13px;
    line-height: 20px;
    box-shadow: var(--bubble-shadow);
    cursor: pointer;
    transition: transform 0.12s;
}

.reaction-pill:active {
    transform: scale(0.9);
}

.reaction-pill.mine {
    border-color: var(--green-2);
    background: rgba(0, 168, 132, 0.18);
}

@media (prefers-color-scheme: dark) {
    .message-reply strong {
        color: #7ee2c8;
    }
}


/* =========================================================
   WHATSAPP-STYLE REACTIONS + OPEN AT LATEST MESSAGE
   ========================================================= */

/* no sliding animation when the chat opens: it jumps straight to the newest message */
#messages {
    scroll-behavior: auto;
    transition: opacity 0.18s ease;
}

#messages.is-loading {
    opacity: 0;
}

/* reaction pills hang on the bottom edge of the bubble, like WhatsApp */
.message-reactions {
    position: absolute;
    left: 8px;
    bottom: -17px;
    z-index: 2;
    display: flex;
    gap: 3px;
    margin: 0;
}

.message-row:has(.reaction-pill) {
    margin-bottom: 22px;
}

.reaction-pill {
    margin: 0;
    padding: 0 6px;
    line-height: 21px;
    font-size: 13px;
    animation: pillIn 0.22s cubic-bezier(0.3, 1.7, 0.5, 1) both;
}

@keyframes pillIn {
    from {
        opacity: 0;
        transform: scale(0.4);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* reaction bar that pops above the selected message */
.reaction-picker {
    padding: 5px 8px;
    gap: 0;
    transform-origin: bottom center;
    animation: pickerIn 0.2s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}

.reaction-picker button {
    width: 44px;
    height: 44px;
    font-size: 28px;
}

.reaction-picker button:hover {
    background: transparent;
    transform: scale(1.3) translateY(-3px);
}

@keyframes pickerIn {
    from {
        opacity: 0;
        transform: scale(0.6) translateY(10px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* selected bubble keeps its own colour; only the row gets the green highlight */
.message-row.selected .message.me {
    background: var(--bubble-me);
}

.message-row.selected .message.other {
    background: var(--bubble-other);
}
