* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    height: 100%;
    width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
    background-color: #ededed;
    overflow: hidden;
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #ededed;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 10;
}

/* Hidden state for chat room (off-screen right) */
#page-chat {
    transform: translateX(100%);
    z-index: 20;
    background-color: #ededed;
}

/* Active state for chat room */
#page-chat.active {
    transform: translateX(0);
}

/* Settings Page - Same Slide Logic */
#page-settings {
    transform: translateX(100%);
    z-index: 30; /* Higher than chat */
    background-color: #f7f7f7;
}
#page-settings.active {
    transform: translateX(0);
}

#page-messages {
    transform: translateX(100%);
    z-index: 35; /* Higher than settings */
    background-color: #ededed;
}
#page-messages.active {
    transform: translateX(0);
}

/* --- Header --- */
.app-header {
    height: 44px;
    background-color: #ededed;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    flex-shrink: 0;
    z-index: 100;
    position: relative;
}

.header-title {
    font-size: 17px;
    font-weight: 600;
    color: #181818;
}

.msg-count {
    color: #181818;
    font-weight: 600;
}

.header-icons {
    display: flex;
    gap: 16px;
    color: #181818;
}

.icon-btn svg {
    display: block;
}

/* --- Scrollable Content --- */
.content-scrollable {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* --- Bottom Tab Bar --- */
.tab-bar {
    height: 56px;
    background-color: #f7f7f7;
    border-top: 0.5px solid #dcdcdc;
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom);
}

.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    flex: 1;
    height: 100%;
    color: #181818;
}

.tab-icon {
    width: 28px;
    height: 28px;
    margin-bottom: 2px;
    color: #181818;
}

.tab-text {
    font-size: 10px;
    transform: scale(0.9);
    color: #181818;
    font-weight: 500;
}

.tab-item.active .tab-icon, 
.tab-item.active .tab-text {
    color: #07c160;
}

/* --- Chat Room Specifics --- */
.chat-room-header {
    background-color: #ededed;
    border-bottom: 0.5px solid #dcdcdc;
}

.header-left {
    display: flex;
    align-items: center;
    font-size: 16px;
    color: #181818;
    cursor: pointer;
    flex: 1;
}

.back-icon {
    margin-right: -4px;
}

.back-count {
    font-size: 16px;
    font-weight: 500;
    margin-left: 4px;
}

.header-title {
    flex: 2;
    text-align: center;
}

.header-right {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    cursor: pointer;
}

.chat-container {
    background-color: #ededed;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 20px;
    cursor: pointer;
}

.message-row {
    display: flex;
    align-items: flex-start;
    margin-bottom: 4px; /* Tighter spacing */
}

.message-row .avatar {
    width: 42px;
    height: 42px;
    border-radius: 6px;
    flex-shrink: 0;
}

.message-row.received .avatar {
    margin-right: 10px;
}

.message-row.sent {
    flex-direction: row-reverse;
}

.message-row.sent .avatar {
    margin-left: 10px;
}

/* BUBBLES */
.bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 4px;
    font-size: 16px;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    display: flex;
    align-items: center;
    min-height: 42px;
}

/* Call Bubble Specifics */
.call-bubble {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
}
.call-icon {
    display: flex;
    align-items: center;
}
.call-text {
    font-size: 15px;
}

/* Received style */
.received .bubble {
    background-color: #fff;
    color: #181818;
}
.received .bubble::before {
    content: "";
    position: absolute;
    left: -6px;
    top: 14px;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-right: 6px solid #fff;
}

/* Sent style */
.sent .bubble {
    background-color: #95ec69;
    color: #181818;
}
.sent .bubble::before {
    content: "";
    position: absolute;
    right: -6px;
    top: 14px;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 6px solid #95ec69;
}

/* Image Bubble - No triangle, no bg color visible, rounded corners */
.image-bubble {
    max-width: 60%;
}
.image-bubble img {
    width: 100%;
    height: auto;
    border-radius: 6px;
    display: block;
    border: 1px solid #e5e5e5;
}
.sent .image-bubble {
    margin-right: 0; /* Aligns better without triangle */
}


