/* ============================================
   Pixia - JPEG to PDF studio (jpeg-to-pdf.html)
   Complements css/ai-tool.css (.at-* primitives)
   Scope: body.at-jpeg-to-pdf   Accent: Pixia orange
   ============================================ */

body.at-jpeg-to-pdf {
  --j2p-accent: #ff9800;
  --j2p-accent-2: #ffc947;
  --j2p-accent-ink: #221a08;
  --j2p-line: var(--glass-border);
}

/* ---------- Layout ---------- */
.j2p-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 22px;
  align-items: start;
}

.j2p-main { min-width: 0; display: grid; gap: 16px; }

.j2p-side {
  position: sticky;
  inset-block-start: 84px;
  display: grid;
  gap: 16px;
}

@media (max-width: 1020px) {
  .j2p-layout { grid-template-columns: 1fr; }
  .j2p-side { position: static; }
}

.j2p-panel { min-height: 0; }
body.at-jpeg-to-pdf .j2p-side .at-panel + .at-panel { margin-block-start: 0; }

.j2p-panel h2 { display: flex; align-items: center; gap: 9px; }
.j2p-panel h2 svg { width: 18px; height: 18px; color: var(--j2p-accent); flex: 0 0 auto; }

.j2p-hint {
  margin: 0 0 14px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-tertiary);
}

/* ---------- Drop zone ---------- */
.j2p-drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 38px 22px;
  border: 1.6px dashed var(--glass-border-hover);
  border-radius: var(--at-radius-lg);
  background: var(--glass-bg);
  cursor: pointer;
  transition: border-color .25s var(--at-ease), background .25s var(--at-ease), transform .25s var(--at-ease);
}
.j2p-drop:hover,
.j2p-drop.drag { border-color: var(--j2p-accent); }
.j2p-drop.drag {
  background: color-mix(in srgb, var(--j2p-accent) 7%, var(--glass-bg));
  transform: scale(1.01);
}
.j2p-drop input { display: none; }

.j2p-drop-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: color-mix(in srgb, var(--j2p-accent) 16%, transparent);
  color: var(--j2p-accent);
}
.j2p-drop-icon svg { width: 27px; height: 27px; }

.j2p-drop-title { font-size: 15px; font-weight: 600; }
.j2p-drop-sub { font-size: 12.5px; color: var(--text-tertiary); line-height: 1.55; }

.j2p-drop-cta {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-block-start: 6px;
  padding: 9px 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--j2p-accent), var(--j2p-accent-2));
  color: var(--j2p-accent-ink);
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 10px 22px -14px var(--j2p-accent);
}
.j2p-drop-cta svg { width: 16px; height: 16px; }

/* ---------- Queue ---------- */
.j2p-queue { margin-block-start: 18px; padding-block-start: 16px; border-block-start: 1px solid var(--glass-border); }

.j2p-queue-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-block-end: 10px;
}
.j2p-queue-count { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }

.j2p-clear-btn {
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: color .2s var(--at-ease), border-color .2s var(--at-ease);
}
.j2p-clear-btn:hover:not(:disabled) { color: #ef4444; border-color: rgba(239, 68, 68, .5); }
.j2p-clear-btn:disabled { opacity: .5; cursor: not-allowed; }

.j2p-file-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
}

.j2p-file {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  background: var(--glass-bg);
  cursor: pointer;
  transition: border-color .2s var(--at-ease), background .2s var(--at-ease);
}
.j2p-file:hover { border-color: color-mix(in srgb, var(--j2p-accent) 45%, var(--glass-border)); }
.j2p-file.is-active {
  border-color: var(--j2p-accent);
  background: color-mix(in srgb, var(--j2p-accent) 9%, var(--glass-bg));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--j2p-accent) 30%, transparent);
}
.j2p-file.is-reading { opacity: .85; }

.j2p-file-icon {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  overflow: hidden;
  color: var(--j2p-accent);
  background: color-mix(in srgb, var(--j2p-accent) 13%, transparent);
}
.j2p-file-icon svg { width: 21px; height: 21px; }
.j2p-file-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }

.j2p-file-info { min-width: 0; flex: 1; display: grid; gap: 2px; }
.j2p-file-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.j2p-file-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 11.5px; color: var(--text-muted); }
.j2p-file-size { white-space: nowrap; }

