/* -----------------------------------------------------------------------------
   Identidade visual herdada do nova_vida / Lemmit_Salao:
   fundo #0f1115, primaria #6366f1, Inter, glow radial, cards em glassmorphism.
   O miolo e que muda: dropzone, previa de custo, barra de progresso.
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
   Inter servida LOCALMENTE (public/fonts), nao pelo fonts.googleapis.com.
   Esta pagina exibe PII: nao ha razao para avisar um terceiro, a cada
   carregamento, que alguem abriu a tela de higienizacao. Tambem e o que permite
   a CSP fechada em 'self' (font-src 'self').

   Sao os subsets latin e latin-ext do arquivo variavel Inter v20 (weight 100-900),
   os mesmos que o Google entrega para pt-BR. latin-ext carrega os acentos que a
   interface usa de fato.
----------------------------------------------------------------------------- */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('fonts/inter-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
        U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
        U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('fonts/inter-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
        U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
        U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    --bg-color: #0f1115;
    --card-bg: rgba(23, 25, 30, 0.7);
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --text-main: #ffffff;
    --text-muted: #9ca3af;
    --border-color: rgba(255, 255, 255, 0.1);
    --glass-border: 1px solid rgba(255, 255, 255, 0.08);
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
        'Helvetica Neue', Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 2rem;
    overflow-x: hidden;
}

.background-glow {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at center, rgba(99, 102, 241, 0.15) 0%, rgba(15, 17, 21, 0) 60%);
    z-index: -1;
    pointer-events: none;
}

.container {
    width: 100%;
    max-width: 900px;
}

.header {
    text-align: center;
    margin-bottom: 2.5rem;
    animation: fadeInDown 0.8s ease-out;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.saldo-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.25);
    color: #c7d2fe;
    padding: 0.4rem 1rem;
    border-radius: 999px;
    font-size: 0.85rem;
}

.saldo-chip strong {
    color: #fff;
}

/* --- Cards ---------------------------------------------------------------- */

.card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: var(--glass-border);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    animation: fadeInUp 0.5s ease-out;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    gap: 1rem;
}

.card-header h2 {
    font-size: 1.15rem;
    font-weight: 600;
}

.badge {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
}

.badge.ok { background: rgba(52, 211, 153, 0.12); color: var(--success); }
.badge.alerta { background: rgba(251, 191, 36, 0.12); color: var(--warning); }
.badge.erro { background: rgba(248, 113, 113, 0.12); color: var(--danger); }

/* --- Dropzone ------------------------------------------------------------- */

.dropzone {
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s ease;
    background: rgba(0, 0, 0, 0.15);
}

.dropzone:hover,
.dropzone.arrastando {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.07);
    box-shadow: var(--shadow-glow);
}

.dropzone svg {
    margin-bottom: 1rem;
    opacity: 0.8;
}

.dropzone h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.dropzone p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.dropzone .formatos {
    margin-top: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    opacity: 0.75;
}

/* --- Botoes --------------------------------------------------------------- */

.btn-primary,
.btn-secondary {
    border: none;
    padding: 0.9rem 1.75rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
}

.btn-primary:disabled,
.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-loader {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
}

.btn-primary.loading .btn-text { display: none; }
.btn-primary.loading .btn-loader { display: block; }

@keyframes spin { 100% { transform: rotate(360deg); } }

.acoes {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}

/* --- Grade de numeros ----------------------------------------------------- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.stat {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
}

.stat .rotulo {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.4rem;
}

.stat .valor {
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.2;
    word-break: break-word;
}

.stat.destaque {
    border-color: rgba(99, 102, 241, 0.4);
    background: rgba(99, 102, 241, 0.08);
}

.stat.destaque .valor { color: #c7d2fe; }
.stat.positivo .valor { color: var(--success); }
.stat.alerta .valor { color: var(--warning); }
.stat.negativo .valor { color: var(--danger); }

/* --- Aviso de custo ------------------------------------------------------- */

.aviso-custo {
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.28);
    border-radius: 12px;
    padding: 1.25rem;
    margin-top: 1.5rem;
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.aviso-custo .icone {
    font-size: 1.4rem;
    line-height: 1;
}

.aviso-custo h4 {
    font-size: 1rem;
    margin-bottom: 0.35rem;
    color: var(--warning);
}

