/* ============================================================
   ÁREA PRINCIPAL
   ============================================================ */

.download-hero {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 50px 20px 35px;
    box-sizing: border-box;
    background: radial-gradient(circle at 50% 20%, rgba(52, 211, 153, .12), transparent 45%), linear-gradient(135deg, #071a18 0%, #0d332e 50%, #061714 100%);
    box-shadow: 0 15px 50px rgba(0,0,0,.20);
}

/* ============================================================
   ÁREA DA FÍSICA
   NÃO ALTERADA
   ============================================================ */

.physics-background {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    overflow: hidden;
    background: radial-gradient(circle at 50% 20%, rgba(52, 211, 153, .10), transparent 45%), linear-gradient(135deg, #071a18 0%, #0d332e 50%, #061714 100%);
}

#physics-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    z-index: 1;
}

.physics-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    background: radial-gradient(ellipse at center, rgba(5, 20, 18, .08) 0%, rgba(5, 20, 18, .50) 100%);
}

.physics-info {
    position: absolute;
    top: 20px;
    left: 26px;
    z-index: 3;
    color: #e2e8f0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    pointer-events: none;
    text-shadow: 0 2px 5px rgba(0, 0, 0, .5);
}

    .physics-info h2 {
        margin: 0 0 5px;
        font-size: 1.10rem;
        font-weight: 700;
    }

    .physics-info p {
        margin: 0;
        font-size: .88rem;
        opacity: .9;
    }

    .physics-info strong {
        color: #34d399;
        font-size: 1.05rem;
    }

/* ============================================================
   CARD
   ============================================================ */

.download-hero .card-wrap {
    position: relative;
    z-index: 10;
    width: min(620px, 100%);
    max-height: 100%;
    margin: 0;
    padding: 0;
    text-align: center;
}

/* ============================================================
   TÍTULO
   ============================================================ */

.download-hero .page-title {
    color: white;
    font-family: Arial, Helvetica, sans-serif;
    font-size: clamp(1.6rem, 3vw, 2.25rem);
    font-weight: 600;
    margin: 0 0 7px;
    line-height: 1.2;
    letter-spacing: normal;
    text-shadow: 0 3px 10px rgba(0, 0, 0, .45);
}

.download-hero .page-sub {
    color: rgba(134, 213, 180, 0.82);
    margin: 0 0 16px;
    font-size: .92rem;
    text-shadow: 0 1px 4px rgba(0,0,0,.3);
}

/* ============================================================
   CARD DE CONSULTA
   ============================================================ */

.download-hero .query-card {
    position: relative;
    width: 100%;
    padding: 24px;
    border-radius: 18px;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
    border: 1px solid rgba(255,255,255,.8);
    text-align: left;
    box-sizing: border-box;
    z-index: 1;
}

    .download-hero .query-card::before {
        content: "";
        position: absolute;
        left: -15px;
        right: -15px;
        top: -15px;
        bottom: -15px;
        border-radius: 33px;
        background: rgba(255,255,255,.96);
        border: 1px solid rgba(255,255,255,.8);
        box-shadow: 0 20px 60px rgba(0,0,0,.35);
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
        z-index: -1;
        pointer-events: none;
    }

/* ============================================================
   TIPO
   ============================================================ */

.type-toggle {
    display: flex;
    gap: 6px;
    padding: 5px;
    background: #eef2f1;
    border-radius: 12px;
    margin-bottom: 18px;
    position: relative;
    z-index: 2;
}

    .type-toggle button {
        flex: 1;
        border: 0;
        background: transparent;
        color: #64748b;
        padding: 10px 12px;
        border-radius: 9px;
        font-size: .92rem;
        font-weight: 600;
        cursor: pointer;
        transition: background .2s ease, color .2s ease, box-shadow .2s ease;
    }

        .type-toggle button:hover {
            color: #417A4A;
        }

        .type-toggle button.active {
            background: #417A4A;
            color: #ffffff;
            box-shadow: 0 2px 8px rgba(0,0,0,.15);
        }

            .type-toggle button.active:hover {
                background: #2f5c36;
                color: #ffffff;
            }

/* ============================================================
   DIVISOR
   ============================================================ */

.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #64748b;
    font-size: .82rem;
    font-weight: 600;
    margin-bottom: 16px;
    position: relative;
    z-index: 2;
}

    .divider::after {
        content: "";
        flex: 1;
        height: 1px;
        background: #e2e8f0;
    }

