/* ==========================================================================
   PDF Tools - styling khusus halaman PDF Tools (pdf_tools.php & tool_page.php)
   Mengikuti palet dark theme situs (lihat css/dark-theme.css / var --pb-*).
   File ini dimuat SETELAH dark-theme.css sehingga variabel --pb-* selalu
   tersedia; urutan pemuatan tidak masalah karena var() diselesaikan langsung
   saat dipakai, bukan saat file di-parse.
   ========================================================================== */

.pdf-tools-hero { border-radius: 0 0 2rem 2rem; }

.pdf-tool-badge {
    width: 64px;
    height: 64px;
    border-radius: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    background: var(--pb-gradient);
    color: #fff;
    font-size: 1.9rem;
    box-shadow: 0 8px 22px rgba(79, 107, 255, .35);
}

.pdf-tool-card {
    transition: transform .15s ease, box-shadow .15s ease;
}
.pdf-tool-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 1rem 2rem rgba(79, 107, 255, .25) !important;
}

.pdf-tool-container { max-width: 900px; margin: 0 auto; }

/* ---- Dropzone ---- */
.pdf-dropzone {
    border: 2px dashed var(--pb-border-strong);
    border-radius: 1.25rem;
    padding: 3.5rem 1.5rem;
    text-align: center;
    cursor: pointer;
    background: var(--pb-surface);
    transition: border-color .15s ease, background-color .15s ease;
}
.pdf-dropzone:hover,
.pdf-dropzone:focus-visible {
    border-color: var(--pb-accent-1);
    background: var(--pb-surface-2);
    outline: none;
}
.pdf-dropzone-active {
    border-color: var(--pb-accent-1);
    background: var(--pb-surface-2);
}
.pdf-dropzone-hint { max-width: 420px; margin-left: auto; margin-right: auto; }

/* ---- Generic file card (merge / split / compress / watermark / page-numbers) ---- */
.pdf-file-list-sortable,
.pdf-image-list-sortable { display: flex; flex-direction: column; gap: .6rem; }

.pdf-file-card,
.pdf-image-card {
    display: flex;
    align-items: center;
    gap: .9rem;
    background: var(--pb-surface);
    border: 1px solid var(--pb-border);
    border-radius: .9rem;
    padding: .7rem 1rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}
.pdf-file-card-handle,
.pdf-image-card .pdf-file-card-handle {
    cursor: grab;
    color: var(--pb-text-muted);
    font-size: 1.1rem;
}

/* Thumbnail nyata halaman pertama PDF (pratinjau ala iLovePDF), dengan ikon
   generik sebagai fallback selama thumbnail masih dimuat / gagal dirender. */
.pdf-file-card-thumb {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    border-radius: .6rem;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--pb-surface-2);
    border: 1px solid var(--pb-border);
    font-size: 1.6rem;
    color: var(--pb-accent-1);
}
.pdf-file-card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.pdf-file-card-icon { font-size: 1.9rem; color: var(--pb-accent-1); flex-shrink: 0; }
.pdf-image-card img {
    width: 48px; height: 48px; object-fit: cover; border-radius: .5rem; flex-shrink: 0;
    border: 1px solid var(--pb-border);
}
.pdf-file-card-info { flex-grow: 1; min-width: 0; text-align: left; }
.pdf-file-card-name {
    font-weight: 600; font-size: .95rem;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pdf-file-card-meta { font-size: .8rem; color: var(--pb-text-muted); }
.pdf-file-card-remove { flex-shrink: 0; }
.pdf-file-card.sortable-ghost,
.pdf-image-card.sortable-ghost { opacity: .4; }

/* ---- Options panel ---- */
.pdf-options-card {
    background: var(--pb-surface);
    border: 1px solid var(--pb-border);
    border-radius: 1rem;
    padding: 1.5rem;
    text-align: left;
}

/* ---- Progress bar ---- */
.pdf-progress { max-width: 420px; height: .6rem; border-radius: 1rem; margin-top: .75rem; background-color: var(--pb-surface-3); }
.pdf-progress .progress-bar { background-color: var(--pb-accent-1); transition: width .2s ease; }

/* ---- Rotate PDF / Organize PDF thumbnail grid ---- */
.pdf-rotate-grid,
.pdf-organize-grid,
.pdf-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.pdf-rotate-thumb,
.pdf-organize-thumb {
    background: var(--pb-surface);
    border: 1px solid var(--pb-border);
    border-radius: .8rem;
    padding: .6rem;
    text-align: center;
    position: relative;
}
.pdf-rotate-thumb-imgwrap,
.pdf-organize-thumb-imgwrap {
    display: flex; align-items: center; justify-content: center;
    height: 150px; overflow: hidden; margin-bottom: .5rem;
}
.pdf-rotate-thumb img,
.pdf-organize-thumb img {
    max-width: 100%; max-height: 100%;
    transition: transform .15s ease;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .45);
    background: #fff;
}
.pdf-rotate-thumb-controls,
.pdf-organize-thumb-controls {
    display: flex; align-items: center; justify-content: space-between; gap: .25rem;
}
.pdf-organize-thumb-remove {
    position: absolute; top: .35rem; right: .35rem;
    width: 1.75rem; height: 1.75rem; padding: 0;
    border-radius: 50%; line-height: 1;
}
.pdf-organize-thumb.sortable-ghost { opacity: .35; }