.aviso-custo p {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.aviso-custo strong { color: #fff; }

/* --- Progresso ------------------------------------------------------------ */

.barra {
    height: 12px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.barra .preenchida {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), #818cf8);
    border-radius: 999px;
    transition: width 0.4s ease;
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.6);
}

.barra.parcial .preenchida {
    background: linear-gradient(90deg, #b45309, var(--warning));
    box-shadow: none;
}

.linha-progresso {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.6rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    gap: 1rem;
}

.linha-progresso .contagem { color: #fff; font-weight: 600; }

.arquivo-nome {
    font-size: 0.85rem;
    color: var(--text-muted);
    word-break: break-all;
}

/* --- Mensagens ------------------------------------------------------------ */

.hidden { display: none !important; }

.error-message,
.info-message {
    padding: 1rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.5rem;
    animation: fadeInDown 0.3s ease-out;
    font-size: 0.92rem;
    line-height: 1.45;
}

.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.info-message {
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.25);
    color: #93c5fd;
}

.error-icon,
.info-icon {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.08);
}

.rodape {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-top: 2rem;
    line-height: 1.6;
}

@media (max-width: 768px) {
    body { padding: 1rem; }
    .acoes { flex-direction: column; }
    .acoes button { width: 100%; }
}

/* --- Animacoes ------------------------------------------------------------ */

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Utilitario: substitui os style="margin-top:1.5rem" que existiam no HTML.
   Atributo style inline e bloqueado pela CSP (style-src 'self'). */
.espaco-acima {
    margin-top: 1.5rem;
}

/* -----------------------------------------------------------------------------
   Campo de autoria
   Etiqueta digitada pelo operador e guardada no navegador. Nao e login: nao
   protege nada, so diz quem rodou o lote na biblioteca.
----------------------------------------------------------------------------- */
.campo-autor {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 1.25rem;
}

.campo-autor label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.campo-autor input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.65rem 0.85rem;
    color: var(--text-main);
    font-size: 0.95rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.campo-autor input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.campo-autor .dica {
    font-size: 0.78rem;
    color: var(--text-muted);
    opacity: 0.75;
}

/* -----------------------------------------------------------------------------
   Biblioteca de lotes
   Sai da largura do container (900px) porque a grade de cards pede espaco.
----------------------------------------------------------------------------- */
.secao-lotes {
    width: min(1200px, calc(100vw - 4rem));
    margin-left: 50%;
    transform: translateX(-50%);
    margin-top: 3rem;
}

.lotes-cabecalho {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 1.25rem;
    padding: 0 0.25rem;
}

.lotes-cabecalho h2 {
    font-size: 1.3rem;
    font-weight: 600;
}

.lotes-total {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.lotes-grade {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 1.25rem;
}

.lotes-vazio {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.95rem;
    padding: 2.5rem 1rem;
    border: 1px dashed var(--border-color);
    border-radius: 16px;
}

.lotes-rodape {
    display: flex;
    justify-content: center;
    margin-top: 1.5rem;
}

/* --- o card ---------------------------------------------------------------- */
.lote-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: var(--glass-border);
    border-radius: 16px;
    padding: 1.15rem 1.25rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.lote-card.processando {
    border-color: rgba(99, 102, 241, 0.45);
}

.lote-topo {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}

.lote-nome {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
    word-break: break-word;
}

.lote-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    line-height: 1.4;
}

.lote-quantidade {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
}

/* --- linha do provedor ----------------------------------------------------- */
.provedor-topo {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.provedor-nome {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.provedor-ponto {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.7);
    flex-shrink: 0;
}

.provedor-numeros {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: right;
    line-height: 1.4;
}

.provedor-numeros .com-tel {
    color: var(--success);
    font-weight: 600;
}

.provedor-numeros .com-erro {
    color: var(--danger);
}

.provedor-barra {
    height: 8px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.provedor-preenchida {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #059669, var(--success));
    border-radius: 999px;
    transition: width 0.4s ease;
}

.provedor-acao {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.6rem;
    justify-content: flex-end;
    min-height: 30px;
}

.completo {
    color: var(--success);
    font-size: 0.82rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

/* --- detalhe e acoes ------------------------------------------------------- */
.lote-detalhe {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.6;
    border-top: 1px solid var(--border-color);
    padding-top: 0.75rem;
}

.lote-acoes {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn-lote {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 0.45rem 0.85rem;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.btn-lote:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.05);
}

.btn-lote:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-lote.baixar {
    border-color: rgba(52, 211, 153, 0.45);
    color: var(--success);
    flex: 1;
    justify-content: center;
}

.btn-lote.baixar:hover:not(:disabled) {
    background: rgba(52, 211, 153, 0.1);
}

.btn-lote.retentar {
    border-color: rgba(251, 191, 36, 0.5);
    color: var(--warning);
}

.btn-lote.retentar:hover:not(:disabled) {
    background: rgba(251, 191, 36, 0.1);
}

.btn-lote.excluir {
    border-color: rgba(248, 113, 113, 0.4);
    color: var(--danger);
    padding: 0.45rem 0.7rem;
}

.btn-lote.excluir:hover:not(:disabled) {
    background: rgba(248, 113, 113, 0.12);
}

.lote-aviso {
    font-size: 0.75rem;
    color: var(--warning);
    line-height: 1.5;
}

@media (max-width: 640px) {
    .secao-lotes {
        width: 100%;
        margin-left: 0;
        transform: none;
    }
    .lotes-grade { grid-template-columns: 1fr; }
}

/* -----------------------------------------------------------------------------
   Tela de login
----------------------------------------------------------------------------- */
.container-login {
    max-width: 420px;
}

.container-login .campo-autor {
    margin-top: 0;
    margin-bottom: 1.1rem;
}

.container-login .acoes {
    margin-top: 1.5rem;
}

.container-login .btn-primary {
    width: 100%;
    justify-content: center;
}

/* --- identificação de quem está logado ------------------------------------ */
.barra-usuario {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.link-sair {
    background: none;
    border: none;
    color: var(--text-muted);
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0;
}

.link-sair:hover {
    color: var(--text-main);
}

/* -----------------------------------------------------------------------------
   Alerta da sentinela de saldo
   Vermelho e permanente enquanto durar: consumo sem origem e dinheiro saindo
   sem ninguem pedir. Nao pode se parecer com um aviso qualquer.
----------------------------------------------------------------------------- */
.alerta-sentinela {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.45);
    border-radius: 12px;
    padding: 1rem 1.15rem;
    margin-bottom: 1.5rem;
}

.alerta-sentinela h4 {
    color: var(--danger);
    font-size: 0.95rem;
    margin-bottom: 0.3rem;
}

.alerta-sentinela .alerta-texto {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.alerta-icone {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--danger);
    color: #0f1115;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}
