/* =========================================================================
   Automatiza Contábil - Consulta & Gestão de Eventos NFe
   Identidade "Expert Modern" — Light + Dark Mode via CSS Variables
   ========================================================================= */

.ac-sefaz-wrapper,
.ac-layout-grid,
.ac-config-panel,
.ac-modal-overlay {
    --ac-primary: #1A2B4C;
    --ac-primary-soft: #24365c;
    --ac-accent: #FF6B00;
    --ac-accent-hover: #e05d00;
    --ac-bg: #F4F6F8;
    --ac-surface: #FFFFFF;
    --ac-text: #2C3E50;
    --ac-text-muted: #64748B;
    --ac-border: #E2E8F0;
    --ac-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0,0,0,0.04);

    color: var(--ac-text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Dark Mode — aplicado via classe no <body> (alternada pelo toggle em JS) */
body.ac-dark-mode .ac-sefaz-wrapper,
body.ac-dark-mode .ac-layout-grid,
body.ac-dark-mode .ac-config-panel,
body.ac-dark-mode .ac-modal-overlay {
    --ac-primary: #7FA1FF;
    --ac-primary-soft: #93b0ff;
    --ac-accent: #FF8A3D;
    --ac-accent-hover: #ff9c5c;
    --ac-bg: #121824;
    --ac-surface: #1E293B;
    --ac-text: #E2E8F0;
    --ac-text-muted: #94A3B8;
    --ac-border: #2E3B52;
    --ac-shadow: 0 4px 10px -2px rgba(0, 0, 0, 0.4);
}

/* -------------------------------------------------------------------- */
/* Cards e Estrutura Geral                                               */
/* -------------------------------------------------------------------- */

.ac-card {
    background: var(--ac-surface);
    border: 1px solid var(--ac-border);
    border-radius: 10px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--ac-shadow);
    color: var(--ac-text);
    transition: background 0.25s ease, border-color 0.25s ease;
}

.ac-title {
    color: var(--ac-primary);
    font-family: 'Montserrat', sans-serif;
    margin: 0;
    font-size: 20px;
}

.ac-subtitle {
    color: var(--ac-text-muted);
    font-size: 14px;
    margin-top: -8px;
}

.ac-hint {
    color: var(--ac-text-muted);
    font-size: 12.5px;
    margin: 6px 0 0;
}

/* -------------------------------------------------------------------- */
/* Topbar + Toggle de Tema                                               */
/* -------------------------------------------------------------------- */

.ac-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

/* -------------------------------------------------------------------- */
/* Abas (Consulta / Certificados)                                        */
/* -------------------------------------------------------------------- */

.ac-tabs {
    display: flex;
    gap: 6px;
    background: var(--ac-bg);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--ac-border);
}

.ac-tab-btn {
    background: transparent;
    border: none;
    padding: 8px 16px;
    border-radius: 7px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--ac-text-muted);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    font-family: inherit;
}

.ac-tab-btn:hover { color: var(--ac-text); }

.ac-tab-btn.active {
    background: var(--ac-surface);
    color: var(--ac-primary);
    box-shadow: var(--ac-shadow);
}

.ac-tab-panel { animation: ac-fade-in 0.15s ease; }

@keyframes ac-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* -------------------------------------------------------------------- */
/* Lista de Certificados                                                 */
/* -------------------------------------------------------------------- */

.ac-cert-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.ac-cert-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--ac-bg);
    border: 1px solid var(--ac-border);
    border-radius: 8px;
    gap: 12px;
}

.ac-cert-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ac-cert-info strong { color: var(--ac-text); font-size: 14px; }
.ac-cert-meta { font-size: 12px; color: var(--ac-text-muted); }

.ac-btn-excluir-cert {
    background: transparent;
    border: 1px solid #C62828;
    color: #C62828;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, color 0.2s;
}
.ac-btn-excluir-cert:hover { background: #C62828; color: #fff; }

.ac-theme-toggle {
    background: var(--ac-bg);
    border: 1px solid var(--ac-border);
    border-radius: 999px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--ac-primary);
    transition: background 0.2s, transform 0.2s;
}

.ac-theme-toggle:hover {
    transform: rotate(15deg);
    background: var(--ac-border);
}

.ac-icon-moon { display: none; }
body.ac-dark-mode .ac-icon-sun { display: none; }
body.ac-dark-mode .ac-icon-moon { display: block; }

/* -------------------------------------------------------------------- */
/* Formulários                                                           */
/* -------------------------------------------------------------------- */

.ac-form-group { margin-bottom: 16px; }

.ac-label-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
}

.ac-form-group label {
    display: block;
    font-weight: 600;
    font-size: 14px;
    color: var(--ac-text);
}

.ac-chave-counter {
    font-size: 13px;
    color: var(--ac-text-muted);
}
.ac-chave-counter strong { color: var(--ac-accent); }