/* ---- PDF to JPG preview grid ---- */
.pdf-preview-thumb {
    background: var(--pb-surface); border: 1px solid var(--pb-border); border-radius: .7rem;
    padding: .5rem; text-align: center;
}
.pdf-preview-thumb img { max-width: 100%; max-height: 130px; box-shadow: 0 1px 6px rgba(0, 0, 0, .4); background: #fff; }
.pdf-preview-thumb span { display: block; margin-top: .35rem; }

/* ---- Watermark / Page numbers: pratinjau langsung di atas halaman ---- */
.pdf-watermark-preview,
.pdf-pagenum-preview {
    background: var(--pb-surface);
    border: 1px solid var(--pb-border);
    border-radius: 1rem;
    padding: 1.25rem;
    display: flex;
    justify-content: center;
}
.pdf-watermark-preview-page,
.pdf-pagenum-preview-page {
    position: relative;
    display: inline-block;
    line-height: 0;
    max-width: 100%;
    border-radius: .3rem;
    overflow: hidden;
    box-shadow: 0 6px 22px rgba(0, 0, 0, .45);
    background: #fff;
}
.pdf-watermark-preview-page img,
.pdf-pagenum-preview-page img { display: block; max-width: 100%; height: auto; }

.pdf-watermark-preview-text {
    position: absolute;
    white-space: nowrap;
    pointer-events: none;
    font-weight: 700;
    user-select: none;
    transform-origin: center center;
}
.pdf-pagenum-preview-text {
    position: absolute;
    pointer-events: none;
    font-weight: 600;
    background: rgba(0, 0, 0, .6);
    color: #fff;
    padding: .1rem .45rem;
    border-radius: .3rem;
    font-size: .8rem;
    white-space: nowrap;
}

/* ---- Steps ---- */
.pdf-step { animation: pdfFadeIn .2s ease; }
@keyframes pdfFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

#pdfDoneStep i.bi-check-circle-fill { color: #2ecc71; }
#pdfErrorBanner { max-width: 900px; margin-left: auto; margin-right: auto; }

/* ---- Signature pad (dipakai Sign PDF & Edit PDF) ---- */
.pdf-signpad {
    display: block;
    width: 100%;
    max-width: 500px;
    height: auto;
    background: #fff;
    border: 1px dashed var(--pb-border-strong);
    border-radius: .8rem;
    touch-action: none;
    cursor: crosshair;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .35);
}

/* ---- Crop PDF ---- */
.pdf-crop-preview {
    background: var(--pb-surface);
    border: 1px solid var(--pb-border);
    border-radius: 1rem;
    padding: 1.25rem;
    display: flex;
    justify-content: center;
}
.pdf-crop-preview-page {
    position: relative;
    display: inline-block;
    line-height: 0;
    max-width: 100%;
    border-radius: .3rem;
    overflow: hidden;
    box-shadow: 0 6px 22px rgba(0, 0, 0, .45);
    background: #fff;
    touch-action: none;
}
.pdf-crop-preview-page img { display: block; max-width: 100%; height: auto; user-select: none; }
.pdf-crop-box {
    position: absolute;
    border: 2px solid var(--pb-accent-2);
    background: rgba(255, 63, 166, .12);
    box-shadow: 0 0 0 2000px rgba(10, 14, 23, .55);
    cursor: move;
    touch-action: none;
}
.pdf-crop-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--pb-accent-2);
    border: 2px solid #fff;
    border-radius: 50%;
    touch-action: none;
}
.pdf-crop-handle[data-handle="nw"] { top: -8px; left: -8px; cursor: nwse-resize; }
.pdf-crop-handle[data-handle="ne"] { top: -8px; right: -8px; cursor: nesw-resize; }
.pdf-crop-handle[data-handle="sw"] { bottom: -8px; left: -8px; cursor: nesw-resize; }
.pdf-crop-handle[data-handle="se"] { bottom: -8px; right: -8px; cursor: nwse-resize; }

