/* ============================================
   Pixia - EPUB to PDF studio
   (epub-to-pdf.html)
   Complements css/ai-tool.css (.at-* primitives)
   Scope: body.at-epub
   ============================================ */

body.at-epub {
  --ep-accent: #10b981;
  --ep-accent-2: #0d9488;
  --ep-accent-ink: #ffffff;
  --ep-shadow: 0 16px 34px -18px rgba(16, 185, 129, .7);
  --ep-ease: var(--at-ease, cubic-bezier(.22, .61, .36, 1));
}

body.at-epub [hidden] { display: none !important; }

/* Emerald identity replaces the shared default. */
body.at-epub .at-kicker {
  background: linear-gradient(135deg, #10b981, #0d9488);
  color: #ffffff;
}
body.at-epub .at-btn {
  background: linear-gradient(135deg, #10b981, #0d9488);
  color: #ffffff;
  box-shadow: var(--ep-shadow);
}
body.at-epub .at-btn-alt {
  background: var(--glass-bg);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  box-shadow: none;
}
body.at-epub .at-drop-icon {
  background: linear-gradient(135deg, rgba(16, 185, 129, .18), rgba(13, 148, 136, .18));
  color: #059669;
}

/* ---------- Layout ---------- */
body.at-epub .ep-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 22px;
  align-items: start;
}
.ep-main {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}
.ep-side {
  min-width: 0;
  position: sticky;
  inset-block-start: 84px;
  display: grid;
  gap: 16px;
}
@media (max-width: 1060px) {
  body.at-epub .ep-layout { grid-template-columns: 1fr; }
  .ep-side { position: static; }
}

body.at-epub .at-panel { min-height: 0; min-width: 0; }

.ep-panel h2 {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-block-end: 12px;
}
.ep-count {
  margin-inline-start: auto;
  font-family: var(--font-primary);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 3px 10px;
}

/* ---------- Drop zone ---------- */
.ep-source { display: flex; flex-direction: column; gap: 12px; min-height: 0; }

.ep-drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 30px 20px;
  border: 1.6px dashed var(--glass-border-hover);
  border-radius: var(--at-radius-lg);
  background: var(--glass-bg);
  cursor: pointer;
  transition: border-color .2s var(--ep-ease), background .2s var(--ep-ease), transform .2s var(--ep-ease);
}
.ep-drop:hover { border-color: var(--ep-accent); }
.ep-drop.is-drag {
  border-color: var(--ep-accent);
  background: linear-gradient(180deg, rgba(16, 185, 129, .12), rgba(13, 148, 136, .06));
  transform: scale(1.01);
}
.ep-drop-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(16, 185, 129, .18), rgba(13, 148, 136, .18));
  color: var(--ep-accent);
}
.ep-drop-icon svg { width: 26px; height: 26px; }
.ep-drop-title { font-family: var(--font-display); font-size: 1.02rem; font-weight: 600; color: var(--text-primary); }
.ep-drop-sub { font-size: 12.5px; color: var(--text-tertiary); line-height: 1.55; }
.ep-drop-meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-block-start: 4px; }
.ep-drop-meta span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 3px 10px;
}

/* ---------- Source file list ---------- */
.ep-files { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.ep-files-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow: auto; padding-inline-end: 2px; }

