/* ============================================
   Zoho CRM ↔ Protheus Widget Styles
   ============================================ */

:root {
    --sidebar-width: 250px;
    --header-height: 56px;
    --primary-color: #0d6efd;
    --success-color: #198754;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --info-color: #0dcaf0;
}

body {
    font-size: 14px;
    background-color: #f8f9fa;
}

/* Header */
.navbar {
    height: var(--header-height);
    z-index: 1000;
}

/* Sidebar */
.sidebar {
    min-height: calc(100vh - var(--header-height));
    background-color: #fff;
    border-right: 1px solid #dee2e6;
    padding-top: 1rem;
}

.sidebar .nav-link {
    color: #495057;
    padding: 0.75rem 1rem;
    border-radius: 0.375rem;
    margin-bottom: 0.25rem;
    transition: all 0.2s;
}

.sidebar .nav-link:hover {
    background-color: #e9ecef;
    color: var(--primary-color);
}

.sidebar .nav-link.active {
    background-color: var(--primary-color);
    color: #fff;
    font-weight: 500;
}

.sidebar .nav-link i {
    width: 20px;
}

/* Main Content */
main {
    padding-top: 1.5rem;
    padding-bottom: 2rem;
}

/* Cards */
.card {
    border: 1px solid #dee2e6;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    transition: box-shadow 0.15s ease-in-out;
}

.card:hover {
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    font-weight: 600;
}

/* Status Badges */
.badge {
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
}

.badge i {
    font-size: 0.6rem;
    margin-right: 0.25rem;
}

/* Connection Status */
#connectionStatus .bi-circle-fill {
    animation: pulse 2s infinite;
}

#connectionStatus.connected .bi-circle-fill {
    color: var(--success-color);
    animation: none;
}

#connectionStatus.disconnected .bi-circle-fill {
    color: var(--danger-color);
}

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

/* Forms */
.form-label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: #495057;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.auth-fields {
    padding: 1rem;
    background-color: #f8f9fa;
    border-radius: 0.375rem;
    margin-top: 1rem;
}

/* Tables */
.table-responsive {
    border-radius: 0.375rem;
}

.table {
    margin-bottom: 0;
}

.table thead th {
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    color: #495057;
}

.table tbody tr {
    transition: background-color 0.15s ease-in-out;
}

.table tbody tr:hover {
    background-color: #f8f9fa;
}

/* Mapping Table */
.mapping-table {
    width: 100%;
}

.mapping-table .form-control,
.mapping-table .form-select {
    font-size: 0.875rem;
}

/* Searchable Select (Input com Datalist) */
.searchable-select {
    position: relative;
}

.searchable-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.searchable-select::placeholder {
    color: #6c757d;
    font-style: italic;
    font-size: 0.875rem;
}

/* Datalist styling - melhorar visualização das opções */
datalist {
    position: absolute;
    max-height: 200px;
    overflow-y: auto;
    background-color: white;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    z-index: 1000;
}

datalist option {
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out;
}

datalist option:hover {
    background-color: #f8f9fa;
}

.mapping-row {
    transition: background-color 0.2s;
}

.mapping-row:hover {
    background-color: #f8f9fa;
}

.mapping-row.new-row {
    background-color: #e7f3ff;
}

/* Buttons */
.btn {
    font-weight: 500;
    transition: all 0.2s;
}

.btn-sm {
    font-size: 0.875rem;
    padding: 0.25rem 0.75rem;
}

/* Toggle Switch */
.form-check-input {
    width: 3rem;
    height: 1.5rem;
    cursor: pointer;
}

.form-check-input:checked {
    background-color: var(--success-color);
    border-color: var(--success-color);
}

/* Skeleton Loaders */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 0.25rem;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
}

.skeleton-text:last-child {
    margin-bottom: 0;
    width: 60%;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-overlay .spinner-border {
    width: 3rem;
    height: 3rem;
}

/* Entity Tab Content */
.entity-section {
    margin-bottom: 2rem;
}

.entity-section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #495057;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #dee2e6;
}

/* Status Indicators */
.status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 0.5rem;
}

.status-indicator.enabled {
    background-color: var(--success-color);
}

.status-indicator.disabled {
    background-color: #6c757d;
}

.status-indicator.warning {
    background-color: var(--warning-color);
}

.status-indicator.error {
    background-color: var(--danger-color);
}

/* Logs Table */
#logsTableBody tr {
    font-size: 0.875rem;
}

.log-type-info {
    color: var(--info-color);
}

.log-type-success {
    color: var(--success-color);
}

.log-type-warning {
    color: var(--warning-color);
}

.log-type-error {
    color: var(--danger-color);
}

/* Toast Customization */
.toast {
    min-width: 300px;
}

.toast-header {
    font-weight: 600;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: -100%;
        width: var(--sidebar-width);
        height: calc(100vh - var(--header-height));
        transition: left 0.3s;
        z-index: 999;
        overflow-y: auto;
    }

    .sidebar.show {
        left: 0;
    }

    main {
        margin-left: 0;
    }
}

/* Utility Classes */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.dirty-indicator {
    color: var(--warning-color);
    font-size: 0.75rem;
    margin-left: 0.5rem;
}

/* Auto-map Button */
.btn-auto-map {
    position: relative;
}

.btn-auto-map .spinner-border-sm {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6c757d;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Validation States */
.is-invalid {
    border-color: var(--danger-color);
}

.is-valid {
    border-color: var(--success-color);
}

.invalid-feedback {
    display: block;
    font-size: 0.875rem;
    color: var(--danger-color);
}

/* Auth Overlay */
.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 2rem;
}

