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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f6fa;
}

.header {
    background: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    color: #2c3e50;
    font-size: 24px;
}

/* Use Bootstrap's button styles (remove custom .btn rules to avoid conflict) */

.dashboard-grid {
    position: relative;
    /* Essencial para o posicionamento absoluto dos filhos */
    border: 1px dashed #ccc;
    min-height: 970px;
}

.widget {
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 15px;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    /* Permitir que dimensões sejam definidas via JavaScript */
    box-sizing: border-box;
}

/* Widget no modo antigo (drag & drop livre) */
.widget.legacy-position {
    position: absolute;
}

.widget:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* Estilos para widgets sem header */
.widget.no-header {
    padding: 10px;
}

.widget.no-header .widget-content {
    border-radius: 10px;
}

.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #ecf0f1;
    cursor: move;
}

.widget-title {
    font-size: 16px;
    font-weight: 600;
    color: #2c3e50;
    text-align: center !important;
}

.widget-controls {
    display: flex;
    gap: 5px;
}

.widget-content {
    flex: 1;
    /* Ocupa todo o espaço disponível */
    /* display: flex; */
    /* align-items: center;
    justify-content: center; */
    overflow: auto;
    /* Remover altura mínima fixa para permitir dimensões personalizadas */
}

.resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 50%, #95a5a6 50%);
}

