/**
 * public/css/tools/rotate.css  (v2.0 — Production Upgrade)
 *
 * Rotate PDF Tool — Organize Step
 * Prefix: rot-
 * Accent: #7E57C2 (purple)
 *
 * New in v2.0:
 *   • rot-bulk-group / rot-bulk-label — labeled button groups (All / Odd / Even)
 *   • rot-tb-btn--odd / --even — tinted variants
 *   • rot-hint-pill — info pill in canvas header
 *   • rot-thumb-canvas[data-rotated] — proper clip for 90°/270° thumbnails
 *   • rot-mobile-bar-actions — mobile bulk rotate row
 *   • rot-mobile-bulk — icon-only bulk buttons in mobile bar
 */

/* ══ LOCAL ACCENT VARS ══════════════════════════════════════════════════════ */
.rot-shell, .rot-overlay, .rot-mobile-bar {
  --rot-accent:        #7E57C2;
  --rot-accent-dark:   #512DA8;
  --rot-accent-xdark:  #311B92;
  --rot-accent-light:  #EDE7F6;
  --rot-accent-glow:   rgba(126,87,194,.30);
  --rot-odd-color:     #0288D1;
  --rot-odd-light:     #E1F5FE;
  --rot-even-color:    #00897B;
  --rot-even-light:    #E0F2F1;
}

/* ══ RESET ══════════════════════════════════════════════════════════════════ */
.rot-shell *, .rot-shell *::before, .rot-shell *::after,
.rot-overlay *, .rot-mobile-bar * { box-sizing: border-box; }
.rot-shell button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ══ SHELL ══════════════════════════════════════════════════════════════════ */
.rot-shell {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--nav-h, 68px));
  background: #f0f2f7;
}

/* ══ STEP BAR ═══════════════════════════════════════════════════════════════ */
.rot-stepbar { background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; z-index: 10; }
.rot-stepbar-inner {
  display: flex; align-items: center; justify-content: center;
  height: 44px; gap: 0; padding: 0 20px;
  max-width: 1500px; margin: 0 auto;
}
.rot-step {
  display: flex; align-items: center; gap: 8px;
  font-size: .76rem; font-weight: 700; letter-spacing: .02em; padding: 0 4px;
}
.rot-step-line        { width: 40px; height: 2px; background: var(--border); flex-shrink: 0; margin: 0 2px; }
.rot-step-line--done  { background: var(--rot-accent); }
.rot-step-dot {
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all .2s;
}
.rot-step--done   .rot-step-dot { background: var(--rot-accent); color: #fff; }
.rot-step--active .rot-step-dot { background: var(--rot-accent); color: #fff; box-shadow: 0 0 0 4px var(--rot-accent-glow); }
.rot-step--off    .rot-step-dot { background: var(--surface-2); color: var(--text-muted); border: 1.5px solid var(--border); }
.rot-step--done span, .rot-step--active span { color: var(--rot-accent); }
.rot-step--off span  { color: var(--text-muted); }

/* ══ TOOLBAR ════════════════════════════════════════════════════════════════ */
.rot-toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(30,50,100,.05);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 200;
}
.rot-toolbar-inner {
  display: flex; align-items: center; gap: 6px;
  padding: 0 16px; height: 56px;
  max-width: 1500px; margin: 0 auto;
}

/* File pill */
.rot-file-pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--rot-accent-light); color: var(--rot-accent-dark);
  border-radius: 20px; padding: 5px 12px;
  font-size: .75rem; font-weight: 700; flex-shrink: 0; max-width: 240px;
}
.rot-file-pill svg { flex-shrink: 0; color: var(--rot-accent); }
.rot-file-pill-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.rot-file-pill-sep  { color: #B39DDB; }

.rot-tb-spacer    { flex: 1; min-width: 4px; }
.rot-tb-spacer-sm { width: 8px; }
.rot-tb-sep       { width: 1px; height: 22px; background: var(--border); flex-shrink: 0; margin: 0 2px; }

/* ── Bulk action groups ─────────────────────────────────────────────────── */
.rot-bulk-group {
  display: flex; align-items: center; gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 6px 3px 8px;
}

.rot-bulk-label {
  font-size: .65rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-right: 2px;
  white-space: nowrap;
  flex-shrink: 0;
}
.rot-bulk-label--odd  { color: var(--rot-odd-color); }
.rot-bulk-label--even { color: var(--rot-even-color); }

/* Toolbar buttons */
.rot-tb-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 10px;
  border: 1.5px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: .78rem; font-weight: 600;
  white-space: nowrap;
  transition: var(--transition);
}
.rot-tb-btn:hover {
  border-color: var(--rot-accent);
  color: var(--rot-accent);
  background: var(--rot-accent-light);
}
.rot-tb-btn svg { flex-shrink: 0; }

