* {
    box-sizing: border-box;
}

:root {
    --font-family: 'Segoe UI', 'Helvetica Neue', system-ui, -apple-system, sans-serif;
    --wa-bg: #ece5dd;
    --sidebar-bg: #f6f6f6;
    --sidebar-border: #d1d7db;
    --conversation-bg: #f0f2f5;
    --wallpaper-base: #efeae2;
    --wallpaper-ink: rgba(0, 0, 0, 0.025);
    --text-primary: #111b21;
    --text-secondary: #54656f;
    --chat-divider: rgba(17, 27, 33, 0.08);
    --bubble-user: #d9fdd3;
    --bubble-assistant: #ffffff;
    --bubble-error: #ffe2e2;
    --accent: #25d366;
    --muted: #8696a0;
    --icon-bg: rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
    --wa-bg: #0b141a;
    --sidebar-bg: #111b21;
    --sidebar-border: #1f2c34;
    --conversation-bg: #0b141a;
    --wallpaper-base: #0b141a;
    --wallpaper-ink: rgba(255, 255, 255, 0.04);
    --text-primary: #e9edef;
    --text-secondary: #95a9b3;
    --chat-divider: rgba(255, 255, 255, 0.08);
    --bubble-user: #005c4b;
    --bubble-assistant: #202c33;
    --bubble-error: #5c1212;
    --accent: #25d366;
    --muted: #7d8c93;
    --icon-bg: rgba(255, 255, 255, 0.05);
}

body {
    margin: 0;
    font-family: var(--font-family);
    background: var(--wa-bg);
    color: var(--text-primary);
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
}

.whatsapp-app {
    display: flex;
    min-height: 100vh;
    max-height: 100vh;
    height: 100vh;
    overflow: hidden;
}

.chat-sidebar {
    width: 33%;
    min-width: 340px;
    background: var(--sidebar-bg);
    border-left: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

.conversation-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--conversation-bg);
    border-left: 1px solid var(--sidebar-border);
    height: 100vh;
    max-height: 100vh;
}

.sidebar-top {
    padding: 18px 20px 10px;
    border-bottom: 1px solid var(--sidebar-border);
    overflow-y: auto;
    max-height: 40vh;
}

.profile-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.current-business {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-primary);
}

.business-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
}

.top-icons {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--icon-bg);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1rem;
}

.icon-btn i,
.header-actions button i {
    font-size: 1.1rem;
    pointer-events: none;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sidebar-search {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--bubble-assistant);
    border-radius: 999px;
    padding: 0 12px;
    border: 1px solid var(--sidebar-border);
}

.sidebar-search input {
    width: 100%;
    border: none;
    background: transparent;
    padding: 12px 8px;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.sidebar-search input:focus {
    outline: none;
}

.sidebar-search .icon {
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.filter-tabs {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.filter-tabs button {
    border: none;
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 0.85rem;
    cursor: pointer;
    background: transparent;
    color: var(--text-secondary);
}

.filter-tabs button.active {
    background: var(--bubble-assistant);
    color: var(--accent);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.filter-dropdown .dropdown-toggle {
    background: var(--icon-bg);
    border-radius: 999px;
    border: none;
    padding: 8px 14px;
    cursor: pointer;
    color: var(--text-secondary);
}

.chat-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
}

.chat-list::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 999px;
}

.chat-list-item {
    display: flex;
    gap: 12px;
    padding: 14px 18px;
    cursor: pointer;
    border-bottom: 1px solid var(--sidebar-border);
    transition: background 0.2s ease;
}

.chat-list-item:hover,
.chat-list-item.active {
    background: rgba(37, 211, 102, 0.08);
}

.chat-list-item .avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-snippet {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-snippet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-snippet-header h3 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.chat-snippet-header span {
    font-size: 0.75rem;
    color: var(--muted);
}

.chat-snippet p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-empty {
    padding: 40px;
    text-align: center;
    color: var(--muted);
}

.conversation-header {
    padding: 18px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--sidebar-border);
    background: var(--conversation-bg);
}

.contact-meta {
    display: flex;
    align-items: center;
    gap: 14px;
}

.peer-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-peer-name {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
}

.chat-peer-status {
    color: var(--text-secondary);
}

.header-actions {
    display: flex;
    gap: 10px;
}

.header-actions button {
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--icon-bg);
    cursor: pointer;
    color: var(--text-primary);
}

.chat-wallpaper {
    flex: 1;
    overflow-y: auto;
    background-color: var(--wallpaper-base);
    background-image:
        radial-gradient(circle at 10% 20%, var(--wallpaper-ink) 2px, transparent 2px),
        radial-gradient(circle at 80% 0%, var(--wallpaper-ink) 2px, transparent 2px),
        radial-gradient(circle at 0% 50%, var(--wallpaper-ink) 3px, transparent 3px);
    background-size: 220px 220px;
    display: flex;
    flex-direction: column;
}

.chat-container {
    flex: 1;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 32px 48px;
    overflow-y: auto;
}

.chat-container::-webkit-scrollbar {
    width: 6px;
}

.chat-container::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 999px;
}

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 16px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08);
    align-self: flex-start;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    .typing-indicator strong {
        font-size: 0.8rem;
        font-weight: 500;
    }

    [data-theme="dark"] .typing-indicator {
        background: rgba(32, 44, 51, 0.95);
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.5);
    }
    border-radius: 50%;
    background: var(--text-secondary);
    animation: bounce 1s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.1s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.2s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.composer-shell {
    padding: 12px 24px 24px;
    background: var(--conversation-bg);
    flex-shrink: 0;
    position: relative;
}

