/* ==========================================
   Atende360 — Premium Dark Theme CSS
   ========================================== */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-tertiary: #242836;
    --bg-card: #1e2231;
    --accent-primary: #25D366;
    --accent-secondary: #128C7E;
    --accent-gradient: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    --text-primary: #e8eaed;
    --text-secondary: #9aa0a6;
    --text-muted: #5f6368;
    --border-color: #2d3240;
    --danger: #ff4757;
    --warning: #ffa502;
    --success: #25D366;
    --info: #3498db;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body.atende360-body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

/* ==================== Layout ==================== */
.app-wrapper {
    display: flex;
    height: 100vh;
}

/* ==================== Sidebar ==================== */
.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    z-index: 100;
}

.sidebar.collapsed {
    width: 72px;
}

.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-link-sidebar span,
.sidebar.collapsed .sidebar-footer span {
    display: none;
}

.sidebar-brand {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.brand-icon {
    font-size: 28px;
    color: var(--accent-primary);
}

.brand-text {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.brand-accent {
    color: var(--accent-primary);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-link-sidebar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
}

.nav-link-sidebar:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-link-sidebar.active {
    background: rgba(37, 211, 102, 0.12);
    color: var(--accent-primary);
}

.nav-link-sidebar i {
    width: 20px;
    text-align: center;
    font-size: 16px;
}

/* SuperAdmin submenu */
.sa-submenu {
    padding-left: 16px;
    border-left: 2px solid rgba(37, 211, 102, 0.2);
    margin-left: 24px;
}
.sa-subitem {
    padding: 8px 14px !important;
    font-size: 13px;
}
.sa-subitem i {
    font-size: 13px !important;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid var(--border-color);
}

/* ==================== Main Content ==================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: var(--transition);
}

.main-content.expanded {
    margin-left: 0;
}

/* ==================== Topbar ==================== */
.topbar {
    height: 64px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
}

.btn-toggle-sidebar {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.btn-toggle-sidebar:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.topbar-title {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-name {
    font-size: 14px;
    color: var(--text-secondary);
}

.user-avatar {
    font-size: 28px;
    color: var(--accent-primary);
}

/* ==================== Content Area ==================== */
.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ==================== Cards ==================== */
.card-dark {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.card-dark:hover {
    box-shadow: var(--shadow-md);
    border-color: rgba(37, 211, 102, 0.2);
}

/* ==================== Stat Cards ==================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent-gradient);
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent-primary);
    line-height: 1;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 6px;
    font-weight: 500;
}

.stat-card.danger::before {
    background: linear-gradient(135deg, #ff4757 0%, #ff6b81 100%);
}

.stat-card.danger .stat-value {
    color: var(--danger);
}

/* ==================== Login ==================== */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
    background-image: radial-gradient(circle at 30% 50%, rgba(37, 211, 102, 0.06) 0%, transparent 50%),
                      radial-gradient(circle at 70% 80%, rgba(18, 140, 126, 0.04) 0%, transparent 50%);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo i {
    font-size: 48px;
    color: var(--accent-primary);
    display: block;
    margin-bottom: 12px;
}

.login-logo h2 {
    font-weight: 700;
    font-size: 24px;
}

.form-group-dark {
    margin-bottom: 20px;
}

.form-group-dark label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-control-dark {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition);
}

.form-control-dark:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

.btn-primary-dark {
    width: 100%;
    padding: 14px;
    background: var(--accent-gradient);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.btn-primary-dark:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.login-error {
    background: rgba(255, 71, 87, 0.1);
    border: 1px solid rgba(255, 71, 87, 0.3);
    border-radius: var(--radius-sm);
    padding: 12px;
    color: var(--danger);
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
}

/* ==================== Chat Layout ==================== */
.chat-layout {
    display: flex;
    height: calc(100vh - 64px);
    gap: 0;
}

.chat-sidebar {
    width: 360px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.chat-sidebar-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
}

.chat-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-tertiary);
    padding: 4px;
    border-radius: var(--radius-sm);
}

.chat-tab {
    flex: 1;
    padding: 8px 12px;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.chat-tab.active {
    background: var(--accent-primary);
    color: #fff;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2px;
}

.chat-item:hover {
    background: var(--bg-tertiary);
}

.chat-item.active {
    background: rgba(37, 211, 102, 0.1);
    border: 1px solid rgba(37, 211, 102, 0.2);
}

.chat-item-avatar {
    width: 44px;
    height: 44px;
    background: var(--accent-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-item-info {
    flex: 1;
    min-width: 0;
}

.chat-item-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-preview {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-badge {
    background: var(--accent-primary);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
}

/* ==================== Chat Panel ==================== */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.chat-panel-header {
    height: 64px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
}

.chat-panel-actions {
    display: flex;
    gap: 8px;
}

.btn-chat-action {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.btn-chat-action:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.btn-chat-action.danger:hover {
    border-color: var(--danger);
    color: var(--danger);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-bubble {
    max-width: 60%;
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.5;
    animation: fadeInUp 0.3s ease;
}

.message-bubble.incoming {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message-bubble.outgoing {
    background: var(--accent-secondary);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    position: relative;
}

/* Wrapper para alinhar bolha + botão de opções */
.message-bubble-wrapper {
    display: flex;
    flex-direction: column;
}
.message-bubble-wrapper.outgoing-wrapper {
    align-items: flex-end;
}
.message-bubble-wrapper.incoming-wrapper {
    align-items: flex-start;
}

/* Botão chevron que aparece ao hover na mensagem enviada */
.msg-options-btn {
    display: none;
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0,0,0,0.18);
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    cursor: pointer;
    color: #fff;
    font-size: 11px;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    z-index: 10;
}
.message-bubble.outgoing:hover .msg-options-btn {
    display: flex;
}

/* Dropdown do menu de opções */
.msg-options-menu {
    position: absolute;
    top: 28px;
    right: 0;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.18);
    z-index: 100;
    min-width: 160px;
    overflow: hidden;
}
.msg-options-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    color: #e53935;
    text-align: left;
}
.msg-options-menu button:hover {
    background: #ffeaea;
}

/* Bolha de mensagem apagada */
.message-bubble.deleted-msg {
    background: var(--bg-tertiary) !important;
    color: var(--text-muted) !important;
    font-style: italic;
    border: 1px solid var(--border-color);
}
.message-bubble.outgoing.deleted-msg {
    background: rgba(0,0,0,0.08) !important;
    color: rgba(255,255,255,0.5) !important;
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.message-bubble.outgoing .message-time {
    color: rgba(255,255,255,0.6);
}

.message-attachment {
    margin-top: 6px;
}

.message-attachment a {
    color: var(--accent-primary);
    font-size: 12px;
}

.message-media {
    margin-bottom: 6px;
}

.message-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
    display: block;
}

.message-image:hover {
    transform: scale(1.02);
    opacity: 0.9;
}

/* ==================== Image Lightbox ==================== */
.lightbox-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 16px;
    cursor: pointer;
}

.lightbox-img {
    max-width: 90vw;
    max-height: 80vh;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    cursor: default;
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 24px;
    font-size: 36px;
    color: #fff;
    cursor: pointer;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.lightbox-close:hover {
    opacity: 1;
}

.lightbox-download {
    padding: 8px 20px;
    background: var(--accent-gradient);
    color: #fff;
    border-radius: 20px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.lightbox-download:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.message-video {
    max-width: 320px;
    max-height: 300px;
    border-radius: 8px;
}

.message-media audio {
    width: 100%;
    max-width: 280px;
}

.message-bubble.outgoing .message-attachment a {
    color: rgba(255,255,255,0.85);
}

/* ==================== Media Side Panel ==================== */
.media-panel {
    width: 300px;
    min-width: 300px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.media-panel-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.media-panel-header h4 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.media-panel-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.media-panel-close:hover {
    color: var(--text-primary);
}

.media-panel-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.media-panel-item {
    margin-bottom: 4px;
}

.media-panel-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-primary);
    transition: var(--transition);
}

.media-panel-link:hover {
    background: var(--bg-tertiary);
}

.media-panel-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.media-panel-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: 6px;
    font-size: 18px;
    flex-shrink: 0;
}

.media-panel-info {
    flex: 1;
    min-width: 0;
}

.media-panel-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.media-panel-meta {
    font-size: 11px;
    color: var(--text-muted);
}

/* ==================== Chat Input ==================== */
.chat-input-area {
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-input {
    flex: 1;
    padding: 12px 18px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

.chat-input:focus {
    border-color: var(--accent-primary);
}

.btn-send {
    width: 44px;
    height: 44px;
    background: var(--accent-gradient);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: var(--transition);
}

.btn-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.btn-attach {
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 18px;
    border-radius: 50%;
    transition: var(--transition);
}

.btn-attach:hover {
    color: var(--accent-primary);
    background: var(--bg-tertiary);
}

/* Microphone button */
.btn-mic {
    width: 40px;
    height: 40px;
    background: transparent;
    border: 1px solid rgba(37, 211, 102, 0.3);
    border-radius: 50%;
    color: var(--accent-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: var(--transition);
}

.btn-mic:hover {
    background: rgba(37, 211, 102, 0.1);
    border-color: var(--accent-primary);
}

.btn-mic.recording {
    background: #e53e3e;
    border-color: #e53e3e;
    color: #fff;
    width: auto;
    padding: 0 14px;
    border-radius: 20px;
    font-size: 13px;
    gap: 6px;
    animation: pulse-recording 1.5s ease-in-out infinite;
}

@keyframes pulse-recording {
    0%, 100% { box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(229, 62, 62, 0); }
}

/* Icon buttons (emoji, quick replies) */
.btn-icon {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: var(--transition);
    flex-shrink: 0;
}

.btn-icon:hover {
    color: var(--accent-primary);
    background: var(--bg-tertiary);
}

/* Custom tooltips for action buttons */
.btn-icon, .btn-attach, .btn-mic, .btn-send {
    position: relative;
}

.btn-icon::after, .btn-attach::after, .btn-mic::after, .btn-send::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.85);
    color: #fff;
    font-size: 11px;
    font-weight: 500;
    padding: 5px 10px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    margin-bottom: 6px;
    z-index: 10;
}

.btn-icon:hover::after, .btn-attach:hover::after, .btn-mic:hover::after, .btn-send:hover::after {
    opacity: 1;
}

/* Picker panels (emoji + quick replies) */
.picker-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 12px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    max-height: 180px;
    overflow-y: auto;
}

.emoji-item {
    font-size: 22px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    transition: var(--transition);
}

.emoji-item:hover {
    background: var(--bg-tertiary);
    transform: scale(1.2);
}

/* Quick reply items */
.quick-reply-item {
    width: 100%;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.quick-reply-item:hover {
    background: var(--bg-tertiary);
}

.qr-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-primary);
}

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

/* Tab badges (counters) */
.tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: #e53e3e;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    margin-left: 6px;
}

/* Waiting session highlight */
.chat-item-waiting {
    border-left: 3px solid #ffa500;
}

/* ==================== Empty State ==================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 16px;
}

.empty-state i {
    font-size: 64px;
    opacity: 0.3;
}

.empty-state p {
    font-size: 16px;
}

/* ==================== Tables ==================== */
.table-dark-custom {
    width: 100%;
    border-collapse: collapse;
}

.table-dark-custom th {
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.table-dark-custom td {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border-color);
}

.table-dark-custom tr:hover td {
    background: var(--bg-tertiary);
}

/* ==================== Badges ==================== */
.badge-status {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-active { background: rgba(37, 211, 102, 0.15); color: var(--success); }
.badge-waiting { background: rgba(255, 165, 2, 0.15); color: var(--warning); }
.badge-human { background: rgba(52, 152, 219, 0.15); color: var(--info); }
.badge-closed { background: rgba(95, 99, 104, 0.15); color: var(--text-muted); }
.badge-danger { background: rgba(255, 71, 87, 0.15); color: var(--danger); }

/* ==================== Animations ==================== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ==================== Scrollbar ==================== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ==================== V2: Session Timer ==================== */
.session-timer {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(37, 211, 102, 0.08);
    border: 1px solid rgba(37, 211, 102, 0.15);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: #25D366;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    transition: color 0.5s ease, border-color 0.5s ease;
}

.session-timer i {
    font-size: 12px;
}

/* ==================== V2: Sidebar Search ==================== */
.sidebar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.sidebar-search i {
    color: var(--text-muted);
    font-size: 13px;
}

.sidebar-search input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
}

.sidebar-search input::placeholder {
    color: var(--text-muted);
}

/* ==================== V2: Chat Search Bar ==================== */
.chat-search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.chat-search-bar input {
    flex: 1;
    padding: 8px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.3s;
}

.chat-search-bar input:focus {
    border-color: var(--accent-primary);
}

.chat-search-bar span {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.chat-search-bar button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
}

.chat-search-bar button:hover {
    color: var(--text-primary);
}

/* Message highlight from search */
.message-highlight {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    background: rgba(37, 211, 102, 0.05) !important;
    border-radius: var(--radius);
}

/* ==================== V2: Info Panel ==================== */
.info-panel {
    width: 320px;
    min-width: 320px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.info-panel-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.info-panel-header h4 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.info-panel-content {
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.info-avatar {
    width: 72px;
    height: 72px;
    background: var(--accent-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 28px;
    margin-bottom: 12px;
}

.info-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.info-phone {
    font-size: 13px;
    color: var(--accent-primary);
    cursor: pointer;
    margin-bottom: 8px;
}

.info-phone:hover {
    text-decoration: underline;
}

.info-divider {
    width: 100%;
    height: 1px;
    background: var(--border-color);
    margin: 14px 0;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 6px 0;
}

.info-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.info-value {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

.info-section-title {
    width: 100%;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.info-summary {
    width: 100%;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

.info-actions {
    display: flex;
    gap: 8px;
    width: 100%;
}

.info-action-btn {
    flex: 1;
    padding: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    text-align: center;
}

.info-action-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* ==================== V2: Notes Bar ==================== */
.notes-bar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(255, 165, 2, 0.05);
    border-top: 2px solid rgba(255, 165, 2, 0.3);
    animation: fadeInUp 0.2s ease;
}

.notes-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    color: #ffa502;
}

.notes-header button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
}

.notes-bar textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid rgba(255, 165, 2, 0.2);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    outline: none;
    transition: border-color 0.3s;
}

.notes-bar textarea:focus {
    border-color: #ffa502;
}

.notes-save-btn {
    align-self: flex-end;
    padding: 6px 16px;
    background: rgba(255, 165, 2, 0.15);
    border: 1px solid rgba(255, 165, 2, 0.3);
    border-radius: var(--radius-sm);
    color: #ffa502;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.notes-save-btn:hover {
    background: rgba(255, 165, 2, 0.25);
}

/* ==================== V2: Text Formatting ==================== */
.msg-code-block {
    display: block;
    background: rgba(0,0,0,0.3);
    padding: 8px 12px;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    margin: 4px 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.msg-code-inline {
    background: rgba(0,0,0,0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.msg-link {
    color: #7dd3fc !important;
    text-decoration: underline;
    word-break: break-all;
}

.message-bubble.outgoing .msg-link {
    color: #bfe6ff !important;
}

/* ==================== V2: Toast ==================== */
.app-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #00a884;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 13px;
    z-index: 9999;
    animation: fadeInUp 0.3s ease;
    box-shadow: 0 4px 16px rgba(0,168,132,0.3);
}

/* ==================== V2: Auto-resize Textarea ==================== */
.chat-input-area .chat-input {
    resize: none;
    overflow-y: auto;
    min-height: 44px;
    max-height: 120px;
    line-height: 1.4;
}

/* ==================== V2: Audio Transcription ==================== */
.transcription-block {
    background: rgba(155, 89, 182, 0.08);
    border-left: 3px solid #9b59b6;
    border-radius: 6px;
    padding: 8px 12px;
    margin-top: 4px;
}

.transcription-label {
    font-size: 11px;
    color: #9b59b6;
    font-weight: 600;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.transcription-text {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.4;
    font-style: italic;
}

/* ==================== RESPONSIVE — Tablet (≤1024px) ==================== */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        z-index: 1000;
        box-shadow: var(--shadow-lg);
        transition: left 0.3s ease;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.active {
        display: block;
    }

    .chat-sidebar {
        width: 300px;
    }

    .chat-panel-header {
        flex-wrap: wrap;
        height: auto;
        padding: 12px 16px;
        gap: 8px;
    }

    .chat-panel-actions {
        flex-wrap: wrap;
        gap: 6px;
    }

    .message-bubble {
        max-width: 75%;
    }

    .content-area {
        padding: 16px;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    }
}

/* ==================== RESPONSIVE — Mobile (≤768px) ==================== */
@media (max-width: 768px) {
    body.atende360-body {
        overflow: auto;
        height: 100%;
    }

    /* Navigation sidebar */
    .sidebar {
        width: 280px;
        left: -280px;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar.collapsed {
        width: 280px;
        left: -280px;
    }

    .sidebar.collapsed.open {
        left: 0;
    }

    .sidebar.collapsed .brand-text,
    .sidebar.collapsed .nav-link-sidebar span,
    .sidebar.collapsed .sidebar-footer span {
        display: inline;
    }

    /* Topbar */
    .topbar {
        padding: 0 12px;
        height: 56px;
    }

    .topbar-title {
        font-size: 16px;
    }

    .user-name {
        display: none;
    }

    /* Chat layout — Mobile stacked view */
    .chat-layout {
        flex-direction: column;
        height: calc(100vh - 56px);
        height: calc(100dvh - 56px);
    }

    .chat-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        flex: 1;
        min-height: 0;
    }

    /* When a chat is open, hide the sidebar and show panel */
    .chat-layout.chat-open .chat-sidebar {
        display: none;
    }

    .chat-layout.chat-open .chat-panel {
        display: flex;
        flex: 1;
    }

    .chat-panel {
        display: none;
        flex: 1;
        min-height: 0;
    }

    /* Back button for mobile chat */
    .btn-back-mobile {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border: none;
        background: var(--bg-tertiary);
        color: var(--text-primary);
        border-radius: 50%;
        font-size: 16px;
        cursor: pointer;
        flex-shrink: 0;
    }

    /* Chat panel header — mobile */
    .chat-panel-header {
        height: auto;
        min-height: 56px;
        padding: 10px 12px;
        gap: 10px;
    }

    .chat-panel-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .btn-chat-action {
        padding: 8px 12px;
        font-size: 11px;
    }

    .btn-chat-action i {
        margin-right: 0;
    }

    .btn-chat-action span.btn-text {
        display: none;
    }

    /* Messages */
    .chat-messages {
        padding: 12px;
        gap: 6px;
    }

    .message-bubble {
        max-width: 85%;
        padding: 8px 12px;
        font-size: 14px;
    }

    /* Input area */
    .chat-input-area {
        padding: 10px 12px;
        gap: 8px;
    }

    .chat-input {
        padding: 10px 14px;
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .btn-send {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }

    .btn-attach {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    /* Chat items */
    .chat-item {
        padding: 10px;
        gap: 10px;
    }

    .chat-item-avatar {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }

    .chat-item-name {
        font-size: 13px;
        display: flex;
        align-items: center;
    }

    .chat-item-preview {
        font-size: 11px;
    }

    .badge-status {
        font-size: 10px;
        padding: 3px 8px;
    }

    /* Login */
    .login-card {
        margin: 16px;
        padding: 32px 24px;
    }

    /* Stats */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-value {
        font-size: 24px;
    }

    .stat-label {
        font-size: 11px;
    }

    /* Tables — horizontal scroll */
    .card-dark {
        padding: 16px;
        overflow-x: auto;
    }

    /* Empty state */
    .empty-state i {
        font-size: 48px;
    }

    .empty-state p {
        font-size: 14px;
    }

    /* Transfer modal */
    .transfer-modal-content {
        width: 95vw !important;
        max-height: 80vh;
        overflow-y: auto;
    }
}

/* ==================== RESPONSIVE — Small phones (≤400px) ==================== */
@media (max-width: 400px) {
    .chat-panel-actions {
        flex-wrap: nowrap;
    }

    .btn-chat-action {
        padding: 6px 8px;
        font-size: 10px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        padding: 0 8px;
    }

    .login-card {
        padding: 24px 16px;
    }
}

/* ==================== Safe area (notch/dynamic island) ==================== */
@supports (padding-top: env(safe-area-inset-top)) {
    .topbar {
        padding-top: env(safe-area-inset-top);
    }

    .chat-input-area {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .sidebar {
        padding-top: env(safe-area-inset-top);
    }
}