:root {
    /* Tema Padrão (Light - Azul Profundo) */
    --primary-color: #0f172a;
    --secondary-color: #3b82f6;
    --accent-color: #10b981;
    --bg-color: #f8fafc;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --msg-sent-bg: #3b82f6;
    --msg-sent-text: #ffffff;
    --msg-received-bg: #ffffff;
    --msg-received-text: #1e293b;
    --header-gradient: linear-gradient(135deg, #0f172a, #1e293b);
    --danger-color: #e11d48;
    --warning-color: #92400e;
}

[data-theme="dark"] {
    --primary-color: #f8fafc;
    --secondary-color: #60a5fa;
    --accent-color: #34d399;
    --bg-color: #0f172a;
    --text-color: #f1f5f9;
    --text-muted: #94a3b8;
    --card-bg: #1e293b;
    --border-color: #334155;
    --msg-sent-bg: #2563eb;
    --msg-sent-text: #ffffff;
    --msg-received-bg: #1e293b;
    --msg-received-text: #f1f5f9;
    --header-gradient: linear-gradient(135deg, #020617, #0f172a);
    --danger-color: #fb7185;
    --warning-color: #fcd34d;
}

[data-theme="midnight"] {
    --primary-color: #c084fc;
    --secondary-color: #a855f7;
    --accent-color: #f472b6;
    --bg-color: #2e1065;
    --text-color: #faf5ff;
    --text-muted: #c084fc;
    --card-bg: #4c1d95;
    --border-color: #5b21b6;
    --msg-sent-bg: #7e22ce;
    --msg-sent-text: #ffffff;
    --msg-received-bg: #4c1d95;
    --msg-received-text: #faf5ff;
    --header-gradient: linear-gradient(135deg, #2e1065, #581c87);
    --danger-color: #fda4af;
    --warning-color: #fde68a;
}

/* --- GLOBAL OVERRIDES & TYPOGRAPHY --- */
body {
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
    font-family: 'Inter', -apple-system, sans-serif;
}

/* --- THEME-AWARE CLOSE BUTTONS --- */
.btn-close {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e") !important;
    opacity: 0.7;
    transition: all 0.2s ease;
    filter: none !important;
}

[data-theme="dark"] .btn-close,
[data-theme="midnight"] .btn-close,
.header-gradient .btn-close {
    filter: invert(1) grayscale(1) brightness(2) !important;
}

.btn-close:hover {
    opacity: 1;
    transform: scale(1.1);
}

.text-muted {
    color: var(--text-muted) !important;
}

label,
.form-label {
    color: var(--text-color);
    opacity: 0.85;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.4rem;
    display: block;
}

/* --- COMPONENTS --- */
.header-gradient {
    background: var(--header-gradient);
    color: white;
}

.text-primary-custom {
    color: var(--secondary-color) !important;
}

.bg-primary-custom {
    background-color: var(--secondary-color) !important;
}

.btn-primary-custom {
    background-color: var(--secondary-color);
    border-color: var(--secondary-color);
    color: white;
}

.btn-primary-custom:hover {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

.bg-card {
    background-color: var(--card-bg);
}

.border-custom {
    border-color: var(--border-color) !important;
}

/* Chat Bubbles */
.message-bubble {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 15px;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.msg-sent {
    background-color: var(--msg-sent-bg);
    color: var(--msg-sent-text);
    border-bottom-right-radius: 4px;
}

.msg-received {
    background-color: var(--msg-received-bg);
    color: var(--msg-received-text);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.msg-time {
    font-size: 0.65rem;
    opacity: 0.8;
    margin-top: 4px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.msg-tick {
    display: inline-flex;
    align-items: center;
}

.msg-tick.bi-clock {
    font-size: 0.75rem;
}

.msg-tick.bi-check,
.msg-tick.bi-check-all {
    font-size: 1.0rem;
    line-height: 0;
    margin-left: 6px;
}

.message-read-custom {
    color: #4ade80 !important;
    font-weight: bold;
}

.msg-sent .message-read-custom {
    color: #bbf7d0 !important;
}

/* FAB */
.fab-btn {
    position: absolute;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    z-index: 100;
    background-color: var(--accent-color) !important;
    border: none;
    color: #fff !important;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}

.fab-btn:active {
    transform: scale(0.95);
}

/* --- LAYOUTS --- */
html,
body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
}

#view-chat {
    height: 100dvh;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-color);
    position: relative;
}

#messages-container {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background-color: rgba(0, 0, 0, 0.02);
    min-height: 0;
    scroll-behavior: smooth;
}

#view-chat>.border-top {
    flex-shrink: 0;
    background-color: var(--card-bg);
    z-index: 10;
}

/* Animations */
.pulse-ring {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--secondary-color);
    animation: pulse 2s infinite;
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 20px rgba(59, 130, 246, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
    }
}

.bg-gradient-to-t-black {
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
}

/* --- FORMS --- */
.form-control-theme {
    background-color: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.form-control-theme:focus {
    background-color: var(--bg-color);
    color: var(--text-color);
    border-color: var(--secondary-color);
    box-shadow: none;
}

/* --- DISABLED & LOCKED STATES --- */
.form-control-theme:disabled,
.form-control-theme[readonly],
select.form-control-theme:disabled {
    background-color: rgba(0, 0, 0, 0.15) !important;
    color: var(--text-muted) !important;
    border-color: var(--border-color) !important;
    opacity: 0.7;
    cursor: not-allowed;
    box-shadow: none !important;
    /* Subtle glassmorphism */
    backdrop-filter: blur(2px);
}

/* Theme-specific overrides for disabled fields */
[data-theme="light"] .form-control-theme:disabled {
    background-color: #f1f5f9 !important;
}

[data-theme="dark"] .form-control-theme:disabled,
[data-theme="dark"] select.form-control-theme:disabled {
    background-color: rgba(0, 0, 0, 0.3) !important;
}

[data-theme="midnight"] .form-control-theme:disabled,
[data-theme="midnight"] select.form-control-theme:disabled {
    background-color: rgba(0, 0, 0, 0.4) !important;
}

/* Premium Badge Styling */
.lock-icon {
    font-size: 0.65rem !important;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 3px 10px !important;
    border-radius: 8px !important;
    transition: all 0.2s ease;
}

/* Placeholder visibility */
.form-control-theme::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

/* --- GALLERY --- */
.modal-gallery-container {
    width: 100%;
    aspect-ratio: 1 / 1;
    position: relative;
    background-color: #000;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.gallery-track {
    display: flex;
    width: 100%;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.gallery-track::-webkit-scrollbar {
    display: none;
}

.gallery-track img {
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    object-fit: cover;
    scroll-snap-align: center;
}

/* --- MODALS --- */
.modal-ios {
    border-radius: 20px !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5) !important;
    background-color: var(--card-bg) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow: hidden;
    z-index: 1050;
}

.modal-ios .modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
}

.modal-ios .btn-ios {
    border-radius: 12px;
    font-weight: 600;
    padding: 12px;
}

.report-radio-group .form-check {
    padding: 12px 12px 12px 35px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 8px;
    transition: background-color 0.2s;
}

.report-radio-group .form-check:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* --- OFFCANVAS --- */
.offcanvas.bg-card {
    background-color: var(--card-bg) !important;
}

.list-group-item.text-color {
    color: var(--text-color) !important;
}

.list-group-item:hover {
    background-color: rgba(0, 0, 0, 0.05) !important;
}

[data-theme="dark"] .list-group-item:hover,
[data-theme="midnight"] .list-group-item:hover {
    background-color: rgba(255, 255, 255, 0.05) !important;
}

/* --- DROPDOWNS & SUBMENUS --- */
.dropdown-menu {
    border: 1px solid var(--border-color) !important;
    background-color: var(--card-bg) !important;
    padding: 0.5rem 0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6) !important;
    border-radius: 12px !important;
    overflow: hidden;
    /* Force 100% solid background */
    opacity: 1 !important;
    z-index: 10000 !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

/* Base state for list items */
.chat-item {
    position: relative;
    z-index: 1;
}

/* Stacking context fix: ensures the chat-item with the open menu stays on top */
.chat-item:hover {
    z-index: 5 !important;
}

.chat-item .dropdown {
    z-index: 10;
}

.dropdown-header {
    color: var(--text-muted) !important;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 0.8rem 1.25rem 0.4rem 1.25rem;
    font-size: 0.7rem;
}

.dropdown-item {
    color: var(--text-color) !important;
    padding: 0.75rem 1.25rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    transition: all 0.2s ease;
}

.dropdown-item i {
    font-size: 1.15rem;
    margin-right: 12px;
    width: 20px;
    text-align: center;
}

.dropdown-item:hover {
    background-color: rgba(0, 0, 0, 0.04);
    color: var(--text-color);
}

[data-theme="dark"] .dropdown-item:hover,
[data-theme="midnight"] .dropdown-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.dropdown-item.text-danger {
    color: var(--danger-color) !important;
}

.dropdown-item.text-warning {
    color: var(--warning-color) !important;
}

.dropdown-divider {
    border-top: 1px solid var(--border-color);
    opacity: 0.5;
    margin: 0.5rem 0;
}

/* --- Z-INDEX & STACKING FIXES --- */
.chat-item {
    position: relative;
}

/* Ensure the chat-item containing the open dropdown stays on top of siblings */
.chat-item:has(.dropdown.show) {
    z-index: 1000 !important;
}

.dropdown-menu.show {
    z-index: 1100 !important;
}

/* --- NOTIFICATION SYSTEM (TOASTS) --- */
.r-toast-container {
    position: fixed;
    top: 25px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    pointer-events: none;
    width: 100%;
}

.r-toast {
    background: var(--card-bg);
    color: var(--text-color);
    padding: 8px 18px;
    border-radius: 50px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    font-size: 0.85rem;
    border: 1px solid var(--border-color);
    pointer-events: auto;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    max-width: fit-content;
    white-space: nowrap;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
}

.r-toast.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.r-toast.hide {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
    margin-top: -50px;
}

.r-toast i {
    font-size: 1.25rem;
}

.r-toast-success i {
    color: var(--secondary-color);
}

.r-toast-error i {
    color: var(--danger-color);
}

.r-toast-warning i {
    color: var(--warning-color);
}

.r-toast-info i {
    color: #3b82f6;
}

.r-toast-success {
    border-left: 3px solid #10b981 !important;
}

.r-toast-error {
    border-left: 3px solid #e11d48 !important;
}

.r-toast-warning {
    border-left: 3px solid #f59e0b !important;
}
/* Chat List Preview Sanitization */
.preview-msg {
    max-height: 1.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.preview-msg span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Camera UI Fixes */
.camera-controls {
    z-index: 9999 !important;
    pointer-events: auto !important;
}

.btn-circle-md {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
}

.btn-capture-active {
    border-color: #ff0000 !important;
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.7) !important;
}

@keyframes pulse-red {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.7); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 15px rgba(255, 0, 0, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 0, 0, 0); }
}

