:root {
    --bg-color: #d1d7db;
    --app-bg: #efeae2;
    --sidebar-bg: #ffffff;
    --header-bg: #f0f2f5;
    --search-bg: #f0f2f5;
    --msg-in: #ffffff;
    --msg-out: #d9fdd3;
    --primary-color: #00a884;
    --text-primary: #111b21;
    --text-secondary: #667781;
    --border-color: #e9edef;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.app-container {
    width: 100%;
    max-width: 1600px;
    height: 100vh;
    background-color: var(--app-bg);
    display: flex;
    box-shadow: 0 1px 1px 0 rgba(0,0,0,0.06), 0 2px 5px 0 rgba(0,0,0,0.2);
    overflow: hidden;
}

@media (min-width: 1024px) {
    .app-container {
        height: 95vh;
        top: 2.5vh;
        position: relative;
    }
}

.hidden {
    display: none !important;
}

/* Sidebar */
.sidebar {
    width: 30%;
    min-width: 350px;
    background-color: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.sidebar-header, .chat-header {
    height: 60px;
    background-color: var(--header-bg);
    display: flex;
    align-items: center;
    padding: 10px 16px;
    justify-content: space-between;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #dfe5e7;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    font-size: 20px;
    overflow: hidden;
}

.sidebar-actions button, .chat-input-area button {
    background: none;
    border: none;
    color: #54656f;
    font-size: 20px;
    margin-left: 15px;
    cursor: pointer;
}

.search-bar {
    padding: 8px 12px;
    background-color: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
}

.search-input {
    background-color: var(--search-bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    height: 35px;
}

.search-input i {
    color: var(--text-secondary);
    font-size: 14px;
}

.search-input input {
    border: none;
    background: none;
    outline: none;
    width: 100%;
    margin-left: 15px;
    font-size: 15px;
}

.contact-list {
    flex: 1;
    overflow-y: auto;
}

.contact-item {
    display: flex;
    padding: 12px 15px;
    cursor: pointer;
    background-color: var(--sidebar-bg);
    transition: background 0.2s;
}

.contact-item:hover {
    background-color: var(--search-bg);
}

.contact-item.active {
    background-color: var(--search-bg);
}

.contact-item .avatar {
    margin-right: 15px;
    flex-shrink: 0;
}

.contact-info {
    flex: 1;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    overflow: hidden;
}

.contact-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 3px;
}

.contact-name {
    font-size: 17px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-time {
    font-size: 12px;
    color: var(--text-secondary);
}

.contact-msg {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--app-bg);
    position: relative;
}

.chat-area::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    opacity: 0.06;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10 10h10v10H10zM50 50h10v10H50z' fill='%23000' fill-rule='evenodd'/%3E%3C/svg%3E");
    z-index: 0;
    pointer-events: none;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: var(--header-bg);
    z-index: 1;
}

.empty-state h1 {
    color: #41525d;
    font-weight: 300;
    margin: 0 0 10px;
}

.empty-state p {
    color: var(--text-secondary);
}

.active-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    z-index: 1;
    height: 100%;
}

.chat-header {
    justify-content: flex-start;
}

.back-btn {
    display: none;
    cursor: pointer;
    color: #54656f;
    font-size: 20px;
    margin-right: 15px;
}

.chat-header .avatar {
    margin-right: 15px;
}

.chat-info h2 {
    font-size: 16px;
    color: var(--text-primary);
    font-weight: 500;
}

.chat-info span {
    font-size: 13px;
    color: var(--text-secondary);
}