.composer-shell form {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bubble-assistant);
    border-radius: 999px;
    padding: 8px 16px;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.composer-shell input {
    flex: 1;
    border: none;
    font-size: 0.95rem;
    background: transparent;
    color: var(--text-primary);
}

.composer-shell input:focus {
    outline: none;
}

.composer-shell button[type="submit"] {
    background: var(--accent);
    color: #fff;
    width: auto;
    padding: 8px 20px;
    border-radius: 999px;
}

#send-button {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: linear-gradient(135deg, #25d366, #1aaa52);
    box-shadow: 0 10px 20px rgba(37, 211, 102, 0.25);
    border: none;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

#send-button:enabled:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 26px rgba(37, 211, 102, 0.35);
}

#send-button:enabled:active {
    transform: translateY(1px);
    box-shadow: 0 8px 16px rgba(37, 211, 102, 0.3);
}

#send-button:disabled {
    background: linear-gradient(135deg, rgba(37, 211, 102, 0.35), rgba(26, 170, 82, 0.35));
    box-shadow: none;
}

#send-button i {
    font-size: 1.3rem;
    transition: transform 0.2s ease;
}

#send-button:enabled:hover i {
    transform: translateX(-2px);
}

.composer-shell small {
    display: block;
    margin-top: 8px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.emoji-picker-panel {
    position: absolute;
    bottom: 70px;
    right: 32px;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: 20px;
    padding: 12px;
    box-shadow: 0 16px 30px rgba(0, 0, 0, 0.15);
    z-index: 20;
    width: min(280px, 80vw);
}

.emoji-picker-panel[hidden] {
    display: none;
}

.emoji-palette {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 8px;
}

.emoji-btn {
    border: none;
    background: var(--bubble-assistant);
    border-radius: 12px;
    font-size: 1.3rem;
    padding: 8px 0;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.emoji-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08);
}

.emoji-btn:active {
    transform: scale(0.95);
}

.chat-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 70%;
    line-height: 1.4;
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.assistant {
    align-self: flex-start;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-message.assistant .avatar {
    border: solid 1.5px var(--sidebar-border);
    background: var(--conversation-bg);
    padding: 2px;
    
}

.bubble-wrapper {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    max-width: min(70vw, 520px);
    width: fit-content;
}

.chat-message.user .bubble-wrapper { align-items: flex-end; }
.chat-message.assistant .bubble-wrapper { align-items: flex-start; }

.chat-bubble {
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--bubble-assistant);
    color: var(--text-primary);
    position: relative;
}

.chat-bubble.user {
    background: var(--bubble-user);
    border-bottom-right-radius: 2px;
}

.chat-bubble.assistant {
    border-bottom-left-radius: 2px;
}

.chat-bubble.error {
    background: var(--bubble-error);
    color: #d32f2f;
}

.chat-bubble.pending { opacity: 0.7; }

.bubble-text {
    margin: 0;
    white-space: normal;
    word-break: break-word;
}

.bubble-text strong { font-weight: 700; }
.bubble-text em { font-style: italic; }
.bubble-text s { text-decoration: line-through; }