.message-time {
    text-align: center;
    color: #b2b2b2;
    font-size: 12px;
    margin: 16px 0 8px 0;
}

/* --- Chat Footer Input --- */
.chat-footer {
    min-height: 56px;
    background-color: #f7f7f7;
    border-top: 0.5px solid #dcdcdc;
    display: flex;
    align-items: center;
    padding: 8px 10px;
    gap: 10px;
    flex-shrink: 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    /* FIX: Footer visibility */
    position: relative;
    z-index: 100;
}

.footer-icon {
    color: #181818;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-wrapper {
    flex: 1;
    background-color: #fff;
    border-radius: 6px;
    height: 40px;
    display: flex;
    align-items: center;
    padding: 0 10px;
}

#mobileInput {
    width: 100%;
    border: none;
    outline: none;
    font-size: 16px;
    background: transparent;
    height: 100%;
}

.send-btn-mobile {
    background-color: #07c160;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
}

/* Emoji Rain Animation */
@keyframes fall {
    0% { top: -50px; opacity: 1; transform: translateX(0) rotate(0deg); }
    100% { top: 100vh; opacity: 0; transform: translateX(20px) rotate(360deg); }
}

@keyframes sway {
    0% { transform: translateX(0px) rotate(0deg); }
    25% { transform: translateX(50px) rotate(10deg); }
    50% { transform: translateX(0px) rotate(0deg); }
    75% { transform: translateX(-50px) rotate(-10deg); }
    100% { transform: translateX(0px) rotate(0deg); }
}

.falling-emoji {
    position: fixed;
    font-size: 30px;
    user-select: none;
    pointer-events: none;
    z-index: 9999;
    animation: fall 3s linear forwards;
    
    /* Ensure images fit well */
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Sway Pattern */
.falling-emoji.sway {
    animation: fall 3s linear forwards, sway 2s ease-in-out infinite;
}

/* Diagonal Pattern */
@keyframes diagonalFall {
    0% { top: -50px; transform: translateX(0); opacity: 1; }
    100% { top: 100vh; transform: translateX(50vw); opacity: 0; }
}
@keyframes diagonalFallReverse {
    0% { top: -50px; transform: translateX(0); opacity: 1; }
    100% { top: 100vh; transform: translateX(-50vw); opacity: 0; }
}

.falling-emoji.diagonal {
    animation: diagonalFall 3s linear forwards;
}
.falling-emoji.diagonal.reverse {
    animation: diagonalFallReverse 3s linear forwards;
}

.falling-emoji img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Toast/Modal for Exit */
.custom-toast {
    position: fixed;
    top: 40%; 
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.0); 
    color: #007aff; /* iOS Blue */
    padding: 15px 25px;
    border-radius: 8px;
    font-size: 24px; 
    font-weight: bold;
    z-index: 20000; 
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    text-shadow: 0 2px 10px rgba(255,255,255, 0.8), 0 0 2px white;
}

.custom-toast.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
}

/* Dancing Emoji/Image Animation */
@keyframes dance {
    0% { transform: translate(-50%, -50%) rotate(0deg) scale(1); }
    25% { transform: translate(-50%, -50%) rotate(-15deg) scale(1.1); }
    50% { transform: translate(-50%, -50%) rotate(15deg) scale(1.1); }
    75% { transform: translate(-50%, -50%) rotate(-15deg) scale(1.1); }
    100% { transform: translate(-50%, -50%) rotate(0deg) scale(1); }
}

.dancing-emoji {
    position: fixed;
    top: 25%; /* Moved further up */
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10000;
    pointer-events: none;
    animation: dance 1.5s ease-in-out infinite; /* Slightly slower for better effect */
    
    /* Image specific styles */
    width: 140px; /* Reduced by 30% from 200px */
    height: auto;
    object-fit: contain;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 20000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: white;
    width: 85%;
    max-width: 320px;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 20px 20px 10px;
    text-align: center;
}

