/**
 * Estilos para Gerenciador de Formulários Dinâmicos
 * Maverick DB Manager v1.3.0
 */

/* Mobile First & Layout */
.mv-dm-wrap { 
    max-width: 100%; 
    overflow-x: hidden; 
}

.mv-dm-header { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 15px; 
    align-items: center; 
    margin-bottom: 20px; 
    border-bottom: 1px solid #ccc; 
    padding-bottom: 15px; 
}

.mv-dm-card { 
    background: #fff; 
    border: 1px solid #ccd0d4; 
    padding: 20px; 
    box-shadow: 0 1px 1px rgba(0,0,0,.04); 
    margin-bottom: 20px; 
}

/* Toolbar de Ações (Mobile Friendly) */
.mv-toolbar { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 10px; 
    align-items: center; 
    margin-bottom: 15px; 
    background: #f0f0f1; 
    padding: 10px; 
    border: 1px solid #ccc; 
    border-radius: 4px; 
}

/* Tables */
.mv-dm-table-scroll { 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch; 
    width: 100%; 
    border: 1px solid #e5e5e5; 
}

.mv-dm-table-scroll table { 
    margin: 0; 
}

/* Multi-Row Insert Styles */
.mv-insert-row { 
    background: #f9f9f9; 
    border: 1px solid #ddd; 
    padding: 15px; 
    margin-bottom: 15px; 
    position: relative; 
    border-left: 4px solid #2271b1; 
}

.mv-btn-remove-row { 
    position: absolute; 
    top: 10px; 
    right: 10px; 
    color: #b32d2e; 
    text-decoration: none; 
    font-size: 20px; 
}

.mv-dm-form-row { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 15px; 
    align-items: flex-start; 
}

.mv-dm-form-group { 
    flex: 1; 
    min-width: 200px; 
    display: flex; 
    flex-direction: column; 
    gap: 5px; 
    margin-bottom: 10px; 
}

.mv-dm-form-group label { 
    font-weight: 600; 
    font-size: 12px; 
    color: #555; 
}

.mv-dm-form-group input, 
.mv-dm-form-group select, 
.mv-dm-form-group textarea { 
    width: 100%; 
}

/* Date Widget */
.mv-date-widget { 
    display: flex; 
    gap: 3px; 
}

.mv-date-d, 
.mv-date-y { 
    width: 60px !important; 
}

.mv-date-m { 
    min-width: 100px; 
}

/* SQL & Snippets */
.mv-sql-layout { 
    display: grid; 
    grid-template-columns: 1fr; 
    gap: 20px; 
}

@media(min-width: 768px) { 
    .mv-sql-layout { 
        grid-template-columns: 2fr 1fr; 
    } 
}

.mv-sql-editor { 
    width: 100%; 
    height: 300px; 
    font-family: monospace; 
    background: #2b2b2b; 
    color: #a9b7c6; 
    padding: 10px; 
    border-radius: 4px; 
    border: 1px solid #555; 
}

.mv-snippet-item { 
    background: #f9f9f9; 
    padding: 10px; 
    border: 1px solid #ddd; 
    margin-bottom: 5px; 
}

/* Smart Links & Icons */
.mv-smart-link { 
    display: inline-flex; 
    align-items: center; 
    gap: 4px; 
    text-decoration: none; 
    color: #2271b1; 
    font-weight: 500; 
}

.mv-smart-link:hover { 
    text-decoration: underline; 
}

.mv-action-icon { 
    font-size: 18px; 
    text-decoration: none; 
    margin-right: 5px; 
}

.mv-icon-edit { 
    color: #2271b1; 
}

.mv-icon-del { 
    color: #b32d2e; 
}

/* Query Builder Styles */
.mv-qb-builder { 
    background: #fff; 
    border: 1px solid #ccd0d4; 
    padding: 20px; 
    margin-bottom: 20px; 
}

.mv-qb-section { 
    margin-bottom: 20px; 
    padding: 15px; 
    background: #f9f9f9; 
    border-left: 4px solid #2271b1; 
}

.mv-qb-section h4 { 
    margin-top: 0; 
}

.mv-qb-join-item { 
    background: #fff; 
    padding: 10px; 
    margin-bottom: 10px; 
    border: 1px solid #ddd; 
}

.mv-qb-preview { 
    background: #2b2b2b; 
    color: #a9b7c6; 
    padding: 15px; 
    border-radius: 4px; 
    font-family: monospace; 
    white-space: pre-wrap; 
}

.mv-bulk-update-form { 
    background: #f0f6fc; 
    padding: 20px; 
    border: 1px solid #2271b1; 
    margin-bottom: 20px; 
}

/* Formulários Dinâmicos - Shortcode */
.mv-formulario-container {
    background: #fff;
    padding: 20px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin: 20px 0;
}

.mv-formulario-container.mv-form-responsivo {
    max-width: 100%;
}

.mv-linha-formulario {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-left: 4px solid #2271b1;
    padding: 20px;
    margin-bottom: 15px;
    position: relative;
}

