/**
 * Merge PDF — workspace styles
 * ─────────────────────────────────────────────────────────────────────
 * Renders after files are selected (inside #workspace-page).
 * Scoped under .mp-workspace so it never leaks into other tool pages.
 * Uses the shared design tokens from assets/css/variables.min.css so it
 * automatically follows the site's light/dark theme.
 */

.mp-workspace,
.mp-workspace *,
.mp-workspace *::before,
.mp-workspace *::after { box-sizing: border-box; }
.mp-workspace { font-family: var(--font-base); color: var(--color-text); }
.mp-workspace button,
.mp-workspace input { font-family: inherit; }

.mp-layout {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - var(--header-height, 68px));
  background: var(--color-bg);
}

.mp-main {
  flex: 1;
  padding: 28px 32px;
  min-width: 0;
}
.mp-main-title {
  font-size: .92rem;
  font-weight: 700;
  color: var(--color-text-muted);
  margin-bottom: 22px;
}

/* ── File grid ── */
.mp-file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 20px;
}

/* ── File card ── */
.mp-file-card {
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 14px 12px 12px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: var(--transition-fast);
  cursor: grab;
  user-select: none;
}
.mp-file-card:hover {
  border-color: var(--color-border-strong, var(--color-border));
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
}
.mp-file-card.is-dragging { opacity: .4; }
.mp-file-card.is-drag-over { border-color: var(--color-primary); background: var(--color-primary-light); }

.mp-card-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: var(--transition-fast);
}
.mp-file-card:hover .mp-card-controls { opacity: 1; }

.mp-ctrl-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}
.mp-ctrl-btn svg { width: 15px; height: 15px; }
.mp-ctrl-rotate { background: rgba(0,0,0,.08); color: var(--color-text-muted); }
.mp-ctrl-rotate:hover { background: rgba(0,0,0,.15); }
.mp-ctrl-remove { background: var(--color-primary-light); color: var(--color-primary); }
.mp-ctrl-remove:hover { background: var(--color-primary); color: #fff; }

/* ── Thumb ── */
.mp-thumb-wrap {
  width: 120px;
  height: 155px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.mp-thumb-wrap canvas {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
  display: block;
  opacity: 0;
  transition: opacity .3s;
}
.mp-thumb-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--color-text-muted);
}
.mp-thumb-fallback svg { width: 26px; height: 26px; }
.mp-thumb-label { font-size: 11px; font-weight: 800; color: var(--color-primary); letter-spacing: 1px; }

.mp-file-meta { width: 100%; }
.mp-file-name {
  font-size: .78rem;
  font-weight: 600;
  text-align: center;
  max-width: 150px;
  margin: auto;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.mp-file-pages { text-align: center; margin-top: 4px; font-size: .68rem; color: var(--color-text-muted); }

.mp-order-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Add card ── */
.mp-add-card {
  min-height: 220px;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  cursor: pointer;
  position: relative;
  transition: var(--transition-fast);
}
.mp-add-card:hover { border-color: var(--color-primary); background: var(--color-primary-light); }
.mp-add-card input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.mp-add-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
}
.mp-add-icon svg { width: 22px; height: 22px; }
.mp-add-card:hover .mp-add-icon { background: var(--color-primary-light); color: var(--color-primary); }
.mp-add-text { font-size: .82rem; color: var(--color-text-muted); }

.mp-error {
  margin-top: 18px;
  background: var(--color-primary-light);
  border: 1px solid var(--color-primary);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--color-primary-dark);
  font-size: .82rem;
  display: none;
}

/* ── Sidebar ── */
.mp-sidebar {
  width: 420px;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.mp-sidebar-top { flex: 1; overflow-y: auto; padding: 26px 22px 20px; }
.mp-sidebar-title { font-size: 1.5rem; font-weight: 900; margin-bottom: 18px; }

.mp-info-box { background: var(--blue-light); border: 1px solid var(--blue); border-radius: 12px; padding: 14px; display: flex; gap: 10px; margin-bottom: 16px; }
.mp-info-box svg { width: 16px; height: 16px; color: var(--blue); flex-shrink: 0; margin-top: 2px; }
.mp-info-text { font-size: .82rem; line-height: 1.6; color: var(--blue); }

.mp-sort-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--color-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  margin-bottom: 16px;
  color: var(--color-text);
}
.mp-sort-btn svg { width: 19px; height: 19px; }
.mp-sort-btn:hover { background: var(--color-border); }

