/* Image to PDF — premium tool UI */
:root {
  --itp-primary: #3d85c6;
  --itp-primary-dark: #2c6396;
  --itp-accent: #5ba3e0;
  --itp-success: #10b981;
  --itp-bg: #f4f8fc;
  --itp-surface: rgba(255, 255, 255, 0.78);
  --itp-solid: #ffffff;
  --itp-text: #0f172a;
  --itp-muted: #64748b;
  --itp-border: rgba(61, 133, 198, 0.22);
  --itp-shadow: 0 22px 50px rgba(61, 133, 198, 0.14);
  --itp-radius: 18px;
  --itp-font: 'DM Sans', system-ui, sans-serif;
  --itp-grad: linear-gradient(135deg, #3d85c6 0%, #5ba3e0 55%, #3d85c6 100%);
}

#tool-main {
  font-family: var(--itp-font);
  color: var(--itp-text);
  background: var(--itp-bg);
  background-image:
    radial-gradient(ellipse 70% 50% at 0% 0%, rgba(61, 133, 198, 0.18), transparent),
    radial-gradient(ellipse 50% 40% at 100% 10%, rgba(91, 163, 224, 0.12), transparent);
  padding-bottom: 32px;
}

.itp-wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px;
}

.itp-hero {
  text-align: center;
  margin-bottom: 24px;
  position: relative;
}

.itp-hero h1 {
  font-size: clamp(1.65rem, 4vw, 2.35rem);
  font-weight: 800;
  margin: 0 0 8px;
  background: var(--itp-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.itp-hero p {
  color: var(--itp-muted);
  max-width: 560px;
  margin: 0 auto;
  font-size: 0.95rem;
}

.itp-trust {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  margin-top: 14px;
  font-size: 0.78rem;
  font-weight: 600;
}

.itp-trust span {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--itp-surface);
  border: 1px solid var(--itp-border);
  backdrop-filter: blur(10px);
}

.itp-glass {
  background: var(--itp-surface);
  backdrop-filter: blur(14px);
  border: 1px solid var(--itp-border);
  border-radius: var(--itp-radius);
  box-shadow: var(--itp-shadow);
}

.itp-layout {
  display: grid;
  gap: 20px;
}

@media (min-width: 992px) {
  .itp-layout {
    grid-template-columns: 1fr 340px;
  }
}

/* Upload */
.itp-drop {
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  border: 2px dashed rgba(61, 133, 198, 0.4);
  transition: border-color 0.25s, transform 0.25s, background 0.25s;
  animation: itpPulse 3s ease-in-out infinite;
}

@keyframes itpPulse {
  0%, 100% { border-color: rgba(61, 133, 198, 0.35); }
  50% { border-color: rgba(91, 163, 224, 0.45); }
}

.itp-drop.is-dragover {
  border-color: var(--itp-primary);
  background: rgba(61, 133, 198, 0.08);
  transform: scale(1.01);
}

.itp-drop-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 18px;
  background: var(--itp-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  color: #fff;
}

.itp-upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}

.itp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
}

.itp-btn--primary {
  background: var(--itp-grad);
  color: #fff;
  box-shadow: 0 8px 22px rgba(61, 133, 198, 0.35);
}

.itp-btn--primary:hover:not(:disabled) {
  transform: translateY(-1px);
}

.itp-btn--ghost {
  background: var(--itp-solid);
  border: 1px solid var(--itp-border);
  color: var(--itp-text);
}

.itp-btn--block { width: 100%; }

.itp-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.itp-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--itp-muted);
}

.itp-empty-icon {
  font-size: 3rem;
  opacity: 0.35;
  margin-bottom: 8px;
}

/* Toolbar */
.itp-quick-actions {
  padding: 12px 14px;
  margin-bottom: 14px;
}

@media (min-width: 992px) {
  .itp-quick-actions {
    display: none !important;
  }
}

.itp-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 16px 0 12px;
}

.itp-sort-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.itp-sort-group button {
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--itp-border);
  background: var(--itp-solid);
  color: var(--itp-text);
  cursor: pointer;
}

