/* =====================================================================
   In-browser PDF workspace (.pdfx) + premium gate + tool modal.
   ===================================================================== */

.pdfx { position: relative; display: flex; flex-direction: column; gap: 14px; }
.pdfx.dragging::after { content: "Drop files to add them"; position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; border-radius: 18px;
  border: 2px dashed var(--brand); background: color-mix(in srgb, var(--brand-soft) 88%, transparent); color: var(--brand); font: 700 1.1rem var(--font-d); pointer-events: none; }

/* mode switch */
.pdfx-modes { display: inline-flex; align-self: center; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-3); border: 1px solid var(--line); }
.pdfx-modes button { border: 0; background: none; cursor: pointer; padding: 8px 16px; border-radius: 9px; font: 600 .86rem var(--font-d); color: var(--muted); transition: .15s; }
.pdfx-modes button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.pdfx-modes button:disabled { cursor: default; opacity: .6; }

/* drop zone */
.pdfx-drop { text-align: center; padding: 52px 20px 44px; border-radius: 18px; border: 2px dashed var(--line-strong); background: var(--surface-2); cursor: pointer;
  transition: border-color .2s, background-color .2s; }
.pdfx-drop:hover, .pdfx-drop:focus-visible { border-color: var(--brand); background: var(--brand-soft); outline: none; }
.pdfx-drop-ico { width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 18px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); border: 1px solid var(--line); }
.pdfx-drop-ico .icon { width: 28px; height: 28px; }
.pdfx-drop h4, .pdfx-busy h4, .pdfx-done h4, .pdfx-password h4 { font-size: 1.15rem; margin-bottom: 6px; }
.pdfx-drop p { color: var(--muted); margin-bottom: 14px; font-size: .9rem; }
.pdfx-limit { display: block; margin-top: 14px; font-family: var(--font-m); font-size: .7rem; color: var(--faint); letter-spacing: .04em; }

/* work area */
.pdfx-work { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.pdfx-main { min-width: 0; }
.pdfx-side { position: sticky; top: 90px; display: flex; flex-direction: column; gap: 14px; padding: 18px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface-2); }
.pdfx-hint { font-size: .84rem; color: var(--muted); margin-bottom: 12px; }
.pdfx-opts { display: flex; flex-direction: column; gap: 14px; }
.pdfx-field { display: flex; flex-direction: column; gap: 6px; }
.pdfx-field input[type=range] { width: 100%; accent-color: var(--brand); }
.pdfx-field input[type=file] { font-size: .8rem; color: var(--muted); max-width: 100%; }
.pdfx-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pdfx-color { width: 100%; height: 42px; padding: 3px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); cursor: pointer; }
.pdfx-checks { display: flex; flex-direction: column; gap: 8px; }
.pdfx-radios { display: flex; flex-direction: column; gap: 8px; }
.pdfx-radio { position: relative; cursor: pointer; }
.pdfx-radio input { position: absolute; opacity: 0; }
.pdfx-radio span { display: block; padding: 10px 12px 10px 36px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); transition: .15s; position: relative; }
.pdfx-radio span::before { content: ""; position: absolute; left: 12px; top: 13px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--surface); }
.pdfx-radio strong { display: block; font-size: .86rem; color: var(--ink); }
.pdfx-radio small { display: block; font-size: .74rem; color: var(--muted); line-height: 1.35; }
.pdfx-radio input:checked + span { border-color: var(--brand); background: var(--brand-soft); }
.pdfx-radio input:checked + span::before { border-color: var(--brand); background: var(--brand); box-shadow: inset 0 0 0 3px var(--surface); }
.pdfx-radio input:focus-visible + span { box-shadow: 0 0 0 3px var(--brand-ring); }
.pdfx-actions { display: flex; flex-direction: column; gap: 6px; padding-top: 4px; }