.mp-progress { margin-top: 4px; display: none; }
.mp-progress-bar-wrap { width: 100%; height: 8px; border-radius: 999px; background: var(--color-border); overflow: hidden; margin-bottom: 8px; }
.mp-progress-bar { height: 100%; width: 0; background: var(--color-primary); border-radius: 999px; transition: width .3s; }
.mp-progress-text { font-size: .8rem; color: var(--color-text-muted); }

.mp-success { margin-top: 18px; background: var(--color-surface); border: 1px solid var(--green); border-radius: 14px; padding: 18px; text-align: center; display: none; }
.mp-success h3 { font-size: 1.05rem; }
.mp-success-icon { width: 48px; height: 48px; border-radius: 50%; background: var(--green-light); display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; color: var(--green); }
.mp-success-icon svg { width: 22px; height: 22px; }
.mp-success-desc { font-size: .85rem; color: var(--color-text-muted); margin-top: 6px; }
.mp-btn-download {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  background: var(--green);
  color: #fff;
  padding: 11px 24px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 700;
}
.mp-btn-download svg { width: 16px; height: 16px; }
.mp-btn-again { margin-top: 12px; background: none; border: none; color: var(--color-primary); cursor: pointer; font-weight: 700; display: block; width: 100%; padding: 6px; }

.mp-sidebar-bottom { position: sticky; bottom: 0; background: var(--color-surface); border-top: 1px solid var(--color-border); padding: 18px; }
.mp-btn-merge {
  width: 100%;
  height: 64px;
  border: none;
  border-radius: 18px;
  background: var(--color-primary);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: var(--transition-fast);
  box-shadow: 0 10px 25px rgba(229, 50, 45, .25);
}
.mp-btn-merge:hover:not(:disabled) { background: var(--color-primary-dark); }
.mp-btn-merge:disabled { opacity: .5; cursor: not-allowed; }
.mp-btn-icon { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.2); display: flex; align-items: center; justify-content: center; }
.mp-btn-icon svg { width: 18px; height: 18px; }
.mp-privacy-note { margin-top: 10px; text-align: center; font-size: .7rem; color: var(--color-text-muted); }
.mp-privacy-note svg { width: 12px; height: 12px; vertical-align: -2px; margin-right: 3px; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .mp-sidebar { width: 360px; }
  .mp-main { padding: 24px; }
  .mp-file-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
@media (max-width: 768px) {
  .mp-layout { flex-direction: column; min-height: 0; }
  .mp-main { width: 100%; padding: 16px 14px 130px; }
  .mp-file-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .mp-file-card { border-radius: 16px; padding: 12px 10px; }
  .mp-thumb-wrap { width: 100px; height: 130px; }
  .mp-file-name { max-width: 110px; font-size: .72rem; }
  .mp-file-pages { font-size: .62rem; }
  .mp-add-card { min-height: 190px; }
  .mp-sidebar {
    position: fixed; left: 0; bottom: 0; top: auto; width: 100%; height: auto;
    border-left: none; border-top: 1px solid var(--color-border);
    z-index: 999; box-shadow: 0 -5px 20px rgba(0,0,0,.08);
  }
  .mp-sidebar-top { display: none; }
  .mp-sidebar-bottom { padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); border-top: none; }
  .mp-btn-merge { height: 58px; border-radius: 16px; font-size: 1rem; }
  .mp-privacy-note { display: none; }
}
@media (max-width: 480px) {
  .mp-file-grid { gap: 12px; }
  .mp-thumb-wrap { width: 88px; height: 118px; }
  .mp-file-name { max-width: 92px; font-size: .68rem; }
  .mp-file-pages { font-size: .58rem; }
  .mp-add-card { min-height: 165px; }
  .mp-btn-merge { height: 54px; font-size: .95rem; }
}
@media (max-width: 900px) and (orientation: landscape) {
  .mp-file-grid { grid-template-columns: repeat(3, 1fr); }
  .mp-main { padding-bottom: 120px; }
}