/* Bootstrap modal styles will be used (removed custom .modal/.modal-content rules) */

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

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #2c3e50;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.form-group textarea {
    min-height: 100px;
    font-family: 'Courier New', monospace;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.json-editor {
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 10px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

.btn-group {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.loading {
    text-align: center;
    padding: 20px;
    color: #7f8c8d;
}

.html-widget {
    line-height: 1.6;
}

.empty-dashboard {
    text-align: center;
    padding: 60px 20px;
    color: #7f8c8d;
}

.empty-dashboard h2 {
    margin-bottom: 10px;
    color: #34495e;
}

/* Font Awesome icon spacing */
.btn i {
    margin-right: 5px;
}

.btn i:only-child {
    margin-right: 0;
}

.widget-controls .btn i {
    margin-right: 0;
}

/* Estilos para widgets de filtro */
.filter-widget {
    /* border-left: 4px solid #6c757d; */
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

.filter-widget .widget-header {
    background: rgba(108, 117, 125, 0.1);
    border-radius: 5px;
    margin: -15px -15px 15px -15px;
    padding: 10px 15px;
}

.filter-widget .widget-title {
    color: #495057;
    font-weight: 600;
}

.filter-container {
    padding: 10px 0;
}

.filter-container .form-label {
    font-weight: 600;
    color: #495057;
    margin-bottom: 8px;
    display: block;
}

.date-range-filter {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.date-range-filter input {
    border-radius: 6px;
    border: 1px solid #ced4da;
    padding: 8px 12px;
    font-size: 14px;
}

.filter-container input,
.filter-container select {
    border-radius: 6px;
    border: 1px solid #ced4da;
    padding: 8px 12px;
    font-size: 14px;
    width: 100%;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.filter-container input:focus,
.filter-container select:focus {
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* Distinguir visualmente widgets de consulta */
/* .query-widget {
    border-left: 4px solid #007bff;
} */

/* Estilos personalizados para Choices.js */
.choices {
    margin-bottom: 0;
    border: 1px solid #ced4da !important;
    border-radius: 6px !important;
    box-shadow: none !important;
}

.choices.is-focused {
    border-color: #80bdff !important;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25) !important;
}

.choices__inner {
    background-color: #fff;
    border: 0 !important;
    border-radius: 6px;
    color: #495057;
    cursor: text;
    display: inline-block;
    font-size: 14px;
    min-height: 44px;
    overflow: hidden;
    padding: 7.5px 7.5px 3.75px;
    vertical-align: top;
    width: 100%;
}

.choices__list--multiple .choices__item {
    background-color: #007bff;
    border: 1px solid #006bb3;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    display: inline-block;
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 3.75px;
    margin-right: 3.75px;
    padding: 4px 10px;
    word-break: break-all;
}

.choices__list--multiple .choices__item.is-highlighted {
    background-color: #0056b3;
    border: 1px solid #004085;
}

.choices__button {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg width='21' height='21' viewBox='0 0 21 21' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23FFF' fill-rule='evenodd'%3E%3Cpath d='m2.592.044 18.364 18.364-2.548 2.548L.044 2.592z'/%3E%3Cpath d='M0 18.364 18.364 0l2.548 2.548L2.548 20.912z'/%3E%3C/g%3E%3C/svg%3E");
    border: 0;
    background-color: transparent;
    border-radius: 0;
    cursor: pointer;
    display: inline-block;
    font-size: 0;
    height: 20px;
    margin-left: 4px;
    margin-top: -10px;
    outline: none;
    padding: 0;
    position: absolute;
    right: 0;
    top: 50%;
    vertical-align: top;
    width: 20px;
}

.choices__list--dropdown {
    background-color: #fff;
    border: 1px solid #ced4da;
    border-radius: 6px;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    font-size: 14px;
    max-height: 300px;
    overflow: auto;
    position: absolute;
    top: 100%;
    width: 100%;
    z-index: 1000;
}

.choices__item--choice {
    color: #495057;
    cursor: pointer;
    display: block;
    font-size: 14px;
    padding: 10px;
    word-wrap: break-word;
}

.choices__item--choice.is-highlighted {
    background-color: #f8f9fa;
    color: #495057;
}

.choices__item--choice.is-selected {
    background-color: #007bff;
    color: #fff;
}

.choices__placeholder {
    color: #6c757d;
    opacity: 1;
}

.choices__input {
    background-color: transparent;
    border: 0;
    color: #495057;
    font-size: 14px;
    margin-bottom: 5px;
    max-width: 100%;
    outline: 0;
    padding: 4px 0;
}

.choices__input:focus {
    outline: 0;
}

/* Estilos para colunas Bootstrap vazias */
.empty-column {
    min-height: 200px;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: #f8f9fa;
}

.empty-column:hover {
    border-color: #007bff;
    background-color: #e7f3ff;
}

.add-widget-placeholder {
    text-align: center;
    color: #6c757d;
}

.add-widget-placeholder:hover {
    color: #007bff;
}

.add-widget-placeholder i {
    margin-bottom: 10px;
}

.add-widget-placeholder p {
    margin: 0;
    font-weight: 500;
}

/* Page Builder Styles */
.page-builder-mode .dashboard-grid {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
}

.page-builder-row {
    border: 1px dashed #dee2e6;
    border-radius: 4px;
    margin-bottom: 15px;
    position: relative;
    min-height: 80px;
    background: white;
    display: flex;
    align-items: stretch;
    /* Força colunas a terem a mesma altura */
}

.page-builder-row:hover {
    border-color: #007bff;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.1);
}

.page-builder-col {
    border: 1px dashed #e9ecef;
    border-radius: 4px;
    min-height: 100px;
    position: relative;
    background: #fafafa;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Centralizar widgets */
    justify-content: flex-start;
    overflow: visible;
    /* Permitir que widgets excedam a coluna se necessário */
    box-sizing: border-box;
    padding: 10px;
}

.page-builder-col:hover {
    border-color: #007bff;
    background: #e7f3ff;
}

.page-builder-col.has-widget {
    background: white;
    border-color: #28a745;
}

.row-controls,
.col-controls {
    position: absolute;
    top: -10px;
    right: -10px;
    z-index: 100;
    display: none;
}

.page-builder-row:hover .row-controls,
.page-builder-col:hover .col-controls {
    display: block;
}

.page-builder-row-less {
    border: none;
}

.control-btn {
    background: #007bff;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 10px;
    margin-left: 2px;
    cursor: pointer;
}

.control-btn:hover {
    background: #0056b3;
}

.control-btn.danger {
    background: #dc3545;
}

.control-btn.danger:hover {
    background: #c82333;
}

.resize-handle-col {
    position: absolute;
    right: -5px;
    top: 0;
    bottom: 0;
    width: 10px;
    cursor: col-resize;
    background: rgba(0, 123, 255, 0.1);
    opacity: 0;
    transition: opacity 0.2s;
}

.page-builder-col:hover .resize-handle-col {
    opacity: 1;
}

.page-builder-col-less {
    border: none;
    /* padding: 0; */
}

.widget-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #6c757d;
    font-size: 12px;
    cursor: pointer;
}

.drop-zone {
    border: 2px dashed #007bff !important;
    background: rgba(0, 123, 255, 0.1) !important;
}

.dragging {
    opacity: 0.7;
    transform: scale(0.95);
}

/* Melhorias para filtros de múltipla seleção com muitos valores */
.choices__list--dropdown {
    max-height: 300px;
    overflow-y: auto;
}

.choices__list--dropdown .choices__item--choice {
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
}

.choices__list--dropdown .choices__item--choice:hover {
    background-color: #f8f9fa;
}

.choices__input--cloned {
    min-width: 200px;
}

.choices-actions {
    font-size: 0.875rem;
}

.choices-actions .btn {
    font-size: 0.75rem;
    padding: 2px 8px;
}

/* Loading state para filtros com muitos valores */
.choices.is-loading::after {
    content: "Carregando opções...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.875rem;
    color: #666;
}

/* Contador de itens selecionados */
.choices-counter {
    font-size: 0.75rem;
    color: #666;
    margin-top: 4px;
}

/* Estilos para widgets HTML puro */
.html-raw-widget {
    position: relative;
}

.html-raw-widget .widget-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    transition: opacity 0.2s ease;
}

.html-raw-widget .widget-content {
    position: relative;
    z-index: 1;
}

/* Estilos personalizados para CodeMirror - Similar ao Sublime Text */
.CodeMirror {
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
    font-size: 14px;
    line-height: 1.4;
    height: auto;
    min-height: 150px;
}

.CodeMirror-focused {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.CodeMirror-scroll {
    min-height: 150px;
    max-height: 400px;
}

/* Personalização do tema para ficar mais parecido com Sublime */
.cm-s-monokai.CodeMirror {
    background: #272822;
    color: #f8f8f2;
}

.cm-s-monokai .CodeMirror-gutters {
    background: #272822;
    border-right: 1px solid #3c3d37;
}

.cm-s-monokai .CodeMirror-linenumber {
    color: #90908a;
}

.cm-s-monokai .CodeMirror-cursor {
    border-left: 2px solid #f8f8f0;
}

.cm-s-monokai .CodeMirror-activeline-background {
    background: rgba(255, 255, 255, 0.04);
}

.cm-s-monokai .CodeMirror-selected {
    background: #49483e;
}

/* Ajustes responsivos */
@media (max-width: 768px) {
    .CodeMirror {
        font-size: 12px;
    }
}

/* ==============================================
   CORREÇÃO PARA DROPDOWNS DOS FILTROS CHOICES.JS
   ============================================== */

/* Container dos filtros combobox */
.filter-widget .choices {
    position: relative;
    z-index: 9999;
}

/* Dropdown list dos filtros */
.filter-widget .choices__list--dropdown {
    position: absolute;
    z-index: 10000;
    max-height: 200px;
    overflow-y: auto;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    /* Garantir que apareça fora do widget-content */
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 2px;
    display: block; /* Garantir que seja visível */
}

/* Widget content deve permitir overflow visible para os dropdowns */
.filter-widget .widget-content {
    overflow: visible;
    position: relative;
    z-index: 1;
}

/* Garantir que dropdowns não sejam cortados */
.widget.filter-widget {
    overflow: visible;
    z-index: auto;
}

/* Quando o dropdown está aberto, aumentar z-index do widget */
.filter-widget .choices.is-open {
    z-index: 10001;
}

/* Garantir que as opções sejam visíveis */
.filter-widget .choices__item--choice {
    display: block !important;
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
}

.filter-widget .choices__item--choice:hover {
    background-color: #f8f9fa;
}

/* ==============================================
   ESTILOS PARA GRÁFICOS ESPECIAIS
   ============================================== */

/* Container específico para gráficos de medidor */
.gauge-chart-container,
.speedometer-chart-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* Estilos para melhorar visualização de gráficos de medidor */
.widget-content canvas {
    border-radius: 8px;
}

/* Container para gráficos mistos */
.mixed-chart-container {
    padding: 15px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 8px;
    margin-bottom: 10px;
}

/* Estilos para gráficos de dispersão e bolhas */
.scatter-chart-container,
.bubble-chart-container {
    background: #fafafa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 10px;
}

/* Melhorias visuais para diferentes tipos de gráfico */
.chart-widget {
    transition: transform 0.2s ease-in-out;
}

.chart-widget:hover {
    transform: translateY(-2px);
}

/* Estilos para labels e legendas de gráficos especiais */
.gauge-label,
.speedometer-label {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-weight: bold;
    color: #2c3e50;
    font-size: 14px;
    text-align: center;
}

/* Container para valor do medidor */
.gauge-value {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    font-weight: bold;
    color: #2c3e50;
    text-align: center;
}

/* Melhorias para gráficos horizontais */
.horizontal-bar-chart {
    min-height: 300px;
}

/* Estilos para gráficos de área */
.area-chart-container {
    background: linear-gradient(180deg, rgba(52, 152, 219, 0.1) 0%, rgba(52, 152, 219, 0.05) 100%);
    border-radius: 8px;
    padding: 15px;
    border: 1px solid rgba(52, 152, 219, 0.2);
}

/* Indicadores visuais para diferentes tipos de medidores */
.gauge-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #28a745;
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
}

.gauge-indicator.warning {
    background: #ffc107;
    color: #212529;
}

.gauge-indicator.danger {
    background: #dc3545;
}

/* Estilos para tooltip customizado em gráficos especiais */
.chart-tooltip {
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    position: absolute;
    pointer-events: none;
    z-index: 1000;
}

/* Melhorias para gráficos responsivos */
@media (max-width: 768px) {
    .gauge-chart-container,
    .speedometer-chart-container {
        padding: 10px;
    }
    
    .gauge-value {
        font-size: 18px;
    }
    
    .mixed-chart-container {
        padding: 10px;
    }
}

/* Estilos para animações de entrada dos gráficos */
.chart-entering {
    animation: chartFadeIn 0.6s ease-in-out;
}

@keyframes chartFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Estilos específicos para gráficos radar */
.radar-chart-container {
    background: radial-gradient(circle, rgba(52, 152, 219, 0.1) 0%, transparent 70%);
    border-radius: 50%;
    padding: 20px;
    margin: 10px;
}

/* Container para gráficos de área polar */
.polar-area-chart-container {
    background: conic-gradient(from 0deg, rgba(52, 152, 219, 0.1), rgba(231, 76, 60, 0.1), rgba(46, 204, 113, 0.1), rgba(243, 156, 18, 0.1));
    border-radius: 50%;
    padding: 15px;
}