/* ---- Sign PDF ---- */
.pdf-sign-preview {
    background: var(--pb-surface);
    border: 1px solid var(--pb-border);
    border-radius: 1rem;
    padding: 1.25rem;
    display: flex;
    justify-content: center;
}
.pdf-sign-preview-page {
    position: relative;
    display: inline-block;
    line-height: 0;
    max-width: 100%;
    border-radius: .3rem;
    overflow: hidden;
    box-shadow: 0 6px 22px rgba(0, 0, 0, .45);
    background: #fff;
    touch-action: none;
}
.pdf-sign-preview-page img { display: block; max-width: 100%; height: auto; user-select: none; }
.pdf-sign-box {
    position: absolute;
    border: 2px dashed var(--pb-accent-1);
    cursor: move;
    touch-action: none;
}
.pdf-sign-box img { width: 100%; height: 100%; object-fit: contain; display: block; user-select: none; }
.pdf-sign-resize-handle {
    position: absolute;
    right: -8px;
    bottom: -8px;
    width: 14px;
    height: 14px;
    background: var(--pb-accent-1);
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: nwse-resize;
    touch-action: none;
}

/* ---- Edit PDF ---- */
.pdf-edit-toolbar {
    background: var(--pb-surface);
    border: 1px solid var(--pb-border);
    border-radius: 1rem;
    padding: 1.1rem;
    text-align: left;
}
.pdf-edit-tool-group { display: flex; flex-wrap: wrap; gap: .4rem; }
.pdf-edit-tool-btn.active {
    background: var(--pb-gradient);
    border-color: transparent;
    color: #fff;
}
.pdf-edit-signpad-wrap { text-align: center; }
.pdf-edit-signpad-wrap .pdf-signpad { margin: 0 auto; }

.pdf-edit-page { margin-bottom: 1.75rem; }
.pdf-edit-page-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: .85rem;
    color: var(--pb-text-muted);
    margin-bottom: .4rem;
}
.pdf-edit-page-stage {
    position: relative;
    display: inline-block;
    line-height: 0;
    max-width: 100%;
    width: 100%;
    border-radius: .5rem;
    overflow: hidden;
    box-shadow: 0 6px 22px rgba(0, 0, 0, .45);
    background: #fff;
}
.pdf-edit-page-img { display: block; width: 100%; height: auto; user-select: none; }

.pdf-edit-overlay {
    position: absolute;
    inset: 0;
    z-index: 1;
}
.pdf-edit-overlay-textmode { cursor: text; }

.pdf-edit-ink {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
    touch-action: none;
}
.pdf-edit-ink-active { pointer-events: auto; cursor: crosshair; }

.pdf-edit-el {
    position: absolute;
    border: 1px dashed transparent;
    touch-action: none;
}
.pdf-edit-el.selected {
    border-color: var(--pb-accent-1);
    box-shadow: 0 0 0 1px var(--pb-accent-1);
}
.pdf-edit-el-image { cursor: move; }
.pdf-edit-el-image img { width: 100%; height: 100%; object-fit: contain; display: block; user-select: none; }

.pdf-edit-text-input {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    padding: 0;
    margin: 0;
    font-family: Helvetica, Arial, sans-serif;
    line-height: 1.25;
    overflow: hidden;
}

.pdf-edit-el-toolbar {
    position: absolute;
    top: -2.1rem;
    left: 0;
    display: none;
    align-items: center;
    gap: .3rem;
    background: var(--pb-surface-3);
    border: 1px solid var(--pb-border-strong);
    border-radius: .5rem;
    padding: .2rem .35rem;
    white-space: nowrap;
    z-index: 3;
}
.pdf-edit-el.selected .pdf-edit-el-toolbar { display: flex; }
.pdf-edit-el-grip { cursor: move; color: var(--pb-text-muted); padding: 0 .15rem; }
.pdf-edit-el-fontsize { width: 3.2rem; height: 1.6rem; padding: 0 .25rem; font-size: .75rem; }
.pdf-edit-el-color { width: 1.6rem; height: 1.6rem; padding: 0; border: none; background: none; }
.pdf-edit-el-delete {
    border: none;
    background: none;
    color: var(--pb-text-muted);
    padding: 0 .2rem;
    line-height: 1;
}
.pdf-edit-el-delete:hover { color: var(--pb-accent-2); }

.pdf-edit-resize-handle {
    position: absolute;
    right: -7px;
    bottom: -7px;
    width: 13px;
    height: 13px;
    background: var(--pb-accent-1);
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: nwse-resize;
    touch-action: none;
    z-index: 3;
}

.pdf-edit-clear-ink-btn { padding: .05rem .4rem; font-size: .7rem; }

@media (max-width: 576px) {
    .pdf-dropzone { padding: 2.5rem 1rem; }
    .pdf-file-card, .pdf-image-card { flex-wrap: wrap; }
}
