/* ============================================
   Pixia - Rotate PDF studio (rotate.html)
   Complements css/ai-tool.css (.at-* primitives)
   Scope: body.at-rotate
   ============================================ */

body.at-rotate {
  --rt-accent: #f97316;
  --rt-accent-2: #fb923c;
  --rt-accent-ink: #ffffff;
  --rt-line: var(--glass-border);
  --rt-soft: var(--bg-secondary);
}

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

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

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

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

.rt-panel { min-height: 0; }

body.at-rotate .rt-side .at-panel + .at-panel { margin-block-start: 0; }

.rt-panel h2 {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-block-start: 0;
}

.rt-panel h2 .rt-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;
}

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

/* ---------- Drop zone ---------- */
.rt-drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 42px 22px;
  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(--at-ease), background .2s var(--at-ease), transform .2s var(--at-ease);
}

.rt-drop:hover { border-color: var(--rt-accent); }

.rt-drop.drag {
  border-color: var(--rt-accent);
  background: color-mix(in srgb, var(--rt-accent) 10%, var(--glass-bg));
  transform: scale(1.006);
}

.rt-drop input { display: none; }

.rt-drop-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: color-mix(in srgb, var(--rt-accent) 16%, transparent);
  color: var(--rt-accent);
  margin-block-end: 4px;
}

.rt-drop-icon svg { width: 28px; height: 28px; }

.rt-drop-title {
  font-family: var(--font-display);
  font-size: 1.06rem;
  font-weight: 600;
  color: var(--text-primary);
}

.rt-drop-sub {
  font-size: 13px;
  color: var(--text-tertiary);
  max-width: 46ch;
  line-height: 1.6;
}

.rt-drop-cta {
  margin-block-start: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 22px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--rt-accent), var(--rt-accent-2));
  color: var(--rt-accent-ink);
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 14px 30px -18px rgba(249, 115, 22, .95);
}

.rt-drop-cta svg { width: 17px; height: 17px; }

/* ---------- File list ---------- */
.rt-files {
  display: grid;
  gap: 8px;
  margin-block-start: 16px;
}

.rt-file-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  background: var(--bg-card);
}

.rt-file-thumb {
  position: relative;
  width: 44px;
  height: 58px;
  border-radius: 7px;
  overflow: hidden;
  background:
    repeating-conic-gradient(rgba(128, 128, 128, .18) 0% 25%, transparent 0% 50%) 50% / 13px 13px,
    var(--bg-tertiary);
  border: 1px solid var(--glass-border);
  display: grid;
  place-items: center;
}

.rt-file-thumb img { max-width: 100%; max-height: 100%; display: block; object-fit: contain; }
.rt-file-thumb svg { width: 20px; height: 20px; color: var(--text-muted); }

.rt-file-info { min-width: 0; display: grid; gap: 3px; }

.rt-file-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rt-file-meta {
  font-size: 11.5px;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.rt-file-status { font-size: 11.5px; font-weight: 700; }
.rt-file-status.is-ready { color: var(--accent-emerald, #10b981); }
.rt-file-status.is-reading { color: var(--text-tertiary); }
.rt-file-status.is-error { color: #ef4444; }

/* ---------- Toolbar ---------- */
.rt-pages-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-block-end: 12px;
}

.rt-pages-head h2 { margin: 0; }

.rt-pages-stats {
  margin-inline-start: auto;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.rt-stat {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 4px 11px;
}

.rt-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-block-end: 14px;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  background: var(--bg-secondary);
}

.rt-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.rt-group + .rt-group {
  padding-inline-start: 12px;
  border-inline-start: 1px solid var(--glass-border);
}

.rt-group-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-inline-end: 2px;
}

.rt-toolbar .rt-spacer { margin-inline-start: auto; }

.rt-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 9px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: color .18s var(--at-ease), border-color .18s var(--at-ease), background .18s var(--at-ease);
}

.rt-tool-btn:hover:not(:disabled) { color: var(--text-primary); border-color: var(--glass-border-hover); }
.rt-tool-btn svg { width: 15px; height: 15px; }
.rt-tool-btn[disabled] { opacity: .45; cursor: not-allowed; }

.rt-tool-btn.rt-accent:not(:disabled) {
  color: var(--rt-accent);
  border-color: color-mix(in srgb, var(--rt-accent) 45%, transparent);
}
.rt-tool-btn.rt-accent:hover:not(:disabled) {
  background: color-mix(in srgb, var(--rt-accent) 10%, transparent);
}

.rt-icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: color .16s var(--at-ease), border-color .16s var(--at-ease), background .16s var(--at-ease);
}

