/* ============================================================================
   RESET E VARIÁVEIS
   ============================================================================ */

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

:root {
    --primary-color: #25D366;
    --primary-dark: #128C7E;
    --secondary-color: #075E54;
    --accent-color: #34B7F1;
    --danger-color: #DC3545;
    --success-color: #28A745;
    --warning-color: #FFC107;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-light: #999999;
    --bg-primary: #FFFFFF;
    --bg-secondary: #F5F5F5;
    --bg-tertiary: #E5DDD5;
    --border-color: #DDDDDD;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ============================================================================
   HEADER
   ============================================================================ */

.header {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 30px 40px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-content h1 {
    font-size: 2.5rem;
    margin-bottom: 5px;
}

.header-content p {
    font-size: 1rem;
    opacity: 0.9;
}

.header-nav {
    display: flex;
    gap: 8px;
    align-items: center;
}

.header-nav a.active {
    background: rgba(255, 255, 255, 0.25);
    font-weight: 700;
}

.api-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--warning-color);
    animation: pulse 2s infinite;
}

.status-dot.online {
    background: var(--success-color);
    animation: none;
}

.status-dot.offline {
    background: var(--danger-color);
}

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

/* ============================================================================
   BUSCA
   ============================================================================ */

.search-section {
    background: var(--bg-primary);
    padding: 40px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 30px;
}

.search-box h2 {
    color: var(--secondary-color);
    margin-bottom: 10px;
}

.help-text {
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-size: 0.95rem;
}

.search-input-group {
    display: flex;
    gap: 15px;
}

#searchInput {
    flex: 1;
    padding: 15px 20px;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.3s ease;
}

#searchInput:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}

/* ============================================================================
   BOTÕES
   ============================================================================ */

.btn {
    padding: 15px 30px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: var(--accent-color);
    color: white;
}

.btn-secondary:hover {
    background: #2196F3;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.9rem;
}

/* ============================================================================
   RESULTADOS
   ============================================================================ */

.results-section {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================================
   LISTA DE CONTATOS
   ============================================================================ */

.contacts-list {
    background: var(--bg-primary);
    padding: 30px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.contacts-list h3 {
    color: var(--secondary-color);
    margin-bottom: 20px;
    font-size: 1.5rem;
}

#contactsContainer {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.contact-card {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
    cursor: pointer;
    transition: all 0.3s ease;
}

.contact-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    background: white;
}

.contact-card h4 {
    color: var(--secondary-color);
    margin-bottom: 10px;
    font-size: 1.2rem;
}

.contact-card p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin: 5px 0;
}

/* ============================================================================
   DETALHES DO CONTATO
   ============================================================================ */