.messages-container {
    flex: 1;
    padding: 20px 5%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.message {
    max-width: 65%;
    margin-bottom: 12px;
    padding: 8px 12px;
    border-radius: 7.5px;
    position: relative;
    font-size: 14px;
    line-height: 19px;
    color: var(--text-primary);
    box-shadow: 0 1px 0.5px rgba(11,20,26,.13);
}

.message.in {
    align-self: flex-start;
    background-color: var(--msg-in);
    border-top-left-radius: 0;
}

.message.in::before {
    content: '';
    position: absolute;
    top: 0; left: -8px;
    width: 0; height: 0;
    border-top: 8px solid var(--msg-in);
    border-left: 8px solid transparent;
}

.message.out {
    align-self: flex-end;
    background-color: var(--msg-out);
    border-top-right-radius: 0;
}

.message.out::before {
    content: '';
    position: absolute;
    top: 0; right: -8px;
    width: 0; height: 0;
    border-top: 8px solid var(--msg-out);
    border-right: 8px solid transparent;
}

.msg-time {
    font-size: 11px;
    color: var(--text-secondary);
    float: right;
    margin: 8px 0 -5px 10px;
}

.chat-input-area {
    height: 62px;
    background-color: var(--header-bg);
    display: flex;
    align-items: center;
    padding: 10px 16px;
}

.chat-input-area input {
    flex: 1;
    height: 40px;
    border: none;
    border-radius: 8px;
    padding: 9px 12px;
    margin: 0 10px;
    font-size: 15px;
    background-color: #fff;
    outline: none;
}

/* Responsividade Mobile */
@media (max-width: 768px) {
    .app-container {
        height: 100vh;
        width: 100vw;
    }
    
    .sidebar {
        width: 100%;
        min-width: 100%;
        display: flex;
    }
    
    .chat-area {
        position: absolute;
        top: 0; left: 0;
        width: 100%; height: 100%;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        z-index: 10;
    }
    
    .chat-area.mobile-active {
        transform: translateX(0);
    }
    
    .back-btn { display: block; }
}

/* Tools Panel Styles */
.tools-btn {
    position: absolute;
    right: 25px;
    bottom: 85px;
    top: auto;
    width: 50px;
    height: 50px;
    background-color: var(--sidebar-bg);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    cursor: pointer;
    z-index: 50;
    color: var(--primary-color);
    font-size: 22px;
    transition: background 0.2s, transform 0.2s;
}
.tools-btn:hover { background-color: #f0f2f5; transform: scale(1.05); }

.tools-panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 350px;
    background-color: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: -2px 0 15px rgba(0,0,0,0.1);
}
.tools-panel.open {
    transform: translateX(0);
}
.tools-header {
    height: 60px;
    background-color: var(--header-bg);
    display: flex;
    align-items: center;
    padding: 0 20px;
    justify-content: space-between;
}
.tools-header h2 { font-size: 16px; color: var(--text-primary); font-weight: 500; }
.tools-header button { background: none; border: none; font-size: 20px; color: #54656f; cursor: pointer; transition: 0.2s; }
.tools-header button:hover { color: #111; }

.tools-tabs { display: flex; border-bottom: 1px solid var(--border-color); background: var(--sidebar-bg); }
.tool-tab { flex: 1; text-align: center; padding: 12px 5px; font-size: 13px; font-weight: 500; color: var(--primary-color); border-bottom: 3px solid transparent; cursor: pointer; }
.tool-tab.active { border-bottom: 3px solid var(--primary-color); }

.tools-content { flex: 1; overflow-y: auto; padding: 15px; display: flex; flex-direction: column; background: var(--app-bg); }

.add-seq-btn { width: 100%; padding: 12px; background: #fff; border: 1px dashed #ccc; border-radius: 8px; cursor: pointer; color: var(--primary-color); font-weight: 600; margin-bottom: 15px; font-size: 15px; transition: 0.2s; }
.add-seq-btn:hover { background: #f0f2f5; border-color: var(--primary-color); }

.sequences-list { display: flex; flex-direction: column; gap: 10px; }
.sequence-card { background: #fff; padding: 12px 15px; border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,0.1); display: flex; justify-content: space-between; align-items: center; }
.seq-info h4 { font-size: 15px; color: var(--text-primary); margin-bottom: 4px; font-weight: 500; }
.seq-info span { font-size: 12px; color: var(--text-secondary); }

.seq-actions-card { display: flex; gap: 6px; align-items: center; }
.btn-edit-seq, .btn-delete-seq { background: #f0f2f5; color: #54656f; border: none; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; display: flex; justify-content: center; align-items: center; transition: 0.2s; font-size: 14px; }
.btn-edit-seq:hover { background: #e0e5e9; color: #111; }
.btn-delete-seq:hover { background: #fee2e2; color: #ef4444; }

.btn-send-seq { background: var(--primary-color); color: #fff; border: none; width: 38px; height: 38px; border-radius: 50%; cursor: pointer; display: flex; justify-content: center; align-items: center; transition: 0.2s; font-size: 16px; margin-left: 5px; }
.btn-send-seq:hover { background: #008f6f; transform: scale(1.05); }
.btn-send-seq:disabled { background: #ccc; cursor: not-allowed; transform: none; }

.seq-input { width: 100%; padding: 12px; border: 1px solid #ccc; border-radius: 8px; margin-bottom: 15px; font-size: 15px; outline: none; }
.seq-input:focus { border-color: var(--primary-color); }

.seq-items-container { display: flex; flex-direction: column; gap: 10px; margin-bottom: 15px; flex: 1; overflow-y: auto; }
.seq-item { background: #fff; border-radius: 8px; padding: 12px; box-shadow: 0 1px 2px rgba(0,0,0,0.1); position: relative; border-left: 4px solid var(--primary-color); }
.seq-item-remove { position: absolute; top: -8px; right: -8px; background: #ff4a4a; color: white; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 12px; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.seq-item-remove:hover { background: #e00000; }
.seq-item-text { width: 100%; min-height: 80px; padding: 10px; border: 1px solid #eee; border-radius: 6px; resize: vertical; font-size: 14px; outline: none; background: #fafafa; }
.seq-item-text:focus { border-color: #ccc; background: #fff; }
.seq-item-media { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--text-secondary); }
.seq-item-media img { width: 50px; height: 50px; object-fit: cover; border-radius: 6px; }

.seq-actions { display: flex; gap: 15px; margin-bottom: 15px; justify-content: center; }
.seq-actions button, .seq-actions label { background: #fff; border: 1px solid #ddd; width: 45px; height: 45px; border-radius: 50%; display: flex; justify-content: center; align-items: center; cursor: pointer; color: #54656f; font-size: 18px; transition: 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.seq-actions button:hover, .seq-actions label:hover { background: #f0f2f5; border-color: #ccc; color: var(--primary-color); }

.seq-footer { display: flex; gap: 10px; margin-top: auto; }
.btn-cancel, .btn-save { flex: 1; padding: 12px; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 15px; transition: 0.2s; }
.btn-cancel { background: #fff; border: 1px solid #ccc; color: #54656f; }
.btn-cancel:hover { background: #f0f2f5; }
.btn-save { background: var(--primary-color); color: #fff; }
.btn-save:hover { background: #008f6f; }
.btn-save:disabled { opacity: 0.7; cursor: not-allowed; }

@media (max-width: 768px) {
    .tools-panel { width: 100%; }
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 3px; }

/* Auth / Login & Settings */
.login-screen { position: fixed; top:0; left:0; width:100%; height:100%; background: linear-gradient(135deg, #f5f7fb 0%, #e5eaf0 100%); display:flex; justify-content:center; align-items:center; z-index: 1000; }

.auth-container { display: flex; width: 900px; max-width: 95%; height: 550px; background: #fff; border-radius: 20px; box-shadow: 0 15px 35px rgba(0,0,0,0.1); overflow: hidden; }
.auth-left { flex: 1; background: linear-gradient(135deg, var(--primary-color) 0%, #008f6f 100%); color: white; padding: 50px; display: flex; flex-direction: column; justify-content: center; position: relative; }
.auth-left::after { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"); opacity: 0.5; pointer-events: none; }
.auth-left-content { position: relative; z-index: 1; }
.auth-left h1 { font-size: 32px; margin-bottom: 15px; font-weight: 700; }
.auth-left p { font-size: 16px; opacity: 0.9; margin-bottom: 40px; line-height: 1.5; }
.auth-features { display: flex; flex-direction: column; gap: 20px; }
.feature-item { display: flex; align-items: center; font-size: 16px; font-weight: 500; }
.feature-item i { background: rgba(255,255,255,0.2); width: 40px; height: 40px; display: flex; justify-content: center; align-items: center; border-radius: 50%; margin-right: 15px; font-size: 18px; }
.auth-right { flex: 1; display: flex; justify-content: center; align-items: center; padding: 40px; background: #fff; }
.auth-box { width: 100%; max-width: 320px; }
.auth-header { text-align: center; margin-bottom: 30px; }
.auth-header h2 { font-size: 24px; color: var(--text-primary); margin-bottom: 5px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.auth-header p { color: var(--text-secondary); font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 15px; }
.input-group { position: relative; }
.input-group i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: #a0aeb7; font-size: 16px; }
.input-group input { width: 100%; padding: 14px 15px 14px 45px; border: 1px solid #e0e5e9; border-radius: 10px; font-size: 15px; outline: none; transition: 0.3s; background: #f9fbfd; }
.input-group input:focus { border-color: var(--primary-color); background: #fff; box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.1); }
.btn-auth { width: 100%; padding: 14px; background: var(--primary-color); color: #fff; border: none; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 16px; transition: 0.3s; margin-top: 10px; box-shadow: 0 4px 10px rgba(0, 168, 132, 0.2); }
.btn-auth:hover { background: #008f6f; transform: translateY(-2px); box-shadow: 0 6px 15px rgba(0, 168, 132, 0.3); }
.auth-switch { text-align: center; font-size: 14px; color: var(--text-secondary); margin-top: 15px; }
.auth-switch a { color: var(--primary-color); text-decoration: none; font-weight: 600; transition: 0.2s; }
.auth-switch a:hover { text-decoration: underline; }
.auth-error { color: #ef4444; font-size: 13px; margin-top: 15px; text-align: center; background: #fee2e2; padding: 10px; border-radius: 8px; display: none; }

@media (max-width: 768px) {
    .auth-container { flex-direction: column; height: auto; max-height: 90vh; overflow-y: auto; }
    .auth-left { padding: 30px; }
    .auth-features { display: none; }
    .auth-left p { margin-bottom: 0; }
}

.settings-overlay { position: fixed; top:0; left:0; width:100%; height:100%; background: rgba(0,0,0,0.6); z-index: 200; display:flex; justify-content:center; align-items:center; }
.settings-box { background: #fff; width: 500px; max-width: 95%; max-height: 90%; border-radius: 8px; display:flex; flex-direction:column; overflow:hidden; }
.settings-header { display:flex; justify-content:space-between; align-items:center; padding: 15px 20px; background: var(--header-bg); border-bottom: 1px solid var(--border-color); }
.settings-header button { background:none; border:none; font-size:20px; color:#555; cursor:pointer; }
.settings-tabs { display:flex; border-bottom: 1px solid #ddd; }
.setting-tab { flex:1; text-align:center; padding:12px; cursor:pointer; font-weight:500; color:#555; }
.setting-tab.active { border-bottom: 3px solid var(--primary-color); color: var(--primary-color); }
.settings-content { padding: 20px; flex:1; overflow-y:auto; }
.settings-content label { display:block; font-size:13px; color:#555; margin-bottom:5px; font-weight:500; }
.settings-content input { width:100%; padding:10px; margin-bottom:15px; border:1px solid #ddd; border-radius:5px; outline:none; }
.btn-primary { background: var(--primary-color); color:#fff; border:none; padding:10px 15px; border-radius:5px; cursor:pointer; font-weight:500; width:100%; }
.btn-secondary { background: #f0f2f5; color:#555; border:1px solid #ddd; padding:10px 15px; border-radius:5px; cursor:pointer; font-weight:500; width:100%; }
.btn-small { padding: 5px 10px; border-radius:3px; border:none; cursor:pointer; font-size:12px; }

/* Animations */
.animate-enter {
    animation: slideInUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes slideInUp {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

/* IA Badge & Toggle */
.ia-badge {
    background: #e7f3ff;
    color: #0080ff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    text-transform: uppercase;
}
.ia-badge.active {
    background: #d9fdd3;
    color: #00a884;
}

.header-ia-toggle {
    width: 36px !important;
    height: 36px !important;
    border-radius: 50% !important;
    background: #f0f2f5 !important;
    display: flex !important;
    justify-content: center;
    align-items: center;
    margin-left: 5px !important;
    transition: 0.2s;
}
.header-ia-toggle.active {
    background: var(--primary-color) !important;
    color: white !important;
}
.header-ia-toggle:hover {
    background: #e1e4e7 !important;
}

/* Unread Badge */
.contact-msg-wrapper {
    display: flex; justify-content: space-between; align-items: center;
}
.unread-badge {
    background-color: #25D366; color: #fff; font-size: 12px; font-weight: bold;
    border-radius: 50%; min-width: 20px; height: 20px; display: flex;
    justify-content: center; align-items: center; padding: 0 6px;
    margin-left: 10px;
}

/* Chat Actions Dropdown */
.dropdown-menu {
    position: absolute; right: 0; top: 100%; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    border-radius: 8px; overflow: hidden; z-index: 100; min-width: 150px;
}
.dropdown-menu a {
    display: block; padding: 12px 16px; text-decoration: none; color: var(--text-primary); font-size: 14px; transition: 0.2s;
}
.dropdown-menu a:hover { background: #f0f2f5; }
.dropdown-menu a i { margin-right: 8px; width: 16px; text-align: center; }

/* Custom Audio Player */
.custom-audio-player {
    display: flex; align-items: center; background: #f0f2f5; border-radius: 20px; padding: 5px 10px; width: 220px; gap: 8px;
}
.play-pause-btn { background: var(--primary-color) !important; color: white !important; width: 30px; height: 30px; border-radius: 50%; display: flex; justify-content: center; align-items: center; margin-left:0 !important; transition: 0.2s; }
.progress-wrapper { flex: 1; height: 6px; background: #ddd; border-radius: 3px; cursor: pointer; position: relative; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: var(--primary-color); }
.time-display { font-size: 11px; color: var(--text-secondary); min-width: 35px; text-align: right; }

/* Image tweaks */
.msg-image { max-width: 100%; max-height: 250px; border-radius: 6px; margin-bottom: 8px; display: block; cursor: pointer; transition: transform 0.2s; }
.msg-image:hover { transform: scale(1.02); }

/* Image Modal */
.image-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); z-index: 9999; display: flex; justify-content: center; align-items: center; opacity: 0; animation: fadeIn 0.3s forwards; }
@keyframes fadeIn { to { opacity: 1; } }
.image-modal-content { position: relative; max-width: 90%; max-height: 90%; display: flex; flex-direction: column; align-items: center; gap: 15px; }
.image-modal-content img { max-width: 100%; max-height: 80vh; object-fit: contain; border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.5); }
.close-image-modal { position: absolute; top: -40px; right: 0; background: none; border: none; color: white; font-size: 30px; cursor: pointer; }
.download-btn { background: var(--primary-color); color: white; padding: 10px 20px; border-radius: 20px; text-decoration: none; font-weight: 500; font-size: 14px; transition: 0.2s; }
.download-btn:hover { background: #008f6f; }