.rt-icon-btn:hover:not(:disabled) { color: var(--text-primary); border-color: var(--glass-border-hover); }
.rt-icon-btn[disabled] { opacity: .45; cursor: not-allowed; }
.rt-icon-btn svg { width: 16px; height: 16px; }

.rt-zoom { display: inline-flex; align-items: center; gap: 8px; }

.rt-zoom-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  min-width: 38px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- Page grid ---------- */
.rt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(122px * var(--rt-zoom, 1)), 1fr));
  gap: 12px;
  padding: 2px;
}

.rt-file-head {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-block-start: 10px;
  padding-block-end: 6px;
  border-block-end: 1px solid var(--glass-border);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
}

.rt-file-head:first-child { margin-block-start: 0; }

.rt-file-head .rt-file-head-icon { color: var(--rt-accent); }
.rt-file-head .rt-file-head-icon svg { width: 15px; height: 15px; }
.rt-file-head-count { margin-inline-start: auto; color: var(--text-muted); font-weight: 600; }

.rt-page {
  position: relative;
  border: 1.5px solid var(--glass-border);
  border-radius: 10px;
  background: var(--bg-card);
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: border-color .16s var(--at-ease), transform .16s var(--at-ease), box-shadow .16s var(--at-ease);
}

.rt-page:hover {
  border-color: var(--glass-border-hover);
  transform: translateY(-2px);
  box-shadow: 0 16px 30px -24px rgba(0, 0, 0, .7);
}

.rt-page:focus-visible {
  outline: none;
  border-color: var(--rt-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--rt-accent) 30%, transparent);
}

.rt-page.is-sel {
  border-color: var(--rt-accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--rt-accent) 45%, transparent);
}

.rt-page-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 7px 0;
}

.rt-page-num {
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, #000 60%, transparent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  text-align: center;
}

.rt-page-rot {
  font-size: 10px;
  font-weight: 700;
  color: var(--rt-accent);
  background: color-mix(in srgb, var(--rt-accent) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--rt-accent) 35%, transparent);
  border-radius: 999px;
  padding: 1px 6px;
  font-variant-numeric: tabular-nums;
}

.rt-thumb {
  position: relative;
  margin: 6px 7px 7px;
  aspect-ratio: var(--ar, 3 / 4);
  border-radius: 7px;
  overflow: hidden;
  touch-action: none;
  background:
    repeating-conic-gradient(rgba(128, 128, 128, .18) 0% 25%, transparent 0% 50%) 50% / 14px 14px,
    var(--bg-tertiary);
  display: grid;
  place-items: center;
}

.rt-thumb-img {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.rt-thumb-img img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform: rotate(var(--rt, 0deg)) scale(var(--rtScale, 1));
  transition: transform .3s var(--at-ease);
  will-change: transform;
  pointer-events: none;
  -webkit-user-drag: none;
  user-drag: none;
}

.rt-thumb-img:not(.has-img)::after {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--glass-border-hover);
  border-top-color: var(--rt-accent);
  animation: at-spin .7s linear infinite;
}

.rt-thumb-img.is-failed { display: block; }