.itp-hint {
  font-size: 0.8rem;
  color: var(--itp-accent);
  font-weight: 600;
}

.itp-hint[hidden] { display: none !important; }

/* Preview grid */
.itp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.itp-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 0;
  background: var(--itp-solid);
  border: 1px solid var(--itp-border);
  border-radius: 14px;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
}

.itp-card:hover {
  box-shadow: 0 8px 24px rgba(61, 133, 198, 0.15);
}

.itp-card.is-dragging {
  opacity: 0.45;
  transform: scale(0.96);
}

.itp-card.is-drag-over {
  outline: 2px solid var(--itp-primary);
  transform: scale(1.02);
}

.itp-card-drag {
  grid-row: 1 / 3;
  padding: 8px 4px;
  color: var(--itp-muted);
  cursor: grab;
  align-self: center;
}

.itp-card-preview {
  position: relative;
  grid-column: 2;
  height: 120px;
  background: #e2e8f0;
  overflow: hidden;
}

.itp-card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.itp-card-preview img[style*="rotate(90deg)"],
.itp-card-preview img[style*="rotate(270deg)"] {
  object-fit: contain;
  width: 100%;
  height: 100%;
}

.itp-page-num {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: rgba(15, 23, 42, 0.75);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
}

.itp-skeleton {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: itpShimmer 1.2s infinite;
}

@keyframes itpShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.itp-card-body {
  grid-column: 2;
  padding: 8px 10px;
}

.itp-card-name {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.itp-card-meta {
  font-size: 0.68rem;
  color: var(--itp-muted);
}

.itp-card-tools {
  grid-column: 1 / -1;
  display: flex;
  border-top: 1px solid var(--itp-border);
}

.itp-card-tools button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--itp-muted);
}

.itp-card-tools button:hover {
  background: rgba(61, 133, 198, 0.08);
  color: var(--itp-primary);
}

.itp-card-tools button:last-child:hover {
  color: #ef4444;
}

/* Sidebar actions — Create PDF first, settings collapsed */
.itp-aside {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

@media (max-width: 991px) {
  .itp-aside {
    position: sticky;
    top: calc(var(--header-h, 72px) + 8px);
    z-index: 5;
  }
}

.itp-actions-panel {
  padding: 16px;
}

.itp-btn--create {
  font-size: 1.05rem;
  padding: 14px 20px;
  box-shadow: 0 10px 28px rgba(61, 133, 198, 0.4);
}

.itp-actions-hint {
  margin: 8px 0 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--itp-muted);
}

.itp-estimate--compact {
  margin-bottom: 12px;
  padding: 10px 12px;
}

.itp-settings-dropdown {
  margin-top: 14px;
  border: 1px solid var(--itp-border);
  border-radius: 12px;
  background: var(--itp-solid);
  overflow: hidden;
}

.itp-settings-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--itp-text);
  list-style: none;
  user-select: none;
}

.itp-settings-summary::-webkit-details-marker {
  display: none;
}

.itp-settings-chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--itp-primary);
  border-bottom: 2px solid var(--itp-primary);
  transform: rotate(45deg);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.itp-settings-dropdown[open] .itp-settings-chevron {
  transform: rotate(-135deg);
  margin-top: 4px;
}

.itp-settings-dropdown[open] .itp-settings-summary {
  border-bottom: 1px solid var(--itp-border);
  background: rgba(61, 133, 198, 0.06);
}

.itp-settings-body {
  padding: 14px;
  max-height: min(52vh, 420px);
  overflow-y: auto;
}

.itp-field {
  margin-bottom: 12px;
}

.itp-field label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.itp-field .form-select,
.itp-field .form-control {
  font-size: 0.85rem;
  border-radius: 10px;
  border-color: var(--itp-border);
  background: var(--itp-solid);
  color: var(--itp-text);
}

.itp-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.itp-estimate {
  padding: 12px;
  margin-top: 12px;
  border-radius: 12px;
  background: rgba(61, 133, 198, 0.08);
  font-size: 0.82rem;
}

.itp-estimate[hidden] { display: none !important; }

.itp-estimate strong { color: var(--itp-primary); }