.bubble-inline-code {
    font-family: 'Courier New', monospace;
    background: rgba(0, 0, 0, 0.08);
    padding: 0 4px;
    border-radius: 4px;
    display: inline-block;
}

[data-theme="dark"] .bubble-inline-code {
    background: rgba(255, 255, 255, 0.15);
}

.bubble-code {
    margin-top: 8px;
    padding: 10px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.04);
    direction: ltr;
    text-align: left;
}

[data-theme="dark"] .bubble-code {
    background: rgba(255, 255, 255, 0.08);
}

.bubble-code code {
    font-family: 'Courier New', monospace;
    white-space: pre-wrap;
    color: inherit;
    display: block;
}

.chat-bubble::after {
    content: "";
    position: absolute;
    bottom: 0;
    width: 12px;
    height: 12px;
    background: inherit;
}

.chat-message.user .chat-bubble::after {
    right: -5px;
    clip-path: polygon(0 0, 100% 0, 100% 100%);
}

.chat-message.assistant .chat-bubble::after {
    left: -5px;
    clip-path: polygon(0 0, 0 100%, 100% 100%);
}

.message-meta {
    margin-top: 4px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.message-actions {
    display: flex;
    gap: 6px;
    align-self: flex-end;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-message:hover .message-actions {
    opacity: 1;
}

.message-action-btn {
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.message-action-btn i {
    pointer-events: none;
}

.message-action-btn:hover {
    color: #d32f2f;
    background: rgba(211, 47, 47, 0.12);
}

.read-receipt {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: #53bdeb;
    background: rgba(83, 189, 235, 0.12);
    border-radius: 50%;
}

.read-receipt i {
    font-size: 0.9rem;
}

.error-card {
    background: var(--bubble-error);
    color: #d32f2f;
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.error-card button {
    border: none;
    background: rgba(211, 47, 47, 0.2);
    color: inherit;
    border-radius: 999px;
    padding: 6px 12px;
    cursor: pointer;
}

.empty-state {
    margin: auto;
    text-align: center;
    color: var(--text-secondary);
}

.chat-loading {
    color: var(--text-secondary);
    text-align: center;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 50;
}

.modal {
    background: var(--sidebar-bg);
    border-radius: 18px;
    padding: 24px;
    width: min(420px, 100%);
    border: 1px solid var(--sidebar-border);
}

.modal header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.modal form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal input {
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--sidebar-border);
    font-size: 0.95rem;
}

.modal textarea {
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--sidebar-border);
    font-size: 0.95rem;
    resize: vertical;
    min-height: 140px;
    font-family: inherit;
    background: var(--conversation-bg);
    color: var(--text-primary);
}

.modal textarea:focus {
    outline: 2px solid var(--accent);
    border-color: transparent;
}

.modal-hint {
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.avatar-picker {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 4px;
}

.avatar-picker-title {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.avatar-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
    gap: 10px;
    overflow-y: scroll;
    max-height: 200px;
}

.avatar-option {
    border: 2px solid transparent;
    border-radius: 16px;
    padding: 4px;
    background: var(--conversation-bg);
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.avatar-option img {
    width: 100%;
    height: 54px;
    object-fit: cover;
    border-radius: 12px;
    display: block;
}

.avatar-option.active {
    border-color: var(--accent);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

#avatar-clear-btn {
    align-self: flex-start;
    font-size: 0.85rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 999px;
}

.ghost {
    background: transparent;
    border: 1px solid var(--sidebar-border);
    border-radius: 999px;
    padding: 8px 16px;
}

.modal-close-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--sidebar-border);
    background: var(--conversation-bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.modal-close-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
    border-color: var(--accent);
}

.modal-close-btn:active {
    transform: scale(0.96);
}

.modal-close-btn i {
    font-size: 1.2rem;
    pointer-events: none;
}

.modal-backdrop[hidden],
.typing-indicator[hidden] {
    display: none;
}

@media (max-width: 960px) {
    body {
        height: auto;
        overflow: auto;
    }
    .whatsapp-app {
        flex-direction: column;
        height: auto;
        max-height: none;
    }
    .chat-sidebar {
        width: 100%;
        min-width: auto;
        max-height: none;
        height: auto;
    }
    .conversation-area {
        width: 100%;
        flex: 1;
        height: auto;
    }
}

@media (max-width: 640px) {
    .chat-container {
        padding: 20px 16px;
    }
    .chat-message {
        max-width: 85%;
    }
}