.modal-header h3 {
    margin: 0 0 8px;
    color: #111;
    font-size: 18px;
    font-weight: 600;
}

.modal-header p {
    font-size: 13px;
    color: #888;
    line-height: 1.4;
    margin: 0;
}

.modal-body {
    padding: 10px 20px 20px;
}

.modal-body textarea {
    width: 100%;
    border: none;
    background-color: #f7f7f7;
    border-radius: 8px;
    padding: 12px;
    font-size: 15px;
    color: #333;
    resize: none;
    outline: none;
    font-family: inherit;
    display: block;
}

.modal-body textarea:focus {
    background-color: #f0f0f0;
    box-shadow: inset 0 0 0 1px #e5e5e5;
}

.modal-footer {
    display: flex;
    border-top: 1px solid #eee;
}

.modal-btn {
    flex: 1;
    padding: 16px;
    border: none;
    background: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    outline: none;
}

.modal-btn:active {
    background-color: #f9f9f9;
}

.modal-btn.cancel {
    color: #5f5f5f;
    border-right: 1px solid #eee;
}

.modal-btn.save {
    color: #07c160;
}

/* --- Settings Page Styles --- */
.settings-container {
    background-color: #ededed;
    padding: 20px 16px;
}

.settings-section {
    background-color: #fff;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.section-title {
    font-size: 14px;
    color: #888;
    margin-bottom: 12px;
    font-weight: 500;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 12px;
}

.emoji-item {
    width: 100%;
    aspect-ratio: 1;
    background-color: #f7f7f7;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    position: relative;
    cursor: pointer;
    border: 1px solid transparent;
    overflow: hidden;
}

.emoji-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.emoji-item .delete-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    background: rgba(255, 0, 0, 0.8);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    opacity: 0; 
    transition: opacity 0.2s;
}

.emoji-item:hover .delete-btn {
    opacity: 1;
}

.add-item-btn {
    border: 1px dashed #ccc;
    background-color: white;
}

.add-item-btn:active {
    background-color: #f0f0f0;
}

/* --- Message Manager Styles --- */
.msg-edit-item {
    background: white;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    position: relative;
}

.msg-edit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: #888;
    border-bottom: 1px solid #eee;
    padding-bottom: 6px;
    margin-bottom: 4px;
}

.msg-edit-role {
    font-weight: 600;
    color: #333;
    background: #eee;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
}

.msg-edit-role.boss { color: #ff5722; background: #ffebe6; }
.msg-edit-role.user { color: #07c160; background: #e6f7ec; }

.msg-edit-content {
    font-size: 15px;
    color: #333;
    line-height: 1.4;
    white-space: pre-wrap;
}

.msg-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 6px;
}

.msg-action-btn {
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
    border: 1px solid #eee;
    background: #f9f9f9;
    color: #555;
    cursor: pointer;
}

.msg-action-btn.delete { color: #fa5151; border-color: #fee; background: #fff5f5; }
.msg-action-btn.up, .msg-action-btn.down { font-weight: bold; }

/* Edit Modal Specifics */
.role-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.role-option {
    flex: 1;
    padding: 10px;
    text-align: center;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    color: #555;
    cursor: pointer;
}

.role-option.selected {
    border-color: #07c160;
    color: #07c160;
    background: #e6f7ec;
    font-weight: 600;
}

/* Audio Bubble Specifics */
.audio-bubble {
    min-width: 60px;
    height: 42px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    cursor: pointer;
    color: #181818; /* Explicitly set color to avoid blue */
}

.audio-icon {
    width: 20px;
    height: 20px;
    color: inherit;
    flex-shrink: 0;
}

/* Fix for "Blue Text" - Ensure it matches message text color */
.received .audio-bubble {
    color: #181818;
}

.sent .audio-bubble {
    color: #181818;
}
