* {
    box-sizing: border-box;
}

:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #020617;
    --border: #334155;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --blue: #2563eb;
    --green: #16a34a;
    --red: #dc2626;
    --yellow: #ca8a04;
    --gray: #64748b;
    --purple: #7c3aed;
    --cyan: #0891b2;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, Arial, sans-serif;
    padding: 24px;
}

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

h1 {
    margin: 0;
    font-size: 32px;
    letter-spacing: -0.5px;
}

p {
    margin: 6px 0 0;
    color: var(--muted);
}

.muted-line {
    display: block;
    margin-top: 8px;
    color: var(--muted);
}

.top-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.refresh {
    background: var(--surface);
    padding: 12px 16px;
    border-radius: 12px;
    color: #cbd5e1;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 165px;
}

.refresh span {
    color: var(--muted);
    font-size: 12px;
}

.btn-primary,
.filtro-botao button {
    background: var(--blue);
    color: white;
    border: none;
    padding: 11px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 700;
}

.btn-secondary {
    background: #334155;
    color: #e5e7eb;
    border: 1px solid #475569;
    padding: 10px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 700;
}

.btn-danger-soft {
    background: #450a0a;
    color: #fecaca;
    border: 1px solid #7f1d1d;
    padding: 10px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 700;
}

.btn-secondary:hover,
.btn-primary:hover,
.btn-danger-soft:hover,
.modal-toolbar button:hover {
    filter: brightness(1.15);
}

.cards {
    display: grid;
    grid-template-columns: repeat(7, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: linear-gradient(180deg, #1e293b, #172033);
    border-radius: 18px;
    padding: 18px;
    border-left: 5px solid var(--gray);
    box-shadow: 0 14px 30px rgba(0,0,0,.18);
    min-height: 120px;
}

.card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.card strong {
    display: block;
    font-size: 32px;
    margin-top: 8px;
}

.card small {
    display: block;
    color: #cbd5e1;
    margin-top: 6px;
    font-size: 12px;
    word-break: break-word;
}

.blue { border-color: var(--blue); }
.green { border-color: var(--green); }
.red { border-color: var(--red); }
.yellow { border-color: var(--yellow); }
.gray { border-color: var(--gray); }
.purple { border-color: var(--purple); }
.cyan { border-color: var(--cyan); }

.box {
    background: var(--surface);
    border-radius: 18px;
    padding: 18px;
    margin-bottom: 24px;
    border: 1px solid rgba(148,163,184,.14);
    box-shadow: 0 14px 35px rgba(0,0,0,.16);
}

.box-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.box h2 {
    margin: 0;
}

.box-head span {
    color: var(--muted);
    font-size: 13px;
}

code {
    color: #bfdbfe;
    background: #0f172a;
    padding: 2px 6px;
    border-radius: 6px;
}

.filtros-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(140px, 1fr));
    gap: 14px;
    align-items: end;
}

.filtros-grid label {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 6px;
}

.filtros-grid input,
.filtros-grid select {
    width: 100%;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    outline: none;
}

.filtro-botao {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.processando-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 14px;
}

.proc-card {
    background: #0f172a;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    border-left: 5px solid var(--blue);
}