.j2p-file-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--j2p-accent-ink);
  background: linear-gradient(135deg, var(--j2p-accent), var(--j2p-accent-2));
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}
.j2p-file-badge.is-err { background: rgba(239, 68, 68, .15); color: #ef4444; }
.j2p-file-badge.is-reading { background: var(--glass-bg); color: var(--text-muted); border: 1px solid var(--glass-border); }

.j2p-file-remove {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .2s var(--at-ease), background .2s var(--at-ease);
}
.j2p-file-remove:hover:not(:disabled) { color: #ef4444; background: rgba(239, 68, 68, .12); }
.j2p-file-remove svg { width: 16px; height: 16px; }
.j2p-file-remove:disabled { opacity: .4; cursor: not-allowed; }

.j2p-add-more {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-block-start: 9px;
  width: 100%;
  padding: 10px;
  border: 1.4px dashed var(--glass-border-hover);
  border-radius: var(--at-radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .2s var(--at-ease), color .2s var(--at-ease);
}
.j2p-add-more:hover:not(:disabled) { border-color: var(--j2p-accent); color: var(--j2p-accent); }
.j2p-add-more svg { width: 16px; height: 16px; }
.j2p-add-more:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Pages preview ---------- */
.j2p-pages-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.j2p-pages-count { font-size: 12px; font-weight: 700; color: var(--j2p-accent); }

.j2p-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-block-end: 12px;
}
.j2p-toolbar-spacer { flex: 1; }
.j2p-pages-note { font-size: 12px; color: var(--text-tertiary); font-variant-numeric: tabular-nums; }

.j2p-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: color .2s var(--at-ease), border-color .2s var(--at-ease), background .2s var(--at-ease);
}
.j2p-tool-btn:hover:not(:disabled) { border-color: var(--j2p-accent); color: var(--j2p-accent); }
.j2p-tool-btn:disabled { opacity: .5; cursor: not-allowed; }

.j2p-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 12px;
}

.j2p-item {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 1.5px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  background: var(--bg-secondary);
  cursor: grab;
  text-align: center;
  transition: border-color .18s var(--at-ease), transform .18s var(--at-ease), opacity .18s var(--at-ease), box-shadow .18s var(--at-ease);
  outline-offset: 3px;
  overflow: hidden;
}
.j2p-item:hover { border-color: var(--j2p-accent); transform: translateY(-2px); }
.j2p-item:focus-visible { outline: 2px solid var(--j2p-accent); }
.j2p-item.is-drag { opacity: .4; cursor: grabbing; }
.j2p-item.is-over { box-shadow: 0 0 0 2px var(--j2p-accent); border-color: var(--j2p-accent); }
.j2p-item.is-out { opacity: .42; border-color: var(--glass-border-hover); }
.j2p-item.is-out:hover { opacity: .72; }

/* page frame = simulated PDF page */
.j2p-frame {
  display: block;
  position: relative;
  flex: 0 0 auto;
  align-self: center;
  /* width tracks the page aspect ratio, so tall previews cap at 190px
     without distorting the page shape */
  width: min(100%, calc(190px * var(--j2p-ar, 1)));
  min-height: 56px;
  max-height: 190px;
  margin-block: auto;
  background-color: transparent;
  overflow: hidden;
}
.j2p-pad { display: block; position: absolute; inset: 0; }
.j2p-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.j2p-frame.is-cover img { object-fit: cover; }

.j2p-ph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  color: var(--text-muted);
}

.j2p-spin {
  width: 20px;
  height: 20px;
  border: 2px solid var(--glass-border);
  border-block-start-color: var(--j2p-accent);
  border-radius: 50%;
  animation: j2p-spin .8s linear infinite;
}
@keyframes j2p-spin { to { transform: rotate(360deg); } }

.j2p-num {
  position: absolute;
  inset-block-start: 6px;
  inset-inline-start: 6px;
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(20, 20, 30, .62);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.j2p-item-check {
  position: absolute;
  inset-block-start: 6px;
  inset-inline-end: 6px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--j2p-accent);
  color: var(--j2p-accent-ink);
  pointer-events: none;
  transition: opacity .18s var(--at-ease), transform .18s var(--at-ease);
}
.j2p-item-check svg { width: 13px; height: 13px; }
.j2p-item.is-out .j2p-item-check { opacity: 0; transform: scale(.6); }

.j2p-item-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-block-start: 1px solid var(--glass-border);
  background: var(--bg-card);
}
.j2p-item-name {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: start;
}
.j2p-move {
  display: inline-flex;
  gap: 3px;
  flex: 0 0 auto;
}
.j2p-move-btn {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  background: var(--glass-bg);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  transition: color .18s var(--at-ease), border-color .18s var(--at-ease);
}
.j2p-move-btn:hover:not(:disabled) { color: var(--j2p-accent); border-color: var(--j2p-accent); }
.j2p-move-btn:disabled { opacity: .35; cursor: not-allowed; }
.j2p-move-btn svg { width: 13px; height: 13px; }

.j2p-empty-note {
  padding: 26px 22px;
  text-align: center;
  border: 1px dashed var(--glass-border-hover);
  border-radius: var(--at-radius-md);
  color: var(--text-tertiary);
  font-size: 13px;
}

.j2p-keys-hint {
  margin: 14px 0 0;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ---------- Sidebar fields ---------- */
.j2p-field { margin-block-start: 16px; }
.j2p-field:first-of-type { margin-block-start: 0; }

.j2p-label {
  display: flex;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text-secondary);
  margin-block-end: 8px;
}