.ac-form-group textarea,
.ac-form-group select,
.ac-form-group input[type="text"],
.ac-form-group input[type="password"],
.ac-form-group input[type="file"] {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--ac-border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--ac-bg);
    color: var(--ac-text);
    font-family: inherit;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ac-form-group textarea {
    font-family: 'Courier New', monospace;
    resize: vertical;
}

.ac-form-group textarea:focus,
.ac-form-group select:focus,
.ac-form-group input:focus {
    outline: none;
    border-color: var(--ac-accent);
    box-shadow: 0 0 0 3px rgba(255, 107, 0, 0.15);
}

.ac-checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    font-weight: 500 !important;
    cursor: pointer;
    height: 100%;
    padding-top: 10px;
}
.ac-checkbox-label input { width: auto !important; }

.ac-form-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}
.ac-form-row .ac-form-group { flex: 1; min-width: 160px; margin-bottom: 0; }

.ac-align-end { display: flex; align-items: flex-end; }

/* -------------------------------------------------------------------- */
/* Barra de progresso (consulta em lotes)                                */
/* -------------------------------------------------------------------- */

.ac-progress-wrapper { margin-top: 16px; }

.ac-progress-track {
    width: 100%;
    height: 8px;
    background: var(--ac-border);
    border-radius: 999px;
    overflow: hidden;
}

.ac-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--ac-accent);
    border-radius: 999px;
    transition: width 0.25s ease;
}

.ac-progress-label {
    font-size: 12.5px;
    color: var(--ac-text-muted);
    margin: 6px 0 0;
    text-align: center;
}

/* -------------------------------------------------------------------- */
/* Botões                                                                */
/* -------------------------------------------------------------------- */