/* Odd-tinted buttons */
.rot-tb-btn--odd:hover {
  border-color: var(--rot-odd-color);
  color: var(--rot-odd-color);
  background: var(--rot-odd-light);
}
/* Even-tinted buttons */
.rot-tb-btn--even:hover {
  border-color: var(--rot-even-color);
  color: var(--rot-even-color);
  background: var(--rot-even-light);
}

/* Counter pill */
.rot-counter-pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface-2); color: var(--text-secondary);
  border-radius: 20px; padding: 5px 12px;
  font-size: .75rem; font-weight: 600; white-space: nowrap;
  flex-shrink: 0;
}

/* Start over */
.rot-startover-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  font-size: .78rem; font-weight: 600;
  text-decoration: none; transition: var(--transition);
  white-space: nowrap;
}
.rot-startover-btn:hover { border-color: var(--rot-accent); color: var(--rot-accent); }

/* Finish button */
.rot-finish-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, #7E57C2, #512DA8) !important;
  color: #fff !important; border: none;
  border-radius: var(--radius-md);
  padding: 10px 22px;
  font-family: 'Sora', sans-serif; font-size: .88rem; font-weight: 700;
  cursor: pointer; transition: var(--transition);
  box-shadow: 0 4px 14px rgba(126,87,194,.35) !important;
  white-space: nowrap; flex-shrink: 0;
}
.rot-finish-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #512DA8, #311B92) !important;
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(126,87,194,.50) !important;
}
.rot-finish-btn:disabled { opacity: .6; cursor: default; }

/* ══ WORKSPACE ══════════════════════════════════════════════════════════════ */
.rot-workspace {
  flex: 1; padding: 24px;
  max-width: 1500px; width: 100%; margin: 0 auto;
}
.rot-canvas-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 10px;
}
.rot-canvas-title {
  font-family: 'Sora', sans-serif; font-size: 1.1rem; font-weight: 700;
  color: var(--text-primary); margin: 0;
}
.rot-canvas-sub  { font-size: .78rem; color: var(--text-muted); margin-top: 2px; display: block; }
.rot-canvas-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.rot-pages-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 20px; padding: 5px 12px;
  font-size: .75rem; font-weight: 700; color: var(--text-secondary);
}

/* Hint pill */
.rot-hint-pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--rot-accent-light);
  border-radius: 20px; padding: 5px 12px;
  font-size: .72rem; font-weight: 600; color: var(--rot-accent-dark);
  white-space: nowrap;
}
.rot-hint-pill svg { color: var(--rot-accent); flex-shrink: 0; }

/* Loading */
.rot-loading {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 60px 20px;
  color: var(--text-muted); font-size: .88rem; font-weight: 600;
}
.rot-spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--border); border-top-color: var(--rot-accent);
  border-radius: 50%; animation: rotSpin .8s linear infinite;
}
@keyframes rotSpin { to { transform: rotate(360deg); } }

/* Empty state */
.rot-empty {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; padding: 60px 20px;
  color: var(--text-muted); font-size: .9rem; text-align: center;
}
.rot-empty svg { color: var(--border); }
.rot-empty a { color: var(--rot-accent); font-weight: 600; text-decoration: underline; }

/* ══ PAGE CARD GRID ═════════════════════════════════════════════════════════ */
.rot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 18px;
}