.proc-card.stage-download { border-left-color: #0ea5e9; }
.proc-card.stage-validacao { border-left-color: #eab308; }
.proc-card.stage-conversao { border-left-color: #a855f7; }
.proc-card.stage-upload { border-left-color: #22c55e; }
.proc-card.stage-mongo { border-left-color: #14b8a6; }
.proc-card.stage-api { border-left-color: #f97316; }
.proc-card.stage-clean { border-left-color: #64748b; }
.proc-card.stage-erro { border-left-color: var(--red); }
.proc-card.stage-ok { border-left-color: var(--green); }

.proc-title {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}

.proc-title strong {
    font-size: 16px;
}

.proc-meta {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    color: #cbd5e1;
    font-size: 13px;
}

.proc-stage {
    margin-top: 12px;
    padding: 10px;
    background: #111827;
    border: 1px solid #334155;
    border-radius: 12px;
}

.progress {
    width: 100%;
    height: 8px;
    background: #334155;
    border-radius: 999px;
    overflow: hidden;
    margin-top: 10px;
}

.progress > div {
    height: 100%;
    background: var(--blue);
    width: 30%;
    animation: pulseBar 1.3s infinite ease-in-out;
}

@keyframes pulseBar {
    0% { width: 18%; }
    50% { width: 80%; }
    100% { width: 18%; }
}

.table-wrap {
    overflow-x: auto;
    border-radius: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1600px;
}

th,
td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
    font-size: 13px;
}

th {
    background: var(--surface-2);
    color: #cbd5e1;
    position: sticky;
    top: 0;
    z-index: 1;
}

tr:hover td {
    background: rgba(15, 23, 42, .45);
}

.mono {
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
    color: #dbeafe;
    word-break: break-all;
}

.badge {
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    display: inline-block;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.rodando { background: var(--blue); color: white; }
.concluido { background: var(--green); color: white; }
.erro { background: var(--red); color: white; }
.pendente { background: var(--gray); color: white; }
.warn { background: var(--yellow); color: white; }

.stage-pill {
    display: inline-flex;
    border-radius: 999px;
    padding: 6px 10px;
    font-weight: 800;
    font-size: 12px;
    color: white;
    background: var(--blue);
}

.stage-pill.stage-download { background: #0ea5e9; }
.stage-pill.stage-validacao { background: #eab308; color: #111827; }
.stage-pill.stage-conversao { background: #a855f7; }
.stage-pill.stage-upload { background: #22c55e; }
.stage-pill.stage-mongo { background: #14b8a6; }
.stage-pill.stage-api { background: #f97316; }
.stage-pill.stage-clean { background: #64748b; }
.stage-pill.stage-erro { background: var(--red); }
.stage-pill.stage-ok { background: var(--green); }

.btn-log,
.btn-erro,
.btn-json {
    color: white;
    border: none;
    padding: 8px 11px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 800;
    margin: 2px;
}

.btn-log { background: var(--blue); }
.btn-erro { background: var(--red); }
.btn-json { background: var(--purple); }

.sem-erro {
    color: var(--gray);
    font-size: 13px;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.88);
    z-index: 9999;
    padding: 30px;
}

.modal.ativo {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-box {
    background: var(--surface-2);
    width: 94%;
    max-width: 1350px;
    max-height: 92vh;
    border-radius: 18px;
    padding: 20px;
    border: 1px solid var(--border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    gap: 16px;
}

.modal-header h2 {
    margin: 0;
}

.modal-header button {
    background: var(--red);
    color: white;
    border: none;
    padding: 9px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 800;
}

.modal-resumo {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.modal-pill {
    background: #0f172a;
    border: 1px solid var(--border);
    padding: 10px;
    border-radius: 12px;
}

.modal-pill span {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.modal-pill strong {
    display: block;
    margin-top: 4px;
    word-break: break-all;
}

.modal-toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    background: #020617;
    padding: 10px 0 12px;
    border-bottom: 1px solid #334155;
    margin-bottom: 12px;
}

.modal-toolbar button {
    background: #1e293b;
    color: #e5e7eb;
    border: 1px solid #334155;
    padding: 8px 12px;
    border-radius: 9px;
    cursor: pointer;
    font-weight: 700;
}

.modal-toolbar .danger-soft {
    border-color: #7f1d1d;
    background: #450a0a;
    color: #fecaca;
}

#modalConteudo {
    background: #0f172a;
    color: #e5e7eb;
    padding: 16px;
    border-radius: 12px;
    max-height: 66vh;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 13px;
    line-height: 1.55;
    flex: 1;
}

.empty {
    color: var(--muted);
    padding: 14px;
}

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    background: #16a34a;
    color: #fff;
    padding: 12px 16px;
    border-radius: 12px;
    font-weight: 700;
    box-shadow: 0 18px 40px rgba(0,0,0,.35);
    transform: translateY(120px);
    opacity: 0;
    transition: .2s ease;
    z-index: 10000;
}

.toast.ativo {
    transform: translateY(0);
    opacity: 1;
}

@media (max-width: 1100px) {
    .cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .filtros-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    body {
        padding: 14px;
    }
}

@media (max-width: 640px) {
    .cards,
    .filtros-grid {
        grid-template-columns: 1fr;
    }

    .top-actions {
        justify-content: flex-start;
    }
}