.contact-details {
    background: var(--bg-primary);
    padding: 30px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.contact-details h3 {
    color: var(--secondary-color);
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.contact-info {
    background: var(--bg-secondary);
    padding: 25px;
    border-radius: 8px;
    margin-bottom: 30px;
}

.info-row {
    display: flex;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 150px;
}

.info-value {
    color: var(--text-primary);
}

/* ============================================================================
   TICKETS
   ============================================================================ */

.tickets-section {
    margin-top: 30px;
}

.tickets-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.ticket-filters {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.filter-label {
    font-weight: 600;
    color: var(--text-primary);
}

.tickets-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.tickets-table thead {
    background: var(--secondary-color);
    color: white;
}

.tickets-table th,
.tickets-table td {
    padding: 15px;
    text-align: left;
}

.tickets-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
}

.tickets-table tbody tr:hover {
    background: var(--bg-secondary);
}

.ticket-status {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.status-open {
    background: #E3F2FD;
    color: #1976D2;
}

.status-pending {
    background: #FFF3E0;
    color: #F57C00;
}

.status-closed {
    background: #E8F5E9;
    color: #388E3C;
}

/* ============================================================================
   MODAL
   ============================================================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    background: var(--secondary-color);
    color: white;
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.modal-body {
    padding: 30px;
    max-height: calc(80vh - 80px);
    overflow-y: auto;
}

/* ============================================================================
   MENSAGENS
   ============================================================================ */

.message {
    margin-bottom: 20px;
    padding: 15px;
    border-radius: 8px;
    max-width: 70%;
}

.message-outbound {
    background: #DCF8C6;
    margin-left: auto;
    border-bottom-right-radius: 0;
}

.message-inbound {
    background: white;
    margin-right: auto;
    border-bottom-left-radius: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.message-body {
    color: var(--text-primary);
    margin-bottom: 5px;
    word-wrap: break-word;
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-light);
    text-align: right;
}

.message-inbound .message-time {
    text-align: left;
}

/* Enhanced modal elements */
.modal-ticket-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    font-size: 0.85rem;
}

.modal-ticket-attendant {
    font-weight: 600;
    color: var(--text-primary);
}

.modal-ticket-dates {
    color: var(--text-light);
    font-size: 0.8rem;
}

/* Notes in modal */
.message-notes-section {
    margin-bottom: 16px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #e6d18a;
}

.message-notes-header {
    background: #fff9e6;
    padding: 10px 16px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
    color: #8a7530;
}

.message-notes-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.message-notes-section.expanded .message-notes-body {
    max-height: 400px;
    overflow-y: auto;
}

.message-note {
    padding: 10px 16px;
    background: #fffdf0;
    border-bottom: 1px solid #e6d18a;
}

.message-note:last-child {
    border-bottom: none;
}

.message-note-header {
    font-size: 0.8rem;
    color: #8a7530;
    font-weight: 600;
    margin-bottom: 4px;
}

.message-note-body {
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* Media in messages */
.message-media {
    margin-bottom: 8px;
}

.message-media img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.message-media img:hover {
    opacity: 0.9;
}

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

.message-file-link {
    display: inline-block;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    color: var(--accent-color);
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.message-file-link:hover {
    background: var(--border-color);
}

/* Attendant name in messages */
.message-attendant {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent-color);
    margin-bottom: 4px;
}

/* ============================================================================
   LOADING
   ============================================================================ */

.loading {
    text-align: center;
    padding: 40px;
}

.spinner {
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================================================
   EMPTY STATE
   ============================================================================ */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

/* ============================================================================
   ENVIO DE MENSAGENS
   ============================================================================ */

.send-message-section {
    margin: 30px 0;
    background: var(--bg-secondary);
    padding: 25px;
    border-radius: 8px;
}

.send-message-section h3 {
    color: var(--secondary-color);
    margin-bottom: 20px;
}

.message-composer {
    background: white;
    border-radius: 8px;
    padding: 20px;
}

#messageInput {
    width: 100%;
    padding: 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    min-height: 100px;
    transition: border-color 0.3s ease;
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary-color);
}

.composer-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    gap: 15px;
    flex-wrap: wrap;
}

.file-upload-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.file-name {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-style: italic;
}

.send-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-secondary);
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* ============================================================================
   TOAST NOTIFICATIONS
   ============================================================================ */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 300px;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideInRight 0.3s ease;
    border-left: 4px solid;
}

.toast.success {
    border-left-color: var(--success-color);
}

.toast.error {
    border-left-color: var(--danger-color);
}

.toast.info {
    border-left-color: var(--accent-color);
}

.toast.warning {
    border-left-color: var(--warning-color);
}

.toast-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.toast-message {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.toast-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-light);
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.toast-close:hover {
    background: var(--bg-secondary);
}

@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

.toast.hiding {
    animation: slideOutRight 0.3s ease forwards;
}

/* ============================================================================
   USER GREETING
   ============================================================================ */

.user-greeting {
    font-size: 0.9rem;
    opacity: 0.9;
    font-weight: 500;
}