/* ============================================================
   LABEL
   ============================================================ */

.field-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 7px;
    position: relative;
    z-index: 2;
}

    .field-label-row label {
        color: #1e293b;
        font-size: .88rem;
        font-weight: 700;
    }

.char-count {
    color: #94a3b8;
    font-size: .78rem;
}

    .char-count strong {
        color: #417A4A;
    }

/* ============================================================
   INPUT
   ============================================================ */

.key-input {
    width: 100%;
    height: 50px;
    box-sizing: border-box;
    border: 1px solid #dbe3e1;
    border-radius: 11px;
    padding: 0 15px;
    color: #17211f;
    background: #ffffff;
    font-family: "Consolas", "Courier New", monospace;
    font-size: .90rem;
    outline: none;
    transition: border-color .2s ease, box-shadow .2s ease;
    position: relative;
    z-index: 2;
}

    .key-input:focus {
        border-color: #417A4A;
        box-shadow: 0 0 0 4px rgba(65,122,74,.10);
    }

/* ============================================================
   HINT
   ============================================================ */

.hint {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    color: #64748b;
    font-size: .80rem;
    position: relative;
    z-index: 2;
}

    .hint.error {
        color: #d5304a;
    }

    .hint svg {
        width: 17px;
        height: 17px;
        flex-shrink: 0;
    }

/* ============================================================
   BOTÕES
   ============================================================ */

.actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    position: relative;
    z-index: 2;
}

.btn {
    height: 46px;
    border: 0;
    border-radius: 10px;
    padding: 0 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: .88rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .2s ease, opacity .2s ease;
}

    .btn:hover {
        transform: translateY(-1px);
    }

.btn-primary {
    flex: 1;
    background: #417A4A;
    color: white;
    box-shadow: 0 5px 15px rgba(65,122,74,.25);
}

    .btn-primary:hover {
        background: #2f5c36;
        box-shadow: 0 7px 20px rgba(65,122,74,.35);
    }

.btn-secondary {
    background: #edf2f1;
    color: #475569;
    text-decoration: none;
}

    .btn-secondary:hover {
        background: #e2e9e7;
        color: #475569;
    }

/* ============================================================
   STATUS
   ============================================================ */

.status-box {
    display: flex;
    margin-top: 16px;
    padding: 14px;
    border-radius: 12px;
    align-items: flex-start;
    gap: 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    position: relative;
    z-index: 2;
}

    .status-box.success {
        background: #f0fdf4;
        border-color: #bbf7d0;
    }

    .status-box.error {
        background: #fff1f2;
        border-color: #fecdd3;
    }

.status-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

    .status-icon svg {
        width: 28px;
        height: 28px;
    }

.status-title {
    color: #1e293b;
    font-size: .90rem;
    font-weight: 700;
    margin-bottom: 3px;
}

.status-desc {
    color: #64748b;
    font-size: .80rem;
    line-height: 1.4;
}

.status-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.mini-btn {
    border: 0;
    border-radius: 7px;
    background: #417A4A;
    color: white;
    padding: 8px 12px;
    font-size: .76rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: opacity .2s ease;
}

    .mini-btn:hover {
        opacity: .88;
        color: white;
    }

/* ============================================================
   TOAST SERVER SIDE
   ============================================================ */

.server-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    padding: 12px 20px;
    border-radius: 8px;
    color: #fff;
    font-family: sans-serif;
    box-shadow: 0 4px 12px rgba(0,0,0,.2);
    animation: toastIn .3s ease forwards;
}

    .server-toast.success {
        background: #417A4A;
    }

    .server-toast.error {
        background: #d5304a;
    }

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================
   BARRA DE EMPRESA
   ============================================================ */

.empresa-bar {
    position: relative;
    z-index: 10;
    width: min(620px, 100%);
    display: flex;
    align-items: center;
    gap: 0;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.13);
    border-radius: 10px;
    padding: 0 4px 0 14px;
    height: 44px;
    backdrop-filter: blur(6px);
    flex-shrink: 0;
}

.empresa-bar-texto {
    flex: 1;
    font-size: 13.5px;
    color: rgba(255,255,255,0.45);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    user-select: none;
}

.empresa-bar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,0.55);
    padding: 8px 10px;
    border-radius: 7px;
    transition: background .15s, color .15s;
    flex-shrink: 0;
}

    .empresa-bar-btn:hover {
        background: rgba(255,255,255,0.10);
        color: #fff;
    }

    .empresa-bar-btn svg {
        width: 17px;
        height: 17px;
    }