.ep-file {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px 22px;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  background: var(--bg-secondary);
  position: relative;
  overflow: hidden;
}
@media (max-width: 420px) { .ep-file { grid-template-columns: 30px minmax(0, 1fr) 30px 20px; gap: 8px; } }
.ep-file-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--ep-accent);
}
.ep-file-ico svg { width: 18px; height: 18px; }
.ep-file-body { min-width: 0; }
.ep-file-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ep-file-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-block-start: 3px;
  font-size: 11.5px;
  color: var(--text-tertiary);
}
.ep-dot { width: 3px; height: 3px; border-radius: 50%; background: var(--text-tertiary); opacity: .6; }
.ep-detail { color: var(--text-tertiary); }
.ep-status {
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
}
.ep-status-done { color: #0d9488; border-color: rgba(13, 148, 136, .4); }
.ep-status-error { color: #dc2626; border-color: rgba(220, 38, 38, .4); }
.ep-status-reading,
.ep-status-parsing,
.ep-status-chapters,
.ep-status-writing,
.ep-status-converting { color: var(--ep-accent-2); border-color: rgba(16, 185, 129, .4); }

/* progress ring */
.ep-ring { position: relative; width: 34px; height: 34px; display: grid; place-items: center; }
.ep-ring > svg { width: 34px; height: 34px; transform: rotate(-90deg); }
.ep-ring circle { fill: none; stroke-width: 3; }
.ep-ring-track { stroke: var(--glass-border); }
.ep-ring-fill {
  stroke: var(--ep-accent);
  stroke-linecap: round;
  stroke-dasharray: 97.4;
  stroke-dashoffset: 97.4;
  transition: stroke-dashoffset .3s var(--ep-ease), stroke .2s var(--ep-ease);
}
.ep-ring.is-done .ep-ring-fill { stroke: #0d9488; }
.ep-ring.is-error .ep-ring-fill { stroke: #dc2626; }
.ep-ring-txt {
  position: absolute;
  display: grid;
  place-items: center;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-secondary);
  line-height: 1;
}
.ep-ring-txt svg { width: 14px; height: 14px; }
.ep-ring.is-done .ep-ring-txt { color: #0d9488; }
.ep-ring.is-error .ep-ring-txt { color: #dc2626; }

.ep-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background .15s var(--ep-ease), color .15s var(--ep-ease);
}
.ep-icon-btn svg { width: 14px; height: 14px; }
.ep-icon-btn:hover { background: rgba(220, 38, 38, .12); color: #dc2626; }

.ep-files-actions { display: flex; gap: 8px; }
.ep-mini {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .2s var(--ep-ease), color .2s var(--ep-ease);
}
.ep-mini svg { width: 14px; height: 14px; }
.ep-mini:hover { border-color: var(--ep-accent); color: var(--ep-accent-2); }
.ep-mini-danger:hover { border-color: #dc2626; color: #dc2626; }

/* ---------- Preview ---------- */
.ep-preview { min-height: 180px; }
.ep-preview-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 240px;
  text-align: center;
  padding: 26px;
  border: 1px dashed var(--glass-border);
  border-radius: var(--at-radius-lg);
  color: var(--text-tertiary);
}
.ep-preview-empty svg { width: 40px; height: 40px; opacity: .55; }
.ep-preview-empty strong { font-family: var(--font-display); color: var(--text-secondary); font-size: .98rem; }
.ep-preview-body { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 560px) { .ep-preview-body { grid-template-columns: 1fr; } }
.ep-cover {
  border-radius: var(--at-radius-md);
  overflow: hidden;
  border: 1px solid var(--glass-border);
  background: var(--bg-secondary);
  box-shadow: 0 12px 26px -18px rgba(0, 0, 0, .6);
}
.ep-cover img { display: block; width: 100%; height: auto; }
.ep-book-title { font-family: var(--font-display); font-size: 1.06rem; font-weight: 700; color: var(--text-primary); line-height: 1.35; }
.ep-meta { display: flex; flex-direction: column; gap: 5px; margin-block-start: 10px; }
.ep-meta-row { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; }
.ep-meta-row span { color: var(--text-tertiary); }
.ep-meta-row b { color: var(--text-secondary); font-weight: 600; text-align: end; }
.ep-chapters {
  list-style: none;
  margin: 14px 0 0;
  padding: 12px 0 0;
  border-block-start: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 240px;
  overflow: auto;
}
.ep-chapters li { display: flex; gap: 9px; align-items: baseline; font-size: 12.5px; color: var(--text-secondary); }
.ep-ch-num {
  flex: none;
  min-width: 20px;
  text-align: center;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ep-accent-2);
  background: rgba(16, 185, 129, .12);
  border-radius: 6px;
  padding: 1px 4px;
}
.ep-ch-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Page thumbnails ---------- */
.ep-thumbs { margin-block-start: 16px; padding-block-start: 14px; border-block-start: 1px solid var(--glass-border); }
.ep-thumbs-head { display: flex; align-items: center; gap: 10px; margin-block-end: 12px; flex-wrap: wrap; }
.ep-thumbs-title { font-family: var(--font-display); font-size: .92rem; font-weight: 700; color: var(--text-primary); }
.ep-thumbs-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--ep-accent-2);
  background: rgba(16, 185, 129, .12);
  border-radius: 999px;
  padding: 2px 9px;
}
.ep-thumbs-note { margin-inline-start: auto; font-size: 11.5px; color: var(--text-tertiary); display: inline-flex; align-items: center; gap: 6px; }
.ep-thumbs-note.is-busy::before {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid rgba(16, 185, 129, .35);
  border-top-color: var(--ep-accent);
  animation: ep-thumb-spin .7s linear infinite;
}
@keyframes ep-thumb-spin { to { transform: rotate(360deg); } }
.ep-thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 12px;
  max-height: 470px;
  overflow: auto;
  padding: 2px;
}
.ep-thumb { position: relative; }
.ep-thumb-page {
  aspect-ratio: 3 / 4;
  background: #ffffff;
  color: #111827;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  overflow: hidden;
  padding: 8px 8px 18px;
  box-shadow: 0 10px 22px -16px rgba(0, 0, 0, .65);
  font-size: 6px;
  line-height: 1.55;
  transition: transform .16s var(--ep-ease), box-shadow .16s var(--ep-ease);
}
.ep-thumb:hover .ep-thumb-page { transform: translateY(-3px); box-shadow: 0 16px 28px -18px rgba(0, 0, 0, .7); }
.ep-thumb-page b { display: block; font-size: 7.5px; font-weight: 700; margin-block-end: 4px; color: #0f172a; }
.ep-thumb-page p { margin: 0 0 4px; }
.ep-thumb-img { display: block; width: 100%; height: auto; margin: 0 0 5px; border-radius: 3px; }
.ep-thumb-page.is-cover { padding: 0; }
.ep-thumb-page.is-cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
.ep-thumb-canvas { display: block; width: 100%; height: auto; border: 1px solid var(--glass-border); border-radius: 6px; background: #ffffff; box-shadow: 0 10px 22px -16px rgba(0, 0, 0, .65); }
.ep-thumb-num {
  position: absolute;
  inset-block-end: 6px;
  inset-inline-end: 6px;
  font-size: 10px;
  font-weight: 700;
  color: #ffffff;
  background: rgba(15, 23, 42, .74);
  border-radius: 999px;
  padding: 1px 7px;
  line-height: 1.5;
}
.ep-thumb-num.is-cover { background: linear-gradient(135deg, #10b981, #0d9488); }
.ep-thumb-ph {
  aspect-ratio: 3 / 4;
  border: 1px dashed var(--glass-border);
  border-radius: 6px;
  background: var(--glass-bg);
  animation: ep-thumb-pulse 1.2s ease-in-out infinite;
}
@keyframes ep-thumb-pulse { 0%, 100% { opacity: .45; } 50% { opacity: .85; } }

/* ---------- Settings ---------- */
.ep-settings { display: grid; gap: 16px; transition: opacity .2s var(--ep-ease); }
.ep-settings.is-disabled { opacity: .55; pointer-events: none; }

.ep-field { display: flex; flex-direction: column; gap: 7px; margin-block-start: 14px; }
.ep-field:first-of-type { margin-block-start: 4px; }
.ep-legend { font-size: 12px; font-weight: 700; letter-spacing: .01em; color: var(--text-secondary); }
.ep-hint { font-size: 11.5px; color: var(--text-tertiary); line-height: 1.5; margin: 0; }

.ep-select,
.ep-input {
  width: 100%;
  font-family: var(--font-primary);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  padding: 9px 11px;
  outline: none;
  transition: border-color .2s var(--ep-ease), box-shadow .2s var(--ep-ease);
}
.ep-select:focus,
.ep-input:focus { border-color: var(--ep-accent); box-shadow: 0 0 0 3px rgba(16, 185, 129, .16); }
.ep-input::placeholder { color: var(--text-tertiary); }

.ep-seg { display: inline-flex; padding: 3px; gap: 3px; background: var(--bg-secondary); border: 1px solid var(--glass-border); border-radius: 999px; width: 100%; }
.ep-seg button {
  flex: 1 1 0;
  min-width: 0;
  padding: 7px 8px;
  font-family: var(--font-primary);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: transparent;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .18s var(--ep-ease), color .18s var(--ep-ease);
}
.ep-seg button.is-active { background: linear-gradient(135deg, var(--ep-accent), var(--ep-accent-2)); color: #fff; box-shadow: var(--ep-shadow); }

.ep-range-row { display: flex; align-items: center; gap: 12px; }
.ep-range { flex: 1 1 auto; accent-color: var(--ep-accent); }
.ep-range-out {
  flex: none;
  min-width: 52px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 4px 8px;
}

.ep-switch { display: flex; align-items: center; gap: 10px; padding: 7px 0; cursor: pointer; }
.ep-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.ep-switch i {
  position: relative;
  flex: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  transition: background .2s var(--ep-ease), border-color .2s var(--ep-ease);
}
.ep-switch i::after {
  content: "";
  position: absolute;
  inset-block-start: 2px;
  inset-inline-start: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .2s var(--ep-ease);
}
.ep-switch input:checked + i { background: linear-gradient(135deg, var(--ep-accent), var(--ep-accent-2)); border-color: transparent; }
.ep-switch input:checked + i::after { transform: translateX(18px); }
[dir="rtl"] .ep-switch input:checked + i { transform: none; }
[dir="rtl"] .ep-switch input:checked + i::after { transform: translateX(-18px); }
.ep-switch span { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.ep-switch small { display: block; font-size: 11px; font-weight: 500; color: var(--text-tertiary); margin-block-start: 1px; }

/* ---------- Run panel ---------- */
.ep-run-panel { display: flex; flex-direction: column; gap: 10px; }
.ep-run-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.ep-run { flex: 1 1 auto; justify-content: center; }
.ep-run.is-busy { opacity: .7; pointer-events: none; }
.ep-cancel {
  flex: none;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: #dc2626;
  background: transparent;
  border: 1px solid rgba(220, 38, 38, .5);
  border-radius: var(--at-radius-md);
  cursor: pointer;
}
.ep-cancel:hover { background: rgba(220, 38, 38, .1); }

.ep-results { display: flex; flex-direction: column; gap: 8px; margin-block-start: 6px; }
.ep-result {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  background: var(--bg-secondary);
  margin-top: 10px;
}
.ep-dl { padding: 7px 14px; font-size: 12.5px; }
.ep-download-all { justify-content: center; margin-block-start: 4px; }

@media (prefers-reduced-motion: reduce) {
  body.at-epub * { transition-duration: .001ms !important; }
  .ep-drop.is-drag { transform: none; }
}
