/* ==========================================
   MODAL DE RELATÓRIOS — ERPAvel
   Consistente com modal-confirm.css
   ========================================== */

/* Overlay — visibilidade e animação controladas 100% via JS (report.js) */
.report-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9998;
}

/* Container */
.report-modal {
    background: var(--bg-surface);
    border-radius: 16px;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.28),
        0 0 0 1px var(--border-color);
    width: clamp(320px, 92vw, 540px);
    position: relative;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    overflow: hidden;
}

/* Header */
.rm-header {
    padding: 1.5rem 1.75rem 1rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.rm-icon-wrap {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.rm-icon-wrap i {
    font-size: 1.375rem;
    color: #2563eb;
}

.rm-header-text {
    flex: 1;
    min-width: 0;
}

.rm-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 0.2rem;
    line-height: 1.3;
}

.rm-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.4;
}

.rm-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 6px;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.rm-close:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.rm-close i {
    font-size: 1.125rem;
}

/* Body */
.rm-body {
    padding: 1.25rem 1.75rem;
    overflow-y: auto;
    flex: 1;
}

/* Params */
.rm-params {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.rm-field-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.rm-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

.rm-input,
.rm-select {
    width: 100%;
    padding: 0.5625rem 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 0.9375rem;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.rm-input:focus,
.rm-select:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* Row com 2 colunas (ex: data início / data fim) */
.rm-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* Separador de seção */
.rm-section-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.625rem;
}

/* Seleção de formato */
.rm-formats {
    display: flex;
    gap: 0.625rem;
    flex-wrap: wrap;
}

.rm-format-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.375rem;
    padding: 0.75rem 1.125rem;
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 80px;
    font-size: 0.8125rem;
    font-weight: 500;
}

.rm-format-btn i {
    font-size: 1.375rem;
}

.rm-format-btn:hover {
    border-color: #3b82f6;
    color: #2563eb;
    background: rgba(59, 130, 246, 0.04);
}

.rm-format-btn.active {
    border-color: #3b82f6;
    background: rgba(59, 130, 246, 0.08);
    color: #2563eb;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* Sem parâmetros nem seleção de formato: oculta o corpo inteiro */
.report-modal.rm-no-body .rm-body {
    display: none;
}

.report-modal.rm-no-body .rm-footer {
    border-top: none;
    padding-top: 1.5rem;
}

/* Área de resultado inline (nodata / erro) */
.rm-result {
    padding: 0 1.75rem 0.75rem;
}

.rm-result-msg {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.875rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
}

.rm-result-msg i {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.rm-result-msg--warning {
    background: rgba(245, 158, 11, 0.1);
    color: #d97706;
    border: 1px solid rgba(245, 158, 11, 0.25);
}

.rm-result-msg--error {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

body.dark-mode .rm-result-msg--warning {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.3);
}

body.dark-mode .rm-result-msg--error {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
}

/* Footer */
.rm-footer {
    padding: 1rem 1.75rem 1.5rem;
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    border-top: 1px solid var(--border-color);
}

.rm-btn {
    padding: 0.65rem 1.375rem;
    border-radius: 10px;
    font-size: 0.9375rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}

.rm-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.rm-btn-cancel {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.rm-btn-cancel:hover {
    background: var(--bg-surface-secondary);
}

.rm-btn-cancel:active { transform: scale(0.98); }

.rm-btn-generate {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: #fff;
    box-shadow:
        0 2px 8px rgba(59, 130, 246, 0.3),
        0 0 0 1px rgba(0,0,0,0.04) inset;
}

.rm-btn-generate:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
    transform: translateY(-1px);
}

.rm-btn-generate:active { transform: translateY(0); }

.rm-btn-generate:disabled,
.rm-btn-generate.loading {
    opacity: 0.65;
    cursor: wait;
    pointer-events: none;
    transform: none;
}

/* Spinner inline no botão */
.rm-spinner {
    width: 15px;
    height: 15px;
    border: 2px solid rgba(255,255,255,0.5);
    border-top-color: #fff;
    border-radius: 50%;
    animation: rmSpin 0.65s linear infinite;
    display: none;
}

.rm-btn-generate.loading .rm-spinner { display: inline-block; }
.rm-btn-generate.loading .rm-btn-icon { display: none; }

@keyframes rmSpin {
    to { transform: rotate(360deg); }
}

/* ── Autocomplete ────────────────────────────────────────────────────────── */
.rm-autocomplete-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.rm-autocomplete-input {
    flex: 1;
    min-width: 0;
}

.rm-autocomplete-clear {
    padding: 0.5rem 0.5625rem;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s;
}

.rm-autocomplete-clear:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.rm-autocomplete-clear i { font-size: 1rem; }

.rm-autocomplete-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 2.25rem;   /* alinha com o input, não sobre o botão clear */
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.14);
    z-index: 99999;
    max-height: 200px;
    overflow-y: auto;
}

.rm-autocomplete-option {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
    outline: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rm-autocomplete-option:hover,
.rm-autocomplete-option:focus {
    background: var(--bg-surface-hover);
}

.rm-autocomplete-empty {
    padding: 0.625rem 0.75rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-style: italic;
}

body.dark-mode .rm-autocomplete-dropdown {
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

/* Dark mode */
body.dark-mode .report-modal {
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.06);
}

body.dark-mode .rm-icon-wrap {
    background: linear-gradient(135deg, #1e3a5f 0%, #1e40af 100%);
}

body.dark-mode .rm-icon-wrap i { color: #60a5fa; }
body.dark-mode .rm-format-btn.active { background: rgba(96, 165, 250, 0.12); }
body.dark-mode .rm-input,
body.dark-mode .rm-select {
    background: var(--bg-surface-secondary);
}

/* Responsive */
@media (max-width: 576px) {
    .report-modal {
        width: calc(100% - 1rem);
        border-radius: 14px;
        max-height: 96vh;
    }

    .rm-header { padding: 1.25rem 1.25rem 0.875rem; gap: 0.75rem; }
    .rm-body   { padding: 1rem 1.25rem; }
    .rm-footer { padding: 0.875rem 1.25rem 1.25rem; flex-direction: column-reverse; }
    .rm-btn    { width: 100%; justify-content: center; }
    .rm-row-2  { grid-template-columns: 1fr; }
    .rm-formats { gap: 0.5rem; }
    .rm-format-btn { min-width: 70px; padding: 0.625rem 0.875rem; }
}

/* Acessibilidade */
@media (prefers-reduced-motion: reduce) {
    .rm-btn { transition: none; }
}