.ac-btn-primary {
    background: var(--ac-accent);
    color: #FFFFFF;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    white-space: nowrap;
}
.ac-btn-primary:hover { background: var(--ac-accent-hover); }
.ac-btn-primary:active { transform: scale(0.98); }
.ac-btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.ac-btn-secondary {
    background: transparent;
    color: var(--ac-primary);
    border: 1.5px solid var(--ac-primary);
    padding: 10px 18px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.ac-btn-secondary:hover { background: var(--ac-primary); color: #fff; }

.ac-btn-sm {
    background: var(--ac-bg);
    border: 1px solid var(--ac-border);
    color: var(--ac-primary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12.5px;
    cursor: pointer;
    font-weight: 600;
}
.ac-btn-sm:hover { background: var(--ac-border); }

.ac-btn-link {
    background: none;
    border: none;
    color: var(--ac-accent);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 0 0;
}

/* -------------------------------------------------------------------- */
/* Layout Sidebar + Tabela                                               */
/* -------------------------------------------------------------------- */

.ac-layout-grid {
    display: grid;
    grid-template-columns: 450px 1fr;
    gap: 16px;
}

@media (max-width: 900px) {
    .ac-layout-grid { grid-template-columns: 1fr; }
}

.ac-sidebar h4 {
    color: var(--ac-primary);
    font-family: 'Montserrat', sans-serif;
    margin: 0 0 10px;
    font-size: 15px;
}

.ac-filter-hint {
    font-weight: 400;
    color: var(--ac-text-muted);
    font-size: 11.5px;
}

.ac-stats-list {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 14px;
}
.ac-stats-list li {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    color: var(--ac-text-muted);
}
.ac-stats-list strong { color: var(--ac-text); }

.ac-sidebar hr {
    border: none;
    border-top: 1px solid var(--ac-border);
    margin: 16px 0;
}

.ac-alerts-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ac-alert-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    border: 2px solid transparent;
    cursor: pointer;
    width: 100%;
    text-align: left;
    font-family: inherit;
    transition: transform 0.15s, border-color 0.15s;
}
.ac-alert-item:hover { transform: translateX(2px); }
.ac-alert-item.active { border-color: currentColor; }

.alert-orange { background: #FFF3E0; color: #E65100; }
.alert-red { background: #FFEBEE; color: #C62828; }
.alert-darkred { background: #EFEBE9; color: #4E342E; }
.alert-gray { background: #ECEFF1; color: #37474F; }

body.ac-dark-mode .alert-orange { background: #4a2e10; color: #ffb066; }
body.ac-dark-mode .alert-red { background: #4a1f22; color: #ff8a8a; }
body.ac-dark-mode .alert-darkred { background: #3a2620; color: #e0a893; }
body.ac-dark-mode .alert-gray { background: #2a3542; color: #cbd5e1; }

.ac-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}
.ac-card-header h3 {
    margin: 0;
    color: var(--ac-primary);
    font-family: 'Montserrat', sans-serif;
    font-size: 17px;
}

.ac-table-responsive { overflow-x: auto; }

.ac-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.ac-table th, .ac-table td {
    padding: 12px;
    border-bottom: 1px solid var(--ac-border);
    text-align: left;
    white-space: nowrap;
}

.ac-table th {
    background: var(--ac-bg);
    color: var(--ac-primary);
    font-family: 'Montserrat', sans-serif;
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.ac-table tbody tr:hover { background: var(--ac-bg); }
.ac-table td code { font-size: 12px; color: var(--ac-text-muted); }

.ac-truncate {
    display: inline-block;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
    cursor: help;
}

.ac-empty {
    text-align: center;
    color: var(--ac-text-muted);
    padding: 30px !important;
    white-space: normal;
}

.ac-badge-uf {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    background: var(--ac-primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.ac-badge-event {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--ac-bg);
    border: 1px solid var(--ac-border);
    font-size: 12px;
    font-weight: 600;
}
.ac-badge-event.evt-cce { background: #FFF3E0; color: #E65100; }
.ac-badge-event.evt-cancelamento { background: #FFEBEE; color: #C62828; }
.ac-badge-event.evt-desconhecimento { background: #EFEBE9; color: #4E342E; }
.ac-badge-event.evt-naorealizada { background: #ECEFF1; color: #37474F; }

.ac-row-erro { background: rgba(198, 40, 40, 0.06); }

/* -------------------------------------------------------------------- */
/* Configurações / Badges                                                */
/* -------------------------------------------------------------------- */

.ac-badge {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
}
.ac-badge-success { background: #E8F5E9; color: #2E7D32; }
.ac-badge-warning { background: #FFF8E1; color: #F9A825; }

body.ac-dark-mode .ac-badge-success { background: #1e3a24; color: #7ed99a; }
body.ac-dark-mode .ac-badge-warning { background: #3a3312; color: #ffd873; }

/* -------------------------------------------------------------------- */
/* Modal de Histórico Completo                                          */
/* -------------------------------------------------------------------- */

.ac-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    padding: 20px;
}

.ac-modal {
    background: var(--ac-surface);
    color: var(--ac-text);
    border-radius: 12px;
    max-width: 560px;
    width: 100%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0,0,0,0.25);
}

.ac-modal-largo { max-width: 96vw; width: 96vw; }

.ac-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid var(--ac-border);
}
.ac-modal-header h4 {
    margin: 0;
    color: var(--ac-primary);
    font-family: 'Montserrat', sans-serif;
}

.ac-modal-close {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--ac-text-muted);
}

.ac-modal-body {
    padding: 18px 22px;
    overflow-y: auto;
}

.ac-evento-item {
    border-left: 3px solid var(--ac-accent);
    padding: 8px 14px;
    margin-bottom: 12px;
    background: var(--ac-bg);
    border-radius: 0 8px 8px 0;
}
.ac-evento-item strong { color: var(--ac-primary); }
.ac-evento-item p { margin: 4px 0 0; font-size: 13px; color: var(--ac-text-muted); }

/* -------------------------------------------------------------------- */
/* Monitor de Eventos                                                    */
/* -------------------------------------------------------------------- */

.ac-monitor-grupo {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.ac-monitor-card {
    background: var(--ac-bg);
    border: 1px solid var(--ac-border);
    border-radius: 10px;
    padding: 14px 16px;
}

.ac-monitor-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

.ac-monitor-card-acoes {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.ac-monitor-progress-track {
    width: 100%;
    height: 6px;
    background: var(--ac-border);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 8px;
}

.ac-monitor-progress-bar {
    height: 100%;
    background: var(--ac-accent);
    border-radius: 999px;
    transition: width 0.3s ease;
}

.ac-monitor-meta {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--ac-text-muted);
    margin-bottom: 8px;
}

.ac-monitor-alertas {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.ac-sidebar-monitor-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--ac-border);
}
.ac-sidebar-monitor-item:last-child { border-bottom: none; }

.ac-sidebar-monitor-item-alerta {
    background: rgba(255, 107, 0, 0.06);
    border-radius: 8px;
    padding: 10px 10px;
    margin: 2px 0;
}

.ac-monitor-alerta-novidade {
    display: block;
    width: 100%;
    text-align: left;
    background: var(--ac-accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    margin: 6px 0;
    transition: background 0.2s;
}
.ac-monitor-alerta-novidade:hover { background: var(--ac-accent-hover); }

.ac-sidebar-monitor-linha1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.ac-sidebar-monitor-nome {
    font-size: 13px;
    font-weight: 600;
    color: var(--ac-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ac-sidebar-monitor-nome small { font-weight: 400; color: var(--ac-text-muted); }

.ac-sidebar-monitor-acoes {
    display: flex;
    gap: 10px;
}
.ac-sidebar-monitor-acoes .ac-btn-link { padding: 0; font-size: 12px; }

/* -------------------------------------------------------------------- */
/* Responsividade Geral                                                  */
/* -------------------------------------------------------------------- */

@media (max-width: 600px) {
    .ac-form-row { flex-direction: column; align-items: stretch; }
    .ac-card { padding: 18px; }
}