/* file list */
.pdfx-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.pdfx-file { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 13px; border: 1px solid var(--line); background: var(--surface); transition: border-color .15s, opacity .15s; }
.pdfx-file[draggable=true] { cursor: grab; }
.pdfx-file.failed { border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.pdfx-file.failed small { color: var(--danger); }
.pdfx-file.drag-over, .pdfx-page.drag-over { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.pdfx-file.drag-src, .pdfx-page.drag-src { opacity: .4; }
.pdfx-grip { color: var(--faint); font-size: .8rem; letter-spacing: -2px; user-select: none; }
.pdfx-file-ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--danger-soft); color: var(--danger); flex: none; }
.pdfx-file-meta { flex: 1; min-width: 0; }
.pdfx-file-meta strong { display: block; font-size: .88rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdfx-file-meta small { font-size: .76rem; color: var(--muted); }
.pdfx-file-actions { display: flex; gap: 2px; }
.pdfx-add { margin-top: 10px; }
.pdfx-preview { margin-top: 14px; padding: 22px; border-radius: 14px; background: var(--surface-3); display: grid; place-items: center; }
.pdfx-preview img { max-height: 380px; max-width: 100%; border-radius: 4px; background: #fff; box-shadow: var(--shadow); }
.pdfx-preview img:not([src]) { width: 240px; height: 320px; background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }

/* page grid */
.pdfx-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.pdfx-count { margin-left: auto; font-family: var(--font-m); font-size: .72rem; color: var(--muted); }
.pdfx-pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 14px; max-height: 620px; overflow-y: auto; padding: 4px; }
.pdfx-page { position: relative; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 10px 10px 28px; transition: border-color .15s, box-shadow .15s; }
.pdfx-page[draggable=true] { cursor: grab; }
.pdfx-page.selectable { cursor: pointer; }
.pdfx-page.selected { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); background: var(--brand-soft); }
.pdfx-thumb { aspect-ratio: 1 / 1.3; display: grid; place-items: center; overflow: hidden; border-radius: 6px; background: var(--surface-3); }
.pdfx-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; box-shadow: 0 2px 8px rgba(0,0,0,.15); transition: transform .25s var(--ease); background: #fff; }
.pdfx-thumb img:not([src]) { width: 70%; height: 80%; background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite; box-shadow: none; }
@keyframes shimmer { to { background-position: -200% 0; } }
.pdfx-blank { font-family: var(--font-m); font-size: .7rem; color: var(--faint); text-transform: uppercase; letter-spacing: .1em; }
.pdfx-pno { position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; font-family: var(--font-m); font-size: .7rem; color: var(--muted); }
.pdfx-tick { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line-strong); color: transparent; }
.pdfx-tick .icon { width: 12px; height: 12px; stroke-width: 3; }
.pdfx-page.selected .pdfx-tick { background: var(--brand); border-color: var(--brand); color: #fff; }
.pdfx-page-actions { position: absolute; left: 50%; bottom: 30px; transform: translateX(-50%); display: flex; gap: 2px; padding: 3px; border-radius: 9px; background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow); opacity: 0; transition: opacity .15s; }
.pdfx-page:hover .pdfx-page-actions, .pdfx-page:focus-within .pdfx-page-actions { opacity: 1; }
@media (hover: none) { .pdfx-page-actions { opacity: 1; } }
.pdfx-page-actions button { width: 26px; height: 26px; display: grid; place-items: center; border: 0; background: none; border-radius: 6px; color: var(--muted); cursor: pointer; }
.pdfx-page-actions button:hover { background: var(--surface-3); color: var(--brand); }
.pdfx-page-actions button[data-act=del]:hover { color: var(--danger); }
.pdfx-page-actions .icon { width: 14px; height: 14px; }

/* password */
.pdfx-password { text-align: center; padding: 34px 20px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface-2); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pdfx-password p { color: var(--muted); font-size: .88rem; }
.pdfx-pw-row { display: flex; gap: 8px; width: min(380px, 100%); margin-top: 6px; }