.mv-campos-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}

@media(min-width: 768px) {
    .mv-campos-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media(min-width: 1024px) {
    .mv-campos-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.mv-campo-grupo {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.mv-campo-grupo label {
    font-weight: 600;
    font-size: 13px;
    color: #333;
}

.mv-campo-grupo label .obrigatorio {
    color: #b32d2e;
    margin-left: 3px;
}

.mv-campo-grupo input[type="text"],
.mv-campo-grupo input[type="number"],
.mv-campo-grupo input[type="email"],
.mv-campo-grupo input[type="date"],
.mv-campo-grupo select,
.mv-campo-grupo textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 14px;
}

.mv-campo-grupo textarea {
    resize: vertical;
    min-height: 80px;
}

.mv-acoes-multiplas {
    margin: 15px 0;
    padding: 15px;
    background: #f0f0f1;
    border-radius: 4px;
}

.mv-acoes-formulario {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #ddd;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.mv-remover-linha-formulario {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #b32d2e;
    color: #fff;
    border: none;
    padding: 5px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
}

.mv-remover-linha-formulario:hover {
    background: #a12828;
}

.mv-adicionar-linha-formulario {
    width: 100%;
    padding: 10px;
    text-align: center;
}

.mv-formulario-erro,
.mv-formulario-sucesso {
    padding: 15px;
    margin: 15px 0;
    border-radius: 4px;
}

.mv-formulario-erro {
    background: #fef2f2;
    border-left: 4px solid #b32d2e;
    color: #b32d2e;
}

.mv-formulario-sucesso {
    background: #f0f9ff;
    border-left: 4px solid #2271b1;
    color: #2271b1;
}

.mv-debug-info {
    background: #fff3cd;
    border: 1px solid #ffc107;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
}

.mv-debug-info pre {
    margin: 10px 0 0 0;
    max-height: 300px;
    overflow-y: auto;
}

/* Bulk Update Matrix Style */
.mv-bulk-update-matriz {
    overflow-x: auto;
    margin: 20px 0;
}

.mv-bulk-update-matriz table {
    width: 100%;
    border-collapse: collapse;
}

.mv-bulk-update-matriz th,
.mv-bulk-update-matriz td {
    padding: 10px;
    border: 1px solid #ddd;
    text-align: left;
}

.mv-bulk-update-matriz th {
    background: #f0f0f1;
    font-weight: 600;
    position: sticky;
    top: 0;
}

.mv-bulk-update-matriz input[type="checkbox"] {
    margin-right: 5px;
}

.mv-bulk-update-matriz input[type="text"],
.mv-bulk-update-matriz input[type="number"],
.mv-bulk-update-matriz select,
.mv-bulk-update-matriz textarea {
    width: 100%;
    padding: 5px;
    border: 1px solid #ddd;
    border-radius: 3px;
}

.mv-bulk-update-matriz tr:hover {
    background: #f9f9f9;
}

/* Estilos para Campos Dinâmicos - v1.4.0 */

/* Loading state para formulário individual */
.mv-formulario-individual.mv-loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.mv-formulario-individual.mv-loading::before {
    content: 'Carregando dados...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 15px 30px;
    border: 2px solid #2271b1;
    border-radius: 4px;
    font-weight: bold;
    color: #2271b1;
    z-index: 1000;
}

/* Estado de erro */
.mv-formulario-individual.mv-erro {
    border: 2px solid #d63638;
    background: #fcf0f1;
}

/* Campos dinâmicos */
[data-campo-dinamico="true"] {
    transition: all 0.3s ease;
}

[data-campo-dinamico="true"]:disabled {
    background-color: #f6f7f7;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Campo inválido */
.campo-invalido {
    border-color: #d63638 !important;
    background-color: #fcf0f1 !important;
}

.campo-invalido:focus {
    border-color: #d63638 !important;
    box-shadow: 0 0 0 1px #d63638 !important;
}

/* Indicador de campo obrigatório dependente */
.mv-campo-obrigatorio-dependente label::after {
    content: ' *';
    color: #d63638;
    font-weight: bold;
}

/* Container de campo com visibilidade condicional */
.mv-campo-condicional-oculto {
    display: none;
}

/* Feedback visual para campo com dependência */
.mv-campo-grupo[data-campo-pai] {
    position: relative;
}

.mv-campo-grupo[data-campo-pai]::before {
    content: '🔗';
    position: absolute;
    right: 10px;
    top: 10px;
    font-size: 14px;
    opacity: 0.3;
    pointer-events: none;
}

/* Animação de carregamento para select dependente */
[data-campo-dinamico="true"].carregando {
    background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 50 50"><circle cx="25" cy="25" r="20" fill="none" stroke="%232271b1" stroke-width="4"><animate attributeName="stroke-dasharray" values="1,200;100,200;100,200" dur="1.5s" repeatCount="indefinite"/><animate attributeName="stroke-dashoffset" values="0;-15;-125" dur="1.5s" repeatCount="indefinite"/></circle></svg>');
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 20px 20px;
    padding-right: 40px;
}

/* Responsividade Adicional */
@media(max-width: 768px) {
    .mv-linha-formulario {
        padding: 15px 10px;
    }
    
    .mv-campos-grid {
        grid-template-columns: 1fr;
    }
    
    .mv-acoes-formulario {
        flex-direction: column;
    }
    
    .mv-acoes-formulario .button {
        width: 100%;
        text-align: center;
    }
    
    .mv-formulario-individual.mv-loading::before {
        font-size: 14px;
        padding: 10px 20px;
    }
}

/* ================================================
   MODO SELEÇÃO - Seleção múltipla com preservação de FK
   ================================================ */

/* Container principal - herda estilos dos outros modos */
.mv-modo-selecao,
.mv-modo-selecao-matriz {
    margin: 20px 0;
}

.mv-modo-selecao .mv-dm-card,
.mv-modo-selecao-matriz .mv-dm-card {
    background: #fff;
    border: 1px solid #ccd0d4;
    padding: 20px;
    box-shadow: 0 1px 1px rgba(0,0,0,.04);
    margin-bottom: 20px;
}

.mv-modo-selecao .mv-dm-header h3,
.mv-modo-selecao-matriz .mv-dm-header h3 {
    margin: 0 0 5px 0;
    font-size: 18px;
}

.mv-modo-selecao .mv-dm-header p,
.mv-modo-selecao-matriz .mv-dm-header p {
    margin: 0;
    color: #666;
    font-size: 13px;
}

/* Tabela de seleção */
.mv-modo-selecao table th.check-column {
    width: 40px;
    text-align: center;
}

.mv-modo-selecao table td.check-column {
    vertical-align: middle;
}

/* Contador de selecionados */
.mv-contador-selecionados {
    display: inline-block;
    padding: 5px 10px;
    background: #f0f0f1;
    border-radius: 3px;
    font-size: 13px;
}

/* Botões de ação - herda estilo dos outros modos */
.mv-modo-selecao .mv-acoes-formulario,
.mv-modo-selecao-matriz .mv-acoes-formulario {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #ddd;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

/* Linha do formulário - usa mesmo estilo de outros modos */
.mv-modo-selecao-matriz .mv-linha-formulario {
    background: #fafafa;
    border: 1px solid #e5e5e5;
    padding: 20px;
    margin-bottom: 0;
    position: relative;
    transition: all 0.3s ease;
}

/* Matriz de edição */
.mv-modo-selecao-matriz table input[type="text"],
.mv-modo-selecao-matriz table input[type="number"],
.mv-modo-selecao-matriz table input[type="date"],
.mv-modo-selecao-matriz table select,
.mv-modo-selecao-matriz table textarea {
    width: 100%;
    max-width: 300px;
    font-size: 13px;
    padding: 6px 8px;
    border: 1px solid #8c8f94;
    border-radius: 4px;
}

.mv-modo-selecao-matriz table input[type="text"]:focus,
.mv-modo-selecao-matriz table input[type="number"]:focus,
.mv-modo-selecao-matriz table input[type="date"]:focus,
.mv-modo-selecao-matriz table select:focus,
.mv-modo-selecao-matriz table textarea:focus {
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
    outline: 2px solid transparent;
}

.mv-modo-selecao-matriz table textarea {
    min-height: 60px;
    resize: vertical;
}

.mv-modo-selecao-matriz table th:first-child,
.mv-modo-selecao-matriz table td:first-child {
    position: sticky;
    left: 0;
    background: #fff;
    z-index: 1;
    box-shadow: 2px 0 3px rgba(0,0,0,0.1);
}

@media (max-width: 782px) {
    .mv-modo-selecao-matriz table input[type="text"],
    .mv-modo-selecao-matriz table input[type="number"],
    .mv-modo-selecao-matriz table input[type="date"],
    .mv-modo-selecao-matriz table select,
    .mv-modo-selecao-matriz table textarea {
        max-width: 200px;
    }
}

/* Campos Filter-Only (Issue #49) */
.mv-campo-filter-only {
    position: relative;
}

.mv-campo-filter-only::before {
    content: '';
    position: absolute;
    top: 0;
    left: -5px;
    width: 3px;
    height: 100%;
    background: #f59e0b;
    border-radius: 2px;
}

.mv-badge-filter {
    display: inline-block;
    background: #fef3c7;
    color: #92400e;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    vertical-align: middle;
}

.mv-campo-filter-only input,
.mv-campo-filter-only select,
.mv-campo-filter-only textarea {
    border-left: 3px solid #f59e0b;
    background-color: #fffbeb;
}

.mv-campo-filter-only input:focus,
.mv-campo-filter-only select:focus,
.mv-campo-filter-only textarea:focus {
    background-color: #fef3c7;
    border-left-color: #d97706;
}