.empresa-bar-sep {
    width: 1px;
    height: 24px;
    background: rgba(255,255,255,0.12);
    flex-shrink: 0;
}

.empresa-bar-add {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(52,211,153,0.15);
    border: none;
    cursor: pointer;
    color: #34d399;
    padding: 8px 10px;
    border-radius: 7px;
    margin-left: 2px;
    transition: background .15s, color .15s;
    flex-shrink: 0;
}

    .empresa-bar-add:hover {
        background: rgba(52,211,153,0.28);
        color: #6ee7b7;
    }

    .empresa-bar-add svg {
        width: 17px;
        height: 17px;
    }

/* ============================================================
   LISTA DE EMPRESAS
   ============================================================ */

.empresa-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 9px;
    border: 1.5px solid var(--gray-200);
    margin-bottom: 8px;
    transition: border-color .15s;
}

    .empresa-item.selecionada {
        border-color: var(--blue-accent);
        background: color-mix(in srgb, var(--blue-accent) 6%, transparent);
    }

.empresa-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

    .empresa-item-info strong {
        font-size: 14px;
        color: var(--navy-950);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .empresa-item-info span {
        font-size: 12px;
        color: var(--gray-400);
    }

.empresa-item-acoes {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.emp-btn-selecionar {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: 7px;
    border: none;
    background: var(--blue-accent);
    color: #fff;
    font-size: 13px;
    cursor: pointer;
    transition: opacity .15s;
}

    .emp-btn-selecionar svg {
        width: 14px;
        height: 14px;
    }

    .emp-btn-selecionar:hover {
        opacity: .85;
    }

.emp-btn-editar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 7px;
    border: 1.5px solid var(--gray-200);
    background: var(--gray-50);
    color: var(--gray-500);
    cursor: pointer;
    transition: border-color .15s, color .15s;
}

    .emp-btn-editar svg {
        width: 15px;
        height: 15px;
    }

    .emp-btn-editar:hover {
        border-color: var(--blue-accent);
        color: var(--blue-accent);
    }

/* Modal de edição: fechado por padrão */
.modal-editar {
    display: none;
    opacity: 0;
    pointer-events: none;
}

    /* Abre quando a âncora bate com o id */
    .modal-editar:target {
        display: flex;
        opacity: 1;
        pointer-events: all;
    }

/* ============================================================
   MODAL DO PDF
   ============================================================ */

.pdf-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(7, 26, 24, 0.70);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    animation: pdfFade .2s ease;
}

.pdf-modal-close {
    position: fixed;
    top: 12px;
    right: 16px;
    z-index: 10000;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(0,0,0,.55);
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}

    .pdf-modal-close:hover {
        background: rgba(0,0,0,.75);
    }

.pdf-modal-box {
    position: relative;
    width: 90vw;
    height: 90vh;
    background: #fff;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
    animation: pdfSobe .25s ease;
}

    /* Quando é erro, a caixa fica compacta em vez de ocupar a tela toda */
    .pdf-modal-box.compacto {
        width: min(440px, 92vw);
        height: auto;
    }

    .pdf-modal-box iframe {
        width: 100%;
        height: 100%;
        border: none;
    }

.pdf-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 28px;
    color: #64748b;
    box-sizing: border-box;
}

    .pdf-state h3 {
        margin: 16px 0 6px;
        font-size: 1.1rem;
        font-weight: 700;
        color: #1e293b;
    }

    .pdf-state p {
        margin: 0;
        font-size: .88rem;
    }

.pdf-erro-icone {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #fff1f2;
    border: 1px solid #fecdd3;
    color: #d5304a;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .pdf-erro-icone svg {
        width: 32px;
        height: 32px;
    }

.pdf-erro-chave {
    margin-top: 14px !important;
    font-family: "Consolas", "Courier New", monospace;
    font-size: .72rem !important;
    word-break: break-all;
    background: #eef2f1;
    padding: 8px 12px;
    border-radius: 8px;
    color: #475569;
}

.pdf-erro-acoes {
    display: flex;
    gap: 10px;
    margin-top: 24px;
    width: 100%;
}