/* busy + done */
.pdfx-busy, .pdfx-done { text-align: center; padding: 48px 20px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface-2); }
.pdfx-busy p { color: var(--muted); font-size: .84rem; margin-top: 12px; }
.pdfx-spinner { width: 48px; height: 48px; margin: 0 auto 18px; border-radius: 50%; border: 4px solid var(--brand-soft); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pdfx-bar { width: min(360px, 90%); height: 8px; margin: 14px auto 0; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.pdfx-bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--brand), var(--accent)); transition: width .25s ease; }
.pdfx-done-ico { width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); animation: popIn .45s var(--ease); }
.pdfx-done-ico .icon { width: 30px; height: 30px; stroke-width: 2.6; }
@keyframes popIn { from { transform: scale(.5); opacity: 0; } }
.pdfx-note { color: var(--muted); font-size: .88rem; }
.pdfx-done-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.pdfx-done-actions .btn-lg { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.pdfx-results { list-style: none; max-width: 520px; margin: 20px auto 0; text-align: left; max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.pdfx-results li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: .84rem; }
.pdfx-results li:last-child { border-bottom: 0; }
.pdfx-results li span { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pdfx-error { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent); color: var(--ink); font-size: .88rem; }
.pdfx-error .icon { color: var(--danger); margin-top: 1px; }
.pdfx-privacy { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: .78rem; color: var(--muted); text-align: center; }
.pdfx-privacy .icon { color: var(--accent); width: 16px; height: 16px; }

/* premium gate */
.premium-gate { text-align: center; padding: 44px 24px; border-radius: 20px; position: relative; overflow: hidden;
  background: radial-gradient(circle at 85% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 50%), var(--surface-2); border: 1px solid var(--line); }
.premium-gate .pg-ico { width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 18px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #F5B53F, #E07A1F); box-shadow: 0 12px 26px -12px rgba(224, 122, 31, .7); }
.premium-gate .pg-ico .icon { width: 28px; height: 28px; }
.premium-gate h4 { font-size: 1.25rem; margin-bottom: 8px; }
.premium-gate p { color: var(--muted); max-width: 44ch; margin: 0 auto 20px; font-size: .92rem; }
.premium-gate ul { list-style: none; display: inline-flex; flex-direction: column; gap: 8px; text-align: left; margin-bottom: 22px; font-size: .88rem; }
.premium-gate li { display: flex; gap: 9px; align-items: center; }
.premium-gate li .icon { color: var(--accent); width: 16px; height: 16px; stroke-width: 2.6; }
.premium-gate .pg-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.badge-premium { background: linear-gradient(135deg, #FFF3DA, #FFE6C4); color: #A4570D; border-color: #F7D29A; }
[data-theme="dark"] .badge-premium { background: rgba(245, 181, 63, .14); color: #F5B53F; border-color: rgba(245, 181, 63, .3); }
.btn-premium { background: linear-gradient(135deg, #F5B53F, #E07A1F); color: #fff; box-shadow: 0 10px 22px -12px rgba(224, 122, 31, .8); }
.btn-premium:hover { transform: translateY(-1px); }

/* landing modal */
dialog.tool-modal { margin: auto; padding: 0; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); color: var(--text);
  width: min(1120px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: var(--shadow-lg); overflow: hidden; }
dialog.tool-modal[open] { display: flex; flex-direction: column; animation: toastIn .3s var(--ease); }
dialog.tool-modal::backdrop { background: rgba(8, 15, 30, .55); backdrop-filter: blur(4px); }
.tool-modal-head { display: flex; align-items: center; gap: 14px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.tool-modal-head .t-ico { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.tool-modal-head h3 { font-size: 1.1rem; }
.tool-modal-head p { font-size: .8rem; color: var(--muted); }
.tool-modal-head .spacer { flex: 1; }
.tool-modal-body { padding: 20px; overflow-y: auto; }

@media (max-width: 860px) {
  .pdfx-work { grid-template-columns: 1fr; }
  .pdfx-side { position: static; }
  .pdfx-pages { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); max-height: 480px; }
  .tool-modal-head .open-page { display: none; }
}