/* ── Card ────────────────────────────────────────────────────────────────── */
.rot-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  overflow: hidden;
  cursor: grab;
  transition: box-shadow .18s, border-color .18s, transform .18s;
  user-select: none;
  position: relative;
  outline: none;
  animation: rotCardIn .22s ease both;
}
@keyframes rotCardIn {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.rot-card:hover {
  border-color: var(--rot-accent);
  box-shadow: 0 6px 24px var(--rot-accent-glow);
  transform: translateY(-2px); z-index: 2;
}
.rot-card:focus-visible { border-color: var(--rot-accent); box-shadow: 0 0 0 3px var(--rot-accent-glow); }
.rot-card:active { cursor: grabbing; }

/* Rotated card accent border */
.rot-card[data-rotation="90"],
.rot-card[data-rotation="180"],
.rot-card[data-rotation="270"] {
  border-color: var(--rot-accent);
}

/* Sortable drag states */
.rot-card--ghost  { opacity: .35; background: var(--rot-accent-light); border-style: dashed; }
.rot-card--chosen { box-shadow: 0 8px 32px var(--rot-accent-glow); transform: scale(1.04); z-index: 100; }
.rot-card--drag   { opacity: .9; }

/* Deletion animation */
.rot-card--deleting { animation: rotCardOut .22s ease forwards; pointer-events: none; }
@keyframes rotCardOut { to { opacity: 0; transform: scale(.85); } }

/* ── Card preview ────────────────────────────────────────────────────────── */
.rot-card-preview {
  position: relative; width: 100%; aspect-ratio: 3/4;
  background: #f4f4f7;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}

/* Thumbnail wrap */
.rot-thumb-wrap {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  position: relative;
}

/* Canvas — base state */
.rot-thumb-canvas {
  max-width: 94%;
  max-height: 94%;
  object-fit: contain;
  display: block;
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  transform-origin: center center;
}

/* Placeholder before PDF.js renders */
.rot-thumb-placeholder {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  color: #d1d5de;
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  transform-origin: center center;
}

/* Rotation badge (e.g. "90°") */
.rot-rotation-badge {
  position: absolute; top: 6px; left: 6px;
  background: var(--rot-accent); color: #fff;
  font-size: .65rem; font-weight: 800;
  padding: 2px 8px; border-radius: 10px;
  letter-spacing: .04em;
  pointer-events: none; z-index: 3;
  box-shadow: 0 2px 6px rgba(126,87,194,.4);
}

/* Page number overlay (top-right, only on hover) */
.rot-card-preview::after {
  content: attr(data-pagenum);
  position: absolute; bottom: 6px; right: 6px;
  background: rgba(0,0,0,.45); color: #fff;
  font-size: .62rem; font-weight: 700;
  padding: 1px 6px; border-radius: 8px;
  pointer-events: none; z-index: 2;
  opacity: 0; transition: opacity .18s;
}
.rot-card:hover .rot-card-preview::after { opacity: 1; }

/* ── Hover action bar ────────────────────────────────────────────────────── */
.rot-card-actions {
  position: absolute; top: 0; left: 0; right: 0;
  padding: 8px 6px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: linear-gradient(to bottom, rgba(0,0,0,.58), transparent);
  opacity: 0; transition: opacity .18s; z-index: 5;
}
.rot-card:hover .rot-card-actions,
.rot-card:focus-within .rot-card-actions { opacity: 1; }

.rot-act-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,.93); color: var(--text-primary);
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer;
  transition: background .15s, color .15s, transform .15s;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.rot-act-btn:hover          { background: #fff; transform: scale(1.12); }
.rot-act-left:hover         { color: var(--rot-accent); }
.rot-act-right:hover        { color: var(--rot-accent); }
.rot-act-del:hover          { color: #E53935; background: #FFEBEE; }

/* ── Card footer ─────────────────────────────────────────────────────────── */
.rot-card-footer {
  padding: 8px 10px;
  display: flex; flex-direction: column; gap: 2px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.rot-card-num {
  font-size: .76rem; font-weight: 700; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rot-card-rot-label {
  font-size: .68rem; font-weight: 800;
  color: var(--rot-accent); min-height: 12px;
}
/* Hide label when 0° */
.rot-card-rot-label:empty { display: none; }

/* ══ MOBILE STICKY BAR ══════════════════════════════════════════════════════ */
.rot-mobile-bar {
  display: none; /* shown via media query */
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 500;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 14px 10px;
  flex-direction: column; gap: 8px;
  box-shadow: 0 -4px 20px rgba(0,0,0,.08);
}
.rot-mobile-bar-actions {
  display: flex; align-items: center; justify-content: space-between;
}
.rot-mobile-bar-count {
  font-size: .82rem; font-weight: 700; color: var(--text-secondary);
}
.rot-mobile-bulk {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--rot-accent-light); color: var(--rot-accent);
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer;
  transition: background .15s, transform .15s;
}
.rot-mobile-bulk:hover { background: var(--rot-accent); color: #fff; transform: scale(1.08); }
.rot-mobile-finish {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, #7E57C2, #512DA8) !important;
  color: #fff !important; border: none;
  border-radius: var(--radius-md);
  padding: 12px; width: 100%;
  font-family: 'Sora', sans-serif; font-size: .9rem; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(126,87,194,.35) !important;
}

/* ══ PROCESSING OVERLAY ══════════════════════════════════════════════════════ */
.rot-overlay {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(15,20,40,.6);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  align-items: center; justify-content: center;
}
.rot-overlay--visible { display: flex; }
.rot-overlay-card {
  background: var(--surface); border-radius: var(--radius-xl);
  padding: 40px 48px; text-align: center;
  max-width: 360px; width: 90%;
  box-shadow: 0 24px 64px rgba(0,0,0,.22);
  animation: rotOverlayIn .3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes rotOverlayIn { from { transform: scale(.88); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.rot-overlay-ring {
  width: 56px; height: 56px;
  border: 4px solid var(--border); border-top-color: var(--rot-accent);
  border-radius: 50%; animation: rotSpin .9s linear infinite;
  margin: 0 auto 20px;
}
.rot-overlay-title { font-family: 'Sora', sans-serif; font-size: 1.15rem; font-weight: 800; color: var(--text-primary); margin-bottom: 6px; }
.rot-overlay-sub   { font-size: .83rem; color: var(--text-muted); margin-bottom: 24px; }
.rot-overlay-stages { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.rot-ov-stage {
  display: flex; align-items: center; gap: 10px;
  font-size: .8rem; font-weight: 600; color: var(--text-muted);
  padding: 8px 12px; border-radius: var(--radius-sm); transition: all .3s;
}
.rot-ov-stage--active { background: var(--rot-accent-light); color: var(--rot-accent-dark); }
.rot-ov-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border); flex-shrink: 0; transition: background .3s;
}
.rot-ov-stage--active .rot-ov-dot {
  background: var(--rot-accent);
  box-shadow: 0 0 6px var(--rot-accent-glow);
  animation: rotDotPulse 1s ease infinite;
}
@keyframes rotDotPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.4); } }

/* ══ RESPONSIVE ══════════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
  /* Compact the bulk groups slightly */
  .rot-bulk-group { padding: 3px 4px 3px 6px; }
  .rot-tb-btn { padding: 6px 8px; }
}

@media (max-width: 900px) {
  .rot-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
  .rot-workspace { padding: 16px; padding-bottom: 100px; }
  /* Icon-only on tablet: hide text labels */
  .rot-tb-btn-txt { display: none; }
  .rot-bulk-label { display: none; }
  .rot-bulk-group { background: none; border: none; padding: 0; gap: 2px; }
  .rot-tb-btn { border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
}

@media (max-width: 640px) {
  .rot-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .rot-mobile-bar { display: flex; }
  .rot-workspace  { padding-bottom: 100px; }
  /* Hide most toolbar items on mobile */
  .rot-finish-btn,
  .rot-bulk-group,
  .rot-counter-pill,
  .rot-startover-btn,
  .rot-tb-sep        { display: none; }
  .rot-toolbar-inner { height: 48px; }
  .rot-canvas-sub    { display: none; }
  .rot-hint-pill     { display: none; }
  .rot-overlay-card  { padding: 28px 24px; }
}

@media (max-width: 380px) {
  .rot-grid { grid-template-columns: repeat(2, 1fr); }
}