.pulse-animation {
    animation: pulse-red 1.5s infinite;
}

/* Ensure modal content takes full pointer priority */
#cameraModal .modal-content {
    pointer-events: auto !important;
}

.media-preview-bubble {
    max-width: 100px;
    max-height: 100px;
    object-fit: cover;
    display: block;
}

.media-container-preview {
    width: 100px;
    height: 100px;
    overflow: hidden;
    border-radius: 12px;
}

/* --- PARTNER GALLERY STYLES --- */
.modal-gallery-container {
    width: 100%;
    aspect-ratio: 1/1;
    overflow: hidden;
    border-radius: 24px;
    background: rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    position: relative;
}

.gallery-track {
    width: 100%;
    height: 100%;
    display: flex;
    position: relative;
}

.gallery-item {
    min-width: 100%;
    width: 100%;
    height: 100%;
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.gallery-item.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

.gallery-nav-btn {
    transition: all 0.2s ease;
    background: rgba(0, 0, 0, 0.5) !important;
    border: none !important;
    backdrop-filter: blur(5px);
}

.gallery-nav-btn:hover {
    background: rgba(0, 0, 0, 0.8) !important;
    transform: scale(1.1);
}

/* --- VOICE RECORDING --- */
.voice-record-pulse {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--danger-color);
    box-shadow: 0 0 0 0 rgba(225, 29, 72, 0.7);
    transition: all 0.3s ease;
}

.voice-recording-active {
    animation: voice-pulse-red 1.5s infinite;
}

@keyframes voice-pulse-red {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(225, 29, 72, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 20px rgba(225, 29, 72, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(225, 29, 72, 0); }
}

.voice-message-player {
    min-width: 200px;
    height: 40px;
    border-radius: 20px;
    outline: none;
}

.msg-sent .voice-message-player {
    filter: invert(1) hue-rotate(180deg) brightness(1.5);
}

.msg-received .voice-message-player {
    filter: brightness(0.9);
}