.pdf-btn,
.pdf-btn-sec {
    flex: 1;
    height: 44px;
    border: 0;
    border-radius: 10px;
    font-size: .88rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform .15s ease, background .2s ease, box-shadow .2s ease;
}

    .pdf-btn:hover,
    .pdf-btn-sec:hover {
        transform: translateY(-1px);
    }

.pdf-btn {
    background: #417A4A;
    color: #fff;
    box-shadow: 0 5px 15px rgba(65,122,74,.25);
}

    .pdf-btn:hover {
        background: #2f5c36;
        box-shadow: 0 7px 20px rgba(65,122,74,.35);
    }

.pdf-btn-sec {
    background: #edf2f1;
    color: #475569;
}

    .pdf-btn-sec:hover {
        background: #e2e9e7;
    }

.pdf-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e2e8f0;
    border-top-color: #417A4A;
    border-radius: 50%;
    animation: pdfGira .8s linear infinite;
    margin-bottom: 14px;
}

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

@keyframes pdfFade {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes pdfSobe {
    from {
        transform: translateY(12px);
        opacity: 0;
    }

    to {
        transform: none;
        opacity: 1;
    }
}

/* ============================================================
   ALTURA PEQUENA
   ============================================================ */

@media (max-height: 750px) and (min-width: 769px) {

    .download-hero {
        padding-top: 45px;
        padding-bottom: 25px;
    }

        .download-hero .card-wrap {
            transform: translateY(-50px);
        }

        .download-hero .query-card {
            padding: 20px;
        }

            .download-hero .query-card::before {
                left: -15px;
                right: -15px;
                top: -15px;
                bottom: -15px;
            }

        .download-hero .page-title {
            font-size: 1.8rem;
        }

        .download-hero .page-sub {
            margin-bottom: 15px;
        }

    .type-toggle {
        margin-bottom: 14px;
    }

    .actions {
        margin-top: 14px;
    }
}

/* ============================================================
   TABLET / CELULAR
   ============================================================ */

@media (max-width: 768px) {

    .download-hero {
        min-height: calc(100dvh - 80px);
        height: calc(100dvh - 80px);
        padding: 55px 15px 25px;
        border-radius: 14px;
    }

        .download-hero .card-wrap {
            width: min(620px, 100%);
            /* Mantém os 50px para cima */
            transform: translateY(-50px);
        }

    .physics-info {
        top: 14px;
        left: 18px;
    }

        .physics-info h2 {
            font-size: 1rem;
        }

        .physics-info p {
            font-size: .78rem;
        }

    .download-hero .query-card {
        padding: 20px;
    }

        .download-hero .query-card::before {
            left: -15px;
            right: -15px;
            top: -15px;
            bottom: -15px;
            border-radius: 29px;
        }

    .download-hero .page-title {
        font-size: 1.6rem;
        font-weight: 600;
    }

    .download-hero .page-sub {
        font-size: .88rem;
        margin-bottom: 18px;
    }

    .pdf-modal-box {
        width: 96vw;
        height: 92vh;
        border-radius: 14px;
    }
}

/* ============================================================
   CELULAR PEQUENO
   ============================================================ */

@media (max-width: 480px) {

    .download-hero {
        min-height: calc(100dvh - 70px);
        height: calc(100dvh - 70px);
        padding: 50px 12px 20px;
    }

        .download-hero .card-wrap {
            transform: translateY(-50px);
        }

        .download-hero .page-title {
            font-size: 1.35rem;
        }

        .download-hero .page-sub {
            font-size: .78rem;
            margin-bottom: 15px;
        }

        .download-hero .query-card {
            padding: 15px;
            border-radius: 14px;
        }

            .download-hero .query-card::before {
                left: -15px;
                right: -15px;
                top: -15px;
                bottom: -15px;
                border-radius: 29px;
            }

    .type-toggle {
        margin-bottom: 14px;
    }

        .type-toggle button {
            font-size: .80rem;
            padding: 9px 6px;
        }

    .key-input {
        height: 48px;
        font-size: .75rem;
        padding: 0 11px;
    }

    .hint {
        font-size: .74rem;
    }

    .actions {
        flex-direction: column;
        gap: 8px;
        margin-top: 15px;
    }

    .btn {
        width: 100%;
    }

    .status-actions {
        flex-direction: column;
    }

    .mini-btn {
        width: 100%;
        text-align: center;
    }

    .server-toast {
        left: 15px;
        right: 15px;
        bottom: 15px;
        text-align: center;
    }

    .pdf-erro-acoes {
        flex-direction: column;
    }
}