/* ============================================================================
   DARK MODE (tela principal)
   ============================================================================ */

body.dark-mode {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    color: #e0e0e0;
}

.dark-mode {
    --primary-color: #25D366;
    --primary-dark: #128C7E;
    --secondary-color: #00bfa5;
    --accent-color: #64b5f6;
    --danger-color: #ef5350;
    --success-color: #66bb6a;
    --warning-color: #ffb74d;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-light: #808080;
    --bg-primary: #2d2d2d;
    --bg-secondary: #1e1e1e;
    --bg-tertiary: #1a1a1a;
    --border-color: #404040;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.dark-mode .header {
    background: linear-gradient(135deg, #1a1a1a 0%, #0a0a0a 100%);
    border: 1px solid #404040;
}

.dark-mode .header-nav a.active {
    background: rgba(255, 255, 255, 0.15);
}

.dark-mode .search-section,
.dark-mode .contacts-list,
.dark-mode .contact-details {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
}

.dark-mode .contact-card {
    background: var(--bg-secondary);
    border-left-color: var(--primary-color);
}

.dark-mode .contact-card:hover {
    background: var(--bg-primary);
}

.dark-mode .contact-info,
.dark-mode .send-message-section {
    background: var(--bg-secondary);
}

.dark-mode .message-composer,
.dark-mode #messageInput,
.dark-mode #searchInput {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.dark-mode .tickets-table {
    background: var(--bg-primary);
}

.dark-mode .tickets-table thead {
    background: #1a1a1a;
}

.dark-mode .tickets-table tbody tr:hover {
    background: var(--bg-secondary);
}

.dark-mode .modal-content {
    background: var(--bg-primary);
}

.dark-mode .modal-header {
    background: #1a1a1a;
}

.dark-mode .modal-body {
    background: var(--bg-primary);
}

.dark-mode .message-inbound {
    background: var(--bg-secondary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.dark-mode .message-outbound {
    background: #1e3a1e;
}

.dark-mode .toast {
    background: var(--bg-primary);
    border-color: var(--border-color);
}

.dark-mode .message-notes-section {
    border-color: #5a4f2a;
}

.dark-mode .message-notes-header {
    background: #3a3520;
    color: #d4c67a;
}

.dark-mode .message-note {
    background: #2d2a1e;
    border-color: #5a4f2a;
}

.dark-mode .message-note-header {
    color: #d4c67a;
}

.dark-mode .message-file-link {
    background: var(--bg-secondary);
    color: var(--accent-color);
}

/* ============================================================================
   GLOBAL SEARCH
   ============================================================================ */

.global-search-wrapper {
    position: relative;
}

.global-search-input {
    padding: 8px 14px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 0.85rem;
    width: 200px;
    transition: width 0.3s ease, background 0.2s ease;
}

.global-search-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.global-search-input:focus {
    outline: none;
    width: 280px;
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

.global-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    min-width: 300px;
    background: var(--bg-primary);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    margin-top: 4px;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
}

.gs-category {
    padding: 8px 14px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-light);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.gs-item {
    display: block;
    padding: 10px 14px;
    text-decoration: none;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s ease;
}

.gs-item:last-child {
    border-bottom: none;
}

.gs-item:hover {
    background: var(--bg-secondary);
}

.gs-item-title {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
}

.gs-item-sub {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.gs-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-light);
    font-size: 0.85rem;
}

/* ============================================================================
   RESPONSIVO
   ============================================================================ */

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .header {
        flex-direction: column;
        gap: 20px;
        padding: 20px;
    }

    .header-content h1 {
        font-size: 2rem;
    }

    .search-input-group {
        flex-direction: column;
    }

    #contactsContainer {
        grid-template-columns: 1fr;
    }

    .message {
        max-width: 85%;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
    }

    .composer-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .send-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .toast-container {
        right: 10px;
        left: 10px;
    }

    .toast {
        min-width: auto;
    }
}
