/* --- Global Resets & Body --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Roboto', 'Segoe UI', Arial, sans-serif;
    background: #f0f2f5;
    color: #333;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    touch-action: manipulation;
}

.app-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #f0f2f5;
    position: relative;
}

/* --- Sidebar Styles --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 0 0 20px rgba(0,0,0,0.2);
}

.sidebar.active {
    transform: translateX(0);
}

.sidebar-header {
    padding: 15px;
    background: #075e54;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    height: 60px;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
}

.user-name {
    font-weight: 500;
    font-size: 18px;
    color: white;
}

/* RESTORED: Icon Button Style */
.icon-btn {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Search Box --- */
.search-box {
    padding: 10px 15px;
    background: #075e54;
    flex-shrink: 0;
}

.search-container {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-container input {
    border: none;
    outline: none;
    width: 100%;
    font-size: 14px;
    background: transparent;
    color: white;
}

/* --- Compact Conversations List --- */
.conversations-list {
    flex: 1;
    overflow-y: auto;
    background: white;
}

.conversation-item {
    display: flex;
    padding: 8px 12px; /* Compact padding */
    gap: 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f2f5;
    min-height: 60px; /* Compact height */
    align-items: center;
}

.conversation-item.active {
    background: #e0f7f4;
}

.conversation-avatar img {
    width: 44px; /* Slightly smaller for compact look */
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
}

.conversation-info {
    flex: 1;
    min-width: 0;
}

.conversation-name {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conversation-name h3 {
    font-size: 14px;
    margin: 0;
}

/* --- Toggle Switch Styles --- */
.switch { position: relative; display: inline-block; width: 34px; height: 18px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; transition: .4s; border-radius: 34px;
}
.slider:before {
    position: absolute; content: ""; height: 12px; width: 12px; left: 3px; bottom: 3px;
    background-color: white; transition: .4s; border-radius: 50%;
}
input:checked + .slider { background-color: #25D366; }
input:checked + .slider:before { transform: translateX(16px); }

/* --- Chat Container & Header --- */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f0f2f5;
}

.chat-header {
    background: #075e54;
    padding: 0 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
    height: 70px; /* Adjusted for two-line info */
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 5px;
    flex: 1;
    min-width: 0;
}

.chat-contact-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

.contact-name {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.contact-status {
    font-size: 12px;
    opacity: 0.9;
    display: block;
    line-height: 1.2;
}

.back-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    padding: 10px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background-image: url('https://i.pinimg.com/originals/8f/ba/cb/8fbacbd464e496c80a6b63fdcb6c7a3a.jpg');
    background-size: cover;
    background-attachment: fixed;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}

/* --- Global AI & Routing Cards --- */
.global-ai-card {
    background: white; padding: 30px; border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1); margin: 0 auto; max-width: 400px;
    border-top: 5px solid #075e54;
}

.status-badge {
    display: inline-block; padding: 8px 20px; border-radius: 50px;
    font-size: 1.2rem; font-weight: bold; margin: 15px 0;
}
.status-active { background: #e8f5e9; color: #2e7d32; border: 2px solid #2e7d32; }
.status-off { background: #ffebee; color: #c62828; border: 2px solid #c62828; }

.btn-toggle-system {
    width: 100%; padding: 15px; border: none; border-radius: 8px;
    font-weight: bold; cursor: pointer; transition: 0.3s;
}
.btn-on { background: #25D366; color: white; }
.btn-off { background: #ff5252; color: white; }

.routing-group { display: flex; flex-direction: column; gap: 8px; }
.routing-group button {
    padding: 12px; border-radius: 8px; border: 1px solid #ddd;
    background: #f5f5f5; cursor: pointer; font-weight: 600;
}
.routing-group button.active { background: #25D366; color: white; border-color: #25D366; }

/* --- Full-Width Martha Input Area --- */
.chat-input-container {
    width: 100%;
    background: #f0f2f5;
}

.message-input-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    width: 100%;
    box-sizing: border-box;
    border-top: 1px solid #ddd;
}

#manual-message-input {
    flex: 1;
    padding: 12px 18px;
    border-radius: 25px;
    border: 1px solid #ccc;
    outline: none;
    font-size: 15px;
    background: white;
}

#manual-message-input:disabled {
    background: #e9ecef;
    color: #999;
}

#send-manual-btn {
    flex-shrink: 0;
    background: #075e54;
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

/* --- Messages --- */
.message {
    min-width: 260px; max-width: 85%; padding: 10px 12px; border-radius: 18px; line-height: 1.4; font-size: 14px;

}
.message.sent { background: #dcf8c6; align-self: flex-end; border-bottom-right-radius: 5px; }
.message.received { background: white; align-self: flex-start; border-bottom-left-radius: 5px; }
/* NEW: Human (Martha) color - Soft Blue */
.message.human { 
    background: #e3f2fd; 
    align-self: flex-end; 
    border-bottom-right-radius: 2px; 
    border: 1px solid #bbdefb;
}
.message-time { font-size: 10px; color: #54656f; text-align: right; margin-top: 5px; }

/* --- Toast Notifications --- */
#toast-container { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); z-index: 9999; }
.toast {
    background: #333; color: white; padding: 12px 25px; border-radius: 30px;
    margin-top: 10px; box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    animation: fadeInUp 0.3s ease-out;
}

/* --- Responsive Layout --- */
@media (min-width: 768px) {
    .app-container { flex-direction: row; }
    .sidebar { position: relative; width: 350px; transform: none; box-shadow: 1px 0 5px rgba(0,0,0,0.1); }
    .back-btn { display: none !important; }
}

@media (max-width: 767px) {
    .sidebar-header, .chat-header { height: 60px; }
    .back-btn { display: flex !important; }
}

@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* Styling for clickable links in chat */
.chat-link {
    color: #0275d8;
    text-decoration: underline;
    word-break: break-all;
    font-size: 13px;
    display: inline-block;
    margin-top: 5px;
}

/* Styling if you decide to use the thumbnail preview (Option B) */
.chat-thumbnail {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    margin-top: 8px;
    cursor: pointer;
    border: 1px solid #ddd;
    display: block;
}

/* Media Containers */
.media-container {
    margin-bottom: 8px;
    display: block;
    max-width: 100%;
}

.chat-thumbnail {
    max-width: 100%;
    max-height: 250px;
    border-radius: 10px;
    cursor: pointer;
    display: block;
    object-fit: cover;
}

.chat-video {
    max-width: 100%;
    border-radius: 10px;
    max-height: 250px;
}

.chat-document {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,0.05);
    padding: 10px;
    border-radius: 8px;
    text-decoration: none;
    color: #075e54;
    font-weight: 500;
    font-size: 13px;
}

.chat-document i {
    font-size: 20px;
}

.chat-audio {
    width: 100%;       /* Allow it to fill the bubble width */
    max-width: 240px;  /* But don't let it get too huge */
    height: 40px;
    outline: none;
}