.j2p-subhint {
  display: block;
  margin-block-start: 8px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-muted);
}

.j2p-seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 11px;
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
}

.j2p-seg-btn {
  border: 0;
  padding: 9px 6px;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s var(--at-ease), color .2s var(--at-ease), box-shadow .2s var(--at-ease);
}
.j2p-seg-btn:hover:not(:disabled) { color: var(--text-primary); }
.j2p-seg-btn:disabled { opacity: .45; cursor: not-allowed; }
.j2p-seg-btn.is-active {
  background: #fff;
  color: #b45309;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .12), 0 0 0 1px color-mix(in srgb, var(--j2p-accent) 55%, transparent);
}
html[data-theme="dark"] .j2p-seg-btn.is-active {
  background: #2a2320;
  color: var(--j2p-accent-2);
  box-shadow: 0 1px 6px rgba(0, 0, 0, .45), 0 0 0 1px color-mix(in srgb, var(--j2p-accent) 55%, transparent);
}

.j2p-input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .2s var(--at-ease), box-shadow .2s var(--at-ease);
}
.j2p-input:focus { border-color: var(--j2p-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--j2p-accent) 22%, transparent); }
.j2p-input:disabled { opacity: .55; cursor: not-allowed; }

.j2p-field.is-disabled { opacity: .5; }

/* ---------- Summary ---------- */
.j2p-summary-rows {display: grid;gap: 9px;min-height: 165px;}
.j2p-sum-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12.5px;
}
.j2p-sum-label { color: var(--text-tertiary); }
.j2p-sum-val { font-weight: 600; color: var(--text-primary); font-variant-numeric: tabular-nums; text-align: end; }

/* ---------- Run panel ---------- */
.j2p-run-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--j2p-accent), var(--j2p-accent-2));
  color: var(--j2p-accent-ink);
  box-shadow: 0 16px 34px -18px var(--j2p-accent);
}
.j2p-run-btn:hover:not([disabled]) { transform: translateY(-2px); }

.j2p-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-block-start: 12px;
}
.j2p-progress-row .at-progress-msg { margin: 0; }
.j2p-processing-hint { display: block; margin-block-start: 10px; }

/* The .at-progress primitive is display:none until shown; reactivate inside the run panel */
body.at-jpeg-to-pdf #j2pProgress .at-progress { display: block; }
body.at-jpeg-to-pdf #j2pProgress .at-progress-fill {
  background: linear-gradient(90deg, var(--j2p-accent), var(--j2p-accent-2));
}
body.at-jpeg-to-pdf .at-spinner { border-block-start-color: var(--j2p-accent); }

/* ---------- Result ---------- */
.j2p-result { margin-block-start: 18px; padding-block-start: 16px; border-block-start: 1px solid var(--glass-border); }
.j2p-result-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.j2p-result-head h3 { margin: 0; font-family: var(--font-display); font-size: 1.02rem; }
.j2p-result-summary { font-size: 12px; color: var(--text-tertiary); font-weight: 600; }

.j2p-result-list { display: grid; gap: 9px; margin-block-start: 14px; }

.j2p-result-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  background: var(--glass-bg);
}
.j2p-result-icon {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: var(--j2p-accent);
  background: color-mix(in srgb, var(--j2p-accent) 14%, transparent);
}
.j2p-result-icon svg { width: 22px; height: 22px; }

.j2p-result-info { min-width: 0; flex: 1; display: grid; gap: 3px; }
.j2p-result-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.j2p-result-meta { font-size: 11.5px; color: var(--text-muted); }

.j2p-result-dl {
  flex: 0 0 auto;
  padding: 9px 14px;
  font-size: 12.5px;
  white-space: nowrap;
  background: linear-gradient(135deg, var(--j2p-accent), var(--j2p-accent-2));
  color: var(--j2p-accent-ink);
  border-radius: 10px;
}
.j2p-result-dl:hover:not([disabled]) { transform: translateY(-1px); }
html[data-theme="dark"] .j2p-result-dl { color: #221a08; }

.j2p-actions { display: grid; gap: 9px; margin-block-start: 16px; }
.j2p-actions .at-btn { width: 100%; }

/* ---------- Scrollbars ---------- */
.j2p-file-list::-webkit-scrollbar,
.j2p-grid::-webkit-scrollbar { width: 6px; height: 6px; }
.j2p-file-list::-webkit-scrollbar-thumb,
.j2p-grid::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 999px; }

/* ---------- RTL ---------- */
[dir="rtl"] .j2p-drop-cta svg,
[dir="rtl"] .j2p-add-more svg { transform: scaleX(-1); }

/* ---------- Mobile ---------- */
@media (max-width: 560px) {
  .j2p-toolbar { gap: 6px; }
  .j2p-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 9px; }
  .j2p-frame { min-height: 70px; }
  .j2p-item-foot { padding: 6px 6px; }
}