.auth-container {
    width: 100%;
    max-width: 500px;
}

.auth-container .card {
    border: none;
    border-radius: 1rem;
}

.auth-container .list-unstyled {
    text-align: left;
    display: inline-block;
}

.auth-container .list-unstyled li {
    margin: 0.25rem 0;
    font-size: 0.875rem;
}

/* Mapping Counter */
.mapping-counter {
    font-size: 0.875rem;
    color: #6c757d;
    margin-top: 0.5rem;
}

.mapping-counter.warning {
    color: var(--warning-color);
    font-weight: 600;
}

.mapping-counter.success {
    color: var(--success-color);
    font-weight: 600;
}

/* Entity Tabs - Corrigir espaçamento e altura */
.tab-content {
    min-height: 0 !important;
}

.tab-pane {
    min-height: 0 !important;
    padding-top: 0 !important;
}

.tab-pane:not(.show):not(.active) {
    display: none !important;
}

/* Garantir que sub-panes dentro de entity-parent-tab sejam visíveis quando ativos */
.entity-parent-tab .tab-content .tab-pane.show.active {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.entity-parent-tab .tab-content .tab-pane:not(.show):not(.active) {
    display: none !important;
}

.entity-tab-pane {
    min-height: 0 !important;
    height: auto !important;
    padding-top: 0 !important;
}

/* Garantir que tabs de entidades não herdam altura de tabs anteriores */
#entityTabsContainer {
    min-height: 0 !important;
}

#entityTabsContainer .tab-pane {
    min-height: 0 !important;
    height: auto !important;
}

.entity-content {
    min-height: 0 !important;
    height: auto !important;
}

/* Sub-abas e navegação hierárquica */
.sub-nav {
    list-style: none;
    padding-left: 0;
    margin-top: 0.25rem;
    margin-bottom: 0.5rem;
}

.sub-nav .nav-item {
    margin-bottom: 0.25rem;
}

.sub-nav-link {
    font-size: 0.9rem !important;
    padding: 0.5rem 1rem 0.5rem 2rem !important;
    color: #6c757d !important;
    display: block !important;
    width: 100% !important;
    text-align: left !important;
    border: none !important;
    background: transparent !important;
    text-decoration: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    font-weight: normal !important;
}

.sub-nav-link:hover {
    color: var(--primary-color) !important;
    background-color: #e9ecef !important;
}

.sub-nav-link.active {
    color: #fff !important;
    background-color: var(--primary-color) !important;
    font-weight: 500 !important;
}

.sub-nav-link:focus {
    outline: none;
    box-shadow: none;
}

/* Garantir que o texto dentro do sub-nav-link seja visível */
.sub-nav-link * {
    color: inherit !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.entity-parent-tab .nav-tabs {
    border-bottom: 2px solid #dee2e6;
    margin-bottom: 1rem;
}

.entity-parent-tab .nav-tabs .nav-link {
    color: #495057;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.5rem 1rem;
}

.entity-parent-tab .nav-tabs .nav-link:hover {
    border-bottom-color: #dee2e6;
}

.entity-parent-tab .nav-tabs .nav-link.active {
    color: #0d6efd;
    border-bottom-color: #0d6efd;
    background-color: transparent;
    font-weight: 500;
}

/* Entity Tabs - Corrigir espaçamento */
.entity-tab-pane {
    min-height: auto !important;
    padding-top: 0 !important;
}

.tab-content {
    min-height: auto;
}

.tab-pane {
    min-height: auto !important;
}

/* Garantir que tabs de entidades não herdam altura de tabs anteriores */
#entityTabsContainer .tab-pane {
    min-height: 0 !important;
    height: auto !important;
}

/* Campo obrigatório - barra interna na esquerda */
.field-required {
    border-left: 3px solid #dc3545 !important;
    padding-left: calc(0.5rem - 3px) !important;
}

.field-required:focus {
    border-left-color: #dc3545 !important;
}

/* Botão de remover - estilo melhorado */
.btn-link.text-danger {
    text-decoration: none;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.25rem;
}

.btn-link.text-danger:hover {
    background-color: rgba(220, 53, 69, 0.1);
    transform: scale(1.1);
    color: #dc3545 !important;
}

.btn-link.text-danger:active {
    transform: scale(0.95);
}

/* Filtros - Tags de valores múltiplos */
.filter-value-multiple {
    width: 100%;
}

.filter-value-multiple .badge {
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
    margin: 0.125rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    cursor: default;
}

.filter-value-multiple .badge .btn-close {
    font-size: 0.6rem;
    padding: 0.125rem;
    margin-left: 0.25rem;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.filter-value-multiple .badge .btn-close:hover {
    opacity: 1;
}

.filter-value-multiple .input-group {
    margin-top: 0.5rem;
}

.filter-value-multiple .input-group .btn {
    border-left: none;
}

.filter-value-multiple .form-text {
    margin-top: 0.5rem;
    font-size: 0.75rem;
}

.filter-value-multiple .form-text code {
    background-color: #f8f9fa;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-size: 0.7rem;
    color: #495057;
}

/* Filtros - Tabela */
.filter-table {
    width: 100%;
}

.filter-table .form-control,
.filter-table .form-select {
    font-size: 0.875rem;
}

.filter-table tbody tr {
    vertical-align: middle;
}