/* per-page hover tools */
.rt-page-tools {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 0;
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 7px 6px;
  background: linear-gradient(0deg, color-mix(in srgb, #000 62%, transparent), transparent);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .16s var(--at-ease), transform .16s var(--at-ease);
}

.rt-page:hover .rt-page-tools,
.rt-page:focus-within .rt-page-tools { opacity: 1; transform: translateY(0); }

@media (hover: none) {
  .rt-page-tools { opacity: 1; transform: none; }
  .rt-page { cursor: pointer; }
}

.rt-pbtn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 28px;
  border-radius: 8px;
  border: 0;
  background: rgba(255, 255, 255, .92);
  color: #1f2937;
  cursor: pointer;
  transition: background .14s var(--at-ease), color .14s var(--at-ease), transform .14s var(--at-ease);
}

.rt-pbtn:hover { background: #fff; transform: translateY(-1px); }
.rt-pbtn.is-accent:hover { background: var(--rt-accent); color: #fff; }
.rt-pbtn svg { width: 15px; height: 15px; }

.rt-page-check {
  position: absolute;
  inset-block-start: 6px;
  inset-inline-end: 6px;
  width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--rt-accent);
  color: var(--rt-accent-ink);
  opacity: 0;
  transform: scale(.6);
  transition: opacity .16s var(--at-ease), transform .16s var(--at-ease);
}

.rt-page-check svg { width: 12px; height: 12px; }
.rt-page.is-sel .rt-page-check { opacity: 1; transform: scale(1); }

/* ---------- Rotation sidebar ---------- */
.rt-angle-field { display: grid; gap: 8px; }

.rt-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
}

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

.rt-seg-btn {
  padding: 8px 6px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: color .16s var(--at-ease), background .16s var(--at-ease), box-shadow .16s var(--at-ease);
}

.rt-seg-btn:hover { color: var(--text-primary); }

.rt-seg-btn.active {
  background: var(--rt-accent);
  color: var(--rt-accent-ink);
  box-shadow: 0 6px 14px -8px rgba(249, 115, 22, .9);
}

.rt-angle-hint {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-tertiary);
  line-height: 1.55;
}

.rt-apply-btn { width: 100%; }

/* ---------- Fields ---------- */
.rt-field { display: grid; gap: 7px; margin-block-end: 16px; }
.rt-field:last-child { margin-block-end: 0; }

/* ---------- Summary ---------- */
.rt-summary-rows { display: grid; gap: 2px; }

.rt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-block-end: 1px solid var(--glass-border);
  font-size: 13.5px;
}

.rt-row:last-child { border-block-end: 0; }

.rt-row-key {
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.rt-row-key svg { width: 15px; height: 15px; color: var(--text-muted); }
.rt-row-val { font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }

.rt-empty-note {
  padding: 16px 0;
  text-align: center;
  font-size: 13px;
  color: var(--text-tertiary);
}

/* ---------- Run area ---------- */
.rt-run-btn { width: 100%; padding: 15px 22px; font-size: 15.5px; }

.rt-run-panel {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--rt-accent) 7%, transparent), transparent 60%),
    var(--bg-card);
}

body.at-rotate .at-progress-fill {
  background: linear-gradient(90deg, var(--rt-accent), var(--rt-accent-2));
}

.rt-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-block-start: 9px;
}

.rt-progress-row .at-progress-msg { margin: 0; }

/* ---------- Result ---------- */
.rt-result { display: grid; gap: 14px; }

.rt-success {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 14px;
  border-radius: var(--at-radius-md);
  border: 1px solid color-mix(in srgb, var(--accent-emerald, #10b981) 45%, transparent);
  background: color-mix(in srgb, var(--accent-emerald, #10b981) 10%, transparent);
}

.rt-success-icon {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-emerald, #10b981);
  color: #fff;
}

.rt-success-icon svg { width: 17px; height: 17px; }
.rt-success-body { display: grid; gap: 3px; }
.rt-success-title { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.rt-success-desc { font-size: 12.5px; color: var(--text-secondary); line-height: 1.5; }

.rt-result-actions { display: grid; gap: 9px; }

.rt-outfiles { display: grid; gap: 8px; }

.rt-outfile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 13px;
  border: 1px solid var(--glass-border);
  border-radius: var(--at-radius-md);
  background: var(--bg-secondary);
}

.rt-outfile-name {
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rt-outfile-size { font-size: 11.5px; color: var(--text-tertiary); }
.rt-outfile-dl { flex: 0 0 auto; }

/* ---------- Keyboard hint ---------- */
.rt-keys-hint {
  margin: 14px 0 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .rt-drop,
  .rt-page,
  .rt-page-tools,
  .rt-page-check,
  .rt-thumb-img img { transition: none !important; }
}