/* Success */
.itp-success {
  padding: 22px;
  margin-top: 16px;
  border: 1px solid rgba(16, 185, 129, 0.35);
  text-align: center;
  animation: itpSuccessPop 0.45s ease;
}

@keyframes itpSuccessPop {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.itp-success-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, #10b981, #06b6d4);
  color: #fff;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.itp-success-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 4px;
}

.itp-success-actions .itp-btn--primary:hover:not(:disabled) {
  transform: none;
  box-shadow: 0 2px 8px rgba(44, 99, 150, 0.35);
}

.itp-success-stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 14px 0;
  font-size: 0.85rem;
  color: var(--itp-muted);
}

.itp-success-stats strong {
  display: block;
  color: var(--itp-text);
  font-size: 1rem;
}

.itp-muted { color: var(--itp-muted); font-size: 0.85rem; margin: 0; }

/* Related */
.itp-related-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 12px;
}

@media (min-width: 640px) {
  .itp-related-grid { grid-template-columns: repeat(3, 1fr); }
}

.itp-related-card {
  padding: 14px;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: transform 0.2s;
}

.itp-related-card:hover { transform: translateY(-2px); }

.itp-related-card h4 {
  margin: 0 0 4px;
  font-size: 0.9rem;
  color: var(--itp-primary);
}

.itp-related-card p {
  margin: 0;
  font-size: 0.72rem;
  color: var(--itp-muted);
}

/* SEO */
.itp-seo {
  padding: 24px;
  margin-top: 28px;
}

.itp-seo h2 { font-size: 1.2rem; margin-top: 24px; }
.itp-seo h2:first-child { margin-top: 0; }
.itp-seo p, .itp-faq p { color: var(--itp-muted); line-height: 1.65; font-size: 0.92rem; }

.itp-faq details {
  margin-bottom: 8px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--itp-border);
  background: var(--itp-solid);
}

.itp-faq summary { font-weight: 600; cursor: pointer; }

/* Modals */
.itp-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.itp-modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.itp-modal-panel {
  background: var(--itp-solid);
  border-radius: var(--itp-radius);
  max-width: 96vw;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--itp-shadow);
  width: 100%;
}

.itp-modal-panel--lg { max-width: 720px; }

.itp-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--itp-border);
}

.itp-modal-body { padding: 18px; }

.itp-modal-body img {
  max-width: 100%;
  max-height: 70vh;
  display: block;
  margin: 0 auto;
}

.itp-crop-wrap {
  position: relative;
  max-height: 60vh;
  overflow: hidden;
  user-select: none;
}

.itp-crop-wrap img {
  width: 100%;
  display: block;
}

.itp-crop-box {
  position: absolute;
  border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  cursor: move;
  touch-action: none;
}

.itp-modal-actions {
  display: flex;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--itp-border);
}

/* Progress */
.itp-progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.itp-progress-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

.itp-progress-inner { text-align: center; color: #fff; }

.itp-progress-ring {
  width: 130px;
  height: 130px;
  transform: rotate(-90deg);
}

.itp-progress-ring circle.fg {
  fill: none;
  stroke: url(#itpRingGrad);
  stroke-width: 8;
  stroke-linecap: round;
}

.itp-progress-ring circle.bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.2);
  stroke-width: 8;
}

#itpApp.is-busy { pointer-events: none; }
#itpApp.is-busy .itp-drop,
#itpApp.is-busy .itp-card { pointer-events: none; }

body.itp-modal-open { overflow: hidden; }

#toastContainer {
  position: fixed;
  bottom: 20px;
  right: 16px;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 300px;
}

.itp-toast {
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--itp-solid);
  border: 1px solid var(--itp-border);
  box-shadow: var(--itp-shadow);
  font-size: 0.85rem;
  opacity: 0;
  transform: translateX(16px);
  transition: all 0.28s;
}

.itp-toast.is-visible {
  opacity: 1;
  transform: translateX(0);
}

.itp-toast--success { border-left: 4px solid var(--itp-success); }
.itp-toast--error { border-left: 4px solid #ef4444; }
.itp-toast--warning { border-left: 4px solid #f59e0b; }
